Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ee2103a
feat(semanticTokens): use tree-sitter hi group
fannheyward Jan 19, 2022
f9b8d3d
feat: add coc.preferences.semanticTokensFiletypes
fannheyward Jan 18, 2022
13792a8
feat: enable semanticTokens for test
fannheyward Sep 6, 2021
33a6c17
chore: improve docs
fannheyward Sep 7, 2021
d39230d
feat: rm coc_default_semantic_highlight_groups
fannheyward Sep 7, 2021
67c511c
chore(doc): doc for enable for all filetypes
fannheyward Sep 8, 2021
caf6525
chore(docs): improve docs
fannheyward Sep 8, 2021
10c4177
fix(handler): load config semanticTokensFiletypes
fannheyward Jan 19, 2022
9a876c2
test(handler): improve semanticTokens tests
fannheyward Sep 8, 2021
594b8c5
fix: glob pattern for semanticTokensFiletypes
fannheyward Jan 19, 2022
c72774a
fix(semanticTokensHighlights): tokenModifiers
fannheyward Jan 19, 2022
3ab8d7e
fix(language-client): semanticTokens register
fannheyward Jan 18, 2022
d946099
docs: semanticTokensFiletypes
fannheyward Jan 18, 2022
3113331
fix: semanticTokens.test.ts
fannheyward Jan 20, 2022
f6982b0
feat: semanticTokens.filetypes
fannheyward Jan 20, 2022
c5251c2
feat: link CocSem to TS highlight group
fannheyward Jan 21, 2022
a7d8617
fix(plugin): chekc if TS* highlight group exists
chemzqm Jan 21, 2022
1abe162
refactor(semanticTokens): fix token type check
chemzqm Jan 21, 2022
3e0eb26
Merge remote-tracking branch 'origin/master' into feat/use-ts-hi-group
chemzqm Jan 21, 2022
b295d56
feat(semanticTokens): add more configurations
chemzqm Jan 21, 2022
b66c17c
feat(semanticTokens): add semanticTokens.refreshCurrent command
chemzqm Jan 21, 2022
6b8acf0
feat(semanticTokens): support composed highlight group
chemzqm Jan 21, 2022
198aece
feat(semanticTokens): support inspect current token
chemzqm Jan 21, 2022
da29d88
refactor(semanticTokens): always semanticTokens feature
chemzqm Jan 21, 2022
cdc79bf
chore(semanticTokens): more tests
chemzqm Jan 21, 2022
1e2c64c
fix(semanticTokens): avoid test failure
chemzqm Jan 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion autoload/coc/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let s:root = expand('<sfile>:h:h:h')
let s:is_win = has('win32') || has('win64')
let s:is_vim = !has('nvim')
let s:clear_match_by_id = has('nvim-0.5.0') || has('patch-8.1.1084')
let s:vim_api_version = 14
let s:vim_api_version = 15
let s:activate = ""
let s:quit = ""

Expand All @@ -23,6 +23,12 @@ function! coc#util#api_version() abort
return s:vim_api_version
endfunction

function! coc#util#semantic_hlgroups() abort
let res = split(execute('hi'), "\n")
let filtered = filter(res, "v:val =~# '^CocSem'")
return map(filtered, "matchstr(v:val,'\\v^CocSem\\w+')")
endfunction

" get cursor position
function! coc#util#cursor()
return [line('.') - 1, strchars(strpart(getline('.'), 0, col('.') - 1))]
Expand Down Expand Up @@ -555,6 +561,7 @@ function! coc#util#vim_info()
\ 'sign': exists('*sign_place') && exists('*sign_unplace'),
\ 'textprop': has('textprop') && has('patch-8.1.1719') && !has('nvim') ? v:true : v:false,
\ 'dialog': has('nvim-0.4.0') || has('patch-8.2.0750') ? v:true : v:false,
\ 'semanticHighlights': coc#util#semantic_hlgroups()
\}
endfunction

Expand Down
41 changes: 34 additions & 7 deletions data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@
"colors.highlightPriority": {
"type": "number",
"description": "Priority for colors highlights, works on vim8 and neovim >= 0.6.0",
"default": 1000
"default": 1000,
"maximum": 4096
},
"diagnostic.enable": {
"type": "boolean",
Expand All @@ -613,7 +614,8 @@
"diagnostic.highlightPriority": {
"type": "number",
"description": "Priority for diagnostic highlights, works on vim8 and neovim >= 0.6.0",
"default": 4096
"default": 4096,
"maximum": 4096
},
"diagnostic.autoRefresh": {
"type": "boolean",
Expand Down Expand Up @@ -1166,6 +1168,36 @@
"default": "<C-p>",
"description": "Key used for jump to previous cursors position."
},
"semanticTokens.filetypes": {
"type": "array",
"description": "Filetypes that enable semanticTokens highlighting or [\"*\"] for any filetype",
"default": [],
"items": {
"type": "string"
}
},
"semanticTokens.highlightPriority": {
"type": "number",
"description": "Priority for semantic tokens highlight.",
"default": 2048,
"maximum": 4096
},
"semanticTokens.incrementTypes": {
"type": "array",
"description": "Semantic token types that should increase highlight when insert at the start and end position of token.",
"default": ["variable", "string"],
"items": {
"type": "string"
}
},
"semanticTokens.combinedModifiers": {
"type": "array",
"description": "Semantic token modifiers that should combine with syntax highlights.",
"default": ["deprecated"],
"items": {
"type": "string"
}
},
"tree.closedIcon": {
"type": "string",
"default": "+",
Expand Down Expand Up @@ -1318,11 +1350,6 @@
"default": "SNIP",
"description": "Text shown in statusline to indicate snippet session is activated."
},
"coc.preferences.semanticTokensHighlights": {
"type": "boolean",
"description": "Enable semanticTokens highlight if language server support it.",
"default": true
},
"coc.preferences.currentFunctionSymbolAutoUpdate": {
"type": "boolean",
"description": "Automatically update the value of b:coc_current_function on CursorHold event",
Expand Down
136 changes: 91 additions & 45 deletions doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ Configuration |coc-configuration|
Completion |coc-completion|
Interface |coc-interface|
Key mappings |coc-key-mappings|
Variables |coc-variables|
Functions |coc-functions|
Commands |coc-commands|
Autocmds |coc-autocmds|
Highlights |coc-highlights|
Variables |coc-variables|
Buffer variables |coc-buffer-variables|
Global variables |coc-global-variables|
Functions |coc-functions|
Commands |coc-commands|
Autocmds |coc-autocmds|
Highlights |coc-highlights|
Tree |coc-tree|
Tree mappings |coc-tree-mappings|
Tree filter |coc-tree-filter|
Expand Down Expand Up @@ -971,19 +973,38 @@ Built-in configurations:~

Will save handler timeout, default: `500`

"coc.preferences.semanticTokensHighlights"~

Enable semanticTokens highlight if language server support it.
Default: `true`

Note: this configuration is expected to change in the future.

"coc.preferences.renameFillCurrent"~

Disable to stop Refactor-Rename float/popup window from populating
with old name in the New Name field.
Default: `true`

*coc-config-semanticTokens*

"semanticTokens.filetypes"~

Filetypes that should enable semantic tokens highlight feature. Use
`["*"]` for all filetypes, default: `[]`

Note: semantic tokens highlight requires nvim >= 0.5.0 and vim >=
8.1.0579 to work.

"semanticTokens.highlightPriority":~

Priority for semantic tokens highlight, default `2048`

"semanticTokens.incrementTypes":~

Semantic token types that should increase highlight when insert at
the start and end position of token.

Default: `['variable', 'string']`

"semanticTokens.combinedModifiers":~

Semantic token modifiers that should combine with syntax highlights.

Default: `['deprecated']`
*coc-config-cursors*

"cursors.cancelKey":~
Expand Down Expand Up @@ -1485,9 +1506,11 @@ Visual mode key-mappings:~
------------------------------------------------------------------------------
VARIABLES *coc-variables*

User defined variables:~

------------------------------------------------------------------------------

User defined variables:~
Buffer variables *coc-buffer-variables*

b:coc_enabled *b:coc_enabled*

Expand All @@ -1497,7 +1520,7 @@ b:coc_enabled *b:coc_enabled*
" Disable file with size > 1MB
autocmd BufAdd * if getfsize(expand('<afile>')) > 1024*1024 |
\ let b:coc_enabled=0 |
\ ndif
\ endif
<
b:coc_root_patterns *b:coc_root_patterns*

Expand Down Expand Up @@ -1541,6 +1564,10 @@ b:coc_additional_keywords *b:coc_additional_keywords*
" Add keyword characters for css
autocmd FileType css let b:coc_additional_keywords = ["-"]

------------------------------------------------------------------------------

Global variables *coc-global-variables*

g:coc_disable_startup_warning *g:coc_disable_startup_warning*

Disable possible warning on startup for old vim/node version.
Expand Down Expand Up @@ -1760,6 +1787,12 @@ g:coc_highlight_maximum_count *g:coc_highlight_maximum_count*
When highlight items exceed maximum count, the highlights will be
grouped and added by using |timer_start| for better user experience.

g:coc_default_semantic_highlight_groups *g:coc_default_semantic_highlight_groups*

Create default semantic highlight groups for |coc-semantic-highlights|

Default: `1`

------------------------------------------------------------------------------

Some variables are provided by coc.nvim.
Expand Down Expand Up @@ -2562,6 +2595,14 @@ Acceptable {action} names for |CocAction()| and |CocActionAsync|.

Show outgoing calls of current function with |coc-tree|.

"semanticHighlight" *CocAction('semanticHighlight')*

Request semantic tokens highlight for current buffer.

"inspectSemanticToken" *CocAction('inspectSemanticToken')*

Inspect semantic token information at cursor position.

------------------------------------------------------------------------------
COMMANDS *coc-commands*

Expand Down Expand Up @@ -2936,38 +2977,43 @@ vim doesn't support change highlight group of cursorline inside popup.
*CocSelectedRange* for highlight ranges of outgoing calls.

Semantic highlights~
*coc-semantic-highlights*

coc.nvim can use semantic tokens from language server to add additional color
information that depends on language specific symbol information.

Semantic tokens highlighting is disabled by default, you can enable it by use
configuration "semanticTokens.filetypes", see |coc-config-semanticTokens| for
details.

CocSem_* *CocSem*
Comment thread
chemzqm marked this conversation as resolved.

Used for words whose semantics are provided by the language server, which
typically analyzes source code more deeply than vim's builtin syntax parser.

Basic defaults are provided for the "standard" token kinds, but any kind
supported by the server can be highlighted by creating the highlight group.

Default (enabled by setting `g:coc_default_semantic_highlight_groups = 1`):
`hi default link CocSem_namespace Identifier`
`hi default link CocSem_type Type`
`hi default link CocSem_class Structure`
`hi default link CocSem_enum Type`
`hi default link CocSem_interface Type`
`hi default link CocSem_struct Structure`
`hi default link CocSem_typeParameter Type`
`hi default link CocSem_parameter Identifier`
`hi default link CocSem_variable Identifier`
`hi default link CocSem_property Identifier`
`hi default link CocSem_enumMember Constant`
`hi default link CocSem_event Identifier`
`hi default link CocSem_function Function`
`hi default link CocSem_method Function`
`hi default link CocSem_macro Macro`
`hi default link CocSem_keyword Keyword`
`hi default link CocSem_modifier StorageClass`
`hi default link CocSem_comment Comment`
`hi default link CocSem_string String`
`hi default link CocSem_number Number`
`hi default link CocSem_regexp Normal`
`hi default link CocSem_operator Operator`
*CocSem*

Semantic highlight groups are starts with 'CocSem' which links to related
|nvim-treesitter| highlight groups when possible and fallback to builtin
highlight groups, use variable |g:coc_default_semantic_highlight_groups| to
disable creation of these highlight groups.

Currently only semantic tokens types and `deprecated` modifier have default
highlight groups. You need create highlight groups for highlight other
modifiers and specific modifier with type, for example:
>
" Add highlights for defaultLibrary modifier
hi link CocSemDefaultLibrary TSOtherDefaultLibrary
hi link CocSemDefaultLibraryClass TSTypeDefaultLibrary
hi link CocSemDefaultLibraryInterface TSTypeDefaultLibrary
hi link CocSemDefaultLibraryEnum TSTypeDefaultLibrary
hi link CocSemDefaultLibraryType TSTypeDefaultLibrary
hi link CocSemDefaultLibraryNamespace TSTypeDefaultLibrary

" Add highlights for declaration modifier
hi link CocSemDeclaration TSOtherDeclaration
hi link CocSemDeclarationClass TSTypeDeclaration
hi link CocSemDeclarationInterface TSTypeDeclaration
hi link CocSemDeclarationEnum TSTypeDeclaration
hi link CocSemDeclarationType TSTypeDeclaration
hi link CocSemDeclarationNamespace TSTypeDeclaration
<
The modifier highlight groups have higher priority.

==============================================================================
TREE SUPPORT *coc-tree*
Expand Down
15 changes: 15 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# 2022-01-21

- Changed semantic token highlight prefix from `CocSem_` to `CocSem`.
- Changed semantic token highlight disabled by default, use configuration
`semanticTokens.filetypes`
- Add configuration `semanticTokens.filetypes`.
- Add configuration `semanticTokens.highlightPriority`.
- Add configuration `semanticTokens.incrementTypes`.
- Add configuration `semanticTokens.combinedModifiers`.
- Add command `semanticTokens.refreshCurrent`.
- Add command `semanticTokens.inspect`.
- Add action `inspectSemanticToken`.
- Rework command `semanticTokens.checkCurrent` to show highlight information.
- Support semantic tokens highlight group composed with type and modifier.

# 2022-01-21

- Add configuration `workspace.ignoredFolders`.
- Add configuration `workspace.workspaceFolderFallbackCwd`.

Expand Down
60 changes: 35 additions & 25 deletions plugin/coc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ function! s:Hi() abort
hi default CocHintSign ctermfg=Blue guifg=#15aabf guibg=NONE
hi default CocSelectedText ctermfg=Red guifg=#fb4934 guibg=NONE
hi default CocCodeLens ctermfg=Gray guifg=#999999 guibg=NONE
hi default CocUnderline cterm=underline gui=underline
hi default CocUnderline term=underline cterm=underline gui=underline
hi default CocBold term=bold cterm=bold gui=bold
hi default CocItalic term=italic cterm=italic gui=italic
if s:is_vim || has('nvim-0.4.0')
hi default CocStrikeThrough cterm=strikethrough gui=strikethrough
hi default CocStrikeThrough term=strikethrough cterm=strikethrough gui=strikethrough
else
hi default CocStrikeThrough guifg=#989898 ctermfg=gray
endif
Expand Down Expand Up @@ -435,29 +435,39 @@ function! s:Hi() abort
endif
call s:AddAnsiGroups()

if get(g:, 'coc_default_semantic_highlight_groups', 0) == 1
hi default link CocSem_namespace Identifier
hi default link CocSem_type Type
hi default link CocSem_class Structure
hi default link CocSem_enum Type
hi default link CocSem_interface Type
hi default link CocSem_struct Structure
hi default link CocSem_typeParameter Type
hi default link CocSem_parameter Identifier
hi default link CocSem_variable Identifier
hi default link CocSem_property Identifier
hi default link CocSem_enumMember Constant
hi default link CocSem_event Identifier
hi default link CocSem_function Function
hi default link CocSem_method Function
hi default link CocSem_macro Macro
hi default link CocSem_keyword Keyword
hi default link CocSem_modifier StorageClass
hi default link CocSem_comment Comment
hi default link CocSem_string String
hi default link CocSem_number Number
hi default link CocSem_regexp Normal
hi default link CocSem_operator Operator
if get(g:, 'coc_default_semantic_highlight_groups', 1)
let hlMap = {
\ 'Namespace': ['TSNamespace', 'Include'],
\ 'Type': ['TSType', 'Type'],
\ 'Class': ['TSConstructor', 'Special'],
\ 'Enum': ['TSEnum', 'Type'],
\ 'Interface': ['TSInterface', 'Type'],
\ 'Struct': ['TSStruct', 'Identifier'],
\ 'TypeParameter': ['TSParameter', 'Identifier'],
\ 'Parameter': ['TSParameter', 'Identifier'],
\ 'Variable': ['TSSymbol', 'Identifier'],
\ 'Property': ['TSProperty', 'Identifier'],
\ 'EnumMember': ['TSEnumMember', 'Constant'],
\ 'Event': ['TSEvent', 'Keyword'],
\ 'Function': ['TSFunction', 'Function'],
\ 'Method': ['TSMethod', 'Function'],
\ 'Macro': ['TSConstMacro', 'Define'],
\ 'Keyword': ['TSKeyword', 'Keyword'],
\ 'Modifier': ['TSModifier', 'StorageClass'],
\ 'Comment': ['TSComment', 'Comment'],
\ 'String': ['TSString', 'String'],
\ 'Number': ['TSNumber', 'Number'],
\ 'Boolean': ['TSBoolean', 'Boolean'],
\ 'Regexp': ['TSStringRegex', 'String'],
\ 'Operator': ['TSOperator', 'Operator'],
\ 'Decorator': ['TSSymbol', 'Identifier'],
\ 'Deprecated': ['TSStrike', 'CocDeprecatedHighlight']
\ }
for [key, value] in items(hlMap)
let ts = get(value, 0, '')
let fallback = get(value, 1, '')
execute 'hi default link CocSem'.key.' '.(hlexists(ts) ? ts : fallback)
endfor
endif
endfunction

Expand Down
Loading