Skip to content

Commit

Permalink
feat(diagnostic): add DiagnosticWithFileType (#4881)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexh250786313 authored Feb 3, 2024
1 parent 392264f commit 9c079ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/diagnostic/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -317,7 +317,7 @@ export class DiagnosticBuffer implements SyncItem {
return true
}

public async showFloat(diagnostics: Diagnostic[], target = 'float'): Promise<boolean> {
public async showFloat(diagnostics: DiagnosticWithFileType[], target = 'float'): Promise<boolean> {
if (target !== 'float') return false
if (!floatFactory) floatFactory = window.createFloatFactory({ modes: ['n'], autoHide: true })
if (diagnostics.length == 0) {
Expand All @@ -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'
Expand Down
11 changes: 10 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -348,3 +348,12 @@ export interface DidChangeTextDocumentParams {
readonly originalLines: ReadonlyArray<string>
}
// }}

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;
}

0 comments on commit 9c079ad

Please sign in to comment.