Closed AthirsonSilva closed 7 months ago
https://github.com/golang/vscode-go/issues/2286
Looks like semantic tokens are disabled by default. It will be up to the treesitter parser or the language server to provide semantic tokens for them to be highlighted nicely. Syntax is controlled in a general level and not necessarily language specific
You probably just need to configure gopls to enable semantic tokens in the settings to get better highlighting
Oh, then i will take a look at it, many thanks!
I don't know if reopening this issue or making a new post on the Discord would be the correct way, but i tried configuring gopls to enable semantic tokens and it didn't work, here goes my init.lua file:
return {
opts = {
clipboard = "unnamedplus",
setup = {
gopls = function(_, opts)
require("lazyvim.util").on_attach(function(client, bufnr)
if client.name == "gopls" then
client.server_capabilities.semanticTokens = {
full = true,
legend = {
tokenTypes = {
"namespace",
"type",
"class",
"enum",
"interface",
"struct",
"typeParameter",
"parameter",
"variable",
"property",
"enumMember",
"event",
"function",
"method",
"macro",
"keyword",
"modifier",
"comment",
"string",
"number",
"regexp",
"operator",
"decorator",
},
tokenModifiers = {
"declaration",
"definition",
"readonly",
"static",
"deprecated",
"abstract",
"async",
"modification",
"documentation",
"defaultLibrary",
},
},
}
end
end)
opts.settings = {
gopls = {
semanticTokens = true,
},
}
end,
},
},
highlights = {
init = {},
},
plugins = {
"gbprod/cutlass.nvim",
"AstroNvim/astrocommunity",
{ import = "astrocommunity.motion.mini-move" },
{ import = "astrocommunity.project.nvim-spectre" },
{ import = "astrocommunity.project.projectmgr-nvim" },
},
mappings = {
-- first key is the mode
n = {
-- second key is the lefthand side of the map
-- mappings seen under group name "Buffer"
["<leader>bn"] = { "<cmd>tabnew<cr>", desc = "New tab" },
["<leader>bD"] = {
function()
require("astronvim.utils.status").heirline.buffer_picker(
function(bufnr) require("astronvim.utils.buffer").close(bufnr) end
)
end,
desc = "Pick to close",
},
-- tables with the `name` key will be registered with which-key if it's installed
-- this is useful for naming menus
["<leader>b"] = { name = "Buffers" },
-- quick save
["<C-s>"] = { ":w!<cr>", desc = "Save File" }, -- change description but the same command
["d"] = { '"_d', desc = "Deletes current line without copying the contents" },
-- ["<Del>"] = { '"_d', desc = "Delete visual selection without saving to clipboard" },
},
v = {
-- setting a mapping to false will disable it
-- ["<esc>"] = false,
["<Del>"] = { '"_d', desc = "Delete visual selection without saving to clipboard" },
},
},
}
I found this configuration on this Reddit post: https://www.reddit.com/r/neovim/comments/11xekjx/how_to_make_semantic_token_highlighting_work_with/
One interesting thing is that in the post it was mentioned that semantic tokens are built into neovim now, and i am already using a recent version of neovim right now, and since the link @mehalter posted was from 2022, it makes sense to be built in now.
That is also this post that says the same thing: https://www.reddit.com/r/neovim/comments/zg6bvs/lsp_semantic_tokens_support_merged/
NVIM v0.10.0-dev Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Run "nvim -V1 -v" for more info
This is incorrect @AthirsonSilva
LazyVim
which aren't available in AstroNvimAll you need to do is create a file user/lsp/config/gopls.lua
and give it the content:
return {
settings = {
gopls = {
semanticTokens = true,
},
},
}
here is an example with just that added in a base AstroNvim install.
Is your feature related to a problem?
I migrated from VSCode today and, currently, everything is going smoothly, but one thing that is really bothering me is how the default theme doesn't show the "complete" syntax highlighting for Golang, and Golang only, i tested with Java, Lua, HTML and TypeScript and the syntax highlighting worked well with every single one.
Describe the new feature
Basically, it would be cool to make the syntax highlighting integrate better on Go, here goes a comparation between how the syntax highlighting works with Golang and TypeScript, and how much better it works for TypeScript.
Additional context
For additional context, i have the Golang LSP installed on my setup.