-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathvala.js
More file actions
61 lines (52 loc) · 1.49 KB
/
vala.js
File metadata and controls
61 lines (52 loc) · 1.49 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
import Gio from "gi://Gio";
import { isValaAvailable } from "../../Extensions/Extensions.js";
import { createLSPClient } from "../../common.js";
import { getLanguage, copy } from "../../util.js";
export function setup({ document }) {
if (!isValaAvailable()) return;
const { file, buffer, code_view } = document;
// VLS needs the project to be already setup once it starts,
// otherwise it won't pick it up later.
setupValaProject(file.get_parent()).catch(console.error);
const lspc = createLSPClient({
lang: getLanguage("vala"),
root_uri: file.get_parent().get_uri(),
quiet: true,
});
lspc.buffer = buffer;
lspc.uri = file.get_uri();
lspc.connect(
"notification::textDocument/publishDiagnostics",
(_self, params) => {
if (params.uri !== file.get_uri()) {
return;
}
code_view.handleDiagnostics(params.diagnostics);
},
);
lspc.start().catch(console.error);
buffer.connect("modified-changed", () => {
if (!buffer.get_modified()) return;
lspc.didChange().catch(console.error);
});
return lspc;
}
const vala_template_dir = Gio.File.new_for_path(
pkg.pkgdatadir,
).resolve_relative_path("langs/vala/template");
export async function setupValaProject(destination) {
return Promise.all([
copy(
"meson.build",
vala_template_dir,
destination,
Gio.FileCopyFlags.OVERWRITE,
),
copy(
"workbench.vala",
vala_template_dir,
destination,
Gio.FileCopyFlags.OVERWRITE,
),
]);
}