#Rust-analyzer on VS Code only works on save in 2024?

126 messages · Page 1 of 1 (latest)

pine kindle
#

I did look into it for a while and found some people saying it doesn't support it because of this and that (I can link the discussion I found if necessary), but that's been said at least 3 or 4 years ago and it was always mentioned that it didn't support it yet, and most cite the rust-analyzer's first blog post that says it was a "new tool" which shouldn't be true by this point.

Is there a way, currently, to have that work even as a workaround? I am even willing to homebrew a vs code extension for that (I don't know how to do that yet, to be clear).

P.S.: I started learning rust a few years ago, but I only just got serious about it, so I consider myself a beginner, which is why I tagged this post with that too.

#

Oh also, I am aware of the "files.autoSave": "afterDelay" + "file.autoSaveDelay": 1000 hack. That is not real time. By that I mean linting every keystroke without having to save the file.

pine kindle
#

I just tested and it does save in real time on nvim using lspconfig with the rust-analyzer lsp

pine kindle
#

On VSCode in small projects it seems to work sometimes (not always), but testing on, for example, rustlings init doesn't seem to work at all

olive oar
#

It's not a normal project

pine kindle
#

sure, but I also tried with tokio

#

same thing

#

I git cloned it

olive oar
#

However it does things like type inference by itself

pine kindle
#

right, I did notice the variables were correctly inferred, but the type errors were not shown

olive oar
#

Yeah, and cargo needs everything on disk to work on it

pine kindle
#

that would make sense if it didn't work on any circunstance, but it works sometimes

olive oar
#

Note rust analyzer also does syntax errors by itself

olive oar
olive oar
#

Yes

#

If the error diagnostic says rustc on it then it hit disk

pine kindle
#

hm

pine kindle
#

something like this works

olive oar
#

Save it

pine kindle
#

no error

olive oar
pine kindle
olive oar
#

It's invalid code

pine kindle
#

rustc doesn't complain though

#

oh now it did

#

it was looking at an error above

#

I see

olive oar
#

Rust analyzer's syntax check only fails for impossible programs

#

?play ```rs
let x = 42;
x;

sturdy vesselBOT
olive oar
#

This is allowed (it doesn't do anything meaningful) but you didn't have a variable named aasd

#

So that makes it invalid

pine kindle
#

I see

olive oar
#

But rust analyzer doesn't check that part

pine kindle
#

somehow rust-analyzer in nvim does error that

#

without saving

olive oar
#

What does the diagnostic say?

pine kindle
#

there's.... no diagnostic...

#

what

#

should show this

#

it only shows squiggly line

olive oar
#

Then it's probably some other thing

#

Like a spell check

pine kindle
#

spell check...

olive oar
#

Does hello; have an underline

pine kindle
#
    ● actions-preview.nvim 1.17ms  VeryLazy
    ● blackjack.nvim 2.93ms  start
    ● cmp-nvim-lsp 0.04ms  lsp-zero.nvim
    ● Colorizer 1.15ms  start
    ● dashboard-nvim 3.46ms  VimEnter
    ● lazy.nvim 5.15ms  init.lua
    ● lsp-zero.nvim 29.68ms  start
    ● lualine.nvim 7.22ms  start
    ● LuaSnip 2.41ms  lsp-zero.nvim
    ● mason-lspconfig.nvim 0.04ms  start
    ● mason.nvim 0.3ms  lsp-zero.nvim
    ● mini.files 1.4ms  start
    ● nvim-autopairs 1.85ms  InsertEnter
    ● nvim-cmp 1.19ms  lsp-zero.nvim
    ● nvim-hlslens 1.5ms  nvim-scrollbar
    ● nvim-lspconfig 8.35ms  lsp-zero.nvim
    ● nvim-origami 1.86ms  BufReadPost
    ● nvim-scrollbar 4.27ms  start
    ● nvim-surround 1.32ms  VeryLazy
    ● nvim-tetris 0.37ms  start
    ● nvim-treesitter 5.01ms  start
    ● nvim-web-devicons 0.1ms  start
    ● nvimesweeper 0.26ms  start
    ● plenary.nvim 0.32ms  blackjack.nvim
    ● suda.vim 0.43ms  start
    ● telescope.nvim 6.04ms  start
    ● tokyonight 3.48ms  start
    ● vim-commentary 0.25ms  start
    ● vim-fugitive 0.76ms  start
    ● vim-gnupg 0.14ms  start
    ● which-key.nvim 0.82ms  start
#

my plugins

pine kindle
#

hello in my language does too

olive oar
#

Do hello in english

pine kindle
#

I did, it had a squiggly line

olive oar
#

Hmm

pine kindle
#

both cases

olive oar
#

It's possible treesitter doesn't like it

pine kindle
#

ooooh

#

lemme disable it rq

olive oar
#

I'm not seeing anything else in the list that stands out

pine kindle
#

nope, it was not treesitter

olive oar
#

It's something, but I don't know what it is

pine kindle
#

I mean, if that something somehow also worked on vscode I would be happy

#

it is lsp-zero

#

I disabled it and it didn't show squiggly line

#

but that should be using rust-analyzer

#

more specifically, it's mason

olive oar
#

checking on my neovim it doesn't do this

#

i don't use mason

#

so that checks out

pine kindle
#

I have one extension for all lsp needs

#

that is lsp-zero

#

and that has a mason dependency

#

if I comment the 2 lines where that dependency is declared, the squiggly line goes away

#

these two

olive oar
pine kindle
#

right

#

that's what happens when I save

olive oar
#

yeah i have auto save on exiting insert mode

pine kindle
#

I see

olive oar
#

Mason has some extra thing it's doing outside of rust analyzer

pine kindle
#

right, I wonder if I can do the same on vscode

#

wait, that's still weird

#

mason is a package manager

#

for lsps, daps, etc

#

and specifically installed rust-analyzer with it

olive oar
#

What modules does mason have installed?

pine kindle
#

these ones

#

only rust-analyzer is being run, I know because I used :LspInfo

olive oar
#

What config does rust analyzer have?

pine kindle
#

the default, I just installed it

#

lemme get the json

#
{
    "links": {
        "bin": {
            "rust-analyzer": "rust-analyzer-x86_64-unknown-linux-gnu"
        },
        "opt": {},
        "share": {
            "mason-schemas\/lsp\/rust-analyzer.json": "mason-schemas\/lsp.json"
        }
    },
    "name": "rust-analyzer",
    "secondary_sources": [],
    "schema_version": "1.1",
    "primary_source": {
        "id": "pkg:github\/rust-lang\/rust-analyzer@2024-07-15",
        "type": "registry+v1"
    },
    "metrics": {
        "start_time": 1721043990886,
        "completion_time": 1721043993597
    }
}
#

should be that? idk

olive oar
#

I have no clue what it's doing

pine kindle
#

I don't think that's it, but I don't know where the default configuration is

olive oar
#

I definitely know the default config for rust analyzer doesn't do this

pine kindle
#

right

#

I did not change it though

#

just to be clear, the squiggly line disappears when I do valid code

olive oar
#

I'm going to say that your mason install is haunted and leave it at that ferrisClueless

pine kindle
#

like do varThatWasDeclared;

pine kindle
olive oar
#

~~time to perform the summoning ritual ~~

pine kindle
#

rm -rf $(realpath $(dirname $(which nvim)))

#

I'll try to find what plugin is doing that

#

maybe it's not mason

#

if I find something I'll send it here, for completion's sake

olive oar
#

I think I found the setting

#

It's probably the experimental diagnostics setting in rust analyzer

#

Setting that in vscode I get a lint for a hello; line

#

No idea why neovim doesn't show the text for it

pine kindle
#

what

#

what is that

#

YOOOOOO

#

amazing

#

that's everything I wanted

olive oar
#

I have no idea what type of lints this enables

pine kindle
#

I prefer false positives than nothing

olive oar
#

It's still a mystery to me why/how the mason version seems to have this on my default

pine kindle
#

and if I want clippy I can just save

pine kindle
#

that said, my initial problem was solved, thanks