Skip to content

Commit

Permalink
feat(semanticTokens)!: token highlight groups
Browse files Browse the repository at this point in the history
CocSemType + type
CocSemTypeMod + type + modifier
  • Loading branch information
fannheyward committed Nov 10, 2023
1 parent eb06300 commit 6f02963
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
2 changes: 0 additions & 2 deletions doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
<

Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion history.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin/coc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/handler/semanticTokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: CocSemTypeModFunctionDeclaration')
await window.moveTo({ line: 1, character: 0 })
await commandManager.executeCommand('semanticTokens.inspect')
win = await helper.getFloat()
Expand Down
33 changes: 11 additions & 22 deletions src/handler/semanticTokens/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,39 +232,28 @@ 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
let combine = false
let hlGroup: string

if (tokenModifiers.length) {
// only use first modifier to avoid highlight flicking
const modifier = tokenModifiers[0]
combine = combinedModifiers.includes(modifier)
hlGroup = HLGROUP_PREFIX + 'TypeMod' + toHighlightPart(tokenType) + toHighlightPart(modifier)
} else {
hlGroup = HLGROUP_PREFIX + 'Type' + toHighlightPart(tokenType)
}

highlights.push({
range,
tokenType,
combine,
hlGroup: HLGROUP_PREFIX + 'Type' + toHighlightPart(tokenType),
hlGroup,
tokenModifiers,
})

for (let modifier of tokenModifiers) {
combine = combinedModifiers.includes(modifier)

highlights.push({
range,
tokenType,
combine,
hlGroup: HLGROUP_PREFIX + 'Mode' + toHighlightPart(modifier),
tokenModifiers,
})

highlights.push({
range,
tokenType,
combine,
hlGroup: HLGROUP_PREFIX + 'TypeMod' + toHighlightPart(tokenType) + toHighlightPart(modifier),
tokenModifiers,
})
}
}

private toHighlightItems(highlights: ReadonlyArray<SemanticTokenRange>, startLine?: number, endLine?: number): HighlightItem[] {
Expand Down

0 comments on commit 6f02963

Please sign in to comment.