@volar/language-server 2.0.3 → 2.1.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 +4 -3
- package/browser.js +25 -68
- package/lib/project/inferredCompilerOptions.js +5 -7
- package/lib/project/simpleProject.d.ts +1 -1
- package/lib/project/simpleProject.js +2 -3
- package/lib/project/simpleProjectProvider.d.ts +4 -5
- package/lib/project/simpleProjectProvider.js +46 -42
- package/lib/project/typescriptProject.d.ts +1 -1
- package/lib/project/typescriptProject.js +9 -14
- package/lib/project/typescriptProjectProvider.d.ts +2 -1
- package/lib/project/typescriptProjectProvider.js +163 -172
- package/lib/register/registerEditorFeatures.d.ts +2 -2
- package/lib/register/registerEditorFeatures.js +6 -5
- package/lib/register/registerLanguageFeatures.d.ts +2 -3
- package/lib/register/registerLanguageFeatures.js +4 -29
- package/lib/server.d.ts +5 -12
- package/lib/server.js +63 -71
- package/lib/serverCapabilities.d.ts +3 -0
- package/lib/serverCapabilities.js +91 -0
- package/lib/types.d.ts +2 -34
- package/lib/uri.d.ts +2 -0
- package/lib/uri.js +28 -0
- package/node.d.ts +4 -5
- package/node.js +35 -53
- package/package.json +6 -6
- package/lib/workspaceFolderManager.d.ts +0 -13
- package/lib/workspaceFolderManager.js +0 -39
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sortTSConfigs = exports.
|
|
3
|
+
exports.sortTSConfigs = exports.createTypeScriptProjectProviderFactory = void 0;
|
|
4
4
|
const language_service_1 = require("@volar/language-service");
|
|
5
5
|
const path = require("path-browserify");
|
|
6
6
|
const vscode = require("vscode-languageserver");
|
|
@@ -10,205 +10,196 @@ const uriMap_1 = require("../utils/uriMap");
|
|
|
10
10
|
const inferredCompilerOptions_1 = require("./inferredCompilerOptions");
|
|
11
11
|
const simpleProjectProvider_1 = require("./simpleProjectProvider");
|
|
12
12
|
const typescriptProject_1 = require("./typescriptProject");
|
|
13
|
+
const uri_1 = require("../uri");
|
|
13
14
|
const rootTsConfigNames = ['tsconfig.json', 'jsconfig.json'];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
else if ((change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Deleted) && configProjects.uriHas(change.uri)) {
|
|
27
|
-
if (change.type === vscode.FileChangeType.Deleted) {
|
|
28
|
-
rootTsConfigs.delete(uriToFileName(change.uri));
|
|
15
|
+
function createTypeScriptProjectProviderFactory(ts, tsLocalized) {
|
|
16
|
+
return (context, servicePlugins, getLanguagePlugins) => {
|
|
17
|
+
const { fs } = context.runtimeEnv;
|
|
18
|
+
const configProjects = (0, uriMap_1.createUriMap)(uri_1.fileNameToUri);
|
|
19
|
+
const inferredProjects = (0, uriMap_1.createUriMap)(uri_1.fileNameToUri);
|
|
20
|
+
const rootTsConfigs = new Set();
|
|
21
|
+
const searchedDirs = new Set();
|
|
22
|
+
context.onDidChangeWatchedFiles(({ changes }) => {
|
|
23
|
+
const tsConfigChanges = changes.filter(change => rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1)));
|
|
24
|
+
for (const change of tsConfigChanges) {
|
|
25
|
+
if (change.type === vscode.FileChangeType.Created) {
|
|
26
|
+
rootTsConfigs.add((0, uri_1.uriToFileName)(change.uri));
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
context.updateDiagnosticsAndSemanticTokens();
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
context.workspaceFolders.onDidRemove(folder => {
|
|
43
|
-
for (const uri of configProjects.uriKeys()) {
|
|
44
|
-
const project = configProjects.uriGet(uri);
|
|
45
|
-
project.then(project => {
|
|
46
|
-
if (project.serviceEnv.workspaceFolder === folder.toString()) {
|
|
47
|
-
configProjects.uriDelete(uri);
|
|
48
|
-
project.dispose();
|
|
28
|
+
else if ((change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Deleted) && configProjects.uriHas(change.uri)) {
|
|
29
|
+
if (change.type === vscode.FileChangeType.Deleted) {
|
|
30
|
+
rootTsConfigs.delete((0, uri_1.uriToFileName)(change.uri));
|
|
31
|
+
}
|
|
32
|
+
const project = configProjects.uriGet(change.uri);
|
|
33
|
+
configProjects.uriDelete(change.uri);
|
|
34
|
+
project?.then(project => project.dispose());
|
|
49
35
|
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
return {
|
|
54
|
-
async getProject(uri) {
|
|
55
|
-
const tsconfig = await findMatchTSConfig(vscode_uri_1.URI.parse(uri));
|
|
56
|
-
if (tsconfig) {
|
|
57
|
-
return await getOrCreateConfiguredProject(tsconfig);
|
|
58
36
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
async getProjects() {
|
|
63
|
-
return await Promise.all([
|
|
64
|
-
...configProjects.values(),
|
|
65
|
-
...inferredProjects.values(),
|
|
66
|
-
]);
|
|
67
|
-
},
|
|
68
|
-
reloadProjects() {
|
|
69
|
-
for (const project of [...configProjects.values(), ...inferredProjects.values()]) {
|
|
70
|
-
project.then(project => project.dispose());
|
|
37
|
+
if (tsConfigChanges.length) {
|
|
38
|
+
context.reloadDiagnostics();
|
|
71
39
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
context.reloadDiagnostics();
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
async function findMatchTSConfig(uri) {
|
|
78
|
-
const filePath = uriToFileName(uri.toString());
|
|
79
|
-
let dir = path.dirname(filePath);
|
|
80
|
-
while (true) {
|
|
81
|
-
if (searchedDirs.has(dir)) {
|
|
82
|
-
break;
|
|
40
|
+
else {
|
|
41
|
+
context.updateDiagnosticsAndSemanticTokens();
|
|
83
42
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
async getProject(uri) {
|
|
46
|
+
const tsconfig = await findMatchTSConfig(vscode_uri_1.URI.parse(uri));
|
|
47
|
+
if (tsconfig) {
|
|
48
|
+
return await getOrCreateConfiguredProject(tsconfig);
|
|
49
|
+
}
|
|
50
|
+
const workspaceFolder = (0, simpleProjectProvider_1.getWorkspaceFolder)(uri, context.workspaceFolders);
|
|
51
|
+
return await getOrCreateInferredProject(uri, workspaceFolder);
|
|
52
|
+
},
|
|
53
|
+
async getProjects() {
|
|
54
|
+
return await Promise.all([
|
|
55
|
+
...configProjects.values(),
|
|
56
|
+
...inferredProjects.values(),
|
|
57
|
+
]);
|
|
58
|
+
},
|
|
59
|
+
reloadProjects() {
|
|
60
|
+
for (const project of [...configProjects.values(), ...inferredProjects.values()]) {
|
|
61
|
+
project.then(project => project.dispose());
|
|
62
|
+
}
|
|
63
|
+
configProjects.clear();
|
|
64
|
+
inferredProjects.clear();
|
|
65
|
+
context.reloadDiagnostics();
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
async function findMatchTSConfig(uri) {
|
|
69
|
+
const filePath = (0, uri_1.uriToFileName)(uri.toString());
|
|
70
|
+
let dir = path.dirname(filePath);
|
|
71
|
+
while (true) {
|
|
72
|
+
if (searchedDirs.has(dir)) {
|
|
73
|
+
break;
|
|
89
74
|
}
|
|
75
|
+
searchedDirs.add(dir);
|
|
76
|
+
for (const tsConfigName of rootTsConfigNames) {
|
|
77
|
+
const tsconfigPath = path.join(dir, tsConfigName);
|
|
78
|
+
if ((await fs.stat?.((0, uri_1.fileNameToUri)(tsconfigPath)))?.type === language_service_1.FileType.File) {
|
|
79
|
+
rootTsConfigs.add(tsconfigPath);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
dir = path.dirname(dir);
|
|
90
83
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
84
|
+
await prepareClosestootParsedCommandLine();
|
|
85
|
+
return await findDirectIncludeTsconfig() ?? await findIndirectReferenceTsconfig();
|
|
86
|
+
async function prepareClosestootParsedCommandLine() {
|
|
87
|
+
let matches = [];
|
|
88
|
+
for (const rootTsConfig of rootTsConfigs) {
|
|
89
|
+
if ((0, isFileInDir_1.isFileInDir)((0, uri_1.uriToFileName)(uri.toString()), path.dirname(rootTsConfig))) {
|
|
90
|
+
matches.push(rootTsConfig);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
matches = matches.sort((a, b) => sortTSConfigs((0, uri_1.uriToFileName)(uri.toString()), a, b));
|
|
94
|
+
if (matches.length) {
|
|
95
|
+
await getParsedCommandLine(matches[0]);
|
|
100
96
|
}
|
|
101
97
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
function findIndirectReferenceTsconfig() {
|
|
99
|
+
return findTSConfig(async (tsconfig) => {
|
|
100
|
+
const project = await configProjects.pathGet(tsconfig);
|
|
101
|
+
return project?.askedFiles.uriHas(uri.toString()) ?? false;
|
|
102
|
+
});
|
|
105
103
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
function findDirectIncludeTsconfig() {
|
|
114
|
-
return findTSConfig(async (tsconfig) => {
|
|
115
|
-
const map = (0, uriMap_1.createUriMap)(fileNameToUri);
|
|
116
|
-
const parsedCommandLine = await getParsedCommandLine(tsconfig);
|
|
117
|
-
for (const fileName of parsedCommandLine?.fileNames ?? []) {
|
|
118
|
-
map.pathSet(fileName, true);
|
|
119
|
-
}
|
|
120
|
-
return map.uriHas(uri.toString());
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
async function findTSConfig(match) {
|
|
124
|
-
const checked = new Set();
|
|
125
|
-
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTSConfigs(uriToFileName(uri.toString()), a, b))) {
|
|
126
|
-
const project = await configProjects.pathGet(rootTsConfig);
|
|
127
|
-
if (project) {
|
|
128
|
-
let chains = await getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
|
|
129
|
-
if (context.initializeParams.initializationOptions?.reverseConfigFilePriority) {
|
|
130
|
-
chains = chains.reverse();
|
|
104
|
+
function findDirectIncludeTsconfig() {
|
|
105
|
+
return findTSConfig(async (tsconfig) => {
|
|
106
|
+
const map = (0, uriMap_1.createUriMap)(uri_1.fileNameToUri);
|
|
107
|
+
const parsedCommandLine = await getParsedCommandLine(tsconfig);
|
|
108
|
+
for (const fileName of parsedCommandLine?.fileNames ?? []) {
|
|
109
|
+
map.pathSet(fileName, true);
|
|
131
110
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
111
|
+
return map.uriHas(uri.toString());
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async function findTSConfig(match) {
|
|
115
|
+
const checked = new Set();
|
|
116
|
+
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTSConfigs((0, uri_1.uriToFileName)(uri.toString()), a, b))) {
|
|
117
|
+
const project = await configProjects.pathGet(rootTsConfig);
|
|
118
|
+
if (project) {
|
|
119
|
+
let chains = await getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
|
|
120
|
+
// This is to be consistent with tsserver behavior
|
|
121
|
+
chains = chains.reverse();
|
|
122
|
+
for (const chain of chains) {
|
|
123
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
124
|
+
const tsconfig = chain[i];
|
|
125
|
+
if (checked.has(tsconfig)) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
checked.add(tsconfig);
|
|
129
|
+
if (await match(tsconfig)) {
|
|
130
|
+
return tsconfig;
|
|
131
|
+
}
|
|
141
132
|
}
|
|
142
133
|
}
|
|
143
134
|
}
|
|
144
135
|
}
|
|
145
136
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
137
|
+
async function getReferencesChains(parsedCommandLine, tsConfig, before) {
|
|
138
|
+
if (parsedCommandLine.projectReferences?.length) {
|
|
139
|
+
const newChains = [];
|
|
140
|
+
for (const projectReference of parsedCommandLine.projectReferences) {
|
|
141
|
+
let tsConfigPath = projectReference.path.replace(/\\/g, '/');
|
|
142
|
+
// fix https://github.com/johnsoncodehk/volar/issues/712
|
|
143
|
+
if ((await fs.stat?.((0, uri_1.fileNameToUri)(tsConfigPath)))?.type === language_service_1.FileType.File) {
|
|
144
|
+
const newTsConfigPath = path.join(tsConfigPath, 'tsconfig.json');
|
|
145
|
+
const newJsConfigPath = path.join(tsConfigPath, 'jsconfig.json');
|
|
146
|
+
if ((await fs.stat?.((0, uri_1.fileNameToUri)(newTsConfigPath)))?.type === language_service_1.FileType.File) {
|
|
147
|
+
tsConfigPath = newTsConfigPath;
|
|
148
|
+
}
|
|
149
|
+
else if ((await fs.stat?.((0, uri_1.fileNameToUri)(newJsConfigPath)))?.type === language_service_1.FileType.File) {
|
|
150
|
+
tsConfigPath = newJsConfigPath;
|
|
151
|
+
}
|
|
158
152
|
}
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
const beforeIndex = before.indexOf(tsConfigPath); // cycle
|
|
154
|
+
if (beforeIndex >= 0) {
|
|
155
|
+
newChains.push(before.slice(0, Math.max(beforeIndex, 1)));
|
|
161
156
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const referenceParsedCommandLine = await getParsedCommandLine(tsConfigPath);
|
|
169
|
-
if (referenceParsedCommandLine) {
|
|
170
|
-
for (const chain of await getReferencesChains(referenceParsedCommandLine, tsConfigPath, [...before, tsConfig])) {
|
|
171
|
-
newChains.push(chain);
|
|
157
|
+
else {
|
|
158
|
+
const referenceParsedCommandLine = await getParsedCommandLine(tsConfigPath);
|
|
159
|
+
if (referenceParsedCommandLine) {
|
|
160
|
+
for (const chain of await getReferencesChains(referenceParsedCommandLine, tsConfigPath, [...before, tsConfig])) {
|
|
161
|
+
newChains.push(chain);
|
|
162
|
+
}
|
|
172
163
|
}
|
|
173
164
|
}
|
|
174
165
|
}
|
|
166
|
+
return newChains;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return [[...before, tsConfig]];
|
|
175
170
|
}
|
|
176
|
-
return newChains;
|
|
177
171
|
}
|
|
178
|
-
|
|
179
|
-
|
|
172
|
+
async function getParsedCommandLine(tsConfig) {
|
|
173
|
+
const project = await getOrCreateConfiguredProject(tsConfig);
|
|
174
|
+
return project?.getParsedCommandLine();
|
|
180
175
|
}
|
|
181
176
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
function getOrCreateConfiguredProject(tsconfig) {
|
|
188
|
-
tsconfig = tsconfig.replace(/\\/g, '/');
|
|
189
|
-
let projectPromise = configProjects.pathGet(tsconfig);
|
|
190
|
-
if (!projectPromise) {
|
|
191
|
-
const workspaceFolder = (0, simpleProjectProvider_1.getWorkspaceFolder)(fileNameToUri(tsconfig), context.workspaceFolders, uriToFileName);
|
|
192
|
-
const serviceEnv = (0, simpleProjectProvider_1.createServiceEnvironment)(context, workspaceFolder);
|
|
193
|
-
projectPromise = (0, typescriptProject_1.createTypeScriptServerProject)(tsconfig, context, serviceEnv, serverOptions, servicePlugins);
|
|
194
|
-
configProjects.pathSet(tsconfig, projectPromise);
|
|
195
|
-
}
|
|
196
|
-
return projectPromise;
|
|
197
|
-
}
|
|
198
|
-
async function getOrCreateInferredProject(uri, workspaceFolder) {
|
|
199
|
-
if (!inferredProjects.uriHas(workspaceFolder.toString())) {
|
|
200
|
-
inferredProjects.uriSet(workspaceFolder.toString(), (async () => {
|
|
201
|
-
const inferOptions = await (0, inferredCompilerOptions_1.getInferredCompilerOptions)(context.configurationHost);
|
|
177
|
+
function getOrCreateConfiguredProject(tsconfig) {
|
|
178
|
+
tsconfig = tsconfig.replace(/\\/g, '/');
|
|
179
|
+
let projectPromise = configProjects.pathGet(tsconfig);
|
|
180
|
+
if (!projectPromise) {
|
|
181
|
+
const workspaceFolder = (0, simpleProjectProvider_1.getWorkspaceFolder)((0, uri_1.fileNameToUri)(tsconfig), context.workspaceFolders);
|
|
202
182
|
const serviceEnv = (0, simpleProjectProvider_1.createServiceEnvironment)(context, workspaceFolder);
|
|
203
|
-
|
|
204
|
-
|
|
183
|
+
projectPromise = (0, typescriptProject_1.createTypeScriptServerProject)(ts, tsLocalized, tsconfig, context, serviceEnv, servicePlugins, getLanguagePlugins);
|
|
184
|
+
configProjects.pathSet(tsconfig, projectPromise);
|
|
185
|
+
}
|
|
186
|
+
return projectPromise;
|
|
205
187
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
188
|
+
async function getOrCreateInferredProject(uri, workspaceFolder) {
|
|
189
|
+
if (!inferredProjects.uriHas(workspaceFolder)) {
|
|
190
|
+
inferredProjects.uriSet(workspaceFolder, (async () => {
|
|
191
|
+
const inferOptions = await (0, inferredCompilerOptions_1.getInferredCompilerOptions)(context.configurationHost);
|
|
192
|
+
const serviceEnv = (0, simpleProjectProvider_1.createServiceEnvironment)(context, workspaceFolder);
|
|
193
|
+
return (0, typescriptProject_1.createTypeScriptServerProject)(ts, tsLocalized, inferOptions, context, serviceEnv, servicePlugins, getLanguagePlugins);
|
|
194
|
+
})());
|
|
195
|
+
}
|
|
196
|
+
const project = await inferredProjects.uriGet(workspaceFolder.toString());
|
|
197
|
+
project.tryAddFile((0, uri_1.uriToFileName)(uri));
|
|
198
|
+
return project;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
exports.createTypeScriptProjectProviderFactory = createTypeScriptProjectProviderFactory;
|
|
212
203
|
function sortTSConfigs(file, a, b) {
|
|
213
204
|
const inA = (0, isFileInDir_1.isFileInDir)(file, path.dirname(a));
|
|
214
205
|
const inB = (0, isFileInDir_1.isFileInDir)(file, path.dirname(b));
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type * as vscode from 'vscode-languageserver';
|
|
2
|
-
import type { ServerProjectProvider
|
|
3
|
-
export declare function registerEditorFeatures(connection: vscode.Connection, projects: ServerProjectProvider
|
|
2
|
+
import type { ServerProjectProvider } from '../types';
|
|
3
|
+
export declare function registerEditorFeatures(connection: vscode.Connection, projects: ServerProjectProvider): void;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerEditorFeatures = void 0;
|
|
4
4
|
const protocol_1 = require("../../protocol");
|
|
5
|
-
|
|
5
|
+
const uri_1 = require("../uri");
|
|
6
|
+
function registerEditorFeatures(connection, projects) {
|
|
6
7
|
const scriptVersions = new Map();
|
|
7
8
|
const scriptVersionSnapshots = new WeakSet();
|
|
8
9
|
connection.onRequest(protocol_1.DocumentDropRequest.type, async ({ textDocument, position, dataTransfer }, token) => {
|
|
@@ -33,7 +34,7 @@ function registerEditorFeatures(connection, projects, env) {
|
|
|
33
34
|
const languageService = (await projects.getProject(params.uri)).getLanguageService();
|
|
34
35
|
const configFileName = languageService.context.language.typescript?.configFileName;
|
|
35
36
|
if (configFileName) {
|
|
36
|
-
return { uri:
|
|
37
|
+
return { uri: (0, uri_1.fileNameToUri)(configFileName) };
|
|
37
38
|
}
|
|
38
39
|
});
|
|
39
40
|
connection.onRequest(protocol_1.GetVirtualFileRequest.type, async (document) => {
|
|
@@ -54,7 +55,7 @@ function registerEditorFeatures(connection, projects, env) {
|
|
|
54
55
|
fileUri: sourceFile.id,
|
|
55
56
|
virtualCodeId: code.id,
|
|
56
57
|
languageId: code.languageId,
|
|
57
|
-
embeddedCodes: code.embeddedCodes
|
|
58
|
+
embeddedCodes: code.embeddedCodes?.map(prune) || [],
|
|
58
59
|
version,
|
|
59
60
|
disabled: languageService.context.disabledVirtualFileUris.has(uri),
|
|
60
61
|
};
|
|
@@ -68,9 +69,9 @@ function registerEditorFeatures(connection, projects, env) {
|
|
|
68
69
|
const [virtualCode] = languageService.context.language.files.getVirtualCode(params.fileUri, params.virtualCodeId);
|
|
69
70
|
if (virtualCode) {
|
|
70
71
|
for (const map of languageService.context.documents.getMaps(virtualCode)) {
|
|
71
|
-
content = map.
|
|
72
|
+
content = map.embeddedDocument.getText();
|
|
72
73
|
codegenStacks = virtualCode.codegenStacks ?? [];
|
|
73
|
-
mappings[map.
|
|
74
|
+
mappings[map.sourceDocument.uri] = map.map.mappings;
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
return {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { SnapshotDocument } from '@volar/snapshot-document';
|
|
2
1
|
import * as vscode from 'vscode-languageserver';
|
|
3
|
-
import type {
|
|
4
|
-
export declare function registerLanguageFeatures(connection: vscode.Connection, projectProvider: ServerProjectProvider, initParams: vscode.InitializeParams,
|
|
2
|
+
import type { ServerProjectProvider } from '../types';
|
|
3
|
+
export declare function registerLanguageFeatures(connection: vscode.Connection, projectProvider: ServerProjectProvider, initParams: vscode.InitializeParams, semanticTokensLegend: vscode.SemanticTokensLegend): void;
|
|
5
4
|
export declare function sleep(ms: number): Promise<unknown>;
|
|
@@ -4,7 +4,7 @@ exports.sleep = exports.registerLanguageFeatures = void 0;
|
|
|
4
4
|
const embedded = require("@volar/language-service");
|
|
5
5
|
const vscode = require("vscode-languageserver");
|
|
6
6
|
const protocol_1 = require("../../protocol");
|
|
7
|
-
function registerLanguageFeatures(connection, projectProvider, initParams,
|
|
7
|
+
function registerLanguageFeatures(connection, projectProvider, initParams, semanticTokensLegend) {
|
|
8
8
|
let lastCompleteUri;
|
|
9
9
|
let lastCompleteLs;
|
|
10
10
|
let lastCodeLensLs;
|
|
@@ -61,34 +61,10 @@ function registerLanguageFeatures(connection, projectProvider, initParams, initO
|
|
|
61
61
|
return worker(params.textDocument.uri, token, async (service) => {
|
|
62
62
|
lastCompleteUri = params.textDocument.uri;
|
|
63
63
|
lastCompleteLs = service;
|
|
64
|
-
const document = documents.get(params.textDocument.uri);
|
|
65
64
|
const list = await service.doComplete(params.textDocument.uri, params.position, params.context, token);
|
|
66
65
|
for (const item of list.items) {
|
|
67
66
|
fixTextEdit(item);
|
|
68
67
|
}
|
|
69
|
-
if (!initOptions.fullCompletionList && document) {
|
|
70
|
-
list.items = list.items.filter(item => {
|
|
71
|
-
const range = item.textEdit ? (vscode.InsertReplaceEdit.is(item.textEdit)
|
|
72
|
-
? item.textEdit.replace
|
|
73
|
-
: item.textEdit.range) : list.itemDefaults?.editRange ? (vscode.Range.is(list.itemDefaults.editRange)
|
|
74
|
-
? list.itemDefaults.editRange
|
|
75
|
-
: list.itemDefaults.editRange.replace) : undefined;
|
|
76
|
-
if (range) {
|
|
77
|
-
const sourceText = document.getText(range).toLowerCase();
|
|
78
|
-
if (sourceText.trim()) {
|
|
79
|
-
let filterText = (item.filterText ?? item.label).toLowerCase();
|
|
80
|
-
for (const char of sourceText) {
|
|
81
|
-
const index = filterText.indexOf(char);
|
|
82
|
-
if (index === -1) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
filterText = filterText.slice(index + 1);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return true;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
68
|
return list;
|
|
93
69
|
});
|
|
94
70
|
});
|
|
@@ -215,13 +191,11 @@ function registerLanguageFeatures(connection, projectProvider, initParams, initO
|
|
|
215
191
|
return await lastCallHierarchyLs?.callHierarchy.getOutgoingCalls(params.item, token) ?? [];
|
|
216
192
|
});
|
|
217
193
|
connection.languages.semanticTokens.on(async (params, token, _, resultProgress) => {
|
|
218
|
-
await sleep(200);
|
|
219
194
|
return await worker(params.textDocument.uri, token, async (service) => {
|
|
220
195
|
return await service?.getSemanticTokens(params.textDocument.uri, undefined, semanticTokensLegend, token, tokens => resultProgress?.report(tokens));
|
|
221
196
|
}) ?? { data: [] };
|
|
222
197
|
});
|
|
223
198
|
connection.languages.semanticTokens.onRange(async (params, token, _, resultProgress) => {
|
|
224
|
-
await sleep(200);
|
|
225
199
|
return await worker(params.textDocument.uri, token, async (service) => {
|
|
226
200
|
return await service?.getSemanticTokens(params.textDocument.uri, params.range, semanticTokensLegend, token, tokens => resultProgress?.report(tokens));
|
|
227
201
|
}) ?? { data: [] };
|
|
@@ -274,7 +248,8 @@ function registerLanguageFeatures(connection, projectProvider, initParams, initO
|
|
|
274
248
|
});
|
|
275
249
|
function worker(uri, token, cb) {
|
|
276
250
|
return new Promise(resolve => {
|
|
277
|
-
|
|
251
|
+
const timeout = setTimeout(async () => {
|
|
252
|
+
clearTimeout(timeout);
|
|
278
253
|
if (token.isCancellationRequested) {
|
|
279
254
|
resolve(undefined);
|
|
280
255
|
return;
|
|
@@ -292,7 +267,7 @@ function registerLanguageFeatures(connection, projectProvider, initParams, initO
|
|
|
292
267
|
resolve(undefined);
|
|
293
268
|
return;
|
|
294
269
|
}
|
|
295
|
-
});
|
|
270
|
+
}, 0);
|
|
296
271
|
});
|
|
297
272
|
}
|
|
298
273
|
function fixTextEdit(item) {
|
package/lib/server.d.ts
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { LanguagePlugin, ServiceEnvironment, ServicePlugin } from '@volar/language-service';
|
|
2
|
-
import * as vscode from 'vscode-languageserver';
|
|
3
|
-
import { InitializationOptions, ProjectContext, ServerProjectProvider, ServerProjectProviderFactory, ServerRuntimeEnvironment } from './types.js';
|
|
4
|
-
import { createConfigurationHost } from './configurationHost.js';
|
|
5
|
-
import { WorkspaceFolderManager } from './workspaceFolderManager.js';
|
|
6
2
|
import { SnapshotDocument } from '@volar/snapshot-document';
|
|
7
|
-
import type * as ts from 'typescript';
|
|
8
3
|
import type { TextDocuments } from 'vscode-languageserver';
|
|
4
|
+
import * as vscode from 'vscode-languageserver';
|
|
5
|
+
import { createConfigurationHost } from './configurationHost.js';
|
|
6
|
+
import { InitializationOptions, ProjectContext, ServerProjectProvider, ServerProjectProviderFactory, ServerRuntimeEnvironment } from './types.js';
|
|
7
|
+
import { type UriMap } from './utils/uriMap.js';
|
|
9
8
|
export interface ServerContext {
|
|
10
|
-
connection: vscode.Connection;
|
|
11
9
|
initializeParams: Omit<vscode.InitializeParams, 'initializationOptions'> & {
|
|
12
10
|
initializationOptions?: InitializationOptions;
|
|
13
11
|
};
|
|
14
12
|
runtimeEnv: ServerRuntimeEnvironment;
|
|
15
13
|
onDidChangeWatchedFiles: vscode.Connection['onDidChangeWatchedFiles'];
|
|
16
14
|
configurationHost: ReturnType<typeof createConfigurationHost> | undefined;
|
|
17
|
-
|
|
18
|
-
tsLocalized: ts.MapLike<string> | undefined;
|
|
19
|
-
workspaceFolders: WorkspaceFolderManager;
|
|
15
|
+
workspaceFolders: UriMap<boolean>;
|
|
20
16
|
documents: TextDocuments<SnapshotDocument>;
|
|
21
17
|
reloadDiagnostics(): void;
|
|
22
18
|
updateDiagnosticsAndSemanticTokens(): void;
|
|
@@ -32,7 +28,4 @@ export declare function createServerBase(connection: vscode.Connection, getRunti
|
|
|
32
28
|
shutdown: () => void;
|
|
33
29
|
readonly projects: ServerProjectProvider;
|
|
34
30
|
readonly env: ServerRuntimeEnvironment;
|
|
35
|
-
readonly modules: {
|
|
36
|
-
typescript: typeof ts | undefined;
|
|
37
|
-
};
|
|
38
31
|
};
|