Skip to content

Commit

Permalink
feat(diagnostic): add target to diagnosticInfo (#4642)
Browse files Browse the repository at this point in the history
closes #4633
  • Loading branch information
fannheyward authored Aug 31, 2023
1 parent e4ffae5 commit 5571414
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/modules/diagnosticBuffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('diagnostic buffer', () => {
helper.updateConfiguration('diagnostic.messageTarget', 'echo')
let buf = await createDiagnosticBuffer()
let diagnostics = [createDiagnostic('foo')]
let res = await buf.showFloat(diagnostics)
let res = await buf.showFloat(diagnostics, 'echo')
expect(res).toBe(false)
})

Expand Down
9 changes: 5 additions & 4 deletions src/diagnostic/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,11 @@ export class DiagnosticBuffer implements SyncItem {
/**
* Echo diagnostic message under cursor.
*/
public async echoMessage(truncate = false, position: Position): Promise<boolean> {
public async echoMessage(truncate = false, position: Position, target?: string): Promise<boolean> {
const config = this.config
if (!config.enable || config.enableMessage === 'never' || config.displayByAle) return false
let useFloat = config.messageTarget == 'float'
if (!target) target = config.messageTarget
let useFloat = target == 'float'
let diagnostics = this.getDiagnosticsAtPosition(position)
if (config.messageLevel) {
diagnostics = diagnostics.filter(diagnostic => {
Expand Down Expand Up @@ -316,8 +317,8 @@ export class DiagnosticBuffer implements SyncItem {
return true
}

public async showFloat(diagnostics: Diagnostic[]): Promise<boolean> {
if (this.config.messageTarget !== 'float') return false
public async showFloat(diagnostics: Diagnostic[], target = 'float'): Promise<boolean> {
if (target !== 'float') return false
if (!floatFactory) floatFactory = window.createFloatFactory({ modes: ['n'], autoHide: true })
if (diagnostics.length == 0) {
floatFactory.close()
Expand Down
4 changes: 2 additions & 2 deletions src/diagnostic/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,11 @@ class DiagnosticManager implements Disposable {
return res[0].getDiagnosticsAtPosition(res[1])
}

public async echoCurrentMessage(): Promise<void> {
public async echoCurrentMessage(target?: string): Promise<void> {
let res = await this.getBufferAndPosition()
if (!res) return
let [item, position] = res
await item.echoMessage(false, position)
await item.echoMessage(false, position, target)
}

public async jumpRelated(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class Plugin {
this.addAction('refreshSource', name => sources.refresh(name))
this.addAction('toggleSource', name => sources.toggleSource(name))
this.addAction('diagnosticRefresh', bufnr => diagnosticManager.refresh(bufnr))
this.addAction('diagnosticInfo', () => diagnosticManager.echoCurrentMessage())
this.addAction('diagnosticInfo', target => diagnosticManager.echoCurrentMessage(target))
this.addAction('diagnosticToggle', enable => diagnosticManager.toggleDiagnostic(enable))
this.addAction('diagnosticToggleBuffer', (bufnr, enable) => diagnosticManager.toggleDiagnosticBuffer(bufnr, enable))
this.addAction('diagnosticNext', severity => diagnosticManager.jumpNext(severity))
Expand Down

0 comments on commit 5571414

Please sign in to comment.