Skip to content

Weird issue on semantic tokens highlighting when switching from a razor to a normal cs file #278

@Sofistico

Description

@Sofistico

Description

The semantic token highlight is lost when switching from a razor buffer to a c# buffer

The minimal config can't reproduce the error consistently, but my personal config can:

https://github.com/Sofistico/nvim_config/tree/d04bbbe1a607156a500f9fcf3a1dff4b7592a7da

Neovim version

NVIM v0.11.5

Operating system and version

Windows 11

Expected behavior

The semantic token highlight is consistent like this:

Image

Actual behavior

Image

There is this error when i go to my alternate buffer and when i switch to the cs file:

Image

Only the first half of the buffer is highlighted, the rest only follows the hightlight from treesitter:

Example using the var service:
Image

Image

The full error log:

Image E5108: Error executing lua: vim/_editor.lua:445: nvim_exec2()[1]..BufWinEnter Autocommands for "": Vim(append):Error executing lua callback: ...rrent/share/nvim/runtime/lua/vim/lsp/sem antic_tokens.lua:281: attempt to index field 'semanticTokensProvider' (a nil value) stack traceback: ...rrent/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:281: in function 'send_request' ...rrent/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:195: in function <...rrent/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:194> [C]: in function 'nvim_exec2' vim/_editor.lua:445: in function 'cmd' ...m-data/lazy/telescope.nvim/lua/telescope/actions/set.lua:102: in function 'edit_buffer' ...m-data/lazy/telescope.nvim/lua/telescope/actions/set.lua:194: in function 'run_replace_or_original' ...im-data/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'run_replace_or_original' ...im-data/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'run_replace_or_original' ...im-data/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func' ...nvim-data/lazy/telescope.nvim/lua/telescope/mappings.lua:293: in function <...nvim-data/lazy/telescope.nvim/lua/telescope/mappings.lua:292> stack traceback: [C]: in function 'nvim_exec2' vim/_editor.lua:445: in function 'cmd' ...m-data/lazy/telescope.nvim/lua/telescope/actions/set.lua:102: in function 'edit_buffer' ...m-data/lazy/telescope.nvim/lua/telescope/actions/set.lua:194: in function 'run_replace_or_original' ...im-data/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'run_replace_or_original' ...im-data/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'run_replace_or_original' ...im-data/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func' ...nvim-data/lazy/telescope.nvim/lua/telescope/mappings.lua:293: in function <...nvim-data/lazy/telescope.nvim/lua/telescope/mappings.lua:292> Error detected while processing InsertLeave Autocommands for "": Error executing lua callback: ...rrent/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:281: attempt to index field 'semanticTokensProvider' (a nil value) stack traceback: ...rrent/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:281: in function 'send_request' ...rrent/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:195: in function <...rrent/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:194>

Minimal config

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
	spec = {
		{
			"mason-org/mason.nvim",
			opts = {
				registries = {
					"github:mason-org/mason-registry",
					"github:crashdummyy/mason-registry",
				},
			},
		},
		{
			"seblyng/roslyn.nvim",
			opts = {},
			config = function(_, opts)
				require("roslyn").setup(opts)
			end,
		},
		{
			"nvim-telescope/telescope.nvim",
			tag = "v0.2.0",
			dependencies = { "nvim-lua/plenary.nvim" },
		},
		{ -- Highlight, edit, and navigate code
			"nvim-treesitter/nvim-treesitter",
			build = ":TSUpdate",
			main = "nvim-treesitter.configs", -- Sets main module to use for opts
			cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" },
			opts = {
				ensure_installed = {
					"c_sharp",
				},
				auto_install = true,
				highlight = {
					enable = true,
					-- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
					--  If you are experiencing weird indenting issues, add the language to
					--  the list of additional_vim_regex_highlighting and disabled languages for indent.
					additional_vim_regex_highlighting = { "ruby" },
				},
			},
		},
	},
})

vim.cmd([[hi @lsp.type.enum.cs guifg=SlateBlue]])
vim.cmd([[hi @lsp.type.property.cs guifg=DarkCyan]])
vim.cmd([[hi @property.c_sharp guifg=DarkCyan]])
vim.api.nvim_create_autocmd({ "BufEnter" }, {
	group = vim.api.nvim_create_augroup("sofistico_" .. "razor_generated_file", { clear = true }),
	pattern = { "%__virtual.cs$", "%_cshtml.g.cs$" },
	callback = function()
		vim.bo.swapfile = false
	end,
})

vim.lsp.config("html", {
	filetypes = { "html", "templ", "razor" },
})

vim.lsp.enable("html")

vim.keymap.set('n', '<space><space>', '<cmd>Telescope find_files<cr>')

Roslyn checkhealth

==============================================================================
roslyn:                                                                     ✅

roslyn.nvim: Requirements ~
- ✅ OK Neovim >= 0.11
- ✅ OK dotnet: found

roslyn.nvim: Roslyn Language Server ~
- ✅ OK C:/Users/joaorodrigues/AppData/Local/nvim-data/mason/bin/roslyn.cmd: found
- ✅ OK Razor extension: found at C:/Users/joaorodrigues/AppData/Local/nvim-data/mason/packages/roslyn/libexec/.razorExtension
- ✅ OK vscode-html-language-server: found
- ✅ OK html-lsp client: configured

roslyn.nvim: File Watching Configuration ~
- ✅ OK File watching: roslyn (using Roslyn's built-in file watcher)

roslyn.nvim: Solution Detection ~
- ✅ OK Selected solution: C:/Users/joaorodrigues/source/repos/TrabalhaBrasil/Sine.sln

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstream bugServer/neovim issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions