-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathconvert.ts
More file actions
73 lines (68 loc) · 1.9 KB
/
Copy pathconvert.ts
File metadata and controls
73 lines (68 loc) · 1.9 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
/**
* Pure adapters from the shared `posecode-language` service to LSP wire types.
* Kept separate from the server wiring so they can be unit-tested without a
* running connection.
*/
import {
DiagnosticSeverity,
CompletionItemKind,
MarkupKind,
type Diagnostic,
type CompletionItem,
type Hover,
} from "vscode-languageserver";
import {
getDiagnostics,
getCompletions,
getHover,
type CompletionKind,
} from "posecode-language";
export function toDiagnostics(text: string): Diagnostic[] {
const lines = text.split(/\r?\n/);
return getDiagnostics(text).map((d): Diagnostic => {
const lineText = lines[d.line - 1] ?? "";
return {
range: {
start: { line: d.line - 1, character: 0 },
end: { line: d.line - 1, character: lineText.length },
},
severity:
d.severity === "error"
? DiagnosticSeverity.Error
: DiagnosticSeverity.Warning,
source: "posecode",
message: d.message,
};
});
}
const KIND_MAP: Record<CompletionKind, CompletionItemKind> = {
keyword: CompletionItemKind.Keyword,
kind: CompletionItemKind.TypeParameter,
pose: CompletionItemKind.Constant,
avatar: CompletionItemKind.Constant,
rig: CompletionItemKind.Constant,
easing: CompletionItemKind.Constant,
joint: CompletionItemKind.Variable,
action: CompletionItemKind.Function,
effector: CompletionItemKind.Constant,
};
export function toCompletions(
text: string,
line: number,
character: number,
): CompletionItem[] {
return getCompletions(text, line, character).map((c): CompletionItem => ({
label: c.label,
kind: KIND_MAP[c.kind],
...(c.detail ? { detail: c.detail } : {}),
}));
}
export function toHover(
text: string,
line: number,
character: number,
): Hover | null {
const info = getHover(text, line, character);
if (!info) return null;
return { contents: { kind: MarkupKind.Markdown, value: info.contents } };
}