forked from Dart-Code/Dart-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dart_diagnostic_provider.ts
49 lines (42 loc) · 1.49 KB
/
dart_diagnostic_provider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"use strict";
import { DiagnosticCollection, Diagnostic, DiagnosticSeverity, Uri, Range, Position } from "vscode";
import { Analyzer } from "./analyzer";
import * as as from "./analysis_server_types";
export class DartDiagnosticProvider {
private analyzer: Analyzer;
private diagnostics: DiagnosticCollection;
constructor(analyzer: Analyzer, diagnostics: DiagnosticCollection) {
this.analyzer = analyzer;
this.diagnostics = diagnostics;
this.analyzer.registerForAnalysisErrors(es => this.handleErrors(es));
}
private handleErrors(notification: as.AnalysisErrorsNotification) {
this.diagnostics.set(
Uri.file(notification.file),
notification.errors.map(e => this.createDiagnostic(e))
);
}
private createDiagnostic(error: as.AnalysisError): Diagnostic {
let startPos = new Position(error.location.startLine - 1, error.location.startColumn - 1); // TODO: Abstract this out; esp as G are 1-based, MS 0-based!
let endPos = startPos.translate(0, error.location.length);
return {
code: error.code,
message: error.message,
range: new Range(startPos, endPos),
severity: this.getSeverity(error.severity),
source: error.type
};
}
private getSeverity(severity: as.AnalysisErrorSeverity): DiagnosticSeverity {
switch (severity) {
case "ERROR":
return DiagnosticSeverity.Error;
case "WARNING":
return DiagnosticSeverity.Warning;
case "INFO":
return DiagnosticSeverity.Information;
default:
throw new Error("Unknown severity type: " + severity);
}
}
}