ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
2.06k stars 123 forks source link

[LSP] gopls default config support SemanticToken #321

Closed youngxhui closed 1 year ago

youngxhui commented 1 year ago

nvim 0.9 has been released which support semantic token, but go.nvim lsp default config not support semanticToken.

ray-x commented 1 year ago

I think it is enabled by default: https://github.com/ray-x/go.nvim/blob/fcc88590e0ad9d4f967ce61e14f2f979acb63b77/lua/go/lsp.lua#L94-L108

youngxhui commented 1 year ago

this is my config

image

code not support semanticToken

it is not support semanticToken.

when i add config in lsp, it support semanticToken

image

nvim_lsp.gopls.setup({
-- other config
on_attach = {
    -- other config
            client.server_capabilities.semanticTokensProvider = {
              full = {
                delta = false
              },
              legend = {
                -- from https://github.com/golang/tools/blob/master/gopls/internal/lsp/semantic.go#L981
                tokenTypes = {
                  "namespace", "type", "class", "enum", "interface",
                  "struct", "typeParameter", "parameter", "variable", "property", "enumMember",
                  "event", "function", "method", "macro", "keyword", "modifier", "comment",
                  "string", "number", "regexp", "operator",
                },
                tokenModifiers = {
                  "declaration", "definition", "readonly", "static",
                  "deprecated", "abstract", "async", "modification", "documentation", "defaultLibrary",
                },
              },
              range = true,
            }
}

})
ray-x commented 1 year ago

Pushed a change for this. Could you take a look?

youngxhui commented 1 year ago

No effect

ray-x commented 1 year ago

what is the result of : vim.lsp.get_active_clients()[1].server_capabilities.semanticTokensProvider

It should be:

{                                                                                                                                                                                               
  full = true,                                                                                                                                                                                  
  legend = {                                                                                                                                                                                    
    tokenModifiers = { "declaration", "definition", "readonly", "static", "deprecated", "abstract", "async", "modification", "documentation", "defaultLibrary" },                               
    tokenTypes = { "namespace", "type", "class", "enum", "interface", "struct", "typeParameter", "parameter", "variable", "property", "enumMember", "event", "function", "method", "macro", "key
word", "modifier", "comment", "string", "number", "regexp", "operator" }                                                                                                                        
  },                                                                                                                                                                                            
  range = true                                                                                                                                                                                  
}     

BTW, the setup was loaded when you use go.nvim on_attach

ray-x commented 1 year ago

Would be helpful to print out your gopls config e.g. The output of lua =vim.lsp.buf_get_clients() and post the gopls setup.

youngxhui commented 1 year ago

what is the result of : vim.lsp.get_active_clients()[1].server_capabilities.semanticTokensProvider

It should be:

{                                                                                                                                                                                               
  full = true,                                                                                                                                                                                  
  legend = {                                                                                                                                                                                    
    tokenModifiers = { "declaration", "definition", "readonly", "static", "deprecated", "abstract", "async", "modification", "documentation", "defaultLibrary" },                               
    tokenTypes = { "namespace", "type", "class", "enum", "interface", "struct", "typeParameter", "parameter", "variable", "property", "enumMember", "event", "function", "method", "macro", "key
word", "modifier", "comment", "string", "number", "regexp", "operator" }                                                                                                                        
  },                                                                                                                                                                                            
  range = true                                                                                                                                                                                  
}     

BTW, the setup was loaded when you use go.nvim on_attach

output

:lua =vim.lsp.get_active_clients()[1].server_capabilities.semanticTokensProvider

{
  full = {
    delta = false
  },
  legend = {
    tokenModifiers = { "declaration", "definition", "readonly", "static", "depre
cated", "abstract", "async", "modification", "documentation", "defaultLibrary" }
,
    tokenTypes = { "namespace", "type", "class", "enum", "interface", "struct",
"typeParameter", "parameter", "variable", "property", "enumMember", "event", "fu
nction", "method", "macro", "keyword", "modifier", "comment", "string", "number"
, "regexp", "operator" }
  },
  range = true
}
ray-x commented 1 year ago

I checked your default config. You did not enable lsp_cfg by default. You should use this:

require('go').setup({
  lsp_cfg = true  -- it is false by default
})
youngxhui commented 1 year ago

thanks. i enable lsp_cfg = true, nvim's semanticToken work successful.