Long time vim user, I am getting started with using LSPs in nvim. I want to use the clangd
LSP to get all those powerful LSP goodies.
I am seeing a bunch of spurious errors whenever I edit a file, so clearly something is wrong in my setup. That's fine, I just have some work to do. But the problem is... I can't even figure out how to debug it!
I am not asking for a fix or a fish, I AM asking for steps to take to debug. I want to know how to fish for myself, and I need help. I want to set up a language server for each of the languages I use, and I will need to go through this a few more times. I need to know how this works better.
As I understand it, LSs are just servers, daemons, running in the background. My editor is an LSP client and will turn my actions into LSP commands, which will hit the server and get serviced. nvim
will direct commands from a buffer to the "attached" language server. You can start and attach a language server with vim.lsp.start
.
- The first thing that I want to do is to know where the LSP's log files are.
- I have read through nvim docs: lsp-core. But
:lua= vim.lsp.log
returnsnil
, so I cannot even askvim.lsp.log.get_filename()
.
- I have read through nvim docs: lsp-core. But
- I have tried setting
verbose = true
in thevim.lsp.start
command. - I have tried added
--log=verbose
to thecmd
in thevim.lsp.start
command.
I have stopped being able to make progress. Here is my setup (in ~/.vim/after/ftplugin/cpp.lua
):
-- Start the 'clangd' language server
vim.lsp.start({
name = 'clangd',
cmd = { 'clangd', '--log=verbose' },
verbose = true,
root_dir = '.'
})
-- Run configuration after attaching (currently does nothing but prints that I have successfully attached)
local augroup_cpp_attach = vim.api.nvim_create_augroup('cpp_lsp_attach', {clear = true})
vim.api.nvim_create_autocmd('LspAttach', {
group = augroup_cpp_attach,
buffer = vim.api.nvim_get_current_buf(),
callback = function(args)
print("C++ LSP attached")
end
})
I have installed clangd
via Mason
so that is fine:
:!which clangd
/Users/arisweedler/.local/share/nvim/mason/bin/clangd
I have created a compile-commands.json
file
:!ls compile_commands.json
compile_commands.json
So my question is: Where can I find the clangd Language Server
's logs? Where can I find good documentation on this? The :help lsp-logs
are wrong, or I have failed to set something up.