fix range of configFile diagnostics

This commit is contained in:
Qiming Zhao 2020-04-17 20:04:36 +08:00
parent fe05e038d5
commit 3a87cacccc

View file

@ -61,16 +61,21 @@ export default class TypeScriptServiceClientHost implements Disposable {
if (body) {
let { configFile, diagnostics } = body
let uri = Uri.file(configFile)
let language = this.findLanguage(uri)
if (!language) return
if (diagnostics.length == 0) {
this.client.diagnosticsManager.configFileDiagnosticsReceived(uri.toString(), [])
} else {
let range = Range.create(Position.create(0, 0), Position.create(0, 1))
let { text, code, category } = diagnostics[0]
let diagnosticList = diagnostics.map(o => {
let { text, code, category, start, end } = o
let range: Range
if (!start || !end) {
range = Range.create(Position.create(0, 0), Position.create(0, 1))
} else {
range = Range.create(start.line - 1, start.offset - 1, end.line - 1, end.offset - 1)
}
let severity = category == 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning
let diagnostic = Diagnostic.create(range, text, severity, code)
this.client.diagnosticsManager.configFileDiagnosticsReceived(uri.toString(), [diagnostic])
return Diagnostic.create(range, text, severity, code)
})
this.client.diagnosticsManager.configFileDiagnosticsReceived(uri.toString(), diagnosticList)
}
}
}, null, this.disposables)