Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(codeLens): add codeLens.display #5129

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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