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