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 error squiggles in VS Code with rls-vscode extension #443

Closed
DeadRabbits307 opened this issue Jun 18, 2020 · 12 comments
Closed

no error squiggles in VS Code with rls-vscode extension #443

DeadRabbits307 opened this issue Jun 18, 2020 · 12 comments

Comments

@DeadRabbits307
Copy link

DeadRabbits307 commented Jun 18, 2020

VS Code: 1.45.1
OS: 4.19.118-1-MANJARO
rls-vscode: 0.7.8

Creating a new crate/workspace like shown here the error squiggles work fine. But opening the root directory of rustlings (directory where Cargo.toml is located):

  • no error squiggles
  • no problems in the PROBLEMS window, despite of code errors

Is this a problem of the rustlings project directory structure? Opening src/main.rs and editing it, the error squiggles appear. Sorry if this topic isn't related to rustlings itself, it's my first time in the Rust world.

@danwilhelm
Copy link
Contributor

danwilhelm commented Jun 18, 2020

Welcome to Rust! Luckily, a Cargo workspace is already set up for you -- so you won't have to make your own.

The general procedure is:

  1. First, build and install the Rustlings CLI program: cargo install --force --path .
  2. Edit the exercises in any text editor.
  3. Use the Rustlings CLI program to check your answers.

If you still have problems with the VS Code extension, it might be best to ask on the Rust Discord (https://www.rust-lang.org/community).

@jrvidal
Copy link
Contributor

jrvidal commented Jun 18, 2020

Unfortunately, it is half-expected. I think rls (and similar tools, like rust-analyzer) expect a conventional project structure, imposed by cargo, to be able to effectively analyze your code. rustlings on the other hand departs from that structure for pedagogical purposes, so each exercise is completely isolated. Not sure if IntelliJ Rust suffers from the same limitations (note that they adapted rustlings).

@fmoko Do you think it'd be worth exploring the possibility of changing the structure of the exercises so cargo (and other tools) can understand it? Not sure if "no analyzers" is a bug or a feature...?

@shadows-withal
Copy link
Member

@jrvidal Hmm, I think it'd be at least worth trying. Maybe we can branch out, change the structure, see if the analyzer hints spoil some of the exercise solutions, and if they don't, we can merge it in?

@Farzy
Copy link

Farzy commented Jun 18, 2020

Hi @jrvidal I had the same issue with Rust in IntelliJ IDEA Ultimate very recently: no hints and some missing autocompletion IIRC. I haven't tried to circumvent it, maybe there's a trick.

@jsejcksn
Copy link
Contributor

jsejcksn commented Jul 12, 2020

What if there were a Rustlings argument specifically for this purpose? One which works with watch and verify and recognizes the capabilities of editor linting and live file reference updates...

(Bear with me as I explain: I've done some basic testing, but I don't know the internals of Rustlings. Also, I'll use VS Code as the example IDE, but it's just the example and this could potentially apply to any IDE)

Instead of the user having edit each exercise directly, Rustlings could create a symlink (for example, exercises/current.rs) to the "currently active" (not meeting passing criteria) file, and the user can simply open and continue to edit that current.rs file, saving changes along the way. When the linked file finally passes, Rustlings would update the symlink to point to the new "currently active" file. (Perhaps in some OS-editor environment combinations, this symlink strategy isn't possible, and Rustlings would need to create a real current.rs file and synchronize content changes with the "currently active" file. I've only tested in VS Code on macOS, and the symlink strategy works fine.)

UX improvements

  • 💆 Not needing to locate, open, and close a file every time a new exercise/quiz is started
  • 🙅🏋️ Avoiding the heft and complexities introduced by constantly analyzing every exercise as a binary target
  • 🔬 Displaying only relevant issues in the VS Code Problems panel (instead of all problems in the entire exercises directory and their dependencies)

Usage

exercises/Cargo.toml would contain something like this:

[package]
name = 'exercises'
version = '0.1.0'
edition = '2018'
authors = ['The Rustlings Maintainers']
publish = false

[[bin]]
name = 'current'
path = 'current.rs'

If using watch:

  1. Run rustings watch --ide (or whatever arg name is decided)
  2. Open $RUSTLINGS_DIR/exercises in VS Code (to create a workspace in which the Rust extension recognizes exercises/Cargo.toml as the project config)
  3. Open current.rs
  4. Edit, save
  5. If the file passes, the content is automatically replaced by the new "current" exercise/quiz. Go to step 4.

If using verify:

  1. Open $RUSTLINGS_DIR/exercises in VS Code (to create a workspace in which the Rust extension recognizes exercises/Cargo.toml as the project config)
  2. Open current.rs
  3. Edit, save
  4. Run rustlings verify --ide (or whatever arg name is decided)
  5. If the file passes, the content is automatically replaced by the new "current" exercise/quiz. Go to step 3.

Issues

  • Errors are produced for targets without a main fn — feat: add fake manifest for analyzers/IDEs (fixes #443) #448 (comment)
  • The exercises/tests folder might need to be renamed so cargo doesn't think it contains integration tests. Otherwise, its contents will continue to be reported perpetually. Maybe this is configurable—if so, I'm not sure how to get the extension to skip that folder.

Other

Maybe it doesn't need to be an argument at all. Maybe it's just the default behavior, and it's ignored by everyone who doesn't want to use it.

@jrvidal
Copy link
Contributor

jrvidal commented Jul 12, 2020

I fear that toying with symlinks and manipulating the file system will introduce more complexity that we can chew. I'm not sure how mature rust-analyzer, for instance, is with regards to its VFS implementation, I'm not sure swapping the content of files will work as seamlessly as we would like.

I'm personally inclined to, instead of going too far with editor integration, perhaps exposing enough metadata so other folks/plugins can integrate easily with the curriculum.

@jsejcksn
Copy link
Contributor

I fear that toying with symlinks and manipulating the file system will introduce more complexity that we can chew. I'm not sure how mature rust-analyzer, for instance, is with regards to its VFS implementation, I'm not sure swapping the content of files will work as seamlessly as we would like.

I realize my setup is just a single configuration amongst many.

Tests can provide the information needed to know if these are real problems and will surface some of the details needed to evaluate the cost of potential solutions.

perhaps exposing enough metadata so other folks/plugins can integrate easily with the curriculum.

Can you expand more on this?

@jrvidal
Copy link
Contributor

jrvidal commented Jul 12, 2020

Can you expand more on this?

It was mostly a random thought inspired by the aforementioned Jetbrains packaging of Rustlings. I think creating those highly-integrated experiences in your editor of choice might not be too difficult, given the metadata in the info.toml file, and I'd be keen to make life easier for packagers.

@jsejcksn
Copy link
Contributor

@jrvidal What kinds of metadata were you thinking about besides the ordered list of exercises/quizzes? For example, an integration would need to know which exercise is the "current" one, (or a listing of all with passed/failed status for each). How might that kind of state be managed and provided?

@nealmcb
Copy link

nealmcb commented Sep 7, 2020

Note also a rather different approach to "integration" with "IDEs" like emacs and vim and other editors at #281, which at least makes it easy to locate and open the next exercise in most any editor.

@jackos
Copy link
Contributor

jackos commented Jan 9, 2022

If using rust-analyzer here is a solution: https://gist.github.com/jackos/7332fa8ab0b67a87f382fd566696f412

@mo8it
Copy link
Contributor

mo8it commented Mar 27, 2024

Closing because the rustlings lsp command now exists as @jackos pointed out :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants