Skip to content

Commit

Permalink
feat(codeLens): add codeLens.display (#5129)
Browse files Browse the repository at this point in the history
Closes #5110
  • Loading branch information
fannheyward authored Aug 28, 2024
1 parent 704295e commit 0e6a8c7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,12 @@
"description": "Enable codeLens feature, require neovim with set virtual text feature.",
"default": false
},
"codeLens.display": {
"type": "boolean",
"scope": "language-overridable",
"default": true,
"description": "Display codeLens."
},
"codeLens.position": {
"type": "string",
"scope": "language-overridable",
Expand Down
6 changes: 6 additions & 0 deletions doc/coc-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ CodeLens~

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

"codeLens.display" *coc-config-codeLens-display*

Display codeLens. Toggle with :CocCommand document.toggleCodeLens

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

"codeLens.position" *coc-config-codeLens-position*

Position of codeLens, requires nvim >= 0.6.0.
Expand Down
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2024-08-28

- Add configuration `codeLens.display`

# 2024-08-20

- Add `CocAction('removeWorkspaceFolder')`.
Expand Down
12 changes: 7 additions & 5 deletions src/handler/codelens/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface CodeLensInfo {
export interface CodeLensConfig {
position: 'top' | 'eol' | 'right_align'
enabled: boolean
display: boolean
separator: string
subseparator: string
}
Expand All @@ -49,7 +50,6 @@ export default class CodeLensBuffer implements SyncItem {
private tokenSource: CancellationTokenSource
private resolveTokenSource: CancellationTokenSource
private _config: CodeLensConfig | undefined
private display = true
public resolveCodeLens: (() => void) & { clear(): void }
public debounceFetch: (() => void) & { clear(): void }
constructor(
Expand All @@ -75,18 +75,20 @@ export default class CodeLensBuffer implements SyncItem {
let config = workspace.getConfiguration('codeLens', this.document)
this._config = {
enabled: config.get<boolean>('enable', false),
display: config.get<boolean>('display', true),
position: config.get<'top' | 'eol' | 'right_align'>('position', 'top'),
separator: config.get<string>('separator', ''),
subseparator: config.get<string>('subseparator', ' ')
}
}

public async toggleDisplay(): Promise<void> {
if (this.display) {
this.display = false
if (!this.hasProvider || !this.config.enabled) return
if (this.config.display) {
this.config.display = false
this.clear()
} else {
this.display = true
this.config.display = true
this.resolveCodeLens.clear()
await this._resolveCodeLenses()
}
Expand Down Expand Up @@ -191,7 +193,7 @@ export default class CodeLensBuffer implements SyncItem {
*/
private setVirtualText(codeLenses: CodeLens[]): void {
let { document } = this
if (!srcId || !document || !codeLenses.length || !this.display) return
if (!srcId || !document || !codeLenses.length || !this.config.display) return
let top = this.config.position === 'top'
let list: Map<number, CodeLens[]> = new Map()
for (let codeLens of codeLenses) {
Expand Down

0 comments on commit 0e6a8c7

Please sign in to comment.