1

I have the following in my config

vim.diagnostic.config {
  virtual_text = false,
  underline = false,
  update_in_insert = false,
  float = {
    focusable = false,
    style = 'minimal',
    border = 'rounded',
    header = '',
    prefix = '',
  },
}

which works as expected. I'd like to enable the virtual_text and underline for certain LSP specifically though. Is there a way to specific the config per LSP?

1
  • Set the config in your LSP's on_attach function. Commented Jul 30, 2024 at 10:15

1 Answer 1

2

You could define an autocommand depending on your filetype to modify your LSP configuration.

For example, to enable virtual_text and underline only for Python filetype:

vim.api.nvim_create_autocmd('BufRead', {
    group = vim.api.nvim_create_augroup('filetype_python', { clear = true }),
    desc = 'Set LSP diagnostics for Python',
    pattern = { '*.py' },
    callback = function()
      vim.diagnostic.config({
        virtual_text = true,
        underline = true,
      })
    end,
  })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.