olimorris / onedarkpro.nvim

🎨 Atom's iconic One Dark theme. Cacheable, fully customisable, Tree-sitter and LSP semantic token support. Comes with variants
MIT License
773 stars 40 forks source link

[Bug]: Onedarkpro's highlights get overriden by typescript-language-server. #189

Closed anthony-S93 closed 1 year ago

anthony-S93 commented 1 year ago

Your OneDarkPro config

-- Minimal config used to test the issue
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
    require('packer').startup({
        function(use)
            use 'wbthomason/packer.nvim'
            --Color schemes
            use
            {
                "olimorris/onedarkpro.nvim",
                config = function()
                    require("onedarkpro").setup({
                        theme = "onedark_vivid",
                        colors = {
                            --shades of orange
                            pumpkin_orange = "#FF7518",

                            --shades of brown
                            saturated_whiskey = "#D88B5D",

                            --shades of yellow
                            onedarkpro_yellow = "#E5C07B",

                            --shades of red
                            onedarkpro_red_bright = "#ED425B",
                            raspberry = "#E30B5C",
                            rose = "#F33A6A",

                            --shades of blue
                            onedarkpro_blue_saturated = "#4FB1FF",

                            --shades of purple
                            onedarkpro_purple = "#D55FDE",
                            lavender = "#9A9AEB",
                            bright_lavender = "#8484e7",

                            --shades of green
                            matcha_sea_green = "#2eb398",
                            lime_green = "#50fa7b",

                            --shades of pink
                            pastel_pink = "#F8C8DC",
                            watermelon_pink = "#E37383",
                        },
                        highlights = {
                            --Generic
                            ["@boolean"] = { fg = "${saturated_whiskey}" },
                            ["@constant"] = { fg = "${saturated_whiskey}" },
                            ["@constant.builtin"] = { fg = "${saturated_whiskey}" },
                            ["@conditional"] = { fg = "${purple}", style = "bold" },
                            ["@field"] = { fg = "${white}" },
                            ["@float"] = { fg = "${saturated_whiskey}" },
                            ["@function"] = { fg = "${blue}" },
                            ["@exception"] = { fg = "${purple}", style = "bold" },
                            ["@include"] = { fg = "${purple}", style = "bold" },
                            ["@keyword"] = { fg = "${purple}", style = "bold" },
                            ["@keyword.function"] = { fg = "${purple}", style = "bold" },
                            ["@keyword.operator"] = { fg = "${purple}", style = "bold" },
                            ["@keyword.return"] = { fg = "${purple}", style = "bold" },
                            ["@number"] = { fg = "${saturated_whiskey}" },
                            ["@namespace"] = { fg = "${onedarkpro_yellow}", style = "bold" },
                            ["@operator"] = { fg = "${cyan}" },
                            ["@property"] = { fg = "${white}" },
                            ["@preproc"] = { fg = "${purple}", style = "bold" },
                            ["@punctuation.bracket"] = { fg = "${white}" },
                            ["@repeat"] = { fg = "${purple}", style = "bold" },
                            ["@string.escape"] = { fg = "${saturated_whiskey}" },
                            ["@statement.punctuation.bracket"] = { fg = "${white}" },
                            ["@type"] = { fg = "${onedarkpro_yellow}", style = "bold" },
                            ["@type.qualifier"] = { fg = "${purple}", style = "bold" },
                            ["@variable"] = { fg = "${red}" },

                            --Javascript
                            ["@constructor.javascript"] = { fg = "${onedarkpro_yellow}", style = "bold" },
                            ["@keyword.operator.javascript"] = { fg = "${purple}", style = "bold" },
                            ["@keyword.javascript"] = { fg = "${purple}", style = "bold" },
                            ["@keyword.return.javascript"] = { fg = "${purple}", style = "bold" },
                            ["@method.javascript"] = { fg = "${blue}" },
                            ["@method.call.javascript"] = { fg = "${blue}" },
                            ["@punctuation.bracket.javascript"] = { fg = "${white}" },
                            ["@odp.statement.punctuation.bracket.javascript"] = { fg = "${white}" },
                            ["@odp.punctuation.bracket.javascript"] = { fg = "${white}" },
                            ["@variable.javascript"] = { fg = "${red}" },
                            ["@variable.builtin.javascript"] = { fg = "${matcha_sea_green}", style = "bold" },

                            --Override highlight options for plugins
                            NvimTreeFolderName = { fg = "${blue}" },
                            NvimTreeOpenedFolderName = { fg = "${blue}" },
                            NvimTreeEmptyFolderName = { fg = "${blue}" },
                            NvimTreeFolderIcon = { fg = "${blue}" },
                            NvimTreeRootFolder = { fg = "${blue}" },
                            NvimTreeExecFile = { fg = "${onedarkpro_red_bright}", style = "bold" },
                            NvimTreeSymLink = { fg = "${lime_green}", style = "bold" },
                        },
                        options = {
                            transparency = true,
                        },
                    })
                    vim.cmd("colorscheme onedark_vivid")

                    --Other highlights
                    vim.api.nvim_set_hl(0, "MatchParen", { fg = "#4FB1FF", bold = true })
                    vim.api.nvim_set_hl(0, "IndentBlanklineContextChar", { fg = "#ED425B", bold = true })
                    vim.api.nvim_set_hl(0, "htmlItalic", { italic = true })
                    vim.api.nvim_set_hl(0, "htmlBold", { bold = true })
                    vim.api.nvim_set_hl(0, "BufferCurrentSign", { fg = "#00BFFF" })
                    vim.api.nvim_set_hl(0, "BufferCurrent", { fg = "white", bold = true})
                    vim.api.nvim_set_hl(0, "BufferCurrentMod", { fg = "#00BFFF", bold = true })
                    vim.api.nvim_set_hl(0, "BufferInactive", { fg = "#5c6370", italic = true })
                    vim.api.nvim_set_hl(0, "BufferInactiveMod", { italic = true })
                    vim.api.nvim_set_hl(0, "FoldColumn", { fg = "#abb2bf" })
                    vim.api.nvim_set_hl(0, "LspInfoBorder", { fg = "#5c6370" })
                end,
            }
            use
            {
                "nvim-treesitter/nvim-treesitter",
                run = ':TSUpdate',
                config = function()
                    require("nvim-treesitter.configs").setup({
                        highlight = {
                            enable = true,
                            additional_vim_regex_highlighting = true,
                        },
                        playground = {
                            enable = true,
                            disable = {},
                            updatetime = 25,
                            persist_queries = false,
                            keybindings = {
                                toggle_query_editor = 'o',
                                toggle_hl_groupd = 'i',
                                toggle_injected_languages = 't',
                                toggle_anonymous_nodes = 'a',
                                toggle_language_display = 'I',
                                focus_language = 'f',
                                unfocus_language = 'F',
                                update = 'R',
                                goto_node = '<cr>',
                                show_help = '?',
                            }
                        },
                        ensure_installed = { "java", "python", "javascript", "c", "cpp", "lua", "rust", "go", "bash", "json", "sql", "html", "css", "yaml", "gitignore", "vim", "swift", "markdown", "awk", "dockerfile" },
                    })
                end,
            }

            use
            {
                "nvim-treesitter/playground"
            }

            use
            {
                "neovim/nvim-lspconfig",
                config = function()
                    local lspconfig = require("lspconfig")
                    local opts = { noremap = true, silent = true }
                    --Basic keymappings
                    vim.keymap.set('n', '<space>d', vim.diagnostic.open_float, opts)
                    vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
                    vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
                    --vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)

                    --Keymappings on attach
                    local on_attach = function(client, bufnr)
                        vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

                        local bufopts = { noremap = true, silent = true, buffer = bufnr }
                        vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
                        vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
                        vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
                        vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
                        vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
                        vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
                        vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
                        vim.keymap.set('n', '<space>wl', function()
                            print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
                        end, bufopts)
                        vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
                        vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
                        vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
                        vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
                    end

                    local lsp_flags = {
                        debounce_text_changes = 150,
                    }

                    --Customize diagnostics
                    local signs = { Error = '󰅙', Warn = '󰀦', Hint = "󰐗", Info = "󰋼" }
                    for type, icon in pairs(signs) do
                        local hl = "DiagnosticSign" .. type
                        vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
                    end
                    vim.diagnostic.config({
                        underline = false,
                        virtual_text = false,
                    })

                    lspconfig.tsserver.setup({
                        init_options = {
                            hostInfo = "neovim",
                            preferences = {
                                autoImportFileExcludePatterns = {},
                                importModuleSpecifierEnding = "js",
                            },
                        },
                        on_attach = on_attach,
                    })

                    -- Enable borders for floating windows
                    local lspconfig_win = require('lspconfig.ui.windows')
                    lspconfig_win.default_options = {
                        border = "single"
                    }
                end
            }

            end,
        config = {
            package_root = package_root,
            compile_path = install_path .. '/plugin/packer_compiled.lua',
            display = { non_interactive = true },
        }
    })
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end

load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!"]]

Error messages

No response

Describe the bug

What I expect to happen

In onedarkpro's config, I set the @variable.builtin.javascript highlight to sea green. The use of tsserver shouldn't mess with my highlighting.

What actually happened

Highlighting Overridden

The color was loaded as sea green, but then got overridden by the default (yellow) after the language server loads. I can confirm that the language server is the culprit. The problem disappeared after I removed the configuration for tsserver - as in I deleted these lines:

lspconfig.tsserver.setup({
                        init_options = {
                            hostInfo = "neovim",
                            preferences = {
                                autoImportFileExcludePatterns = {},
                                importModuleSpecifierEnding = "js",
                            },
                        },
                        on_attach = on_attach,
                    })

To be fair, I wasn't sure if the issue lies with nvim-lspconfig, typescript-language-server, or onedarkpro.nvim. But I figured I would report it here first.

Reproduce the bug

Steps to reproduce: 1) Create a test directory. 2) Create the minimal config file I mentioned above in the test directory. 3) Create a test file testing.js 4) Add the following line to the test file:

console.log("Hello world.")

5) Open the file with neovim using the minimal config file mentioned above.

Final checks

olimorris commented 1 year ago

What happens if you run the :Inspect command? Looks like it will be a semantic token being applied.

anthony-S93 commented 1 year ago

What happens if you run the :Inspect command? Looks like it will be a semantic token being applied.

Semantic tokens have indeed been applied, and it would appear, at the highest priority.

2023-06-11-16-59-18

What do you recommend?

olimorris commented 1 year ago

Yeah that is expected behaviour in Neovim 0.9. I'd suggest overwriting them in your config as part of your custom highlights

anthony-S93 commented 1 year ago

@olimorris Fixed it.

Thanks for the assistance and for the quick response as well! Cheers.

Update: Incidentally, for those of you who prefer Treesitter highlighting over semantic highlighting, here's how you can turn semantic highlighting off. In the on_attach(client, bufnr) passed to the language server, add this line:

client.server_capabilities.semanticTokensProvider = nil
olimorris commented 1 year ago

Great to hear it. As of yesterday, you can set highlight groups to be {}. Which allows you to unset any

anthony-S93 commented 1 year ago

Great to hear it. As of yesterday, you can set highlight groups to be {}. Which allows you to unset any

@olimorris Even those that are linked to other groups? Because I can't seem to disable @lsp.type.variable.javascript with ["@lsp.type.variable.javascript"] = {},

olimorris commented 1 year ago

Yep. Assuming they've been set with the default argument.

Can you share the example Javascript code you're working with?

anthony-S93 commented 1 year ago

Just something as simple as: 2023-06-19-12-43-25

As you can see, @lsp.typemod.variable.defaultLibrary.javascript has already been disabled.

anthony-S93 commented 1 year ago

Hang on. It's working now. I deleted the packer_compiled.lua file and then regenerated it.

olimorris commented 1 year ago

Great to hear. Was just going to say this is what I'm seeing:

Screen Shot 2023-06-18 at 21 51 04@2x
anthony-S93 commented 1 year ago

Great to hear. Was just going to say this is what I'm seeing:

Screen Shot 2023-06-18 at 21 51 04@2x

For some reason my packer_compiled.lua didn't get updated even after a :PackerSync. This isn't the first time this has happened now.

olimorris commented 1 year ago

I'd had similar weird issues in the past so made the switch to Lazy a while back and haven't looked back.

anthony-S93 commented 1 year ago

I'd had similar weird issues in the past so made the switch to Lazy a while back and haven't looked back.

@olimorris So I followed in your footsteps and switched to lazy.nvim as well. lazy.nvim, aside from providing a nice UI for plugin management, cut down my nvim startup time from 140ms to 38ms (which is a bit insane if you ask me). So, yeah. Thanks for yet another helpful suggestion. You were the one who introduced me to nvim-ufo last time as well.

Just out of sheer curiosity, what does your startup times look like?

olimorris commented 1 year ago

140ms to 38ms? That is insane! Mine is actually at around 140ms right now so I may have to dive into that. I have maybe 80 plugins. How does that compare to yours?

I have found Lazy to be awesome; even restructuring the whole of my config. Just feels so much leaner and organised.

anthony-S93 commented 1 year ago

have maybe 80 plugins

140ms with 80 plugins is an insanely good number.

I have 30 plugins and with lazy.nvim, my start up time averages at about 40ms if I just launch neovim without launching a file. If I open a file, the average is around 50ms.

I guess packer is just slower, since it took neovim more than 100ms to start up with the same number of plugins.