Code Monkey home page Code Monkey logo

Comments (6)

mehalter avatar mehalter commented on June 11, 2024 1

This is incorrect @AthirsonSilva

  1. this is using utilities in LazyVim which aren't available in AstroNvim
  2. Semantic tokens are default in 0.9+ so you don't need to enable the capability.

All you need to do is create a file user/lsp/config/gopls.lua and give it the content:

return {
  settings = {
    gopls = {
      semanticTokens = true,
    },
  },
}

from astrotheme.

mehalter avatar mehalter commented on June 11, 2024

golang/vscode-go#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

from astrotheme.

mehalter avatar mehalter commented on June 11, 2024

You probably just need to configure gopls to enable semantic tokens in the settings to get better highlighting

from astrotheme.

AthirsonSilva avatar AthirsonSilva commented on June 11, 2024

Oh, then i will take a look at it, many thanks!

from astrotheme.

AthirsonSilva avatar AthirsonSilva commented on June 11, 2024

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

from astrotheme.

mehalter avatar mehalter commented on June 11, 2024

2024-02-03_10:05:21_screenshot

here is an example with just that added in a base AstroNvim install.

from astrotheme.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.