From 72531dea408fc321d78e93250781077be6537ff3 Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Fri, 10 Nov 2023 14:34:53 +0800 Subject: [PATCH] feat(semanticTokens)!: token highlight groups CocSemType + type CocSemTypeMod + type + modifier --- doc/coc.txt | 2 -- history.md | 1 - plugin/coc.vim | 2 +- src/__tests__/handler/semanticTokens.test.ts | 2 +- src/handler/semanticTokens/buffer.ts | 16 ++++------------ 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/doc/coc.txt b/doc/coc.txt index 29fd935493a..a8f890ecc63 100644 --- a/doc/coc.txt +++ b/doc/coc.txt @@ -3353,7 +3353,6 @@ disable creation of these highlight groups. The highlight groups rules: > `CocSemType + type` for types -`CocSemMod + modifier` for modifiers `CocSemTypeMode + type + modifier` for modifier with type < @@ -3364,7 +3363,6 @@ You need create highlight groups for highlight other modifiers and/or specific modifier with type, for example: > " Add highlights for declaration modifier - hi link CocSemModDeclaration Declaration hi link CocSemTypeModClassDeclaration ClassDeclaration < The modifier highlight groups have higher priority. diff --git a/history.md b/history.md index 3f3284556f1..1f129365830 100644 --- a/history.md +++ b/history.md @@ -2,7 +2,6 @@ - Break change: semanticTokens highlight groups changed: - `CocSem + type` to `CocSemType + type` - - `CocSem + modifier` to `CocSemMod + modifier` - `CocSem + modifier + type` to `CocSemTypeMod + type + modifier` # 2023-09-02 diff --git a/plugin/coc.vim b/plugin/coc.vim index 97e57db50f9..8317a99e039 100644 --- a/plugin/coc.vim +++ b/plugin/coc.vim @@ -588,7 +588,7 @@ function! s:Highlight() abort \ 'TypeDecorator': ['@symbol', 'Identifier'], \ 'ModDeprecated': ['@text.strike', 'CocDeprecatedHighlight'] \ } - " TODO: add CocSemModXXX and CocSemTypeModeXXX + " TODO: add CocSemTypeModeXXX for [key, value] in items(hlMap) let ts = get(value, 0, '') let fallback = get(value, 1, '') diff --git a/src/__tests__/handler/semanticTokens.test.ts b/src/__tests__/handler/semanticTokens.test.ts index 7bd2487c57c..d80f98404eb 100644 --- a/src/__tests__/handler/semanticTokens.test.ts +++ b/src/__tests__/handler/semanticTokens.test.ts @@ -338,7 +338,7 @@ describe('semanticTokens', () => { let buf = await win.buffer let lines = await buf.lines let content = lines.join('\n') - expect(content).toMatch('CocSemTypeFunction') + expect(content).toMatch('Type: function\nModifiers: declaration\nHighlight group: CocSemTypeFunction') await window.moveTo({ line: 1, character: 0 }) await commandManager.executeCommand('semanticTokens.inspect') win = await helper.getFloat() diff --git a/src/handler/semanticTokens/buffer.ts b/src/handler/semanticTokens/buffer.ts index 79ae30d4c99..81a77f8769c 100644 --- a/src/handler/semanticTokens/buffer.ts +++ b/src/handler/semanticTokens/buffer.ts @@ -232,7 +232,6 @@ export default class SemanticTokensBuffer implements SyncItem { private addHighlightItems(highlights: SemanticTokenRange[], range: [number, number, number], tokenType: string, tokenModifiers: string[]): void { // highlight groups: // CocSem + Type + type - // CocSem + Mod + modifier // CocSem + TypeMod + type + modifier let { combinedModifiers } = this.config @@ -246,21 +245,14 @@ export default class SemanticTokensBuffer implements SyncItem { tokenModifiers, }) - for (let modifier of tokenModifiers) { + if (tokenModifiers.length) { + // only use first modifier to avoid highlight flicking + const modifier = tokenModifiers[0] combine = combinedModifiers.includes(modifier) - - highlights.push({ - range, - tokenType, - combine, - hlGroup: HLGROUP_PREFIX + 'Mode' + toHighlightPart(modifier), - tokenModifiers, - }) - highlights.push({ range, tokenType, - combine, + combine: combinedModifiers.includes(modifier), hlGroup: HLGROUP_PREFIX + 'TypeMod' + toHighlightPart(tokenType) + toHighlightPart(modifier), tokenModifiers, })