in the leptos-start example project, neovim will mark the SSR main function as dead code:
the rust-analyzer LSP client inside nvim thinks the SSR flag is disabled by default.
one way to fix this is to pass the "ssr" flag to rust-analyzer globally. neovim LSP lets us define settings for specific language servers.
Warning
this will mean the "ssr" flag gets provided to EVERY rust project you open in neovim! be careful. you may get startup errors when you open any projects that don't support the ssr flag.
according to rust-analyzer docs, the option we should pass is called rust-analyzer.cargo.features
. we'll pass it an array containing the string "ssr"
.
my neovim setup is based on nvim-basic-ide, so my LSP settings go in nvim/lua/user/lsp/settings/rust_analyzer.lua
. you may have to write your settings in a different place.
in here we add a table with the key ["rust-analyzer"]
, and inside that we write a structure representing the rest of the key (rust-analyzer.cargo.features
).
return {
settings = {
["rust-analyzer"] = {
cargo = {
features = { "ssr" } -- features = ssr, for LSP support in leptos SSR functions
}
}
}
}
in vscode, this can be done globally or per-project by putting the following into a .vscode/settings.json
file:
{
"rust-analyzer.cargo.features": ["ssr"],
}
I had the same problem and I've seen that LazyVim works around it using the allFeatures parameter (and expanding macros to make
if_cfg!
sections work. Only drawbacks, it'll compile everything again for that configuration and will keep the (several GBs of) results in your vim tmp directory.The configuration they use is more or less:
The neoconf plugin should be able to merge local per-project configurations into the lsp and other plugins, but I still can't understand how I should go about configuring that (I add a file, nothing happens, not even errors...).