-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathnode.ts
More file actions
67 lines (59 loc) · 1.96 KB
/
node.ts
File metadata and controls
67 lines (59 loc) · 1.96 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
import * as vscode from 'vscode-languageserver/node';
import { listenEditorSettings, provider as httpFsProvider } from './lib/fileSystemProviders/http';
import { provider as nodeFsProvider } from './lib/fileSystemProviders/node';
import { createServerBase } from './lib/server';
export * from 'vscode-languageserver/node';
export * from './index';
export * from './lib/project/simpleProject';
export * from './lib/project/typescriptProject';
export * from './lib/server';
export function createConnection() {
return vscode.createConnection(vscode.ProposedFeatures.all);
}
export function createServer(connection: vscode.Connection) {
const server = createServerBase(connection, {
timer: {
setImmediate: setImmediate,
},
});
server.fileSystem.install('file', nodeFsProvider);
server.fileSystem.install('http', httpFsProvider);
server.fileSystem.install('https', httpFsProvider);
server.onInitialized(() => listenEditorSettings(server));
return server;
}
export function loadTsdkByPath(tsdk: string, locale: string | undefined) {
locale = locale?.toLowerCase();
// webpack compatibility
const _require: NodeJS.Require = eval('require');
return {
typescript: loadLib(),
diagnosticMessages: loadLocalizedDiagnosticMessages(),
};
function loadLib(): typeof import('typescript') {
for (const name of ['./typescript.js', './tsserverlibrary.js']) {
try {
return _require(_require.resolve(name, { paths: [tsdk] }));
}
catch {}
}
// for bun
for (const name of ['typescript.js', 'tsserverlibrary.js']) {
try {
return _require(tsdk + '/' + name);
}
catch {}
}
throw new Error(`Can't find typescript.js or tsserverlibrary.js in ${JSON.stringify(tsdk)}`);
}
function loadLocalizedDiagnosticMessages(): import('typescript').MapLike<string> | undefined {
if (locale === 'en') {
return;
}
try {
const path = _require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] });
return _require(path);
}
catch {}
}
}