EdenEast / nightfox.nvim

🦊A highly customizable theme for vim and neovim with support for lsp, treesitter and a variety of plugins.
MIT License
2.91k stars 136 forks source link

Avoiding Treesitter/LSP conflicts #374

Closed richchurcher closed 9 months ago

richchurcher commented 9 months ago

Opening this and immediately closing, because it was driving me absolutely nuts most of the day until I understood the root cause. It's not actually a Nightfox issue at all, as it turns out. Hopefully this helps someone one day in the same situation! Thanks so much for Nightfox (and especially Duskfox), I love it to bits. :pray:

I couldn't for the life of me figure out why my Nightfox overrides:

-- NOTE: bar
-- TODO: foo
require("nightfox").setup({
    groups = {
        all = {
            ["@text.note"] = { fg = "white", bg = "none" },
            ["@text.todo"] = { fg = "orange", bg = "none" },
        }
    },
    options = {
        styles = {
            comments = "italic",
            keywords = "bold",
            types = "italic,bold",
        }
    }
})

would take effect, but immediately be overridden by a plain @comment.lua highlight (or so I thought). It seemed to happen in all languages. A Dart example, before:

before

after:

after

The clue eventually came when I noticed the :Inspect output had an interesting entry tacked on the end:

image

The new-ish semantic tokens LSP feature adds a highlight group with a higher priority than Treesitter's default 100, completely overriding my changes.

The solution, for me at least, was to disable LSP semantic tokens and let Treesitter do everything. This may not be the best option for all, but I'm happy with it. In your on_attach, add the following:

local on_attach = function(client, bufnr)
    -- ...
    -- LSP semantic tokens conflicts with Treesitter, turn it off:
    client.server_capabilities.semanticTokensProvider = nil
end

(and obviously add it to any lspconfig blocks):

lspconfig['rust_analyzer'].setup {
    capabilities = capabilities,
    on_attach = on_attach,
}

This might be old news to some, but it took me too many hours not to document!