@volar/language-server 1.6.9-patch.1 → 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 +6 -5
- package/out/common/features/languageFeatures.js +5 -5
- package/out/common/project.d.ts +112 -112
- package/out/common/project.js +147 -260
- package/out/common/server.d.ts +5 -1
- package/out/common/server.js +83 -12
- package/out/common/workspace.d.ts +288 -289
- package/out/common/workspace.js +16 -16
- package/out/common/workspaces.d.ts +354 -357
- package/out/common/workspaces.js +3 -6
- package/out/node/index.js +82 -83
- package/out/protocol.d.ts +5 -2
- package/out/protocol.js +16 -12
- package/out/types.d.ts +12 -44
- package/out/types.js +2 -2
- package/package.json +7 -6
package/out/common/project.js
CHANGED
|
@@ -1,62 +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;
|
|
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(() => {
|
|
66
|
+
projectVersion++;
|
|
67
|
+
projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
|
|
68
|
+
});
|
|
69
|
+
const fileWatch = env.onDidChangeWatchedFiles?.(params => {
|
|
70
|
+
onWorkspaceFilesChanged(params.changes);
|
|
71
|
+
});
|
|
38
72
|
let existingOptions;
|
|
39
73
|
for (const plugin of context.workspaces.plugins) {
|
|
40
74
|
if (plugin.resolveExistingOptions) {
|
|
41
75
|
existingOptions = plugin.resolveExistingOptions(existingOptions);
|
|
42
76
|
}
|
|
43
77
|
}
|
|
44
|
-
let parsedCommandLine = createParsedCommandLine(context.workspaces.ts,
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
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();
|
|
55
90
|
return {
|
|
56
|
-
|
|
91
|
+
context,
|
|
57
92
|
tsConfig: context.project.tsConfig,
|
|
58
|
-
scripts,
|
|
59
|
-
|
|
93
|
+
scripts: fsScriptsCache,
|
|
94
|
+
languageHost,
|
|
60
95
|
getLanguageService,
|
|
61
96
|
getLanguageServiceDontCreate: () => languageService,
|
|
62
97
|
getParsedCommandLine: () => parsedCommandLine,
|
|
@@ -67,206 +102,105 @@ async function createProject(context) {
|
|
|
67
102
|
projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
|
|
68
103
|
}
|
|
69
104
|
},
|
|
105
|
+
askedFiles,
|
|
70
106
|
dispose,
|
|
71
107
|
};
|
|
72
108
|
function getLanguageService() {
|
|
73
109
|
if (!languageService) {
|
|
74
|
-
|
|
75
|
-
uriToFileName,
|
|
76
|
-
fileNameToUri,
|
|
77
|
-
locale: context.workspaces.initParams.locale,
|
|
78
|
-
rootUri: context.project.rootUri,
|
|
79
|
-
clientCapabilities: context.workspaces.initParams.capabilities,
|
|
80
|
-
getConfiguration: context.workspaces.configurationHost?.getConfiguration,
|
|
81
|
-
onDidChangeConfiguration: context.workspaces.configurationHost?.onDidChangeConfiguration,
|
|
82
|
-
fileSystemProvider: context.server.runtimeEnv.fileSystemProvide,
|
|
83
|
-
onDidChangeWatchedFiles: context.workspaces.fileSystemHost?.onDidChangeWatchedFiles,
|
|
84
|
-
documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspaces.ts, languageServiceHost, context.project.rootUri.toString()),
|
|
85
|
-
schemaRequestService: async (uri) => {
|
|
86
|
-
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
87
|
-
const builtInHandler = context.server.runtimeEnv.schemaRequestHandlers[protocol];
|
|
88
|
-
if (builtInHandler) {
|
|
89
|
-
return await builtInHandler(uri) ?? '';
|
|
90
|
-
}
|
|
91
|
-
return '';
|
|
92
|
-
},
|
|
93
|
-
sys,
|
|
94
|
-
};
|
|
95
|
-
let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.server.runtimeEnv.uriToFileName(context.workspace.rootUri.toString()), context.workspaces.initOptions.configFilePath) : {}) ?? {};
|
|
96
|
-
for (const plugin of context.workspaces.plugins) {
|
|
97
|
-
if (plugin.resolveConfig) {
|
|
98
|
-
config = plugin.resolveConfig(config, {
|
|
99
|
-
...context,
|
|
100
|
-
env,
|
|
101
|
-
sys,
|
|
102
|
-
host: languageServiceHost,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
languageService = embeddedLS.createLanguageService({ typescript: context.workspaces.ts }, env, config, languageServiceHost);
|
|
110
|
+
languageService = (0, language_service_1.createLanguageService)({ typescript: context.workspaces.ts }, env, config, languageHost);
|
|
107
111
|
}
|
|
108
112
|
return languageService;
|
|
109
113
|
}
|
|
110
|
-
async function
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
else {
|
|
119
|
-
script.version--;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else if (script && change.type === vscode.FileChangeType.Deleted) {
|
|
123
|
-
scripts.uriDelete(change.uri);
|
|
124
|
-
}
|
|
125
|
-
if (script
|
|
126
|
-
|| change.uri.endsWith('.d.ts')
|
|
127
|
-
|| change.uri.endsWith('/package.json')) {
|
|
128
|
-
projectVersion++;
|
|
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));
|
|
129
122
|
}
|
|
130
123
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (creates.length || deletes.length) {
|
|
134
|
-
parsedCommandLine = createParsedCommandLine(context.workspaces.ts, sys, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins, existingOptions);
|
|
135
|
-
projectVersion++;
|
|
136
|
-
typeRootVersion++;
|
|
137
|
-
}
|
|
138
|
-
if (_projectVersion !== projectVersion) {
|
|
139
|
-
projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
|
|
140
|
-
}
|
|
124
|
+
await Promise.all(promises);
|
|
125
|
+
return dirty;
|
|
141
126
|
}
|
|
142
|
-
function
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// ts
|
|
151
|
-
getNewLine: () => sys.newLine,
|
|
152
|
-
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
|
153
|
-
readFile: fileName => {
|
|
154
|
-
readFiles.add(fileName);
|
|
155
|
-
return sys.readFile(fileName);
|
|
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,
|
|
156
135
|
},
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
getDefaultLibFileName: options => {
|
|
168
|
-
if (context.workspaces.initOptions.typescript && context.workspaces.ts) {
|
|
169
|
-
try {
|
|
170
|
-
return context.workspaces.ts.getDefaultLibFilePath(options);
|
|
171
|
-
}
|
|
172
|
-
catch {
|
|
173
|
-
// web
|
|
174
|
-
const tsdk = context.workspaces.initOptions.typescript.tsdk;
|
|
175
|
-
return tsdk + '/' + context.workspaces.ts.getDefaultLibFileName(options);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return '';
|
|
179
|
-
},
|
|
180
|
-
getProjectVersion: () => projectVersion.toString(),
|
|
181
|
-
getTypeRootsVersion: () => typeRootVersion,
|
|
182
|
-
getScriptFileNames: () => parsedCommandLine.fileNames,
|
|
183
|
-
getCompilationSettings: () => parsedCommandLine.options,
|
|
184
|
-
getScriptVersion,
|
|
185
|
-
getScriptSnapshot,
|
|
186
|
-
getScriptLanguageId: (fileName) => {
|
|
187
|
-
return context.workspaces.documents.data.pathGet(fileName)?.languageId;
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
if (context.workspaces.tsLocalized) {
|
|
191
|
-
host.getLocalizedDiagnosticMessages = () => context.workspaces.tsLocalized;
|
|
192
|
-
}
|
|
193
|
-
return host;
|
|
194
|
-
function getScriptVersion(fileName) {
|
|
195
|
-
const doc = context.workspaces.documents.data.pathGet(fileName);
|
|
196
|
-
if (doc) {
|
|
197
|
-
return doc.version.toString();
|
|
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++;
|
|
198
146
|
}
|
|
199
|
-
return scripts.pathGet(fileName)?.version.toString() ?? '';
|
|
200
147
|
}
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const script = scripts.pathGet(fileName);
|
|
207
|
-
if (script && script.snapshotVersion === script.version) {
|
|
208
|
-
return script.snapshot;
|
|
209
|
-
}
|
|
210
|
-
if (context.workspaces.ts && sys.fileExists(fileName)) {
|
|
211
|
-
if (context.workspaces.initOptions.maxFileSize) {
|
|
212
|
-
const fileSize = sys.getFileSize?.(fileName);
|
|
213
|
-
if (fileSize !== undefined && fileSize > context.workspaces.initOptions.maxFileSize) {
|
|
214
|
-
console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspaces.initOptions.maxFileSize}bytes)`);
|
|
215
|
-
return context.workspaces.ts.ScriptSnapshot.fromString('');
|
|
216
|
-
}
|
|
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);
|
|
217
153
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const snapshot = context.workspaces.ts.ScriptSnapshot.fromString(text);
|
|
221
|
-
if (script) {
|
|
222
|
-
script.snapshot = snapshot;
|
|
223
|
-
script.snapshotVersion = script.version;
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
scripts.pathSet(fileName, {
|
|
227
|
-
version: -1,
|
|
228
|
-
fileName: fileName,
|
|
229
|
-
snapshot: snapshot,
|
|
230
|
-
snapshotVersion: -1,
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
return snapshot;
|
|
154
|
+
else if (change.type === vscode.FileChangeType.Deleted) {
|
|
155
|
+
fsScriptsCache.uriSet(change.uri, undefined);
|
|
234
156
|
}
|
|
157
|
+
projectVersion++;
|
|
235
158
|
}
|
|
236
159
|
}
|
|
160
|
+
if (oldProjectVersion !== projectVersion) {
|
|
161
|
+
projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
|
|
162
|
+
}
|
|
237
163
|
}
|
|
238
164
|
function dispose() {
|
|
239
165
|
languageService?.dispose();
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
disposeDocChange();
|
|
166
|
+
fileWatch?.dispose();
|
|
167
|
+
docChangeWatcher.dispose();
|
|
243
168
|
}
|
|
244
169
|
}
|
|
245
170
|
exports.createProject = createProject;
|
|
246
|
-
function createParsedCommandLine(ts,
|
|
171
|
+
async function createParsedCommandLine(ts, env, rootPath, tsConfig, plugins, existingOptions) {
|
|
247
172
|
const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions ?? []).flat();
|
|
248
173
|
if (ts) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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, '/'));
|
|
254
196
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
...tsConfig,
|
|
258
|
-
...existingOptions,
|
|
259
|
-
}, path.join(rootPath, 'jsconfig.json'), undefined, extraFileExtensions);
|
|
197
|
+
catch {
|
|
198
|
+
// will be failed if web fs host first result not ready
|
|
260
199
|
}
|
|
261
|
-
|
|
262
|
-
// https://github.com/microsoft/TypeScript/issues/30457
|
|
263
|
-
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
264
|
-
content.options.outDir = undefined;
|
|
265
|
-
content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
|
|
266
|
-
return content;
|
|
200
|
+
newSysVersion = await sys.sync();
|
|
267
201
|
}
|
|
268
|
-
|
|
269
|
-
|
|
202
|
+
if (content) {
|
|
203
|
+
return content;
|
|
270
204
|
}
|
|
271
205
|
}
|
|
272
206
|
return {
|
|
@@ -275,51 +209,4 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins, existingO
|
|
|
275
209
|
options: {},
|
|
276
210
|
};
|
|
277
211
|
}
|
|
278
|
-
function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
|
|
279
|
-
const documentContext = {
|
|
280
|
-
resolveReference: (ref, base) => {
|
|
281
|
-
if (ts && host) { // support tsconfig.json paths
|
|
282
|
-
const isUri = base.indexOf('://') >= 0;
|
|
283
|
-
const resolveResult = ts.resolveModuleName(ref, isUri ? uriToFileName(base) : base, host.getCompilationSettings(), host);
|
|
284
|
-
const failedLookupLocations = typeof resolveResult === 'object' ? resolveResult.failedLookupLocations : [];
|
|
285
|
-
const dirs = new Set();
|
|
286
|
-
if (!failedLookupLocations) {
|
|
287
|
-
console.warn(`[volar] failedLookupLocations not exists, ts: ${ts.version}`);
|
|
288
|
-
}
|
|
289
|
-
for (let failed of failedLookupLocations ?? []) {
|
|
290
|
-
const fileName = path.basename(failed);
|
|
291
|
-
if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
|
|
292
|
-
dirs.add(path.dirname(failed));
|
|
293
|
-
}
|
|
294
|
-
if (failed.endsWith('.d.ts')) {
|
|
295
|
-
failed = failed.substring(0, failed.length - '.d.ts'.length);
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
if (host.fileExists(failed)) {
|
|
301
|
-
return isUri ? fileNameToUri(failed) : failed;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
for (const dir of dirs) {
|
|
305
|
-
if (host.directoryExists?.(dir) ?? true) {
|
|
306
|
-
return isUri ? fileNameToUri(dir) : dir;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
// original html resolveReference
|
|
311
|
-
if (ref.match(/^\w[\w\d+.-]*:/)) {
|
|
312
|
-
// starts with a schema
|
|
313
|
-
return ref;
|
|
314
|
-
}
|
|
315
|
-
if (ref[0] === '/') { // resolve absolute path against the current workspace folder
|
|
316
|
-
return rootUri + ref;
|
|
317
|
-
}
|
|
318
|
-
const baseUri = vscode_uri_1.URI.parse(base);
|
|
319
|
-
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
|
|
320
|
-
return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
|
|
321
|
-
},
|
|
322
|
-
};
|
|
323
|
-
return documentContext;
|
|
324
|
-
}
|
|
325
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,
|