simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 159 forks source link

Option to disable LSP highlighting #365

Closed mkeeter closed 1 year ago

mkeeter commented 1 year ago

Good morning! I've noticed a regression after updating to neovim 0.9.

A few seconds after startup, it switches from treesitter to LSP highlighting, which is worse (it doesn't correctly highlight docstrings or TODO):

Treesitter

Screenshot 2023-04-12 at 9 00 47 AM

LSP

Screenshot 2023-04-12 at 9 00 59 AM

I attempted to disable this with

      local rt = require'rust-tools'

      rt.config.options.server.capabilities.textDocument.semanticTokens = vim.NIL
      rt.config.options.server.capabilities.workspace.semanticTokens = vim.NIL

in my configuration, but it didn't seem to work.

Any suggestions on how to disable LSP highlighting?

mkeeter commented 1 year ago

Ah, I finally found the right setting:

      vim.api.nvim_set_hl(0, '@lsp.type.comment.rust', {})

This will disable LSP highlighting in Rust comments.

(:help lsp-semantic-highlight for more details)

I'm not sure if rust-tools wants to do this by default, but it was definitely a surprising change in behavior for me!

PSeitz commented 1 year ago

I got the same issue, and this is how to disable it completely.

  local rt = require("rust-tools")

  rt.setup({
    server = {
      on_attach = function(client, bufnr)
        client.server_capabilities.semanticTokensProvider = nil
        -- Hover actions
        vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
        -- Code action groups
        vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
      end,
    },
  })
bleczz commented 1 year ago

I just moved on from vimscript and coc to lua and lsp along with treesitter and I've been debugging for two days because this was driving me insane! Thanks a lot for the hint.

A simple way to disable it completely for every file so only treesitter's highlight is applied would be setting this into your init.lua:

for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
        vim.api.nvim_set_hl(0, group, {})
end
DieracDelta commented 1 year ago

@bleczz is this working or you on neovim 0.9.0? :highlight is showing all the @lsp highlight groups as cleared. But I'm still faced with semantic tokens. Any ideas? I'm getting stuff like: image

I also don't even see @lsp.type.comment.rust listed in :highlight...

bleczz commented 1 year ago

Hi, @DieracDelta. I'm on NVIM v0.10.0-dev

DieracDelta commented 1 year ago

@bleczz which rev?

simrat39 commented 1 year ago

Seems like this is LSP semantic highlighting, so it should be on by default, and can be disabled in the ways said above