VS Code Sway plugin issues

I’m constantly experiencing issues with the VS Code Sway plugin.

Every time I’m writing code in sway, the code navigation feature (the most important one IMHO) breaks after some time/changes. Looks like the plugin just stops working and in order to recover it, I need to restart the IDE, which is annoying

Eventually I end up writing all of the code blindly, cause I can’t navigate to function definitions even within the same file

Is it a known issue and is it possible to fix it? Let me know if you need additional details

PS: it would be awesome to have a plugin for JetBrains IDEs as well. I’m pretty sure that lots of people, including myself, just don’t use and don’t want to use VS Code

3 Likes

Found a related issue on github - Slow plugin · Issue #172 · FuelLabs/sway-vscode-plugin · GitHub

Just to add a few more observations regarding VS Code Sway Plugin & WSL2 use-cases:

  1. If you open a project with several subfolders containing Forc.toml each, the plugin doesn’t index all of these subfolders, only one active (opened) project is being indexed so that to be able to index other subfolders you would need to either restart VS Code/the plugin or add some VS Code configs I am not aware of.
  2. When you make some changes in the currently opened and indexed file and write a piece of code which can’t be compiled yet, the plugin might hang on indexing so every occured save in this file triggers long reindexing which basically prevents users from doing any navigation/lookup as they code through

Hello @mpoplavkov, thanks for reaching out.

First off, which version are you using? (instructions here)

Could you please enable verbose logging (instructions here) and share the logs the next time it happens? This will give us an idea of what’s going on.

If the repo is public, we can try to repro the issue ourselves if you can share the link.

In case this is helpful, you do not need to fully restart the IDE to restart the LSP. You can use the “Developer: Reload Window” command palette (cmd+shift+P). This works for restarting other extensions too.

As for a JetBrains plugin, we don’t have any plans in the near future to build one. JetBrains does not use LSP, it is an entirely different system. We are a small team and are focused on improving the UX of the LSP-based editors like VSCode. LSP improvements also improve the experience for developers using nvim and helix.

If you prefer to use a JetBrains editor, there is a hack that might be helpful for writing Sway. Essentially you can tell the Rust plugin to treat Sway files as Rust, and get decent syntax highlighting and hover docs, since the languages are similar. See Add support in CLion for using `sway-lsp` · Issue #2306 · FuelLabs/sway · GitHub

Hi @mpoplavkov and @Serafim thanks for opening this issue and leaving your observations.

We are aware of this issue, there was a critical bug in the garbage collector between LSP and the compiler that was leading to a non recoverable crash, this is why it seems like the plugin has stopped working. We have fixed this issue as of a few weeks ago and is available in the latest release.

I would suggest the quickest way to get it working would be to checkout the sway repo and follow the below commands to get the server updated.

git checkout https://github.com/FuelLabs/sway
cd sway
cargo install --path ./forc-plugins/forc-lsp
1 Like

Also just to add @Serafim I believe issue 1 should also be resolved with this release, please let us know if this is still not working for you.

Issue 2 is due to the compiler not supporting incremental recompilation so we need to recompile the whole project. We are working on improving this as our top priority at the moment.

1 Like

Hello @Josh,
Thanks for your reply!
I upgraded the version of forc-lsp to 0.56.0 but still experience the issue with multiple subfolders are not indexed within one opened project. Only the one wich was touched last is indexed the others are not. So to be able to navigate I need to click to another subfolder and restart the plugin/VS Code.