Skip to content

Commit

Permalink
chore(symbols): add config setting for current function debounce time…
Browse files Browse the repository at this point in the history
… and fix docs (#4758)
  • Loading branch information
3ximus authored Sep 29, 2023
1 parent 6cde3a2 commit 4992180
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
8 changes: 7 additions & 1 deletion data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,15 @@
"coc.preferences.currentFunctionSymbolAutoUpdate": {
"type": "boolean",
"scope": "language-overridable",
"description": "Automatically update the value of b:coc_current_function on CursorHold event",
"description": "Automatically update the value of b:coc_current_function on CursorMove event",
"default": false
},
"coc.preferences.currentFunctionSymbolDebounceTime": {
"type": "number",
"scope": "language-overridable",
"description": "Set debounce timer for the update of b:coc_current_function on CursorMove event",
"default": 300
},
"coc.preferences.enableLinkedEditing": {
"type": "boolean",
"scope": "language-overridable",
Expand Down
9 changes: 8 additions & 1 deletion doc/coc-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1520,11 +1520,18 @@ Preferences~

"coc.preferences.currentFunctionSymbolAutoUpdate" *coc-preferences-currentFunctionSymbolAutoUpdate*

Automatically update the value of b:coc_current_function on CursorHold
Automatically update the value of b:coc_current_function on CursorMove
event

Scope: `language-overridable`, default: `false`

"coc.preferences.currentFunctionSymbolDebounceTime" *coc-preferences-currentFunctionSymbolDebounceTime*

Set debounce timer for the update of b:coc_current_function on CursorMove
event

Scope: `language-overridable`, default: `300`

"coc.preferences.enableLinkedEditing" *coc-preferences-enableLinkedEditing*

Enable linked editing support.
Expand Down
3 changes: 2 additions & 1 deletion doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,8 @@ b:coc_current_function *b:coc_current_function*
Function string that current cursor in.

Enable |coc-preferences-currentFunctionSymbolAutoUpdate| to update the
value on CursorHold.
value on CursorMove and use |coc-preferences-currentFunctionSymbolDebounceTime|
to set the time to debounce the event.

b:coc_cursors_activated *b:coc_cursors_activated*

Expand Down
9 changes: 6 additions & 3 deletions src/handler/symbols/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import SymbolsBuffer from './buffer'
import Outline from './outline'
import { convertSymbols, SymbolInfo } from './util'

const CURSORMOVE_DEBOUNCE = getConditionValue(300, 0)

export default class Symbols {
private buffers: BufferSync<SymbolsBuffer>
private disposables: Disposable[] = []
Expand Down Expand Up @@ -48,7 +46,7 @@ export default class Symbols {
let buffer = nvim.createBuffer(bufnr)
buffer.setVar('coc_current_function', func ?? '', true)
this.nvim.call('coc#util#do_autocmd', ['CocStatusChange'], true)
}, CURSORMOVE_DEBOUNCE)
}, this.debounceTime())
events.on('CursorMoved', debounced, this, this.disposables)
this.disposables.push(Disposable.create(() => {
debounced.clear()
Expand All @@ -65,6 +63,11 @@ export default class Symbols {
return config.get<boolean>('currentFunctionSymbolAutoUpdate', false)
}

public debounceTime(): number {
let config = workspace.getConfiguration('coc.preferences')
return getConditionValue(config.get<number>('currentFunctionSymbolDebounceTime', 300), 0)
}

public get labels(): { [key: string]: string } {
return workspace.getConfiguration('suggest').get<any>('completionItemKindLabels', {})
}
Expand Down

0 comments on commit 4992180

Please sign in to comment.