@volar/language-server 1.4.0-alpha.0 → 1.4.0-alpha.1
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/fileSystems.js +82 -102
- package/out/browser/index.js +10 -23
- package/out/browser/typescript/core.js +1 -1
- package/out/browser/typescript/corePublic.js +2 -2
- package/out/common/cancellationPipe.js +1 -1
- package/out/common/configurationHost.js +12 -28
- package/out/common/documents.js +2 -3
- package/out/common/features/customFeatures.js +34 -47
- package/out/common/features/languageFeatures.js +126 -151
- package/out/common/project.d.ts +2 -2
- package/out/common/project.js +211 -227
- package/out/common/server.js +51 -65
- package/out/common/utils/inferredCompilerOptions.js +57 -61
- package/out/common/utils/registerFeatures.js +8 -8
- package/out/common/utils/serverConfig.js +2 -2
- package/out/common/utils/uriMap.js +1 -1
- package/out/common/workspace.d.ts +18 -18
- package/out/common/workspace.js +164 -193
- package/out/common/workspaces.d.ts +22 -22
- package/out/common/workspaces.js +81 -107
- package/out/node/fileSystem.js +4 -14
- package/out/node/index.js +7 -18
- package/package.json +4 -4
package/out/common/project.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.createProject = void 0;
|
|
12
3
|
const embeddedLS = require("@volar/language-service");
|
|
@@ -16,242 +7,236 @@ const vscode_uri_1 = require("vscode-uri");
|
|
|
16
7
|
const types_1 = require("../types");
|
|
17
8
|
const serverConfig_1 = require("./utils/serverConfig");
|
|
18
9
|
const uriMap_1 = require("./utils/uriMap");
|
|
19
|
-
function createProject(context) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
10
|
+
async function createProject(context) {
|
|
11
|
+
const uriToFileName = context.workspace.workspaces.server.runtimeEnv.uriToFileName;
|
|
12
|
+
const fileNameToUri = context.workspace.workspaces.server.runtimeEnv.fileNameToUri;
|
|
13
|
+
const sys = context.workspace.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspace.workspaces.fileSystemHost
|
|
14
|
+
? {
|
|
15
|
+
newLine: '\n',
|
|
16
|
+
useCaseSensitiveFileNames: false,
|
|
17
|
+
fileExists: () => false,
|
|
18
|
+
readFile: () => undefined,
|
|
19
|
+
readDirectory: () => [],
|
|
20
|
+
getCurrentDirectory: () => '',
|
|
21
|
+
realpath: () => '',
|
|
22
|
+
resolvePath: () => '',
|
|
23
|
+
}
|
|
24
|
+
: context.workspace.workspaces.fileSystemHost.getWorkspaceFileSystem(context.rootUri);
|
|
25
|
+
let typeRootVersion = 0;
|
|
26
|
+
let projectVersion = 0;
|
|
27
|
+
let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
28
|
+
let languageService;
|
|
29
|
+
let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
|
|
30
|
+
const scripts = (0, uriMap_1.createUriMap)(fileNameToUri);
|
|
31
|
+
const languageServiceHost = createLanguageServiceHost();
|
|
32
|
+
const disposeWatchEvent = context.workspace.workspaces.fileSystemHost?.onDidChangeWatchedFiles(params => {
|
|
33
|
+
onWorkspaceFilesChanged(params.changes);
|
|
34
|
+
});
|
|
35
|
+
const disposeDocChange = context.workspace.workspaces.documents.onDidChangeContent(() => {
|
|
36
|
+
projectVersion++;
|
|
37
|
+
projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
tsConfig: context.tsConfig,
|
|
41
|
+
scripts,
|
|
42
|
+
languageServiceHost,
|
|
43
|
+
getLanguageService,
|
|
44
|
+
getLanguageServiceDontCreate: () => languageService,
|
|
45
|
+
getParsedCommandLine: () => parsedCommandLine,
|
|
46
|
+
tryAddFile: (fileName) => {
|
|
47
|
+
if (!parsedCommandLine.fileNames.includes(fileName)) {
|
|
48
|
+
parsedCommandLine.fileNames.push(fileName);
|
|
49
|
+
projectVersion++;
|
|
50
|
+
projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
34
51
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (!parsedCommandLine.fileNames.includes(fileName)) {
|
|
59
|
-
parsedCommandLine.fileNames.push(fileName);
|
|
60
|
-
projectVersion++;
|
|
61
|
-
projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
dispose,
|
|
65
|
-
};
|
|
66
|
-
function getLanguageService() {
|
|
67
|
-
var _a;
|
|
68
|
-
if (!languageService) {
|
|
69
|
-
let config = (_a = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.workspace.rootUri.path, context.workspace.workspaces.initOptions.configFilePath) : {})) !== null && _a !== void 0 ? _a : {};
|
|
70
|
-
const options = {
|
|
71
|
-
uriToFileName,
|
|
72
|
-
fileNameToUri,
|
|
73
|
-
rootUri: context.rootUri,
|
|
74
|
-
host: languageServiceHost,
|
|
75
|
-
get config() {
|
|
76
|
-
return config;
|
|
77
|
-
},
|
|
78
|
-
locale: context.workspace.workspaces.initParams.locale,
|
|
79
|
-
configurationHost: context.workspace.workspaces.configurationHost,
|
|
80
|
-
fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
|
|
81
|
-
documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
|
|
82
|
-
schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
var _b;
|
|
84
|
-
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
85
|
-
const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
|
|
86
|
-
if (builtInHandler) {
|
|
87
|
-
return (_b = yield builtInHandler(uri)) !== null && _b !== void 0 ? _b : '';
|
|
88
|
-
}
|
|
89
|
-
return '';
|
|
90
|
-
}),
|
|
91
|
-
};
|
|
92
|
-
const lsCtx = {
|
|
93
|
-
project: context,
|
|
94
|
-
options,
|
|
95
|
-
sys,
|
|
96
|
-
host: languageServiceHost,
|
|
97
|
-
};
|
|
98
|
-
for (const plugin of context.workspace.workspaces.plugins) {
|
|
99
|
-
if (plugin.resolveConfig) {
|
|
100
|
-
config = plugin.resolveConfig(config, { typescript: lsCtx.project.workspace.workspaces.ts }, lsCtx);
|
|
52
|
+
},
|
|
53
|
+
dispose,
|
|
54
|
+
};
|
|
55
|
+
function getLanguageService() {
|
|
56
|
+
if (!languageService) {
|
|
57
|
+
let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.workspace.rootUri.path, context.workspace.workspaces.initOptions.configFilePath) : {}) ?? {};
|
|
58
|
+
const options = {
|
|
59
|
+
uriToFileName,
|
|
60
|
+
fileNameToUri,
|
|
61
|
+
rootUri: context.rootUri,
|
|
62
|
+
host: languageServiceHost,
|
|
63
|
+
get config() {
|
|
64
|
+
return config;
|
|
65
|
+
},
|
|
66
|
+
locale: context.workspace.workspaces.initParams.locale,
|
|
67
|
+
configurationHost: context.workspace.workspaces.configurationHost,
|
|
68
|
+
fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
|
|
69
|
+
documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
|
|
70
|
+
schemaRequestService: async (uri) => {
|
|
71
|
+
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
72
|
+
const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
|
|
73
|
+
if (builtInHandler) {
|
|
74
|
+
return await builtInHandler(uri) ?? '';
|
|
101
75
|
}
|
|
76
|
+
return '';
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
const lsCtx = {
|
|
80
|
+
project: context,
|
|
81
|
+
options,
|
|
82
|
+
sys,
|
|
83
|
+
host: languageServiceHost,
|
|
84
|
+
};
|
|
85
|
+
for (const plugin of context.workspace.workspaces.plugins) {
|
|
86
|
+
if (plugin.resolveConfig) {
|
|
87
|
+
config = plugin.resolveConfig(config, { typescript: lsCtx.project.workspace.workspaces.ts }, lsCtx);
|
|
102
88
|
}
|
|
103
|
-
languageService = embeddedLS.createLanguageService(options, context.documentRegistry);
|
|
104
89
|
}
|
|
105
|
-
|
|
90
|
+
languageService = embeddedLS.createLanguageService(options, context.documentRegistry);
|
|
106
91
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
else {
|
|
117
|
-
script.version--;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else if (script && change.type === vscode.FileChangeType.Deleted) {
|
|
121
|
-
scripts.uriDelete(change.uri);
|
|
122
|
-
}
|
|
123
|
-
if (script
|
|
124
|
-
|| change.uri.endsWith('.d.ts')
|
|
125
|
-
|| change.uri.endsWith('/package.json')) {
|
|
126
|
-
projectVersion++;
|
|
127
|
-
}
|
|
92
|
+
return languageService;
|
|
93
|
+
}
|
|
94
|
+
async function onWorkspaceFilesChanged(changes) {
|
|
95
|
+
const _projectVersion = projectVersion;
|
|
96
|
+
for (const change of changes) {
|
|
97
|
+
const script = scripts.uriGet(change.uri);
|
|
98
|
+
if (script && (change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Created)) {
|
|
99
|
+
if (script.version >= 0) {
|
|
100
|
+
script.version = -1;
|
|
128
101
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (creates.length || deletes.length) {
|
|
132
|
-
parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
|
|
133
|
-
projectVersion++;
|
|
134
|
-
typeRootVersion++;
|
|
102
|
+
else {
|
|
103
|
+
script.version--;
|
|
135
104
|
}
|
|
136
|
-
|
|
137
|
-
|
|
105
|
+
}
|
|
106
|
+
else if (script && change.type === vscode.FileChangeType.Deleted) {
|
|
107
|
+
scripts.uriDelete(change.uri);
|
|
108
|
+
}
|
|
109
|
+
if (script
|
|
110
|
+
|| change.uri.endsWith('.d.ts')
|
|
111
|
+
|| change.uri.endsWith('/package.json')) {
|
|
112
|
+
projectVersion++;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
|
|
116
|
+
const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
|
|
117
|
+
if (creates.length || deletes.length) {
|
|
118
|
+
parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
|
|
119
|
+
projectVersion++;
|
|
120
|
+
typeRootVersion++;
|
|
121
|
+
}
|
|
122
|
+
if (_projectVersion !== projectVersion) {
|
|
123
|
+
projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function createLanguageServiceHost() {
|
|
127
|
+
const token = {
|
|
128
|
+
isCancellationRequested() {
|
|
129
|
+
return context.workspace.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
|
|
130
|
+
},
|
|
131
|
+
throwIfCancellationRequested() { },
|
|
132
|
+
};
|
|
133
|
+
let host = {
|
|
134
|
+
// ts
|
|
135
|
+
getNewLine: () => sys.newLine,
|
|
136
|
+
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
|
137
|
+
readFile: sys.readFile,
|
|
138
|
+
writeFile: sys.writeFile,
|
|
139
|
+
directoryExists: sys.directoryExists,
|
|
140
|
+
getDirectories: sys.getDirectories,
|
|
141
|
+
readDirectory: sys.readDirectory,
|
|
142
|
+
realpath: sys.realpath,
|
|
143
|
+
fileExists: sys.fileExists,
|
|
144
|
+
getCurrentDirectory: () => uriToFileName(context.rootUri.toString()),
|
|
145
|
+
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
146
|
+
getCancellationToken: () => token,
|
|
147
|
+
// custom
|
|
148
|
+
getDefaultLibFileName: options => {
|
|
149
|
+
if (context.workspace.workspaces.initOptions.typescript && context.workspace.workspaces.ts) {
|
|
150
|
+
try {
|
|
151
|
+
return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// web
|
|
155
|
+
const tsdk = context.workspace.workspaces.initOptions.typescript.tsdk;
|
|
156
|
+
return tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
|
|
157
|
+
}
|
|
138
158
|
}
|
|
159
|
+
return '';
|
|
160
|
+
},
|
|
161
|
+
getProjectVersion: () => projectVersion.toString(),
|
|
162
|
+
getTypeRootsVersion: () => typeRootVersion,
|
|
163
|
+
getScriptFileNames: () => parsedCommandLine.fileNames,
|
|
164
|
+
getCompilationSettings: () => parsedCommandLine.options,
|
|
165
|
+
getScriptVersion,
|
|
166
|
+
getScriptSnapshot,
|
|
167
|
+
getTypeScriptModule: context.workspace.workspaces.ts ? () => {
|
|
168
|
+
return context.workspace.workspaces.ts;
|
|
169
|
+
} : undefined,
|
|
170
|
+
getScriptLanguageId: (fileName) => {
|
|
171
|
+
return context.workspace.workspaces.documents.data.pathGet(fileName)?.languageId;
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
if (context.workspace.workspaces.initOptions.noProjectReferences) {
|
|
175
|
+
host.getProjectReferences = undefined;
|
|
176
|
+
host.getCompilationSettings = () => ({
|
|
177
|
+
...parsedCommandLine.options,
|
|
178
|
+
rootDir: undefined,
|
|
179
|
+
composite: false,
|
|
139
180
|
});
|
|
140
181
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
// ts
|
|
150
|
-
getNewLine: () => sys.newLine,
|
|
151
|
-
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
|
152
|
-
readFile: sys.readFile,
|
|
153
|
-
writeFile: sys.writeFile,
|
|
154
|
-
directoryExists: sys.directoryExists,
|
|
155
|
-
getDirectories: sys.getDirectories,
|
|
156
|
-
readDirectory: sys.readDirectory,
|
|
157
|
-
realpath: sys.realpath,
|
|
158
|
-
fileExists: sys.fileExists,
|
|
159
|
-
getCurrentDirectory: () => uriToFileName(context.rootUri.toString()),
|
|
160
|
-
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
161
|
-
getCancellationToken: () => token,
|
|
162
|
-
// custom
|
|
163
|
-
getDefaultLibFileName: options => {
|
|
164
|
-
if (context.workspace.workspaces.initOptions.typescript && context.workspace.workspaces.ts) {
|
|
165
|
-
try {
|
|
166
|
-
return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
|
|
167
|
-
}
|
|
168
|
-
catch (_a) {
|
|
169
|
-
// web
|
|
170
|
-
const tsdk = context.workspace.workspaces.initOptions.typescript.tsdk;
|
|
171
|
-
return tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return '';
|
|
175
|
-
},
|
|
176
|
-
getProjectVersion: () => projectVersion.toString(),
|
|
177
|
-
getTypeRootsVersion: () => typeRootVersion,
|
|
178
|
-
getScriptFileNames: () => parsedCommandLine.fileNames,
|
|
179
|
-
getCompilationSettings: () => parsedCommandLine.options,
|
|
180
|
-
getScriptVersion,
|
|
181
|
-
getScriptSnapshot,
|
|
182
|
-
getTypeScriptModule: context.workspace.workspaces.ts ? () => {
|
|
183
|
-
return context.workspace.workspaces.ts;
|
|
184
|
-
} : undefined,
|
|
185
|
-
getScriptLanguageId: (fileName) => {
|
|
186
|
-
var _a;
|
|
187
|
-
return (_a = context.workspace.workspaces.documents.data.pathGet(fileName)) === null || _a === void 0 ? void 0 : _a.languageId;
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
if (context.workspace.workspaces.initOptions.noProjectReferences) {
|
|
191
|
-
host.getProjectReferences = undefined;
|
|
192
|
-
host.getCompilationSettings = () => (Object.assign(Object.assign({}, parsedCommandLine.options), { rootDir: undefined, composite: false }));
|
|
182
|
+
if (context.workspace.workspaces.tsLocalized) {
|
|
183
|
+
host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
|
|
184
|
+
}
|
|
185
|
+
return host;
|
|
186
|
+
function getScriptVersion(fileName) {
|
|
187
|
+
const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
|
|
188
|
+
if (doc) {
|
|
189
|
+
return doc.version.toString();
|
|
193
190
|
}
|
|
194
|
-
|
|
195
|
-
|
|
191
|
+
return scripts.pathGet(fileName)?.version.toString() ?? '';
|
|
192
|
+
}
|
|
193
|
+
function getScriptSnapshot(fileName) {
|
|
194
|
+
const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
|
|
195
|
+
if (doc) {
|
|
196
|
+
return doc.getSnapshot();
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
|
|
201
|
-
if (doc) {
|
|
202
|
-
return doc.version.toString();
|
|
203
|
-
}
|
|
204
|
-
return (_b = (_a = scripts.pathGet(fileName)) === null || _a === void 0 ? void 0 : _a.version.toString()) !== null && _b !== void 0 ? _b : '';
|
|
198
|
+
const script = scripts.pathGet(fileName);
|
|
199
|
+
if (script && script.snapshotVersion === script.version) {
|
|
200
|
+
return script.snapshot;
|
|
205
201
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (script && script.snapshotVersion === script.version) {
|
|
214
|
-
return script.snapshot;
|
|
202
|
+
if (context.workspace.workspaces.ts && sys.fileExists(fileName)) {
|
|
203
|
+
if (context.workspace.workspaces.initOptions.maxFileSize) {
|
|
204
|
+
const fileSize = sys.getFileSize?.(fileName);
|
|
205
|
+
if (fileSize !== undefined && fileSize > context.workspace.workspaces.initOptions.maxFileSize) {
|
|
206
|
+
console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspace.workspaces.initOptions.maxFileSize}bytes)`);
|
|
207
|
+
return context.workspace.workspaces.ts.ScriptSnapshot.fromString('');
|
|
208
|
+
}
|
|
215
209
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
210
|
+
const text = sys.readFile(fileName, 'utf8');
|
|
211
|
+
if (text !== undefined) {
|
|
212
|
+
const snapshot = context.workspace.workspaces.ts.ScriptSnapshot.fromString(text);
|
|
213
|
+
if (script) {
|
|
214
|
+
script.snapshot = snapshot;
|
|
215
|
+
script.snapshotVersion = script.version;
|
|
223
216
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
scripts.pathSet(fileName, {
|
|
233
|
-
version: -1,
|
|
234
|
-
fileName: fileName,
|
|
235
|
-
snapshot: snapshot,
|
|
236
|
-
snapshotVersion: -1,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
return snapshot;
|
|
217
|
+
else {
|
|
218
|
+
scripts.pathSet(fileName, {
|
|
219
|
+
version: -1,
|
|
220
|
+
fileName: fileName,
|
|
221
|
+
snapshot: snapshot,
|
|
222
|
+
snapshotVersion: -1,
|
|
223
|
+
});
|
|
240
224
|
}
|
|
225
|
+
return snapshot;
|
|
241
226
|
}
|
|
242
227
|
}
|
|
243
228
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
229
|
+
}
|
|
230
|
+
function dispose() {
|
|
231
|
+
languageService?.dispose();
|
|
232
|
+
scripts.clear();
|
|
233
|
+
disposeWatchEvent?.();
|
|
234
|
+
disposeDocChange();
|
|
235
|
+
}
|
|
251
236
|
}
|
|
252
237
|
exports.createProject = createProject;
|
|
253
238
|
function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
254
|
-
const extraFileExtensions = plugins.map(plugin =>
|
|
239
|
+
const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions ?? []).flat();
|
|
255
240
|
if (ts) {
|
|
256
241
|
try {
|
|
257
242
|
let content;
|
|
@@ -269,7 +254,7 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
|
269
254
|
content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
|
|
270
255
|
return content;
|
|
271
256
|
}
|
|
272
|
-
catch
|
|
257
|
+
catch {
|
|
273
258
|
// will be failed if web fs host first result not ready
|
|
274
259
|
}
|
|
275
260
|
}
|
|
@@ -282,7 +267,6 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
|
282
267
|
function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
|
|
283
268
|
const documentContext = {
|
|
284
269
|
resolveReference: (ref, base) => {
|
|
285
|
-
var _a, _b;
|
|
286
270
|
if (ts && host) { // support tsconfig.json paths
|
|
287
271
|
const isUri = base.indexOf('://') >= 0;
|
|
288
272
|
const resolveResult = ts.resolveModuleName(ref, isUri ? uriToFileName(base) : base, host.getCompilationSettings(), host);
|
|
@@ -291,7 +275,7 @@ function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
|
|
|
291
275
|
if (!failedLookupLocations) {
|
|
292
276
|
console.warn(`[volar] failedLookupLocations not exists, ts: ${ts.version}`);
|
|
293
277
|
}
|
|
294
|
-
for (let failed of failedLookupLocations
|
|
278
|
+
for (let failed of failedLookupLocations ?? []) {
|
|
295
279
|
const fileName = path.basename(failed);
|
|
296
280
|
if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
|
|
297
281
|
dirs.add(path.dirname(failed));
|
|
@@ -307,7 +291,7 @@ function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
|
|
|
307
291
|
}
|
|
308
292
|
}
|
|
309
293
|
for (const dir of dirs) {
|
|
310
|
-
if (
|
|
294
|
+
if (host.directoryExists?.(dir) ?? true) {
|
|
311
295
|
return isUri ? fileNameToUri(dir) : dir;
|
|
312
296
|
}
|
|
313
297
|
}
|