Closed JoshuaBatty closed 1 year ago
I'm going to re-open this issue until we have logs between neovim and the server working so we can confirm that the server is actually working.
Unfortunately when I pass the init options from the neovim client, they are ignored. I was able to get logs by setting the default log level in the server to TRACE
and installing that locally.
I also realized why most of the keymappings (like K
for hover and ca
for code actions) weren't working: I was missing the on_attach function for sway_lsp. The correct configuration should be:
if not configs.sway_lsp then
configs.sway_lsp = {
default_config = {
cmd = {'forc-lsp'},
filetypes = {'sway'},
-- This was missing!
on_attach = on_attach,
-- These are ignored for some reason :(
-- init_options = {
-- logging = { level = 'trace' },
-- inlayHints = { maxLength = 25, renderColons = true, typeHints = true },
-- trace = { trace = true, server = 'messages' }
},
root_dir = function(fname)
return lspconfig.util.find_git_ancestor(fname)
end;
settings = {};
};
}
end
With this, hover and code actions keymappings are working in neovim!
Here are the logs showing that LSP is being used for hover. The formatting is hard to read and there looks to be extra logs from the logger itself showing up, which I couldn't figure out how to get rid of.
[ERROR][2022-12-27 23:35:24] .../vim/lsp/rpc.lua:733 "rpc" "forc-lsp" "stderr" 'flushing framed transport\nframed transport flushed\nattempting to decode a frame\n<- {"params":{"textDocument":{"uri":"file:\\/\\/\\/Users\\/sophiedankel\\/Development\\/sway\\/examples\\/fizzbuzz\\/src\\/main.sw"},"position":{"line":18,"character":13}},"method":"textDocument\\/hover","id":2,"jsonrpc":"2.0"} \n'
[ERROR][2022-12-27 23:35:24] .../vim/lsp/rpc.lua:733 "rpc" "forc-lsp" "stderr" "frame decoded from buffer\nattempting to decode a frame\n"
[ERROR][2022-12-27 23:35:24] .../vim/lsp/rpc.lua:733 "rpc" "forc-lsp" "stderr" '-> {"jsonrpc":"2.0","result":{"contents":{"kind":"markdown","value":"```sway\\nenum FizzBuzzResult\\n```\\n---\\n documentation!"},"range":{"end":{"character":26,"line":18},"start":{"character":12,"line":18}}},"id":2} \nflushing framed transport\nwriting; \27[3mremaining\27[0m\27[2m=\27[0m233\nflushing framed transport\n'
Inlay hints aren't supported natively in neovim, but there are a few plugins in development which offer partial support: https://github.com/lvimuser/lsp-inlayhints.nvim and https://github.com/simrat39/inlay-hints.nvim
Currently, this repo just supports syntax highlighting. We should expand the functionality to launch the
sway-lsp
language server binary and communicate with an LSP client vim plugin.