@volar/language-server 2.4.30 → 3.0.0-alpha.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/browser.d.ts +6 -12
- package/browser.js +26 -38
- package/lib/features/configurations.js +34 -1
- package/lib/features/editorFeatures.js +1 -13
- package/lib/features/fileSystem.js +34 -1
- package/lib/features/fileWatcher.js +34 -1
- package/lib/features/languageFeatures.js +34 -1
- package/lib/features/textDocuments.js +34 -1
- package/lib/fileSystemProviders/node.js +34 -1
- package/lib/utils/combineChangeRanges.d.ts +2 -2
- package/lib/utils/snapshotDocument.d.ts +2 -2
- package/node.d.ts +0 -5
- package/node.js +23 -38
- package/package.json +3 -16
- package/protocol.d.ts +2 -13
- package/protocol.js +24 -10
- package/lib/project/inferredCompilerOptions.d.ts +0 -3
- package/lib/project/inferredCompilerOptions.js +0 -65
- package/lib/project/typescriptProject.d.ts +0 -22
- package/lib/project/typescriptProject.js +0 -324
- package/lib/project/typescriptProjectLs.d.ts +0 -31
- package/lib/project/typescriptProjectLs.js +0 -232
- package/tests/fixtures/tsServer.js +0 -18
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTypeScriptLS = createTypeScriptLS;
|
|
4
|
-
const language_service_1 = require("@volar/language-service");
|
|
5
|
-
const typescript_1 = require("@volar/typescript");
|
|
6
|
-
const utilities_1 = require("@volar/typescript/lib/typescript/utilities");
|
|
7
|
-
const path = require("path-browserify");
|
|
8
|
-
const vscode = require("vscode-languageserver");
|
|
9
|
-
const vscode_uri_1 = require("vscode-uri");
|
|
10
|
-
const fsFileSnapshots = (0, language_service_1.createUriMap)();
|
|
11
|
-
async function createTypeScriptLS(ts, tsLocalized, tsconfig, server, serviceEnv, workspaceFolder, uriConverter, create) {
|
|
12
|
-
let commandLine;
|
|
13
|
-
let projectVersion = 0;
|
|
14
|
-
const getCurrentDirectory = () => uriConverter.asFileName(workspaceFolder);
|
|
15
|
-
const sys = (0, typescript_1.createSys)(ts.sys, serviceEnv, getCurrentDirectory, uriConverter);
|
|
16
|
-
const projectHost = {
|
|
17
|
-
getCurrentDirectory,
|
|
18
|
-
getProjectVersion() {
|
|
19
|
-
return projectVersion.toString();
|
|
20
|
-
},
|
|
21
|
-
getScriptFileNames() {
|
|
22
|
-
return commandLine.fileNames;
|
|
23
|
-
},
|
|
24
|
-
getCompilationSettings() {
|
|
25
|
-
return commandLine.options;
|
|
26
|
-
},
|
|
27
|
-
getLocalizedDiagnosticMessages: tsLocalized ? () => tsLocalized : undefined,
|
|
28
|
-
getProjectReferences() {
|
|
29
|
-
return commandLine.projectReferences;
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
const { languagePlugins, setup } = await create({
|
|
33
|
-
env: serviceEnv,
|
|
34
|
-
configFileName: typeof tsconfig === 'string' ? tsconfig : undefined,
|
|
35
|
-
projectHost,
|
|
36
|
-
sys,
|
|
37
|
-
uriConverter,
|
|
38
|
-
});
|
|
39
|
-
const unsavedRootFileUris = (0, language_service_1.createUriMap)();
|
|
40
|
-
const disposables = [
|
|
41
|
-
server.documents.onDidOpen(({ document }) => updateFsCacheFromSyncedDocument(document)),
|
|
42
|
-
server.documents.onDidSave(({ document }) => updateFsCacheFromSyncedDocument(document)),
|
|
43
|
-
server.documents.onDidChangeContent(() => projectVersion++),
|
|
44
|
-
serviceEnv.onDidChangeWatchedFiles?.(async ({ changes }) => {
|
|
45
|
-
const createdOrDeleted = changes.some(change => change.type !== vscode.FileChangeType.Changed);
|
|
46
|
-
if (createdOrDeleted) {
|
|
47
|
-
await updateCommandLine();
|
|
48
|
-
}
|
|
49
|
-
projectVersion++;
|
|
50
|
-
}),
|
|
51
|
-
server.documents.onDidOpen(async ({ document }) => {
|
|
52
|
-
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
53
|
-
const isWorkspaceFile = workspaceFolder.scheme === uri.scheme;
|
|
54
|
-
if (!isWorkspaceFile) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const stat = await serviceEnv.fs?.stat(uri);
|
|
58
|
-
const isUnsaved = stat?.type !== 1;
|
|
59
|
-
if (isUnsaved) {
|
|
60
|
-
const lastProjectVersion = projectVersion;
|
|
61
|
-
await updateCommandLine();
|
|
62
|
-
if (lastProjectVersion !== projectVersion) {
|
|
63
|
-
unsavedRootFileUris.set(uri, true);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}),
|
|
67
|
-
server.documents.onDidClose(async ({ document }) => {
|
|
68
|
-
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
69
|
-
if (unsavedRootFileUris.has(uri)) {
|
|
70
|
-
unsavedRootFileUris.delete(uri);
|
|
71
|
-
await updateCommandLine();
|
|
72
|
-
}
|
|
73
|
-
}),
|
|
74
|
-
].filter(d => !!d);
|
|
75
|
-
await updateCommandLine();
|
|
76
|
-
const language = (0, language_service_1.createLanguage)([
|
|
77
|
-
{ getLanguageId: uri => server.documents.get(uri)?.languageId },
|
|
78
|
-
...languagePlugins,
|
|
79
|
-
{ getLanguageId: uri => (0, typescript_1.resolveFileLanguageId)(uri.path) },
|
|
80
|
-
], (0, language_service_1.createUriMap)(sys.useCaseSensitiveFileNames), (uri, includeFsFiles) => {
|
|
81
|
-
const syncedDocument = server.documents.get(uri);
|
|
82
|
-
let snapshot;
|
|
83
|
-
if (syncedDocument) {
|
|
84
|
-
snapshot = syncedDocument.getSnapshot();
|
|
85
|
-
}
|
|
86
|
-
else if (includeFsFiles) {
|
|
87
|
-
const cache = fsFileSnapshots.get(uri);
|
|
88
|
-
const fileName = uriConverter.asFileName(uri);
|
|
89
|
-
const modifiedTime = sys.getModifiedTime?.(fileName)?.valueOf();
|
|
90
|
-
if (!cache || cache[0] !== modifiedTime) {
|
|
91
|
-
if (sys.fileExists(fileName)) {
|
|
92
|
-
const text = sys.readFile(fileName);
|
|
93
|
-
const snapshot = text !== undefined ? ts.ScriptSnapshot.fromString(text) : undefined;
|
|
94
|
-
fsFileSnapshots.set(uri, [modifiedTime, snapshot]);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
fsFileSnapshots.set(uri, [modifiedTime, undefined]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
snapshot = fsFileSnapshots.get(uri)?.[1];
|
|
101
|
-
}
|
|
102
|
-
if (snapshot) {
|
|
103
|
-
language.scripts.set(uri, snapshot);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
language.scripts.delete(uri);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
const project = {
|
|
110
|
-
typescript: {
|
|
111
|
-
configFileName: typeof tsconfig === 'string' ? tsconfig : undefined,
|
|
112
|
-
sys,
|
|
113
|
-
uriConverter,
|
|
114
|
-
...(0, typescript_1.createLanguageServiceHost)(ts, sys, language, s => uriConverter.asUri(s), projectHost),
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
setup?.({ language, project });
|
|
118
|
-
const languageService = (0, language_service_1.createLanguageService)(language, server.languageServicePlugins, serviceEnv, project);
|
|
119
|
-
return {
|
|
120
|
-
languageService,
|
|
121
|
-
tryAddFile(fileName) {
|
|
122
|
-
if (!commandLine.fileNames.includes(fileName)) {
|
|
123
|
-
commandLine.fileNames.push(fileName);
|
|
124
|
-
projectVersion++;
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
dispose: () => {
|
|
128
|
-
sys.dispose();
|
|
129
|
-
languageService?.dispose();
|
|
130
|
-
disposables.forEach(({ dispose }) => dispose());
|
|
131
|
-
disposables.length = 0;
|
|
132
|
-
},
|
|
133
|
-
getCommandLine: () => commandLine,
|
|
134
|
-
};
|
|
135
|
-
function updateFsCacheFromSyncedDocument(document) {
|
|
136
|
-
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
137
|
-
const fileName = uriConverter.asFileName(uri);
|
|
138
|
-
if (fsFileSnapshots.has(uri) || sys.fileExists(fileName)) {
|
|
139
|
-
const modifiedTime = sys.getModifiedTime?.(fileName);
|
|
140
|
-
fsFileSnapshots.set(uri, [modifiedTime?.valueOf(), document.getSnapshot()]);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async function updateCommandLine() {
|
|
144
|
-
const oldFileNames = new Set(commandLine?.fileNames ?? []);
|
|
145
|
-
commandLine = await parseConfig(ts, sys, uriConverter.asFileName(workspaceFolder), tsconfig, languagePlugins.map(plugin => plugin.typescript?.extraFileExtensions ?? []).flat());
|
|
146
|
-
const newFileNames = new Set(commandLine.fileNames);
|
|
147
|
-
if (oldFileNames.size !== newFileNames.size || [...oldFileNames].some(fileName => !newFileNames.has(fileName))) {
|
|
148
|
-
projectVersion++;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async function parseConfig(ts, sys, workspacePath, tsconfig, extraFileExtensions) {
|
|
152
|
-
let commandLine = {
|
|
153
|
-
errors: [],
|
|
154
|
-
fileNames: [],
|
|
155
|
-
options: {},
|
|
156
|
-
};
|
|
157
|
-
let sysVersion;
|
|
158
|
-
let newSysVersion = await sys.sync();
|
|
159
|
-
while (sysVersion !== newSysVersion) {
|
|
160
|
-
sysVersion = newSysVersion;
|
|
161
|
-
try {
|
|
162
|
-
commandLine = parseConfigWorker(ts, sys, workspacePath, tsconfig, extraFileExtensions);
|
|
163
|
-
}
|
|
164
|
-
catch {
|
|
165
|
-
// will be failed if web fs host first result not ready
|
|
166
|
-
}
|
|
167
|
-
newSysVersion = await sys.sync();
|
|
168
|
-
}
|
|
169
|
-
return commandLine;
|
|
170
|
-
}
|
|
171
|
-
function parseConfigWorker(ts, _host, workspacePath, tsconfig, extraFileExtensions) {
|
|
172
|
-
let content = {
|
|
173
|
-
errors: [],
|
|
174
|
-
fileNames: [],
|
|
175
|
-
options: {},
|
|
176
|
-
};
|
|
177
|
-
const maybeUnsavedFileNames = server.documents.all()
|
|
178
|
-
.map(document => vscode_uri_1.URI.parse(document.uri))
|
|
179
|
-
.filter(uri => uri.scheme === workspaceFolder.scheme)
|
|
180
|
-
.map(uri => uriConverter.asFileName(uri));
|
|
181
|
-
const host = {
|
|
182
|
-
..._host,
|
|
183
|
-
readDirectory(rootDir, extensions, excludes, includes, depth) {
|
|
184
|
-
const fsFiles = _host.readDirectory(rootDir, extensions, excludes, includes, depth);
|
|
185
|
-
const unsavedFiles = (0, utilities_1.matchFiles)(rootDir, extensions, excludes, includes, sys.useCaseSensitiveFileNames, getCurrentDirectory(), depth, dirPath => {
|
|
186
|
-
dirPath = dirPath.replace(/\\/g, '/');
|
|
187
|
-
const files = [];
|
|
188
|
-
const dirs = [];
|
|
189
|
-
for (const fileName of maybeUnsavedFileNames) {
|
|
190
|
-
const match = sys.useCaseSensitiveFileNames
|
|
191
|
-
? fileName.startsWith(dirPath + '/')
|
|
192
|
-
: fileName.toLowerCase().startsWith(dirPath.toLowerCase() + '/');
|
|
193
|
-
if (match) {
|
|
194
|
-
const name = fileName.slice(dirPath.length + 1);
|
|
195
|
-
if (name.includes('/')) {
|
|
196
|
-
const dir = name.split('/')[0];
|
|
197
|
-
if (!dirs.includes(dir)) {
|
|
198
|
-
dirs.push(dir);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
files.push(name);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
files,
|
|
208
|
-
directories: dirs,
|
|
209
|
-
};
|
|
210
|
-
}, path => path);
|
|
211
|
-
if (!unsavedFiles.length) {
|
|
212
|
-
return fsFiles;
|
|
213
|
-
}
|
|
214
|
-
return [...new Set([...fsFiles, ...unsavedFiles])];
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
if (typeof tsconfig === 'string') {
|
|
218
|
-
const config = ts.readJsonConfigFile(tsconfig, host.readFile);
|
|
219
|
-
content = ts.parseJsonSourceFileConfigFileContent(config, host, path.dirname(tsconfig), {}, tsconfig, undefined, extraFileExtensions);
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
content = ts.parseJsonConfigFileContent({ files: [] }, host, workspacePath, tsconfig, workspacePath + '/jsconfig.json', undefined, extraFileExtensions);
|
|
223
|
-
}
|
|
224
|
-
// fix https://github.com/johnsoncodehk/volar/issues/1786
|
|
225
|
-
// https://github.com/microsoft/TypeScript/issues/30457
|
|
226
|
-
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
227
|
-
content.options.outDir = undefined;
|
|
228
|
-
content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
|
|
229
|
-
return content;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
//# sourceMappingURL=typescriptProjectLs.js.map
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// A server backed by a TypeScript project and no language plugins.
|
|
2
|
-
const ts = require('typescript');
|
|
3
|
-
const { createConnection, createServer, createTypeScriptProject } = require('../../node');
|
|
4
|
-
|
|
5
|
-
const connection = createConnection();
|
|
6
|
-
const server = createServer(connection);
|
|
7
|
-
|
|
8
|
-
connection.listen();
|
|
9
|
-
|
|
10
|
-
connection.onInitialize(params =>
|
|
11
|
-
server.initialize(
|
|
12
|
-
params,
|
|
13
|
-
createTypeScriptProject(ts, undefined, () => ({ languagePlugins: [] })),
|
|
14
|
-
[],
|
|
15
|
-
)
|
|
16
|
-
);
|
|
17
|
-
connection.onInitialized(server.initialized);
|
|
18
|
-
connection.onShutdown(server.shutdown);
|