diff --git a/src/diagnostic/buffer.ts b/src/diagnostic/buffer.ts index 1f4e47e2216..2d439e38cec 100644 --- a/src/diagnostic/buffer.ts +++ b/src/diagnostic/buffer.ts @@ -4,7 +4,7 @@ import { Diagnostic, DiagnosticSeverity, Position, TextEdit } from 'vscode-langu import events from '../events' import { SyncItem } from '../model/bufferSync' import Document from '../model/document' -import { DidChangeTextDocumentParams, Documentation, FloatFactory, HighlightItem } from '../types' +import { DiagnosticWithFileType, DidChangeTextDocumentParams, Documentation, FloatFactory, HighlightItem } from '../types' import { getConditionValue } from '../util' import { isFalsyOrEmpty } from '../util/array' import { lineInRange, positionInRange } from '../util/position' @@ -317,7 +317,7 @@ export class DiagnosticBuffer implements SyncItem { return true } - public async showFloat(diagnostics: Diagnostic[], target = 'float'): Promise { + public async showFloat(diagnostics: DiagnosticWithFileType[], target = 'float'): Promise { if (target !== 'float') return false if (!floatFactory) floatFactory = window.createFloatFactory({ modes: ['n'], autoHide: true }) if (diagnostics.length == 0) { @@ -335,7 +335,9 @@ export class DiagnosticBuffer implements SyncItem { } diagnostics.forEach(diagnostic => { let filetype = 'Error' - if (ft === '') { + if (diagnostic.filetype) { + filetype = diagnostic.filetype + } else if (ft === '') { switch (diagnostic.severity) { case DiagnosticSeverity.Hint: filetype = 'Hint' diff --git a/src/types.ts b/src/types.ts index c174de03858..7b4ad3eaac5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ 'use strict' import type { Window } from '@chemzqm/neovim' import type { Disposable, Event } from 'vscode-languageserver-protocol' -import type { CreateFile, DeleteFile, Location, Range, RenameFile, TextDocumentEdit } from 'vscode-languageserver-types' +import type { CreateFile, DeleteFile, Diagnostic, Location, Range, RenameFile, TextDocumentEdit } from 'vscode-languageserver-types' import type { URI } from 'vscode-uri' import type RelativePattern from './model/relativePattern' @@ -348,3 +348,12 @@ export interface DidChangeTextDocumentParams { readonly originalLines: ReadonlyArray } // }} + +export interface DiagnosticWithFileType extends Diagnostic { + /** + * The `filetype` property provides the type of file associated with the diagnostic information. + * This information is utilized by the diagnostic buffer panel for highlighting and formatting + * the diagnostic messages according to the specific filetype. + */ + filetype?: string; +}