Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semantic tokens highlighting issue (is it supported?) #1753

Closed
drcxd opened this issue Dec 8, 2022 · 12 comments
Closed

Semantic tokens highlighting issue (is it supported?) #1753

drcxd opened this issue Dec 8, 2022 · 12 comments
Labels
bug Something isn't working

Comments

@drcxd
Copy link

drcxd commented Dec 8, 2022

I am not sure if lua-language-server supports semantic tokens highlighting. I am using emacs + lsp-mode + lua-language-server and after I enable lsp-semantics-token-mode, the tokens are colored properly. However, I noticed that if there is a long comment, then the highlighting after the comment is incorrect.

image

@sumneko sumneko added the Info Needed More information is required label Dec 9, 2022
@sumneko
Copy link
Collaborator

sumneko commented Dec 9, 2022

It dose support semantic tokens highlighting.
I have tested your sample code in VSCode with 3.6.4, and it works properly.

Could you check your version of language-server?

@clason
Copy link

clason commented Dec 9, 2022

Just a short drive-by comment (can open a proper issue later), but I think there's an error in the semantic tokens: currently, identifiers that are assigned a function are labelled as @function:

local foo = function() end

That is fine -- but it's also applied to table keys like

{
  foo = function() end,
}

which I believe is wrong: table keys are not identifiers and are not called?

@sumneko
Copy link
Collaborator

sumneko commented Dec 9, 2022

which I believe is wrong: table keys are not identifiers and are not called?

I have not considered this problem carefully, but the current implementation is just showing higher priority of @function ranther than @tablefield.

@clason
Copy link

clason commented Dec 10, 2022

The same goes for @declaration modifier by the way -- I see this is deliberate, but I think that's not correct, either? (But I might be wrong here.)

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2022

The same goes for @declaration modifier by the way -- I see this is deliberate, but I think that's not correct, either? (But I might be wrong here.)

Could you tell more details in a new issue?

@clason
Copy link

clason commented Dec 16, 2022

sure, #1767

@clason
Copy link

clason commented Dec 19, 2022

I just tested this in Neovim, and all four test are correctly labeled as @property.

So either the issue is with Emacs's client, or there is context missing here. Is this the whole file, or just a screenshot from a bigger file (and project)?

@drcxd
Copy link
Author

drcxd commented Dec 26, 2022

I have tested the same code with 3.6.4 and the result is still the same, i.e., the last two test is not labeled as property. Maybe I have to raise this issue under lsp-mode. Thanks.
@clason This is the whole file.

@drcxd
Copy link
Author

drcxd commented Feb 8, 2023

Hi, I have raised an issue in lsp-mode repository and they fixed the original problem. However, after I upgraded lsp-mode and lua-language-server both to the latest version, I still found some semantic highlighting issues.

image

The keyword local and strings are labeled as comment and thus rendered using the face of comment.

lua-language-server version 3.6.10
lsp-mode version: 20230206.1806

@sumneko Just want to make sure you have seen the updated content.

@drcxd drcxd reopened this Feb 8, 2023
@sumneko sumneko added bug Something isn't working and removed Info Needed More information is required labels Feb 17, 2023
@sumneko
Copy link
Collaborator

sumneko commented Feb 17, 2023

I will check it

@sumneko sumneko closed this as completed in 3c994c6 Mar 6, 2023
@rickalex21
Copy link

Is there a way to turn them off? I tried several things and none of them seem to turn
them off. I'm using neovim/nvim-lspconfig with LazyVim:

return {
    {
        "neovim/nvim-lspconfig",
        enabled = true,

        opts = function(_, options)
            options.servers.lua_ls.settings.Lua.hint.enable = false

            options.setup = {
                lua_ls = function(server, opts)
                    opts.on_init = function(client)
                        client.server_capabilities.semanticTokensProvider = nil -- turn off semantic tokens
                        print("LSP server initialized: " .. client.name)
                        print(vim.inspect(client.server_capabilities))
                    end
                    require("lspconfig")[server].setup(opts)
                end,
            }

            return options
        end,
}
}

I also tried this:

   -- Hide all semantic highlights
	vim.api.nvim_create_autocmd("ColorScheme", {
		pattern = "*",
		callback = function()
			-- Hide all semantic highlights
			for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
				vim.api.nvim_set_hl(0, group, {})
			end
		end,
	})

@rickalex21
Copy link

rickalex21 commented May 22, 2024

I figured out my problem. For anyone using neovim the setting is in nvim-lspconfig and it is document_highlight.

Many posts will recommend this, but this did not work for me:

client.server_capabilities.semanticTokensProvider = nil -- turn off semantic tokens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants