kilbd / nova-rust

A Rust extension for the Nova text editor, using the Rust Analyzer language server.
MIT License
29 stars 5 forks source link

language features in unsaved files and files opened in workspaces whose folder does not contain a `Cargo.toml` file #26

Closed belcar-s closed 2 years ago

belcar-s commented 2 years ago

Is your feature request related to a problem? Please describe. Learning Rust with Nova, I'm always disappointed of that language features aren't enabled while writing tiny, experiment Rust programs.

Describe the solution you'd like I'd love to have language features in unsaved files, as well as in files opened in workspaces whose folder does not include a Cargo.toml file.

Describe alternatives you've considered I can't think of other ways to solve this problem, unfortunately.

Additional context

{
    // …
    "activationEvents": ["onWorkspaceContains:Cargo.toml"],
    // …
}

Here's what happens if the extension is activated despite the lack of a Cargo.toml:

error message saying 'rust-analyzer failed to discover workspace'
kilbd commented 2 years ago

Hello Santiago – thanks for submitting this issue! Glad to hear you're learning Rust. If others haven't done so, I'd like to welcome you to the Rust community! They really are a welcoming bunch.

Practically speaking, if you are looking to gain LSP help then Rust Analyzer expects you to have a Cargo.toml or a rust-project.json file in your workspace. I would agree that I should add an activationEvent for rust-project.json, though it doesn't sound like that's what you want. Note that compiler checks in RA (and thus Nova Issues) depend on Cargo, and these checks don't work on unsaved files.

On a more personal note, Cargo is one of my favorite features of Rust and I'd encourage you to get used to using it. Chris Biscardi once remarked that Cargo is "like a really well executed npm" and I wholeheartedly agree.

On a final note, I'm surprised that the extension tried to activate without a Cargo.toml. That seems like a Nova bug that I should bring up with Panic....

belcar-s commented 2 years ago

Oops; no. Sorry for the confusion! I altered the extension to activate always, and that was the outcome. The current version seems to activate only upon the presence of Cargo.toml.

I understand that this may be a very hard problem to solve if the Language Server doesn't support the use case 🙁. Thanks for taking the time to respond and explain that, though.

By the way, it would be great if there were a mention of this in the README! It was very confusing to me at first; I thought the extension wasn't working.

kilbd commented 2 years ago

I think you've identified 2 good changes:

  1. Also activate the extension for rust-project.json
  2. Update the README with these files as a requirement

Thanks!

kilbd commented 2 years ago

I implemented the above changes in the latest version (2.1.0).