forked from ChelseaKR/tods-validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.ts
More file actions
79 lines (69 loc) · 2.29 KB
/
Copy pathextension.ts
File metadata and controls
79 lines (69 loc) · 2.29 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
// VS Code client for the tods-validate language server.
//
// It launches `tods-validate-lsp` (from the Python package's [lsp] extra) over
// stdio and points it at the TODS files in the workspace. The server does the
// real work: it re-validates the whole feed on open and save and returns
// diagnostics, hovers, and quick fixes. This file only wires the two together.
import { commands, workspace, ExtensionContext, Uri, window } from "vscode";
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind,
} from "vscode-languageclient/node";
// The TODS files the server validates; the client only attaches to these.
const TODS_FILENAMES = [
"run_events.txt",
"employee_run_dates.txt",
"vehicles.txt",
"vehicle_assignments.txt",
"trips_supplement.txt",
"stops_supplement.txt",
"stop_times_supplement.txt",
"routes_supplement.txt",
"calendar_supplement.txt",
"calendar_dates_supplement.txt",
];
let client: LanguageClient | undefined;
const SETUP_GUIDE = Uri.parse(
"https://github.com/ChelseaKR/tods-validate/tree/main/editor/vscode#prerequisites",
);
export function activate(context: ExtensionContext): void {
const serverPath = workspace
.getConfiguration("tods-validate")
.get<string>("serverPath", "tods-validate-lsp");
const serverOptions: ServerOptions = {
command: serverPath,
transport: TransportKind.stdio,
};
const clientOptions: LanguageClientOptions = {
documentSelector: TODS_FILENAMES.map((name) => ({
scheme: "file",
pattern: `**/${name}`,
})),
outputChannelName: "TODS Validate",
};
client = new LanguageClient(
"tods-validate",
"TODS Validate",
serverOptions,
clientOptions,
);
client.start().catch((error) => {
void window
.showErrorMessage(
`TODS Validate could not start '${serverPath}'. Install it with ` +
`"pipx install 'tods-validate[lsp]'" and set tods-validate.serverPath ` +
`to the executable's full path if it is not on your PATH. (${error})`,
"Open setup guide",
)
.then((selection) => {
if (selection === "Open setup guide") {
void commands.executeCommand("vscode.open", SETUP_GUIDE);
}
});
});
}
export function deactivate(): Thenable<void> | undefined {
return client?.stop();
}