catppuccin / nvim

🍨 Soothing pastel theme for (Neo)vim
MIT License
5.7k stars 257 forks source link

Invoking vim.lsp.buf.format temporarily removes highlights #480

Closed dmmulroy closed 1 year ago

dmmulroy commented 1 year ago

Description

When invoking vim.lsp.buf.format highlights + italics are temporarily removed. This is only happening for my catppuccin theme and it seems to only occur when an lsp is connected and running.

https://user-images.githubusercontent.com/2755722/236859390-2c942267-c6ba-4634-8e85-509f0ec1a9c9.mov

Neovim version

NVIM v0.9.0
Build type: Release
LuaJIT 2.1.0-beta3

Terminal and multiplexer

kitty: Version 0.27.1 (0.27.1)

Catppuccin version / branch / rev

main

Steps to reproduce

  1. Install catpuccin and activate the theme
  2. Ensure you have an lsp connected and running
  3. Run vim.lsp.buf.fmt

Expected behavior

No highlights/text should change

Actual behavior

Italics and highlights are removed and reapplied

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "catppuccin/nvim",
  "neovim/nvim-lspconfig",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("catppuccin")
-- add anything else here
require("lspconfig").lua_ls.setup({})
nullchilly commented 1 year ago

Hi this is a new neovim feature called semantic tokens which add addition highlights using LSP servers, refer to :h lsp-semantic-highlight for more information

This is the same behavior in tokyonight, nightfox, kanawaga, etc

If you wish to disable this behavior you can add this code (Taken from :h lsp-semantic-highlight)

-- Hide semantic highlights for functions
vim.api.nvim_set_hl(0, '@lsp.type.function', {})
-- Hide all semantic highlights
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
  vim.api.nvim_set_hl(0, group, {})
end
dmmulroy commented 1 year ago

Ah, thank you this worked! Do you know if it's the intended behavior to reapply highlights in the way that it current is when using the format function?

nullchilly commented 1 year ago

It's "intended" for now. However, languages like C/C++ doesn't have this flickering issue, there are efforts upstream to address this :)

dmmulroy commented 1 year ago

@nullchilly would you happen to have any links to issues for said upstream so I can track?

AnthonyDugarte commented 1 year ago

Not an actual fix, but I disabled formating from lua_ls and instead used the one from null_ls.builtins.formatting.stylua and the highlights are not being removed now

null_ls.setup({
        -- ...,
    sources = {
            -- ...,
        null_ls.builtins.formatting.stylua,
        }
})

-- formatting with: 
    vim.lsp.buf.format({
                async = true,
                filter = function(client)
                    return client.name ~= "lua_ls"
                end,
            })