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(inlayHint): add document enable/disable inlayHint commands. #5025

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
22 changes: 16 additions & 6 deletions src/handler/inlayHint/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,26 @@ export default class InlayHintBuffer implements SyncItem {
return enable === true
}

public toggle(): void {
public enable() {
if (!languages.hasProvider(ProviderName.InlayHint, this.doc.textDocument)) throw new Error('Inlay hint provider not found for current document')
if (!this.configEnabled) throw new Error(`Filetype "${this.doc.filetype}" not enabled by inlayHint configuration`)
this.config.display = true
void this.renderRange()
}

public disable() {
if (!languages.hasProvider(ProviderName.InlayHint, this.doc.textDocument)) throw new Error('Inlay hint provider not found for current document')
if (!this.configEnabled) throw new Error(`Filetype "${this.doc.filetype}" not enabled by inlayHint configuration`)
this.config.display = false
this.clearCache()
this.clearVirtualText()
}

public toggle(): void {
if (this.config.display) {
this.config.display = false
this.clearCache()
this.clearVirtualText()
this.disable()
} else {
this.config.display = true
void this.renderRange()
this.enable()
}
}

Expand Down
33 changes: 33 additions & 0 deletions src/handler/inlayHint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,44 @@ export default class InlayHintHandler {
return this.toggle(bufnr ?? workspace.bufnr)
},
}, false, 'toggle codeLens display of current buffer')
commands.register({
id: 'document.enableInlayHint',
execute: (bufnr?: number) => {
return this.enable(bufnr ?? workspace.bufnr)
},
}, false, 'enable codeLens display of current buffer')
commands.register({
id: 'document.disableInlayHint',
execute: (bufnr?: number) => {
return this.disable(bufnr ?? workspace.bufnr)
},
}, false, 'disable codeLens display of current buffer')

handler.addDisposable(Disposable.create(() => {
disposeAll(this.disposables)
}))
}

public enable(bufnr: number): void {
let item = this.getItem(bufnr)
try {
workspace.getAttachedDocument(bufnr)
item.enable()
} catch (e) {
void window.showErrorMessage((e as Error).message)
}
}

public disable(bufnr: number): void {
let item = this.getItem(bufnr)
try {
workspace.getAttachedDocument(bufnr)
item.disable()
} catch (e) {
void window.showErrorMessage((e as Error).message)
}
}

public toggle(bufnr: number): void {
let item = this.getItem(bufnr)
try {
Expand Down