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 returns nil, so I cannot even ask vim.lsp.log.get_filename().
  • I have tried setting verbose = true in the vim.lsp.start command.
  • I have tried added --log=verbose to the cmd in the vim.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
  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")

I have installed clangd via Mason so that is fine:

:!which clangd

I have created a compile-commands.json file

:!ls 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.

1 Answer 1


It seems like the vim.lsp.log module has to be required.

:lua =require('vim.lsp.log').get_filename() works for me and gives me the correct location.

  • It seems like the vim.lsp.log module has to be required. Oooooooooooooooooh. This will pay dividends in every other case. I was confused by :lua= vim and :lua= vim.lsp BOTH not returning nil, but I guess I never checked that :lua= vim.lsp.log returned nil as well. Once you got it to NOT return nil for me via the require, everything just works as expected. Oct 3, 2023 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.