Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public setDiagnosticInfo(bufnr: number, diagnostics: ReadonlyArray): void {
let lnums = [0, 0, 0, 0]
let info = { error: 0, warning: 0, information: 0, hint: 0, lnums }
for (let diagnostic of diagnostics) {
switch (diagnostic.severity) {
case DiagnosticSeverity.Warning:
info.warning = info.warning + 1
lnums[1] = lnums[1] || diagnostic.range.start.line + 1
break
case DiagnosticSeverity.Information:
info.information = info.information + 1
lnums[2] = lnums[2] || diagnostic.range.start.line + 1
break
case DiagnosticSeverity.Hint:
info.hint = info.hint + 1
lnums[3] = lnums[3] || diagnostic.range.start.line + 1
break
default:
lnums[0] = lnums[0] || diagnostic.range.start.line + 1
info.error = info.error + 1
}
}
this.client.onConfigDiagnosticsReceived(diag => {
let { body } = diag
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 severity = category == 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning
let diagnostic = Diagnostic.create(range, text, severity, code)
this.client.diagnosticsManager.configFileDiagnosticsReceived(uri.toString(), [diagnostic])
}
}
}, null, this.disposables)
private getDiagnosticSeverity(diagnostic: Proto.Diagnostic): DiagnosticSeverity {
if (
this.reportStyleCheckAsWarnings &&
this.isStyleCheckDiagnostic(diagnostic.code) &&
diagnostic.category === PConst.DiagnosticCategory.error
) {
return DiagnosticSeverity.Warning
}
switch (diagnostic.category) {
case PConst.DiagnosticCategory.error:
return DiagnosticSeverity.Error
case PConst.DiagnosticCategory.warning:
return DiagnosticSeverity.Warning
case PConst.DiagnosticCategory.suggestion:
return DiagnosticSeverity.Information
default:
return DiagnosticSeverity.Error
}
}
private getDiagnosticSeverity(diagnostic: Proto.Diagnostic): DiagnosticSeverity {
if (
this.reportStyleCheckAsWarnings &&
this.isStyleCheckDiagnostic(diagnostic.code) &&
diagnostic.category === PConst.DiagnosticCategory.error
) {
return DiagnosticSeverity.Warning
}
switch (diagnostic.category) {
case PConst.DiagnosticCategory.error:
return DiagnosticSeverity.Error
case PConst.DiagnosticCategory.warning:
return DiagnosticSeverity.Warning
case PConst.DiagnosticCategory.suggestion:
return DiagnosticSeverity.Information
default:
return DiagnosticSeverity.Error
}
}
diagnostics.forEach(diagnostic => {
let { source, code, severity, message } = diagnostic
let s = getSeverityName(severity)[0]
let str = `[${source}${code ? ' ' + code : ''}] [${s}] ${message}`
let filetype = 'Error'
if (ft === '') {
switch (diagnostic.severity) {
case DiagnosticSeverity.Hint:
filetype = 'Hint'
break
case DiagnosticSeverity.Warning:
filetype = 'Warning'
break
case DiagnosticSeverity.Information:
filetype = 'Info'
break
}
} else {
filetype = ft
}
docs.push({ filetype, content: str })
})
if (useFloat) {
private getDiagnosticSeverity(diagnostic: Proto.Diagnostic): DiagnosticSeverity {
if (
this.reportStyleCheckAsWarnings &&
this.isStyleCheckDiagnostic(diagnostic.code) &&
diagnostic.category === PConst.DiagnosticCategory.error
) {
return DiagnosticSeverity.Warning
}
switch (diagnostic.category) {
case PConst.DiagnosticCategory.error:
return DiagnosticSeverity.Error
case PConst.DiagnosticCategory.warning:
return DiagnosticSeverity.Warning
case PConst.DiagnosticCategory.suggestion:
return DiagnosticSeverity.Information
default:
return DiagnosticSeverity.Error
}
}
private getDiagnosticSeverity(diagnostic: Proto.Diagnostic): DiagnosticSeverity {
if (
this.reportStyleCheckAsWarnings &&
this.isStyleCheckDiagnostic(diagnostic.code) &&
diagnostic.category === PConst.DiagnosticCategory.error
) {
return DiagnosticSeverity.Warning
}
switch (diagnostic.category) {
case PConst.DiagnosticCategory.error:
return DiagnosticSeverity.Error
case PConst.DiagnosticCategory.warning:
return DiagnosticSeverity.Warning
case PConst.DiagnosticCategory.suggestion:
return DiagnosticSeverity.Information
default:
return DiagnosticSeverity.Error
}
}