Skip to content

Commit

Permalink
feat(diagnostic): remove ANSI codes from virtual text (#5077)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexh250786313 authored Jul 8, 2024
1 parent 16dfda7 commit a00ff12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/diagnostic/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Emitter, Event } from '../util/protocol'
import window from '../window'
import workspace from '../workspace'
import { adjustDiagnostics, DiagnosticConfig, formatDiagnostic, getHighlightGroup, getLocationListItem, getNameFromSeverity, getSeverityType, LocationListItem, severityLevel, sortDiagnostics } from './util'
import { stripAnsiColoring } from '../util/ansiparse'
const signGroup = 'CocDiagnostic'
const NAMESPACE = 'diagnostic'
// higher priority first
Expand Down Expand Up @@ -515,10 +516,11 @@ export class DiagnosticBuffer implements SyncItem {
.slice(0, this._config.virtualTextLines)
.join(this._config.virtualTextLineSeparator)
let arr = map.get(line) ?? []
arr.unshift([virtualTextPrefix + formatDiagnostic(this._config.virtualTextFormat, {
const formattedDiagnostic = formatDiagnostic(this._config.virtualTextFormat, {
...diagnostic,
message: msg
}), highlight])
})
arr.unshift([virtualTextPrefix + stripAnsiColoring(formattedDiagnostic), highlight])
map.set(line, arr)
}
for (let [line, blocks] of map.entries()) {
Expand Down
6 changes: 6 additions & 0 deletions src/util/ansiparse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,9 @@ export function ansiparse(str: string): AnsiItem[] {
}
return result
}

export function stripAnsiColoring(str?: string): string {
// eslint-disable-next-line
const ansiColorCodeRegex = /\u001b\[[0-9;]*m/g
return str.replace(ansiColorCodeRegex, '')
}

0 comments on commit a00ff12

Please sign in to comment.