Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No new dependencies detected (rust-analyzer) #2479

Closed
axdank opened this issue May 15, 2022 · 7 comments · May be fixed by #2653
Closed

No new dependencies detected (rust-analyzer) #2479

axdank opened this issue May 15, 2022 · 7 comments · May be fixed by #2653
Labels
A-language-server Area: Language server client C-enhancement Category: Improvements

Comments

@axdank
Copy link
Contributor

axdank commented May 15, 2022

I don't know how exactly to define the title.
When I open a rust workspace, everything goes fine, libraries and all are loaded, but when I add a new dependency inside Cargo.toml of a crate and try to use it in some file, it is not found or not available, I think that when I modify the Cargo.toml file, rust-analyzer does not verify the change and downloads the missing dependencies, the only way to make it appear is closing and reopening helix. In the case of vscode, as an example, when you add a new dependency, rust-analyzer verifies it and lets you use it in any file.

In helix:
image
image

In vscode:
image
image
image

@pickfire pickfire added C-enhancement Category: Improvements A-language-server Area: Language server client labels May 16, 2022
@pickfire
Copy link
Contributor

Not very familiar with the lsp side but I think maybe we are missing some events to send to language server? So I just mark this as enhancement.

@kyrime
Copy link
Contributor

kyrime commented May 21, 2022

I've looked into this a bit and it seems the LSP spec expects the client (us) to support its DidChangeWatchedFiles notification, and rust-analyzer expects to receive these file-watching notifications from us to inform it when Cargo.toml changes. The LSP spec states that it is allowed for servers to implement file-watching themselves, but not recommended for various reasons it lists.

rust-analyzer's rust-analyzer.files.watcher option allows changing the file-watching implementation from client -- relying on events from us -- to an internal notify implementation, but this does not appear to have the desired functionality. At least, I've tried changing this setting to notify in both Helix and VSCode: Helix continues to not detect dependency changes and VSCode ceases detecting dependency changes. So that seems to be a no-go, unless I'm missing something.

Seems we'll need to drag in a dependency like notify to support the DidChangeWatchedFiles notification. Not sure if we already have something for file-watching. Does that sound acceptable, and would that be the preferred dependency to use?

@the-mikedavis
Copy link
Member

There is some prior work for file watching for the purposes of reloading #588 which pulls in the notify crate. That PR is using the v5 branch: #588 (comment)

@kyrime
Copy link
Contributor

kyrime commented May 21, 2022

Good to know!

I see that PR's been inactive for quite a while, and given that it does have file-watching functionality already, I'm not sure what the right thing to do would be. PR with similar watcher code, or something else?

@the-mikedavis
Copy link
Member

Yeah, I think you could either use it as a guide or even rebase the branch if the conflicts aren't too bad and work off of it if you'd like. I'm not sure what needs to be done on that to be mergeable but since it's been inactive for a while, a PR that supersedes it would definitely be welcome. Or you could just take the parts that would be needed for this feature if you're mostly interested on working on this issue rather than #1125

@paholg
Copy link

paholg commented Feb 22, 2023

I think file watching is not needed for this; I suspect there is a bug in completions only. Maybe a cache that needs to be busted?

If I have the files

src/main.rs:

use serde::Serialize;
fn main() {}

Cargo.toml:

[package]
name = "foo"
version = "0.1.0"

[dependencies]

Then helix will show an error; a cargo add serde and then :w in the editor, and it will no longer show an error for the import, but will not autocomplete use serde:: or such.

Edit: Nevermind. I swear that's how it was working a moment ago, but I can't reproduce it now.

@pascalkuthe
Copy link
Member

The case where the Cargo.toml (or whatevere else) file was edited inside helix was closed by #7665.

The case where the file is edited outside of helix requires a file watcher. That is tracked in #1125 so i am closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-enhancement Category: Improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants