Giter Club home page Giter Club logo

nvim-semantic-tokens's Introduction

nvim-semantic-tokens

This is a reference plugin to assist the development of neovim/neovim#15723

Setup

require'nvim-semantic-tokens'.setup({
  preset = "default"
})

You might want to do a feature tests when you plan to add the snippet above to your config:

if pcall(require, "vim.lsp.nvim-semantic-tokens") then
  require("nvim-semantic-tokens").setup {
    preset = "default"
    -- highlighters is a list of modules following the interface of nvim-semantic-tokens.table-highlighter or 
    -- function with the signature: highlight_token(ctx, token, highlight) where 
    --        ctx (as defined in :h lsp-handler)
    --        token  (as defined in :h vim.lsp.semantic_tokens.on_full())
    --        highlight (a helper function that you can call (also multiple times) with the determined highlight group(s) as the only parameter)
    highlighters = { require 'nvim-semantic-tokens.table-highlighter'}
  }
end

Preset configurations are loaded from ./lua/nvim-semantic-tokens/presets. The "default" preset will set the highlight groups described in ./doc/nvim-semantic-tokens.txt.

Use an autocommand for a filetype for which you have a language server set up that supports semantic tokens (e.g. clangd)

if &filetype == "cpp" || &filetype == "cuda" || &filetype == "c"
  autocmd BufEnter,CursorHold,InsertLeave <buffer> lua require 'vim.lsp.buf'.semantic_tokens_full()
endif

or inside an on_attach call to a LSP client

local on_attach = function(client, bufnr)
    if client.resolved_capabilities.semantic_tokens_full then
        vim.cmd [[autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.buf.semantic_tokens_full()]]
    end
    --...
end

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.