@volar/language-server 1.4.0-alpha.0 → 1.4.0-alpha.10
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 +83 -107
- package/out/browser/index.js +11 -23
- package/out/browser/typescript/core.js +2 -1
- package/out/browser/typescript/corePublic.js +3 -2
- package/out/browser/typescript/path.js +1 -0
- package/out/browser/typescript/types.js +1 -0
- package/out/browser/typescript/utilities.js +1 -0
- package/out/common/cancellationPipe.js +2 -1
- package/out/common/configurationHost.js +13 -28
- package/out/common/documents.js +3 -3
- package/out/common/features/customFeatures.js +35 -47
- package/out/common/features/languageFeatures.js +135 -163
- package/out/common/project.d.ts +66 -62
- package/out/common/project.js +205 -228
- package/out/common/schemaRequestHandlers/file.js +1 -0
- package/out/common/schemaRequestHandlers/http.js +1 -0
- package/out/common/server.js +63 -68
- package/out/common/utils/inferredCompilerOptions.js +58 -61
- package/out/common/utils/isFileInDir.js +1 -0
- package/out/common/utils/registerFeatures.js +11 -12
- package/out/common/utils/serverConfig.js +3 -2
- package/out/common/utils/uriMap.js +2 -1
- package/out/common/workspace.d.ts +605 -568
- package/out/common/workspace.js +182 -194
- package/out/common/workspaces.d.ts +726 -682
- package/out/common/workspaces.js +82 -107
- package/out/index.js +1 -0
- package/out/node/fileSystem.js +13 -16
- package/out/node/index.js +16 -19
- package/out/protocol.d.ts +0 -6
- package/out/protocol.js +2 -5
- package/out/types.d.ts +4 -6
- package/out/types.js +1 -0
- package/package.json +4 -4
package/out/common/workspace.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
1
|
+
"use strict";
|
|
10
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
3
|
exports.sortTsConfigs = exports.createWorkspace = exports.rootTsConfigNames = void 0;
|
|
12
|
-
const path = require("typesafe-path");
|
|
4
|
+
const path = require("typesafe-path/posix");
|
|
13
5
|
const vscode = require("vscode-languageserver");
|
|
14
6
|
const vscode_uri_1 = require("vscode-uri");
|
|
15
7
|
const project_1 = require("./project");
|
|
@@ -17,210 +9,206 @@ const inferredCompilerOptions_1 = require("./utils/inferredCompilerOptions");
|
|
|
17
9
|
const uriMap_1 = require("./utils/uriMap");
|
|
18
10
|
const isFileInDir_1 = require("./utils/isFileInDir");
|
|
19
11
|
exports.rootTsConfigNames = ['tsconfig.json', 'jsconfig.json'];
|
|
20
|
-
function createWorkspace(context) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
if (change.
|
|
34
|
-
|
|
35
|
-
rootTsConfigs.add(uriToFileName(change.uri));
|
|
36
|
-
}
|
|
12
|
+
async function createWorkspace(context) {
|
|
13
|
+
const fileNameToUri = context.workspaces.server.runtimeEnv.fileNameToUri;
|
|
14
|
+
const uriToFileName = context.workspaces.server.runtimeEnv.uriToFileName;
|
|
15
|
+
let inferredProject;
|
|
16
|
+
const sys = context.workspaces.fileSystemHost?.getWorkspaceFileSystem(context.rootUri);
|
|
17
|
+
const documentRegistry = sys ? context.workspaces.ts?.createDocumentRegistry(sys.useCaseSensitiveFileNames, uriToFileName(context.rootUri.toString())) : undefined;
|
|
18
|
+
const projects = (0, uriMap_1.createUriMap)(fileNameToUri);
|
|
19
|
+
const rootTsConfigs = new Set();
|
|
20
|
+
const searchedDirs = new Set();
|
|
21
|
+
const disposeTsConfigWatch = context.workspaces.fileSystemHost?.onDidChangeWatchedFiles(({ changes }) => {
|
|
22
|
+
for (const change of changes) {
|
|
23
|
+
if (exports.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1))) {
|
|
24
|
+
if (change.type === vscode.FileChangeType.Created) {
|
|
25
|
+
if ((0, isFileInDir_1.isFileInDir)(uriToFileName(change.uri), uriToFileName(context.rootUri.toString()))) {
|
|
26
|
+
rootTsConfigs.add(uriToFileName(change.uri));
|
|
37
27
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const project = projects.uriGet(change.uri);
|
|
43
|
-
projects.uriDelete(change.uri);
|
|
44
|
-
project === null || project === void 0 ? void 0 : project.then(project => project.dispose());
|
|
28
|
+
}
|
|
29
|
+
else if ((change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Deleted) && projects.uriHas(change.uri)) {
|
|
30
|
+
if (change.type === vscode.FileChangeType.Deleted) {
|
|
31
|
+
rootTsConfigs.delete(uriToFileName(change.uri));
|
|
45
32
|
}
|
|
33
|
+
const project = projects.uriGet(change.uri);
|
|
34
|
+
projects.uriDelete(change.uri);
|
|
35
|
+
project?.then(project => project.dispose());
|
|
46
36
|
}
|
|
47
37
|
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
projects,
|
|
42
|
+
documentRegistry,
|
|
43
|
+
getProjectAndTsConfig,
|
|
44
|
+
getInferredProject,
|
|
45
|
+
getInferredProjectDontCreate: () => inferredProject,
|
|
46
|
+
reload: clearProjects,
|
|
47
|
+
dispose() {
|
|
48
|
+
clearProjects();
|
|
49
|
+
disposeTsConfigWatch?.();
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
function clearProjects() {
|
|
53
|
+
const _projects = [
|
|
54
|
+
inferredProject,
|
|
55
|
+
...projects.values(),
|
|
56
|
+
];
|
|
57
|
+
_projects.forEach(async (project) => {
|
|
58
|
+
(await project)?.dispose();
|
|
48
59
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
function clearProjects() {
|
|
62
|
-
const _projects = [
|
|
63
|
-
inferredProject,
|
|
64
|
-
...projects.values(),
|
|
65
|
-
];
|
|
66
|
-
_projects.forEach((project) => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
var _a;
|
|
68
|
-
(_a = (yield project)) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
69
|
-
}));
|
|
70
|
-
inferredProject = undefined;
|
|
71
|
-
projects.clear();
|
|
60
|
+
inferredProject = undefined;
|
|
61
|
+
projects.clear();
|
|
62
|
+
}
|
|
63
|
+
async function getProjectAndTsConfig(uri) {
|
|
64
|
+
const tsconfig = await findMatchConfigs(vscode_uri_1.URI.parse(uri));
|
|
65
|
+
if (tsconfig) {
|
|
66
|
+
const project = await getProjectByCreate(tsconfig);
|
|
67
|
+
return {
|
|
68
|
+
tsconfig: tsconfig,
|
|
69
|
+
project,
|
|
70
|
+
};
|
|
72
71
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
}
|
|
73
|
+
function getInferredProject() {
|
|
74
|
+
if (!inferredProject) {
|
|
75
|
+
inferredProject = (async () => {
|
|
76
|
+
const inferOptions = await (0, inferredCompilerOptions_1.getInferredCompilerOptions)(context.workspaces.configurationHost);
|
|
77
|
+
return (0, project_1.createProject)({
|
|
78
|
+
workspace: context,
|
|
79
|
+
rootUri: context.rootUri,
|
|
80
|
+
tsConfig: inferOptions,
|
|
81
|
+
documentRegistry,
|
|
82
|
+
});
|
|
83
|
+
})();
|
|
84
|
+
}
|
|
85
|
+
return inferredProject;
|
|
86
|
+
}
|
|
87
|
+
async function findMatchConfigs(uri) {
|
|
88
|
+
const filePath = uriToFileName(uri.toString());
|
|
89
|
+
let dir = path.dirname(filePath);
|
|
90
|
+
while (true) {
|
|
91
|
+
if (searchedDirs.has(dir)) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
searchedDirs.add(dir);
|
|
95
|
+
for (const tsConfigName of exports.rootTsConfigNames) {
|
|
96
|
+
const tsconfigPath = path.join(dir, tsConfigName);
|
|
97
|
+
if (sys?.fileExists(tsconfigPath)) {
|
|
98
|
+
rootTsConfigs.add(tsconfigPath);
|
|
82
99
|
}
|
|
83
|
-
}
|
|
100
|
+
}
|
|
101
|
+
dir = path.dirname(dir);
|
|
84
102
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
await prepareClosestootParsedCommandLine();
|
|
104
|
+
return await findDirectIncludeTsconfig() ?? await findIndirectReferenceTsconfig();
|
|
105
|
+
async function prepareClosestootParsedCommandLine() {
|
|
106
|
+
let matches = [];
|
|
107
|
+
for (const rootTsConfig of rootTsConfigs) {
|
|
108
|
+
if ((0, isFileInDir_1.isFileInDir)(uriToFileName(uri.toString()), path.dirname(rootTsConfig))) {
|
|
109
|
+
matches.push(rootTsConfig);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
matches = matches.sort((a, b) => sortTsConfigs(uriToFileName(uri.toString()), a, b));
|
|
113
|
+
if (matches.length) {
|
|
114
|
+
await getParsedCommandLine(matches[0]);
|
|
96
115
|
}
|
|
97
|
-
return inferredProject;
|
|
98
116
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
function findDirectIncludeTsconfig() {
|
|
118
|
+
return findTsconfig(async (tsconfig) => {
|
|
119
|
+
const map = (0, uriMap_1.createUriMap)(fileNameToUri);
|
|
120
|
+
const parsedCommandLine = await getParsedCommandLine(tsconfig);
|
|
121
|
+
for (const fileName of parsedCommandLine?.fileNames ?? []) {
|
|
122
|
+
map.pathSet(fileName, true);
|
|
123
|
+
}
|
|
124
|
+
return map.uriHas(uri.toString());
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function findIndirectReferenceTsconfig() {
|
|
128
|
+
return findTsconfig(async (tsconfig) => {
|
|
129
|
+
const project = await projects.pathGet(tsconfig);
|
|
130
|
+
const ls = project?.getLanguageServiceDontCreate();
|
|
131
|
+
const validDoc = ls?.context.typescript?.languageService.getProgram()?.getSourceFile(uriToFileName(uri.toString()));
|
|
132
|
+
return !!validDoc;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
async function findTsconfig(match) {
|
|
136
|
+
const checked = new Set();
|
|
137
|
+
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(uriToFileName(uri.toString()), a, b))) {
|
|
138
|
+
const project = await projects.pathGet(rootTsConfig);
|
|
139
|
+
if (project) {
|
|
140
|
+
let chains = await getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
|
|
141
|
+
if (context.workspaces.initOptions.reverseConfigFilePriority) {
|
|
142
|
+
chains = chains.reverse();
|
|
143
|
+
}
|
|
144
|
+
for (const chain of chains) {
|
|
145
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
146
|
+
const tsconfig = chain[i];
|
|
147
|
+
if (checked.has(tsconfig))
|
|
148
|
+
continue;
|
|
149
|
+
checked.add(tsconfig);
|
|
150
|
+
if (await match(tsconfig)) {
|
|
151
|
+
return tsconfig;
|
|
110
152
|
}
|
|
111
153
|
}
|
|
112
|
-
|
|
113
|
-
if (matches.length) {
|
|
114
|
-
yield getParsedCommandLine(matches[0]);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
154
|
+
}
|
|
117
155
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async function getReferencesChains(parsedCommandLine, tsConfig, before) {
|
|
159
|
+
if (parsedCommandLine.projectReferences?.length) {
|
|
160
|
+
const newChains = [];
|
|
161
|
+
for (const projectReference of parsedCommandLine.projectReferences) {
|
|
162
|
+
let tsConfigPath = projectReference.path.replace(/\\/g, '/');
|
|
163
|
+
// fix https://github.com/johnsoncodehk/volar/issues/712
|
|
164
|
+
if (sys && !sys.fileExists(tsConfigPath)) {
|
|
165
|
+
const newTsConfigPath = path.join(tsConfigPath, 'tsconfig.json');
|
|
166
|
+
const newJsConfigPath = path.join(tsConfigPath, 'jsconfig.json');
|
|
167
|
+
if (sys.fileExists(newTsConfigPath)) {
|
|
168
|
+
tsConfigPath = newTsConfigPath;
|
|
125
169
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
function findIndirectReferenceTsconfig() {
|
|
130
|
-
return findTsconfig((tsconfig) => __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
var _a, _b;
|
|
132
|
-
const project = yield projects.pathGet(tsconfig);
|
|
133
|
-
const ls = project === null || project === void 0 ? void 0 : project.getLanguageServiceDontCreate();
|
|
134
|
-
const validDoc = (_b = (_a = ls === null || ls === void 0 ? void 0 : ls.context.typescript) === null || _a === void 0 ? void 0 : _a.languageService.getProgram()) === null || _b === void 0 ? void 0 : _b.getSourceFile(uriToFileName(uri.toString()));
|
|
135
|
-
return !!validDoc;
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
function findTsconfig(match) {
|
|
139
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
const checked = new Set();
|
|
141
|
-
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(uriToFileName(uri.toString()), a, b))) {
|
|
142
|
-
const project = yield projects.pathGet(rootTsConfig);
|
|
143
|
-
if (project) {
|
|
144
|
-
let chains = yield getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
|
|
145
|
-
if (context.workspaces.initOptions.reverseConfigFilePriority) {
|
|
146
|
-
chains = chains.reverse();
|
|
147
|
-
}
|
|
148
|
-
for (const chain of chains) {
|
|
149
|
-
for (let i = chain.length - 1; i >= 0; i--) {
|
|
150
|
-
const tsconfig = chain[i];
|
|
151
|
-
if (checked.has(tsconfig))
|
|
152
|
-
continue;
|
|
153
|
-
checked.add(tsconfig);
|
|
154
|
-
if (yield match(tsconfig)) {
|
|
155
|
-
return tsconfig;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
170
|
+
else if (sys.fileExists(newJsConfigPath)) {
|
|
171
|
+
tsConfigPath = newJsConfigPath;
|
|
160
172
|
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (sys && !sys.fileExists(tsConfigPath)) {
|
|
172
|
-
const newTsConfigPath = path.join(tsConfigPath, 'tsconfig.json');
|
|
173
|
-
const newJsConfigPath = path.join(tsConfigPath, 'jsconfig.json');
|
|
174
|
-
if (sys.fileExists(newTsConfigPath)) {
|
|
175
|
-
tsConfigPath = newTsConfigPath;
|
|
176
|
-
}
|
|
177
|
-
else if (sys.fileExists(newJsConfigPath)) {
|
|
178
|
-
tsConfigPath = newJsConfigPath;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const beforeIndex = before.indexOf(tsConfigPath); // cycle
|
|
182
|
-
if (beforeIndex >= 0) {
|
|
183
|
-
newChains.push(before.slice(0, Math.max(beforeIndex, 1)));
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
const referenceParsedCommandLine = yield getParsedCommandLine(tsConfigPath);
|
|
187
|
-
if (referenceParsedCommandLine) {
|
|
188
|
-
for (const chain of yield getReferencesChains(referenceParsedCommandLine, tsConfigPath, [...before, tsConfig])) {
|
|
189
|
-
newChains.push(chain);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
173
|
+
}
|
|
174
|
+
const beforeIndex = before.indexOf(tsConfigPath); // cycle
|
|
175
|
+
if (beforeIndex >= 0) {
|
|
176
|
+
newChains.push(before.slice(0, Math.max(beforeIndex, 1)));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const referenceParsedCommandLine = await getParsedCommandLine(tsConfigPath);
|
|
180
|
+
if (referenceParsedCommandLine) {
|
|
181
|
+
for (const chain of await getReferencesChains(referenceParsedCommandLine, tsConfigPath, [...before, tsConfig])) {
|
|
182
|
+
newChains.push(chain);
|
|
193
183
|
}
|
|
194
|
-
return newChains;
|
|
195
184
|
}
|
|
196
|
-
|
|
197
|
-
return [[...before, tsConfig]];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
function getParsedCommandLine(tsConfig) {
|
|
202
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
const project = yield getProjectByCreate(tsConfig);
|
|
204
|
-
return project === null || project === void 0 ? void 0 : project.getParsedCommandLine();
|
|
205
|
-
});
|
|
185
|
+
}
|
|
206
186
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
let project = projects.pathGet(tsConfig);
|
|
212
|
-
if (!project && documentRegistry) {
|
|
213
|
-
project = (0, project_1.createProject)({
|
|
214
|
-
workspace: context,
|
|
215
|
-
rootUri: vscode_uri_1.URI.parse(fileNameToUri(path.dirname(tsConfig))),
|
|
216
|
-
tsConfig,
|
|
217
|
-
documentRegistry,
|
|
218
|
-
});
|
|
219
|
-
projects.pathSet(tsConfig, project);
|
|
187
|
+
return newChains;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
return [[...before, tsConfig]];
|
|
220
191
|
}
|
|
221
|
-
return project;
|
|
222
192
|
}
|
|
223
|
-
|
|
193
|
+
async function getParsedCommandLine(tsConfig) {
|
|
194
|
+
const project = await getProjectByCreate(tsConfig);
|
|
195
|
+
return project?.getParsedCommandLine();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function getProjectByCreate(_tsConfig) {
|
|
199
|
+
const tsConfig = _tsConfig.replace(/\\/g, '/');
|
|
200
|
+
let project = projects.pathGet(tsConfig);
|
|
201
|
+
if (!project && documentRegistry) {
|
|
202
|
+
project = (0, project_1.createProject)({
|
|
203
|
+
workspace: context,
|
|
204
|
+
rootUri: vscode_uri_1.URI.parse(fileNameToUri(path.dirname(tsConfig))),
|
|
205
|
+
tsConfig,
|
|
206
|
+
documentRegistry,
|
|
207
|
+
});
|
|
208
|
+
projects.pathSet(tsConfig, project);
|
|
209
|
+
}
|
|
210
|
+
return project;
|
|
211
|
+
}
|
|
224
212
|
}
|
|
225
213
|
exports.createWorkspace = createWorkspace;
|
|
226
214
|
function sortTsConfigs(file, a, b) {
|