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"],
}
@cristianpjensen
I don't right now, sorry! I haven't worked with leptos in a minute and the issue isn't fresh in my mind. One thing we could try is outlined in this stackoverflow post but it would additionally require changing all the SSR-related
#[config]
lines in a project. I'll try and find some time to test it out today.Another option may be to totally disable the dead code lint warning, but obviously that's not ideal.