-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathConvert.java
More file actions
92 lines (79 loc) · 2.75 KB
/
Convert.java
File metadata and controls
92 lines (79 loc) · 2.75 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package de.peeeq.wurstio.languageserver;
import de.peeeq.wurstscript.ast.Element;
import de.peeeq.wurstscript.attributes.CompileError;
import de.peeeq.wurstscript.parser.WPos;
import org.eclipse.lsp4j.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
*
*/
public class Convert {
public static Location posToLocation(WPos pos) {
String file = WFile.create(pos.getFile()).getUriString();
return new Location(file, posToRange(pos));
}
public static Range posToRange(WPos pos) {
int line = pos.getLine() - 1;
int column = pos.getStartColumn() - 1;
int endLine = pos.getEndLine() - 1;
int endColumn = pos.getEndColumn() - 1;
if (line < 0) {
line = 0;
}
if (endLine < line) {
endLine = line;
}
if (column < 0) {
column = 0;
}
if (endColumn < 0) {
endColumn = 0;
}
if (line == endLine && endColumn <= column) {
endColumn = column + 1;
}
return new Range(
new Position(line, column),
new Position(endLine, endColumn)
);
}
public static Location location(Element e) {
return posToLocation(e.attrSource());
}
public static Location errorLocation(Element e) {
return posToLocation(e.attrErrorPos());
}
public static Range range(Element e) {
return posToRange(e.attrSource());
}
public static Range errorRange(Element e) {
return posToRange(e.attrErrorPos());
}
public static PublishDiagnosticsParams createDiagnostics(String extra, WFile filename, List<CompileError> errors) {
List<Diagnostic> diagnostics = new ArrayList<>();
for (CompileError err : errors) {
Range range = posToLocation(err.getSource()).getRange();
String message = err.getMessage();
DiagnosticSeverity severity;
switch (err.getErrorType()) {
case WARNING:
severity = DiagnosticSeverity.Warning;
break;
case ERROR:
default:
severity = DiagnosticSeverity.Error;
break;
}
Diagnostic diagnostic = new Diagnostic(range, message, severity, "Wurst");
diagnostic.setCode("WURST_" + err.getErrorType().name());
String messageLower = message.toLowerCase();
if (messageLower.contains("deprecated")) {
diagnostic.setTags(Collections.singletonList(DiagnosticTag.Deprecated));
}
diagnostics.add(diagnostic);
}
return new PublishDiagnosticsParams(filename.getUriString(), diagnostics);
}
}