coc-rust-analyzer icon indicating copy to clipboard operation
coc-rust-analyzer copied to clipboard

jumpDefinition will trigger unexpected cargo check and make rust-analyzer unavailable for few seconds

Open BingCoke opened this issue 2 years ago • 22 comments

What's the output of :CocInfo 2023-02-24T09:24:04.666 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:29.306 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:29.307 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:29.307 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:34.283 INFO (pid:113711) [attach] - receive notification: jumpDefinition [] 2023-02-24T09:24:34.311 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:34.345 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:35.373 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:35.374 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:36.151 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:36.475 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:37.431 INFO (pid:113711) [attach] - Request action: diagnosticList [] 2023-02-24T09:24:37.732 INFO (pid:113711) [attach] - Request action: diagnosticList [] 2023-02-24T09:24:42.722 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:42.733 INFO (pid:113711) [attach] - receive notification: highlight [] 2023-02-24T09:24:45.301 INFO (pid:113711) [attach] - receive notification: showInfo []

What's the output of :CocCommand rust-analyzer.serverVersion image

What's your coc-rust-analyzer version? You can get it from :CocList extensions image

**details ** I use jumpDefinition to get a function detail and jump a .rs file.When I come back the original file , that will trigger cargo check three times and make rust-analyzer unavailable for few seconds ( such as I can't use doHover and rust-analyzer can't diagnostics newly code that I written). image

BingCoke avatar Feb 24 '23 01:02 BingCoke

In addition,here is my conf

  "rust-analyzer.checkOnSave": true,
  "rust-analyzer.diagnostics.enable": true,
  "rust-analyzer.workspace.symbol.search.kind": "all_symbols",
  "rust-analyzer.workspace.symbol.search.scope": "workspace_and_dependencies",
  "rust-analyzer.cargo.autoreload": true,

When i set checkOnSave false , that will not trigger cargo check but still make rust-analyzer unavailable for few seconds.

here is :cocinfo

2023-02-24T09:52:03.052 INFO (pid:149429) [attach] - receive notification: jumpDefinition [] 2023-02-24T09:52:03.073 INFO (pid:149429) [attach] - receive notification: highlight [] 2023-02-24T09:52:03.115 INFO (pid:149429) [attach] - receive notification: highlight [] 2023-02-24T09:52:07.600 INFO (pid:149429) [attach] - receive notification: highlight [] 2023-02-24T09:52:07.601 INFO (pid:149429) [attach] - receive notification: highlight [] 2023-02-24T09:52:08.474 INFO (pid:149429) [attach] - receive notification: highlight [] 2023-02-24T09:52:08.882 INFO (pid:149429) [attach] - receive notification: highlight [] 2023-02-24T09:52:10.082 INFO (pid:149429) [attach] - receive notification: doHover [] 2023-02-24T09:52:11.960 INFO (pid:149429) [attach] - receive notification: highlight [] 2023-02-24T09:52:11.961 ERROR (pid:149429) [provider-manager] - Provider error on provideHover: jh [Error] at /home/bk/.local/share/nvim/site/pack/packer/start/coc.nvim/build/index.js:51:3652 at new Promise () at Object.sendRequest (/home/bk/.local/share/nvim/site/pack/packer/start/coc.nvim/build/index.js:51:3401) at Object.sendRequest (/home/bk/.local/share/nvim/site/pack/packer/start/coc.nvim/build/index.js:241:5768) at Nd.sendRequest (/home/bk/.local/share/nvim/site/pack/packer/start/coc.nvim/build/index.js:244:1921) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Object.provideHover (/home/bk/.config/coc/extensions/node_modules/coc-rust-analyzer/lib/index.js:9445:16) { code: -32800, data: undefined } 2023-02-24T09:52:12.506 INFO (pid:149429) [attach] - receive notification: highlight [] 2023-02-24T09:52:13.246 WARN (pid:149429) [workspace] - workspace.showMessage is deprecated, please use window.showMessage instead. at or.doComplete (/home/bk/.config/coc/extensions/node_modules/coc-ultisnips/index.js:13:35) at runMicrotasks ()

BingCoke avatar Feb 24 '23 01:02 BingCoke

coc-rust-analyzer won't trigger cargo check, it's rust-analyzer's behavior.

fannheyward avatar Feb 24 '23 02:02 fannheyward

coc-rust-analyzer won't trigger cargo check, it's rust-analyzer's behavior. but jumpDefinition is coc's behavior.When I use vscode,ererything is fine.

BingCoke avatar Feb 24 '23 02:02 BingCoke

coc-rust-analyzer won't trigger cargo check, it's rust-analyzer's behavior.

When i set checkOnSave true, jumpDefinition will trigger cargo check.So jumpDefinition may will unexpectedly trigger "check on save". Other ide will not happen this.

BingCoke avatar Feb 24 '23 02:02 BingCoke

Yes, coc did jumpDefinition. When you do jumpDefinition, coc requests with file and position to rust-analyzer server, the server responses location and coc jumped. When you return to origin file, coc did nothing.

The cargo check notifications are came from rust-analyzer, coc just display them. I've tested the jumping, can't reproduce the cargo check.

checkOnSave

rust-analyzer.checkOnSave defaults to true, but I don't think this will trigger cargo check because there's no saving.

fannheyward avatar Feb 24 '23 03:02 fannheyward

Yes, coc did jumpDefinition. When you do jumpDefinition, coc requests with file and position to rust-analyzer server, the server responses location and coc jumped. When you return to origin file, coc did nothing.

The cargo check notifications are came from rust-analyzer, coc just display them. I've tested the jumping, can't reproduce the cargo check.

checkOnSave

rust-analyzer.checkOnSave defaults to true, but I don't think this will trigger cargo check because there's no saving.

It seems because of loading mechanism.When I do jumpDefinition to other crate , rust-analyzer will trigger check and make rust-analyzer unavailable few seconds. For example, I do jumpDefinition in Rc::new(1) which in alloc crate, that will happen what I just say(trigger cargo two times).And then I do jumpDefinition in Arc::new(1) and will not trigger check because it has checked already when i do jumpDefinition in Rc::new(1).And I try jumpDefinition in Box::new(), it will not trigger cargo check also. Box,Rc,Arc, all of them is module of alloc crate! When I do jumpDefinition for println!() which in std create, It will trigger cargo check three times; So when use jumpDefinition for outside crate, it will trigger cargo check. Even more surprising, the more outside crate you use jumpDefinition for, the more times cargo check will do. When nvim's bottom status line disappear, it's because it failed to call doHover that means rust-analyzer is unavailable. Peek 2023-02-24 13-32 the phenomenon will not happen in other ide ,so it may beacause of crate's loading mechanism in coc-rust-analyzer. 2

BingCoke avatar Feb 24 '23 05:02 BingCoke

Got your point, and tested in same case to jump on Rc::new.

  1. cursor on new, fire jumpDefinition
  2. jump to rustlib/src/rust/library/alloc/src/rc.rs, cargo check notifications displayed and disappeared, twice
  3. C-t back to origin file, fire jumpDefinition on println to rustlib/src/rust/library/std/src/macros.rs, three cargo check displayed and disappeared
  4. C-t back to origin file, rust-analyzer still working, hover/jump/completion works as expected.

Enable "rust-analyzer.trace.server": "verbose" in your coc-settings.json to trace the requests and responses. You can also enable the same setting in VS Code to debug any different with same operations.

fannheyward avatar Feb 24 '23 07:02 fannheyward

Ok,I got it.After ide send textDocument/definition request and get response, coc and vscode will Sending notification "textDocument/didOpen". That is right.But coc will send notification 'workspace/didChangeWorkspaceFolders' which will make rust-analyzer load a new workspace.I guess rust-analyzer will be unavailable,when it load a new workspace.

[Trace - 15:52:44.978] Sending notification 'workspace/didChangeWorkspaceFolders'.
Params: {
    "event": {
        "added": [
            {
                "uri": "file:///home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc",
                "name": "alloc"
            }
        ],
        "removed": []
    }
}

And then I will get these log in coc




[Trace - 16:05:35.789] Received notification 'experimental/serverStatus'.
Params: {
    "health": "ok",
    "quiescent": false,
    "message": null
}


[Trace - 16:05:35.792] Received request 'window/workDoneProgress/create - (61)'.
Params: {
    "token": "rustAnalyzer/Fetching"
}


[Trace - 16:05:35.794] Sending response 'window/workDoneProgress/create - (61)'. Processing request took 0ms
No result returned.


[Trace - 16:05:35.796] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Fetching",
    "value": {
        "kind": "begin",
        "title": "Fetching",
        "cancellable": false
    }
}



[Trace - 16:05:35.811] Sending notification '$/cancelRequest'.
Params: {
    "id": 190
}


[Trace - 16:05:35.812] Sending request 'textDocument/documentHighlight - (191)'.
Params: {
    "textDocument": {
        "uri": "file:///home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs"
    },
    "position": {
        "line": 130,
        "character": 13
    }
}


[Trace - 16:05:35.884] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Fetching",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "metadata"
    }
}


[Trace - 16:05:35.911] Sending request 'textDocument/inlayHint - (192)'.
Params: {
    "textDocument": {
        "uri": "file:///home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs"
    },
    "range": {
        "start": {
            "line": 113,
            "character": 0
        },
        "end": {
            "line": 148,
            "character": 0
        }
    }
}


[Trace - 16:05:35.913] Received response 'textDocument/inlayHint - (192)' in 2ms.
Result: []


[Trace - 16:05:36.279] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Fetching",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "metadata"
    }
}


[Trace - 16:05:36.665] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Fetching",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "metadata"
    }
}


[Trace - 16:05:37.070] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Fetching",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "metadata"
    }
}


[Trace - 16:05:37.457] Received request 'client/registerCapability - (62)'.
Params: {
    "registrations": [
        {
            "id": "workspace/didChangeWatchedFiles",
            "method": "workspace/didChangeWatchedFiles",
            "registerOptions": {
                "watchers": [
                    {
                        "globPattern": "/home/bk/.cargo/registry/src/github.com-1ecc6299db9ec823/iced_style-0.7.0/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/.cargo/registry/src/github.com-1ecc6299db9ec823/iced_style-0.7.0/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/.cargo/registry/src/github.com-1ecc6299db9ec823/iced_style-0.7.0/**/Cargo.lock"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/**/Cargo.lock"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/**/Cargo.lock"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/**/Cargo.lock"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/**/Cargo.lock"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort/**/Cargo.lock"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/**/Cargo.lock"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/std_detect/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/std_detect/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/std_detect/**/Cargo.lock"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind/**/Cargo.lock"
                    },
                    {
                        "globPattern": "/home/bk/project/rust/cied-test/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/project/rust/cied-test/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/project/rust/cied-test/**/Cargo.lock"
                    }
                ]
            }
        }
    ]
}


[Trace - 16:05:37.459] Sending response 'client/registerCapability - (62)'. Processing request took 0ms
No result returned.


[Trace - 16:05:37.495] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Fetching",
    "value": {
        "kind": "end"
    }
}


[Trace - 16:05:37.496] Received request 'window/workDoneProgress/create - (63)'.
Params: {
    "token": "rustAnalyzer/Roots Scanned"
}


[Trace - 16:05:37.497] Sending response 'window/workDoneProgress/create - (63)'. Processing request took 0ms
No result returned.


[Trace - 16:05:37.499] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "begin",
        "title": "Roots Scanned",
        "cancellable": false,
        "message": "0/244",
        "percentage": 0
    }
}


[Trace - 16:05:37.499] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "1/244",
        "percentage": 0
    }
}


[Trace - 16:05:37.500] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "2/244",
        "percentage": 0
    }
}


[Trace - 16:05:37.502] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "3/244",
        "percentage": 1
    }
}


[Trace - 16:05:37.502] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "4/244",
        "percentage": 1
    }
}


[Trace - 16:05:37.503] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "5/244",
        "percentage": 2
    }
}


[Trace - 16:05:37.504] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "6/244",
        "percentage": 2
    }
}


[Trace - 16:05:37.505] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "7/244",
        "percentage": 2
    }
}


[Trace - 16:05:37.506] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "8/244",
        "percentage": 3
    }
}


[Trace - 16:05:37.506] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "9/244",
        "percentage": 3
    }
}


[Trace - 16:05:37.508] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "10/244",
        "percentage": 4
    }
}


[Trace - 16:05:37.510] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "11/244",
        "percentage": 4
    }
}


[Trace - 16:05:37.512] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "12/244",
        "percentage": 4
    }
}


[Trace - 16:05:37.513] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "13/244",
        "percentage": 5
    }
}


[Trace - 16:05:37.514] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "14/244",
        "percentage": 5
    }
}


[Trace - 16:05:37.515] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "15/244",
        "percentage": 6
    }
}


I will see these log when vscode start rust-analyzer. Such as "Received request 'client/registerCapability - (62)'","Received notification '$/progress'","window/workDoneProgress/create - (61)". But I will see these logs every time when I do jumpDefinition for a new outside crate. In addition, "Received request 'client/registerCapability" will show more lines when I use jumpDefinition for more outside create. In vscode will just appear "Received request 'client/registerCapability" during startup and show few lines.

[Trace - 15:57:17] Received request 'client/registerCapability - (0)'.
Params: {
    "registrations": [
        {
            "id": "textDocument/didSave",
            "method": "textDocument/didSave",
            "registerOptions": {
                "includeText": false,
                "documentSelector": [
                    {
                        "pattern": "**/*.rs"
                    },
                    {
                        "pattern": "**/Cargo.toml"
                    },
                    {
                        "pattern": "**/Cargo.lock"
                    }
                ]
            }
        }
    ]
}

......

[Trace - 15:57:18] Received request 'client/registerCapability - (7)'.
Params: {
    "registrations": [
        {
            "id": "workspace/didChangeWatchedFiles",
            "method": "workspace/didChangeWatchedFiles",
            "registerOptions": {
                "watchers": [
                    {
                        "globPattern": "/home/bk/project/rust/cied-test/**/*.rs"
                    },
                    {
                        "globPattern": "/home/bk/project/rust/cied-test/**/Cargo.toml"
                    },
                    {
                        "globPattern": "/home/bk/project/rust/cied-test/**/Cargo.lock"
                    }
                ]
            }
        }
    ]
}

I think that's may because of my project plugin.So I close project plugin, but the same thing still happens.

BingCoke avatar Feb 24 '23 08:02 BingCoke

coc will send notification 'workspace/didChangeWorkspaceFolders' which will make rust-analyzer load a new workspace

VS Code didn't send this request?

fannheyward avatar Feb 24 '23 08:02 fannheyward

coc will send notification 'workspace/didChangeWorkspaceFolders' which will make rust-analyzer load a new workspace

VS Code didn't send this request?

yes image The subsequent requests I just told only appear when vscode starts rust-analyzer. image But it will appear every times when use jumpDefinition for new outside crate in nvim.

BingCoke avatar Feb 24 '23 08:02 BingCoke

what's more when i do jumpDefinition and trigger cargo check , coc will misinterpret the code is wrong like "tokio::main" proc macro. image Peek 2023-03-09 10-49

But When I reload the project it gets resolved.

Peek 2023-03-09 10-58

BingCoke avatar Mar 09 '23 02:03 BingCoke

Also running into this. This is quite annoying when I jumping into std functions, which tries to load std workspace, and certainly fail since std requires complex environment setup and nightly compilers to build/check.

But coc will send notification 'workspace/didChangeWorkspaceFolders' which will make rust-analyzer load a new workspace.

This behavior is unexpected. IMO, workspace contains all active folders ready for editing (work). Read-only dependencies are processed but not considered new workspace folders without explicit requests, so does any file opened outside the current folder. For VSCode, extra workspace folders must be added explicitly via "File - Add Folder to Workspace".

oxalica avatar Mar 12 '23 07:03 oxalica

@oxalica @BingCoke thank you all for this report, I'm still working on this, but with slow progress because busy with my personal work this week.

Workspace detecting is hard in coc because vim doesn't have workspace support. After you open a file, coc will use rootPattern to find whether current file in a workspace or not. This is why you open a std file, coc changed workspace folder to that.

Try adding std path to workspace.ignoredFolders to stop coc to detect workspace folder.

  "workspace.ignoredFolders": [
    "$HOME",
    "/opt/homebrew/Cellar/rust/1.68.0/lib/rustlib/src/rust/library/std",
    "/opt/homebrew/Cellar/rust/1.68.0/lib/rustlib/src/rust/library/alloc"
  ],

fannheyward avatar Mar 14 '23 03:03 fannheyward

https://github.com/neoclide/coc.nvim/pull/4567

fannheyward avatar Mar 14 '23 08:03 fannheyward

Try adding std path to workspace.ignoredFolders to stop coc to detect workspace folder.

Thanks. I don't know it also supports patterns. This works for me,

{
  "workspace.ignoredFolders": [
    "$CARGO_HOME/**", // Foreign crates from crates.io
    "$HOME/.rustup/**", // Rustup toolchains.
    "/nix/store/**" // Nix managed Rust toolchains for me.
  ]
}

I think the first two should be set by default for coc-rust-analyzer, if possible.

oxalica avatar Mar 15 '23 12:03 oxalica

the first two should be set by default for coc-rust-analyzer

$CARGO_HOME maybe not exists?

fannheyward avatar Mar 15 '23 12:03 fannheyward

{ "workspace.ignoredFolders": [ "$HOME/.rustup/", "$HOME/.cargo/" ] } I think set this up is OK.And thanks for solving a problem that has troubled me for l long time!

BingCoke avatar Mar 15 '23 12:03 BingCoke

@BingCoke You should add ** patterns.

fannheyward avatar Mar 15 '23 12:03 fannheyward

OK, I nearly forgot it.

BingCoke avatar Mar 15 '23 12:03 BingCoke

the first two should be set by default for coc-rust-analyzer

@oxalica coc didn't allow extensions to override configurations https://github.com/neoclide/coc.nvim/commit/2b16d2a3e15a30a75e2f45e5ba2aab8c77188172

You need to set this by yourself.

fannheyward avatar Mar 15 '23 13:03 fannheyward

wow, i have been looking for this for a long time! what do you think about adding this solution to avoid switching workspace and triggering tons of errors to the readme?

jannes avatar May 15 '23 18:05 jannes

rust-analyzer has this config image you can try it?

BingCoke avatar May 16 '23 01:05 BingCoke

https://github.com/neoclide/coc.nvim/pull/5084 has added .cargo folder.

fannheyward avatar Jul 12 '24 01:07 fannheyward