@volar/language-server 1.6.9 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/browser/index.js +57 -62
- package/out/common/cancellationPipe.js +2 -6
- package/out/common/configurationHost.js +7 -2
- package/out/common/documents.d.ts +2 -2
- package/out/common/documents.js +10 -2
- package/out/common/features/customFeatures.js +30 -60
- package/out/common/features/languageFeatures.js +5 -5
- package/out/common/project.d.ts +115 -115
- package/out/common/project.js +150 -248
- package/out/common/server.d.ts +5 -1
- package/out/common/server.js +83 -12
- package/out/common/workspace.d.ts +325 -318
- package/out/common/workspace.js +17 -23
- package/out/common/workspaces.d.ts +400 -393
- package/out/common/workspaces.js +3 -6
- package/out/node/index.js +82 -83
- package/out/protocol.d.ts +5 -5
- package/out/protocol.js +16 -16
- package/out/types.d.ts +13 -44
- package/out/types.js +2 -2
- package/package.json +6 -6
package/out/common/project.js
CHANGED
|
@@ -1,54 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createProject = void 0;
|
|
4
|
-
const
|
|
5
|
-
const path = require("typesafe-path");
|
|
4
|
+
const language_service_1 = require("@volar/language-service");
|
|
5
|
+
const path = require("typesafe-path/posix");
|
|
6
6
|
const vscode = require("vscode-languageserver");
|
|
7
|
-
const vscode_uri_1 = require("vscode-uri");
|
|
8
|
-
const types_1 = require("../types");
|
|
9
7
|
const serverConfig_1 = require("./utils/serverConfig");
|
|
10
8
|
const uriMap_1 = require("./utils/uriMap");
|
|
9
|
+
const typescript_1 = require("@volar/typescript");
|
|
11
10
|
async function createProject(context) {
|
|
12
|
-
const uriToFileName = context.server.runtimeEnv.uriToFileName;
|
|
13
|
-
const fileNameToUri = context.server.runtimeEnv.fileNameToUri;
|
|
14
|
-
const sys = context.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspaces.fileSystemHost
|
|
15
|
-
? {
|
|
16
|
-
args: [],
|
|
17
|
-
newLine: '\n',
|
|
18
|
-
useCaseSensitiveFileNames: false,
|
|
19
|
-
fileExists: () => false,
|
|
20
|
-
readFile: () => undefined,
|
|
21
|
-
readDirectory: () => [],
|
|
22
|
-
getCurrentDirectory: () => '',
|
|
23
|
-
resolvePath: () => '',
|
|
24
|
-
write: () => { },
|
|
25
|
-
writeFile: () => { },
|
|
26
|
-
createDirectory: () => { },
|
|
27
|
-
realpath: path => path,
|
|
28
|
-
directoryExists: () => true,
|
|
29
|
-
exit: () => { },
|
|
30
|
-
getDirectories: () => [],
|
|
31
|
-
getExecutingFilePath: () => '/__fake__.js',
|
|
32
|
-
}
|
|
33
|
-
: context.workspaces.fileSystemHost.getWorkspaceFileSystem(context.project.rootUri);
|
|
34
|
-
let typeRootVersion = 0;
|
|
35
11
|
let projectVersion = 0;
|
|
36
12
|
let projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
|
|
37
13
|
let languageService;
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
14
|
+
const { uriToFileName, fileNameToUri, fs } = context.server.runtimeEnv;
|
|
15
|
+
const env = {
|
|
16
|
+
uriToFileName,
|
|
17
|
+
fileNameToUri,
|
|
18
|
+
fs,
|
|
19
|
+
locale: context.workspaces.initParams.locale,
|
|
20
|
+
rootUri: context.project.rootUri,
|
|
21
|
+
clientCapabilities: context.workspaces.initParams.capabilities,
|
|
22
|
+
getConfiguration: context.server.configurationHost?.getConfiguration,
|
|
23
|
+
onDidChangeConfiguration: context.server.configurationHost?.onDidChangeConfiguration,
|
|
24
|
+
onDidChangeWatchedFiles: context.server.onDidChangeWatchedFiles,
|
|
25
|
+
};
|
|
26
|
+
const fsScriptsCache = (0, uriMap_1.createUriMap)(fileNameToUri);
|
|
27
|
+
const askedFiles = (0, uriMap_1.createUriMap)(fileNameToUri);
|
|
28
|
+
const token = {
|
|
29
|
+
isCancellationRequested() {
|
|
30
|
+
return context.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
|
|
31
|
+
},
|
|
32
|
+
throwIfCancellationRequested() { },
|
|
33
|
+
};
|
|
34
|
+
const languageHost = {
|
|
35
|
+
getProjectVersion: () => projectVersion,
|
|
36
|
+
getScriptFileNames: () => parsedCommandLine.fileNames,
|
|
37
|
+
getScriptVersion: (fileName) => {
|
|
38
|
+
const doc = context.workspaces.documents.data.pathGet(fileName);
|
|
39
|
+
if (doc) {
|
|
40
|
+
return doc.version.toString();
|
|
41
|
+
}
|
|
42
|
+
const fsSnapshot = fsScriptsCache.pathGet(fileName);
|
|
43
|
+
if (fsSnapshot) {
|
|
44
|
+
return fsSnapshot.version.toString();
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
getScriptSnapshot: (fileName) => {
|
|
48
|
+
askedFiles.pathSet(fileName, true);
|
|
49
|
+
const doc = context.workspaces.documents.data.pathGet(fileName);
|
|
50
|
+
if (doc) {
|
|
51
|
+
return doc.getSnapshot();
|
|
52
|
+
}
|
|
53
|
+
const fsSnapshot = fsScriptsCache.pathGet(fileName);
|
|
54
|
+
if (fsSnapshot) {
|
|
55
|
+
return fsSnapshot.snapshot;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
getLanguageId: (fileName) => context.workspaces.documents.data.pathGet(fileName)?.languageId,
|
|
59
|
+
getCancellationToken: () => token,
|
|
60
|
+
getCompilationSettings: () => parsedCommandLine.options,
|
|
61
|
+
getLocalizedDiagnosticMessages: context.workspaces.tsLocalized ? () => context.workspaces.tsLocalized : undefined,
|
|
62
|
+
getCurrentDirectory: () => uriToFileName(context.project.rootUri.toString()),
|
|
63
|
+
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
64
|
+
};
|
|
65
|
+
const docChangeWatcher = context.workspaces.documents.onDidChangeContent(() => {
|
|
45
66
|
projectVersion++;
|
|
46
67
|
projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
|
|
47
68
|
});
|
|
69
|
+
const fileWatch = env.onDidChangeWatchedFiles?.(params => {
|
|
70
|
+
onWorkspaceFilesChanged(params.changes);
|
|
71
|
+
});
|
|
72
|
+
let existingOptions;
|
|
73
|
+
for (const plugin of context.workspaces.plugins) {
|
|
74
|
+
if (plugin.resolveExistingOptions) {
|
|
75
|
+
existingOptions = plugin.resolveExistingOptions(existingOptions);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
let parsedCommandLine = await createParsedCommandLine(context.workspaces.ts, env, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins, existingOptions);
|
|
79
|
+
let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.server.runtimeEnv.uriToFileName(context.workspace.rootUri.toString()), context.workspaces.initOptions.configFilePath) : {}) ?? {};
|
|
80
|
+
for (const plugin of context.workspaces.plugins) {
|
|
81
|
+
if (plugin.resolveConfig) {
|
|
82
|
+
config = await plugin.resolveConfig(config, {
|
|
83
|
+
...context,
|
|
84
|
+
env,
|
|
85
|
+
host: languageHost,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
await syncRootScriptSnapshots();
|
|
48
90
|
return {
|
|
91
|
+
context,
|
|
49
92
|
tsConfig: context.project.tsConfig,
|
|
50
|
-
scripts,
|
|
51
|
-
|
|
93
|
+
scripts: fsScriptsCache,
|
|
94
|
+
languageHost,
|
|
52
95
|
getLanguageService,
|
|
53
96
|
getLanguageServiceDontCreate: () => languageService,
|
|
54
97
|
getParsedCommandLine: () => parsedCommandLine,
|
|
@@ -59,199 +102,105 @@ async function createProject(context) {
|
|
|
59
102
|
projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
|
|
60
103
|
}
|
|
61
104
|
},
|
|
105
|
+
askedFiles,
|
|
62
106
|
dispose,
|
|
63
107
|
};
|
|
64
108
|
function getLanguageService() {
|
|
65
109
|
if (!languageService) {
|
|
66
|
-
|
|
67
|
-
uriToFileName,
|
|
68
|
-
fileNameToUri,
|
|
69
|
-
locale: context.workspaces.initParams.locale,
|
|
70
|
-
rootUri: context.project.rootUri,
|
|
71
|
-
clientCapabilities: context.workspaces.initParams.capabilities,
|
|
72
|
-
getConfiguration: context.workspaces.configurationHost?.getConfiguration,
|
|
73
|
-
onDidChangeConfiguration: context.workspaces.configurationHost?.onDidChangeConfiguration,
|
|
74
|
-
fileSystemProvider: context.server.runtimeEnv.fileSystemProvide,
|
|
75
|
-
onDidChangeWatchedFiles: context.workspaces.fileSystemHost?.onDidChangeWatchedFiles,
|
|
76
|
-
documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspaces.ts, languageServiceHost, context.project.rootUri.toString()),
|
|
77
|
-
schemaRequestService: async (uri) => {
|
|
78
|
-
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
79
|
-
const builtInHandler = context.server.runtimeEnv.schemaRequestHandlers[protocol];
|
|
80
|
-
if (builtInHandler) {
|
|
81
|
-
return await builtInHandler(uri) ?? '';
|
|
82
|
-
}
|
|
83
|
-
return '';
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.server.runtimeEnv.uriToFileName(context.workspace.rootUri.toString()), context.workspaces.initOptions.configFilePath) : {}) ?? {};
|
|
87
|
-
for (const plugin of context.workspaces.plugins) {
|
|
88
|
-
if (plugin.resolveConfig) {
|
|
89
|
-
config = plugin.resolveConfig(config, {
|
|
90
|
-
...context,
|
|
91
|
-
env,
|
|
92
|
-
sys,
|
|
93
|
-
host: languageServiceHost,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
languageService = embeddedLS.createLanguageService({ typescript: context.workspaces.ts }, env, config, languageServiceHost, sys, context.project.documentRegistry);
|
|
110
|
+
languageService = (0, language_service_1.createLanguageService)({ typescript: context.workspaces.ts }, env, config, languageHost);
|
|
98
111
|
}
|
|
99
112
|
return languageService;
|
|
100
113
|
}
|
|
101
|
-
async function
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
else {
|
|
110
|
-
script.version--;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
else if (script && change.type === vscode.FileChangeType.Deleted) {
|
|
114
|
-
scripts.uriDelete(change.uri);
|
|
114
|
+
async function syncRootScriptSnapshots() {
|
|
115
|
+
const promises = [];
|
|
116
|
+
let dirty = false;
|
|
117
|
+
for (const fileName of parsedCommandLine.fileNames) {
|
|
118
|
+
const uri = fileNameToUri(fileName);
|
|
119
|
+
if (!fsScriptsCache.uriHas(uri)) {
|
|
120
|
+
dirty = true;
|
|
121
|
+
promises.push(updateRootScriptSnapshot(uri));
|
|
115
122
|
}
|
|
116
|
-
if (script
|
|
117
|
-
|| change.uri.endsWith('.d.ts')
|
|
118
|
-
|| change.uri.endsWith('/package.json')) {
|
|
119
|
-
projectVersion++;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
|
|
123
|
-
const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
|
|
124
|
-
if (creates.length || deletes.length) {
|
|
125
|
-
parsedCommandLine = createParsedCommandLine(context.workspaces.ts, sys, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins);
|
|
126
|
-
projectVersion++;
|
|
127
|
-
typeRootVersion++;
|
|
128
|
-
}
|
|
129
|
-
if (_projectVersion !== projectVersion) {
|
|
130
|
-
projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
|
|
131
123
|
}
|
|
124
|
+
await Promise.all(promises);
|
|
125
|
+
return dirty;
|
|
132
126
|
}
|
|
133
|
-
function
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// ts
|
|
142
|
-
getNewLine: () => sys.newLine,
|
|
143
|
-
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
|
144
|
-
readFile: sys.readFile,
|
|
145
|
-
writeFile: sys.writeFile,
|
|
146
|
-
directoryExists: sys.directoryExists,
|
|
147
|
-
getDirectories: sys.getDirectories,
|
|
148
|
-
readDirectory: sys.readDirectory,
|
|
149
|
-
realpath: sys.realpath,
|
|
150
|
-
fileExists: sys.fileExists,
|
|
151
|
-
getCurrentDirectory: () => uriToFileName(context.project.rootUri.toString()),
|
|
152
|
-
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
153
|
-
getCancellationToken: () => token,
|
|
154
|
-
// custom
|
|
155
|
-
getDefaultLibFileName: options => {
|
|
156
|
-
if (context.workspaces.initOptions.typescript && context.workspaces.ts) {
|
|
157
|
-
try {
|
|
158
|
-
return context.workspaces.ts.getDefaultLibFilePath(options);
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
// web
|
|
162
|
-
const tsdk = context.workspaces.initOptions.typescript.tsdk;
|
|
163
|
-
return tsdk + '/' + context.workspaces.ts.getDefaultLibFileName(options);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return '';
|
|
167
|
-
},
|
|
168
|
-
getProjectVersion: () => projectVersion.toString(),
|
|
169
|
-
getTypeRootsVersion: () => typeRootVersion,
|
|
170
|
-
getScriptFileNames: () => parsedCommandLine.fileNames,
|
|
171
|
-
getCompilationSettings: () => parsedCommandLine.options,
|
|
172
|
-
getScriptVersion,
|
|
173
|
-
getScriptSnapshot,
|
|
174
|
-
getScriptLanguageId: (fileName) => {
|
|
175
|
-
return context.workspaces.documents.data.pathGet(fileName)?.languageId;
|
|
127
|
+
async function updateRootScriptSnapshot(uri) {
|
|
128
|
+
const text = await context.server.runtimeEnv.fs.readFile(uri);
|
|
129
|
+
const oldVersion = fsScriptsCache.uriGet(uri)?.version ?? 0;
|
|
130
|
+
fsScriptsCache.uriSet(uri, text !== undefined ? {
|
|
131
|
+
snapshot: {
|
|
132
|
+
getText: (start, end) => text.substring(start, end),
|
|
133
|
+
getLength: () => text.length,
|
|
134
|
+
getChangeRange: () => undefined,
|
|
176
135
|
},
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
136
|
+
version: oldVersion + 1,
|
|
137
|
+
} : undefined);
|
|
138
|
+
}
|
|
139
|
+
async function onWorkspaceFilesChanged(changes) {
|
|
140
|
+
const oldProjectVersion = projectVersion;
|
|
141
|
+
const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
|
|
142
|
+
if (creates.length) {
|
|
143
|
+
parsedCommandLine = await createParsedCommandLine(context.workspaces.ts, env, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins, existingOptions);
|
|
144
|
+
if (await syncRootScriptSnapshots()) {
|
|
145
|
+
projectVersion++;
|
|
186
146
|
}
|
|
187
|
-
return scripts.pathGet(fileName)?.version.toString() ?? '';
|
|
188
147
|
}
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const script = scripts.pathGet(fileName);
|
|
195
|
-
if (script && script.snapshotVersion === script.version) {
|
|
196
|
-
return script.snapshot;
|
|
197
|
-
}
|
|
198
|
-
if (context.workspaces.ts && sys.fileExists(fileName)) {
|
|
199
|
-
if (context.workspaces.initOptions.maxFileSize) {
|
|
200
|
-
const fileSize = sys.getFileSize?.(fileName);
|
|
201
|
-
if (fileSize !== undefined && fileSize > context.workspaces.initOptions.maxFileSize) {
|
|
202
|
-
console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspaces.initOptions.maxFileSize}bytes)`);
|
|
203
|
-
return context.workspaces.ts.ScriptSnapshot.fromString('');
|
|
204
|
-
}
|
|
148
|
+
for (const change of changes) {
|
|
149
|
+
const oldSnapshot = fsScriptsCache.uriGet(change.uri);
|
|
150
|
+
if (oldSnapshot) {
|
|
151
|
+
if (change.type === vscode.FileChangeType.Changed) {
|
|
152
|
+
updateRootScriptSnapshot(change.uri);
|
|
205
153
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const snapshot = context.workspaces.ts.ScriptSnapshot.fromString(text);
|
|
209
|
-
if (script) {
|
|
210
|
-
script.snapshot = snapshot;
|
|
211
|
-
script.snapshotVersion = script.version;
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
scripts.pathSet(fileName, {
|
|
215
|
-
version: -1,
|
|
216
|
-
fileName: fileName,
|
|
217
|
-
snapshot: snapshot,
|
|
218
|
-
snapshotVersion: -1,
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
return snapshot;
|
|
154
|
+
else if (change.type === vscode.FileChangeType.Deleted) {
|
|
155
|
+
fsScriptsCache.uriSet(change.uri, undefined);
|
|
222
156
|
}
|
|
157
|
+
projectVersion++;
|
|
223
158
|
}
|
|
224
159
|
}
|
|
160
|
+
if (oldProjectVersion !== projectVersion) {
|
|
161
|
+
projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
|
|
162
|
+
}
|
|
225
163
|
}
|
|
226
164
|
function dispose() {
|
|
227
165
|
languageService?.dispose();
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
disposeDocChange();
|
|
166
|
+
fileWatch?.dispose();
|
|
167
|
+
docChangeWatcher.dispose();
|
|
231
168
|
}
|
|
232
169
|
}
|
|
233
170
|
exports.createProject = createProject;
|
|
234
|
-
function createParsedCommandLine(ts,
|
|
171
|
+
async function createParsedCommandLine(ts, env, rootPath, tsConfig, plugins, existingOptions) {
|
|
235
172
|
const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions ?? []).flat();
|
|
236
173
|
if (ts) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
174
|
+
const sys = (0, typescript_1.createSys)(undefined, ts, {
|
|
175
|
+
...env,
|
|
176
|
+
onDidChangeWatchedFiles: undefined,
|
|
177
|
+
});
|
|
178
|
+
let content;
|
|
179
|
+
let sysVersion;
|
|
180
|
+
let newSysVersion = await sys.sync();
|
|
181
|
+
while (sysVersion !== newSysVersion) {
|
|
182
|
+
sysVersion = newSysVersion;
|
|
183
|
+
try {
|
|
184
|
+
if (typeof tsConfig === 'string') {
|
|
185
|
+
const config = ts.readJsonConfigFile(tsConfig, sys.readFile);
|
|
186
|
+
content = ts.parseJsonSourceFileConfigFileContent(config, sys, path.dirname(tsConfig), existingOptions, tsConfig, undefined, extraFileExtensions);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
content = ts.parseJsonConfigFileContent({ files: [] }, sys, rootPath, { ...tsConfig, ...existingOptions }, rootPath + '/jsconfig.json', undefined, extraFileExtensions);
|
|
190
|
+
}
|
|
191
|
+
// fix https://github.com/johnsoncodehk/volar/issues/1786
|
|
192
|
+
// https://github.com/microsoft/TypeScript/issues/30457
|
|
193
|
+
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
194
|
+
content.options.outDir = undefined;
|
|
195
|
+
content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
|
|
242
196
|
}
|
|
243
|
-
|
|
244
|
-
|
|
197
|
+
catch {
|
|
198
|
+
// will be failed if web fs host first result not ready
|
|
245
199
|
}
|
|
246
|
-
|
|
247
|
-
// https://github.com/microsoft/TypeScript/issues/30457
|
|
248
|
-
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
249
|
-
content.options.outDir = undefined;
|
|
250
|
-
content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
|
|
251
|
-
return content;
|
|
200
|
+
newSysVersion = await sys.sync();
|
|
252
201
|
}
|
|
253
|
-
|
|
254
|
-
|
|
202
|
+
if (content) {
|
|
203
|
+
return content;
|
|
255
204
|
}
|
|
256
205
|
}
|
|
257
206
|
return {
|
|
@@ -260,51 +209,4 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
|
260
209
|
options: {},
|
|
261
210
|
};
|
|
262
211
|
}
|
|
263
|
-
function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
|
|
264
|
-
const documentContext = {
|
|
265
|
-
resolveReference: (ref, base) => {
|
|
266
|
-
if (ts && host) { // support tsconfig.json paths
|
|
267
|
-
const isUri = base.indexOf('://') >= 0;
|
|
268
|
-
const resolveResult = ts.resolveModuleName(ref, isUri ? uriToFileName(base) : base, host.getCompilationSettings(), host);
|
|
269
|
-
const failedLookupLocations = typeof resolveResult === 'object' ? resolveResult.failedLookupLocations : [];
|
|
270
|
-
const dirs = new Set();
|
|
271
|
-
if (!failedLookupLocations) {
|
|
272
|
-
console.warn(`[volar] failedLookupLocations not exists, ts: ${ts.version}`);
|
|
273
|
-
}
|
|
274
|
-
for (let failed of failedLookupLocations ?? []) {
|
|
275
|
-
const fileName = path.basename(failed);
|
|
276
|
-
if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
|
|
277
|
-
dirs.add(path.dirname(failed));
|
|
278
|
-
}
|
|
279
|
-
if (failed.endsWith('.d.ts')) {
|
|
280
|
-
failed = failed.substring(0, failed.length - '.d.ts'.length);
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
if (host.fileExists(failed)) {
|
|
286
|
-
return isUri ? fileNameToUri(failed) : failed;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
for (const dir of dirs) {
|
|
290
|
-
if (host.directoryExists?.(dir) ?? true) {
|
|
291
|
-
return isUri ? fileNameToUri(dir) : dir;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
// original html resolveReference
|
|
296
|
-
if (ref.match(/^\w[\w\d+.-]*:/)) {
|
|
297
|
-
// starts with a schema
|
|
298
|
-
return ref;
|
|
299
|
-
}
|
|
300
|
-
if (ref[0] === '/') { // resolve absolute path against the current workspace folder
|
|
301
|
-
return rootUri + ref;
|
|
302
|
-
}
|
|
303
|
-
const baseUri = vscode_uri_1.URI.parse(base);
|
|
304
|
-
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
|
|
305
|
-
return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
|
|
306
|
-
},
|
|
307
|
-
};
|
|
308
|
-
return documentContext;
|
|
309
|
-
}
|
|
310
212
|
//# sourceMappingURL=project.js.map
|
package/out/common/server.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver';
|
|
2
2
|
import { InitializationOptions, LanguageServerPlugin, RuntimeEnvironment } from '../types';
|
|
3
|
+
import { createConfigurationHost } from './configurationHost';
|
|
3
4
|
export interface ServerContext {
|
|
4
5
|
server: {
|
|
6
|
+
initializeParams: vscode.InitializeParams;
|
|
5
7
|
connection: vscode.Connection;
|
|
6
8
|
runtimeEnv: RuntimeEnvironment;
|
|
7
9
|
plugins: LanguageServerPlugin[];
|
|
10
|
+
onDidChangeWatchedFiles: vscode.Connection['onDidChangeWatchedFiles'];
|
|
11
|
+
configurationHost: ReturnType<typeof createConfigurationHost> | undefined;
|
|
8
12
|
};
|
|
9
13
|
}
|
|
10
|
-
export declare function startCommonLanguageServer(connection: vscode.Connection,
|
|
14
|
+
export declare function startCommonLanguageServer(connection: vscode.Connection, _plugins: LanguageServerPlugin[], getRuntimeEnv: (params: vscode.InitializeParams, options: InitializationOptions) => RuntimeEnvironment): Promise<void>;
|
package/out/common/server.js
CHANGED
|
@@ -12,20 +12,40 @@ const documents_1 = require("./documents");
|
|
|
12
12
|
const registerFeatures_1 = require("./utils/registerFeatures");
|
|
13
13
|
const serverConfig_1 = require("./utils/serverConfig");
|
|
14
14
|
const workspaces_1 = require("./workspaces");
|
|
15
|
-
|
|
15
|
+
const request_light_1 = require("request-light");
|
|
16
|
+
async function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
|
|
16
17
|
let initParams;
|
|
17
18
|
let options;
|
|
18
19
|
let roots = [];
|
|
19
|
-
let fsHost;
|
|
20
20
|
let projects;
|
|
21
|
-
let configurationHost;
|
|
22
21
|
let plugins;
|
|
23
22
|
let documents;
|
|
24
23
|
let context;
|
|
24
|
+
const didChangeWatchedFilesCallbacks = new Set();
|
|
25
25
|
connection.onInitialize(async (_params) => {
|
|
26
26
|
initParams = _params;
|
|
27
27
|
options = initParams.initializationOptions;
|
|
28
|
-
|
|
28
|
+
const env = getRuntimeEnv(initParams, options);
|
|
29
|
+
context = {
|
|
30
|
+
server: {
|
|
31
|
+
initializeParams: initParams,
|
|
32
|
+
connection,
|
|
33
|
+
runtimeEnv: {
|
|
34
|
+
...env,
|
|
35
|
+
fs: createFsWithCache(env.fs),
|
|
36
|
+
},
|
|
37
|
+
plugins: _plugins,
|
|
38
|
+
configurationHost: initParams.capabilities.workspace?.configuration ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined,
|
|
39
|
+
onDidChangeWatchedFiles: cb => {
|
|
40
|
+
didChangeWatchedFilesCallbacks.add(cb);
|
|
41
|
+
return {
|
|
42
|
+
dispose: () => {
|
|
43
|
+
didChangeWatchedFilesCallbacks.delete(cb);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
29
49
|
plugins = context.server.plugins.map(plugin => plugin(options, {
|
|
30
50
|
typescript: options.typescript ? context.server.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined
|
|
31
51
|
}));
|
|
@@ -54,14 +74,13 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
54
74
|
},
|
|
55
75
|
},
|
|
56
76
|
};
|
|
57
|
-
configurationHost = initParams.capabilities.workspace?.configuration ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
|
|
58
77
|
let services = {};
|
|
59
78
|
for (const root of roots) {
|
|
60
79
|
if (root.scheme === 'file') {
|
|
61
80
|
let config = (0, serverConfig_1.loadConfig)(root.path, options.configFilePath) ?? {};
|
|
62
81
|
for (const plugin of plugins) {
|
|
63
82
|
if (plugin.resolveConfig) {
|
|
64
|
-
config = plugin.resolveConfig(config, undefined);
|
|
83
|
+
config = await plugin.resolveConfig(config, undefined);
|
|
65
84
|
}
|
|
66
85
|
}
|
|
67
86
|
if (config.services) {
|
|
@@ -85,9 +104,10 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
85
104
|
catch { }
|
|
86
105
|
return result;
|
|
87
106
|
});
|
|
88
|
-
connection.onInitialized(() => {
|
|
89
|
-
|
|
90
|
-
configurationHost?.
|
|
107
|
+
connection.onInitialized(async () => {
|
|
108
|
+
context.server.configurationHost?.ready();
|
|
109
|
+
context.server.configurationHost?.onDidChangeConfiguration?.(updateHttpSettings);
|
|
110
|
+
updateHttpSettings();
|
|
91
111
|
if (initParams.capabilities.workspace?.workspaceFolders) {
|
|
92
112
|
connection.workspace.onDidChangeWorkspaceFolders(e => {
|
|
93
113
|
for (const folder of e.added) {
|
|
@@ -109,8 +129,17 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
109
129
|
},
|
|
110
130
|
]
|
|
111
131
|
});
|
|
132
|
+
connection.onDidChangeWatchedFiles(e => {
|
|
133
|
+
for (const cb of didChangeWatchedFilesCallbacks) {
|
|
134
|
+
cb(e);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
112
137
|
}
|
|
113
138
|
}
|
|
139
|
+
async function updateHttpSettings() {
|
|
140
|
+
const httpSettings = await context.server.configurationHost?.getConfiguration?.('http');
|
|
141
|
+
(0, request_light_1.configure)(httpSettings?.proxy, httpSettings?.proxyStrictSSL ?? false);
|
|
142
|
+
}
|
|
114
143
|
});
|
|
115
144
|
connection.onShutdown(async () => {
|
|
116
145
|
if (projects) {
|
|
@@ -120,16 +149,58 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
120
149
|
}
|
|
121
150
|
});
|
|
122
151
|
connection.listen();
|
|
152
|
+
function createFsWithCache(fs) {
|
|
153
|
+
const readFileCache = new Map();
|
|
154
|
+
const statCache = new Map();
|
|
155
|
+
const readDirectoryCache = new Map();
|
|
156
|
+
didChangeWatchedFilesCallbacks.add(({ changes }) => {
|
|
157
|
+
for (const change of changes) {
|
|
158
|
+
if (change.type === vscode.FileChangeType.Deleted) {
|
|
159
|
+
readFileCache.set(change.uri, undefined);
|
|
160
|
+
statCache.set(change.uri, undefined);
|
|
161
|
+
const dir = change.uri.substring(0, change.uri.lastIndexOf('/'));
|
|
162
|
+
readDirectoryCache.delete(dir);
|
|
163
|
+
}
|
|
164
|
+
else if (change.type === vscode.FileChangeType.Changed) {
|
|
165
|
+
readFileCache.delete(change.uri);
|
|
166
|
+
statCache.delete(change.uri);
|
|
167
|
+
}
|
|
168
|
+
else if (change.type === vscode.FileChangeType.Created) {
|
|
169
|
+
readFileCache.delete(change.uri);
|
|
170
|
+
statCache.delete(change.uri);
|
|
171
|
+
const dir = change.uri.substring(0, change.uri.lastIndexOf('/'));
|
|
172
|
+
readDirectoryCache.delete(dir);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
readFile: uri => {
|
|
178
|
+
if (!readFileCache.has(uri)) {
|
|
179
|
+
readFileCache.set(uri, fs.readFile(uri));
|
|
180
|
+
}
|
|
181
|
+
return readFileCache.get(uri);
|
|
182
|
+
},
|
|
183
|
+
stat: uri => {
|
|
184
|
+
if (!statCache.has(uri)) {
|
|
185
|
+
statCache.set(uri, fs.stat(uri));
|
|
186
|
+
}
|
|
187
|
+
return statCache.get(uri);
|
|
188
|
+
},
|
|
189
|
+
readDirectory: uri => {
|
|
190
|
+
if (!readDirectoryCache.has(uri)) {
|
|
191
|
+
readDirectoryCache.set(uri, fs.readDirectory(uri));
|
|
192
|
+
}
|
|
193
|
+
return readDirectoryCache.get(uri);
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
123
197
|
async function createLanguageServiceHost() {
|
|
124
198
|
const ts = options.typescript ? context.server.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
|
|
125
|
-
fsHost = ts ? context.server.runtimeEnv.createFileSystemHost(ts, initParams.capabilities, context.server.runtimeEnv, options) : undefined;
|
|
126
199
|
const tsLocalized = options.typescript && initParams.locale ? await context.server.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
|
|
127
200
|
const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
|
|
128
201
|
projects = (0, workspaces_1.createWorkspaces)({
|
|
129
202
|
...context,
|
|
130
203
|
workspaces: {
|
|
131
|
-
fileSystemHost: fsHost,
|
|
132
|
-
configurationHost,
|
|
133
204
|
ts,
|
|
134
205
|
tsLocalized,
|
|
135
206
|
initParams,
|