Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Latest commit

 

History

History
132 lines (104 loc) · 3.98 KB

README.md

File metadata and controls

132 lines (104 loc) · 3.98 KB

nvim-lsp-clangd-highlight

nvim-lsp-clangd-highlight uses Neovim's build- in Language Server Protocol to enable clangd's support for semantic highlighting.

It's a fork of deprecated clangd-nvim plugin. Big thanks to Robert Oleynik! I personally don't find treesitter highlighting to be enough for cpp so I intend to keep this plugin alive.

Left: nvim-lsp-clangd-highlight + nvim-lsp; Right: no plugin

Roadmap

  • Implement basic semantic highlight support
  • Implement highlight groups
  • Enable/Disable semantic highlighting
  • Change highlight color

Features

  • Semantic Highlighting for c,cpp

Requirements

Install

" Required
Plug 'neovim/nvim-lsp'
" Plugin
Plug 'adam-wolski/nvim-lsp-clangd-highlight'

Setup

Add to init file:

lua << EOF
local nvim_lsp_clangd_highlight = require'nvim-lsp-clangd-highlight'

require'lspconfig'.clangd.setup{
    capabilities = {
        textDocument = {
            semanticHighlightingCapabilities = {
                semanticHighlighting = true
            }
        }
    },
    on_init = nvim_lsp_clangd_highlight.on_init
}
EOF

Functions

Enable semantic highlighting

Enabled by default

lua require'nvim-lsp-clangd-highlight'.enable()

Disable semantic highlighting

lua require'nvim-lsp-clangd-highlight'.disable()

Reload current buffer's semantic highlight

lua require'nvim-lsp-clangd-highlight'.reload()

Clear current buffer's semantic highlight

lua require'nvim-lsp-clangd-highlight'.clear_highlight()

Change Colors

  1. Add to init file (init.vim)
augroup ConfigSetup
    autocmd!
    autocmd VimEnter,ColorScheme * runtime syntax/custom_colors.vim
augroup END
  1. Add to neovim config folder syntax/custom_colors.vim-File (on Linux ~/.config/nvim/syntax/custom_colors.vim)
  2. Change Colors by:
hi! default link <clangd-syntax-highlight-group> <vim-syntax-highlight-group>
" Example:
hi! default link ClangdClass Type

Note: :so $VIMRUNTIME/syntax/hitest.vim lists all available syntax highlight groups with colors.

Symbols And Syntax Highlight Groups

Clangd Symbol Highlight Group Default Value
entity.name.function.cpp ClangdFunction Function
entity.name.function.method.cpp ClangdMemberFunction Function
entity.name.function.method.static.cpp ClangdStaticMemberFunction Function
entity.name.function.preprocessor.cpp ClangdPreprocessor Macro
entity.name.namespace.cpp ClangdNamespace Namespace
entity.name.other.dependent.cpp ClangdDependentName Function
entity.name.type.class.cpp ClangdClass Type
entity.name.type.concept.cpp ClangdConcept Type
entity.name.type.dependent.cpp ClangdDependentType Type
entity.name.type.enum.cpp ClangdEnum Type
entity.name.type.typedef.cpp ClangdTypedef Type
entity.name.type.template.cpp ClangdTemplateParameter Type
storage.type.primitive.cpp ClangdPrimitive Type
variable.other.cpp ClangdVariable Variable
variable.other.local.cpp ClangdLocalVariable Variable
variable.parameter.cpp ClangdParameter Variable
variable.other.field.cpp ClangdField Variable
variable.other.static.field.cpp ClangdStaticField Variable
variable.other.enummember.cpp ClangdEnumConstant Constant
meta.disabled ClangdInactiveCode Comment