@volar/language-server 1.0.22 → 1.1.0-1.2.0-alpha.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/out/browser/fileSystems.js +15 -20
- package/out/browser/index.js +8 -3
- package/out/common/documents.d.ts +1 -0
- package/out/common/documents.js +3 -0
- package/out/common/features/customFeatures.js +12 -13
- package/out/common/features/languageFeatures.d.ts +2 -1
- package/out/common/features/languageFeatures.js +97 -82
- package/out/common/project.d.ts +2 -2
- package/out/common/project.js +78 -63
- package/out/common/server.js +28 -22
- package/out/common/utils/isFileInDir.d.ts +2 -0
- package/out/common/utils/isFileInDir.js +9 -0
- package/out/common/utils/registerFeatures.js +24 -55
- package/out/common/utils/serverConfig.d.ts +2 -5
- package/out/common/utils/serverConfig.js +3 -3
- package/out/common/utils/uriMap.js +1 -1
- package/out/common/workspace.js +14 -13
- package/out/common/workspaces.js +8 -4
- package/out/index.d.ts +1 -0
- package/out/index.js +1 -0
- package/out/node/fileSystem.js +1 -1
- package/out/node/index.js +8 -2
- package/out/protocol.js +12 -12
- package/out/types.d.ts +24 -7
- package/package.json +7 -6
package/out/common/project.js
CHANGED
|
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.createProject = void 0;
|
|
12
|
-
const embedded = require("@volar/language-core");
|
|
13
12
|
const embeddedLS = require("@volar/language-service");
|
|
14
13
|
const shared = require("@volar/shared");
|
|
15
14
|
const path = require("typesafe-path");
|
|
16
15
|
const vscode = require("vscode-languageserver");
|
|
16
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
17
17
|
const types_1 = require("../types");
|
|
18
18
|
const uriMap_1 = require("./utils/uriMap");
|
|
19
19
|
function createProject(context) {
|
|
@@ -35,7 +35,7 @@ function createProject(context) {
|
|
|
35
35
|
let projectVersion = 0;
|
|
36
36
|
let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
37
37
|
let languageService;
|
|
38
|
-
let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.
|
|
38
|
+
let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
|
|
39
39
|
const scripts = (0, uriMap_1.createUriMap)();
|
|
40
40
|
const languageServiceHost = createLanguageServiceHost();
|
|
41
41
|
const disposeWatchEvent = (_a = context.workspace.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.onDidChangeWatchedFiles(params => {
|
|
@@ -62,39 +62,37 @@ function createProject(context) {
|
|
|
62
62
|
dispose,
|
|
63
63
|
};
|
|
64
64
|
function getLanguageService() {
|
|
65
|
+
var _a, _b, _c, _d, _e, _f;
|
|
65
66
|
if (!languageService) {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const config = {
|
|
68
|
+
languages: Object.assign({}, (_b = (_a = context.serverConfig) === null || _a === void 0 ? void 0 : _a.languages) !== null && _b !== void 0 ? _b : {}),
|
|
69
|
+
plugins: Object.assign({}, (_d = (_c = context.serverConfig) === null || _c === void 0 ? void 0 : _c.plugins) !== null && _d !== void 0 ? _d : {}),
|
|
70
|
+
rules: Object.assign({}, (_e = context.serverConfig) === null || _e === void 0 ? void 0 : _e.rules),
|
|
71
|
+
};
|
|
72
|
+
const env = {
|
|
73
|
+
rootUri: context.rootUri,
|
|
74
|
+
configurationHost: context.workspace.workspaces.configurationHost,
|
|
75
|
+
fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
|
|
76
|
+
documentContext: getDocumentContext(context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
|
|
77
|
+
schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
79
|
+
const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
|
|
80
|
+
if (builtInHandler) {
|
|
81
|
+
return yield builtInHandler(uri);
|
|
82
|
+
}
|
|
83
|
+
return '';
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
|
+
const lsCtx = {
|
|
87
|
+
project: context,
|
|
88
|
+
env,
|
|
89
|
+
sys,
|
|
69
90
|
host: languageServiceHost,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
...context.workspace.workspaces.plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.getLanguageServicePlugins) === null || _a === void 0 ? void 0 : _a.call(plugin, languageServiceHost, languageServiceContext)) !== null && _b !== void 0 ? _b : []; }).flat(),
|
|
76
|
-
];
|
|
77
|
-
},
|
|
78
|
-
env: {
|
|
79
|
-
rootUri: context.rootUri,
|
|
80
|
-
configurationHost: context.workspace.workspaces.configurationHost,
|
|
81
|
-
fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
|
|
82
|
-
documentContext: context.workspace.workspaces.ts
|
|
83
|
-
? getHTMLDocumentContext(context.workspace.workspaces.ts, languageServiceHost)
|
|
84
|
-
: undefined,
|
|
85
|
-
schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
87
|
-
const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
|
|
88
|
-
if (builtInHandler) {
|
|
89
|
-
return yield builtInHandler(uri);
|
|
90
|
-
}
|
|
91
|
-
return '';
|
|
92
|
-
}),
|
|
93
|
-
},
|
|
94
|
-
documentRegistry: context.documentRegistry,
|
|
95
|
-
getLanguageService: () => languageService,
|
|
96
|
-
});
|
|
97
|
-
languageService = embeddedLS.createLanguageService(languageServiceContext);
|
|
91
|
+
};
|
|
92
|
+
for (const plugin of context.workspace.workspaces.plugins) {
|
|
93
|
+
(_f = plugin.resolveConfig) === null || _f === void 0 ? void 0 : _f.call(plugin, config, lsCtx);
|
|
94
|
+
}
|
|
95
|
+
languageService = embeddedLS.createLanguageService(languageServiceHost, config, env, context.documentRegistry);
|
|
98
96
|
}
|
|
99
97
|
return languageService;
|
|
100
98
|
}
|
|
@@ -121,7 +119,7 @@ function createProject(context) {
|
|
|
121
119
|
const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
|
|
122
120
|
const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
|
|
123
121
|
if (creates.length || deletes.length) {
|
|
124
|
-
parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.
|
|
122
|
+
parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
|
|
125
123
|
projectVersion++;
|
|
126
124
|
typeRootVersion++;
|
|
127
125
|
}
|
|
@@ -148,7 +146,7 @@ function createProject(context) {
|
|
|
148
146
|
readDirectory: sys.readDirectory,
|
|
149
147
|
realpath: sys.realpath,
|
|
150
148
|
fileExists: sys.fileExists,
|
|
151
|
-
getCurrentDirectory: () => shared.
|
|
149
|
+
getCurrentDirectory: () => shared.uriToFileName(context.rootUri.toString()),
|
|
152
150
|
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
153
151
|
getCancellationToken: () => token,
|
|
154
152
|
// custom
|
|
@@ -170,8 +168,12 @@ function createProject(context) {
|
|
|
170
168
|
getCompilationSettings: () => parsedCommandLine.options,
|
|
171
169
|
getScriptVersion,
|
|
172
170
|
getScriptSnapshot,
|
|
173
|
-
getTypeScriptModule: () => {
|
|
171
|
+
getTypeScriptModule: context.workspace.workspaces.ts ? () => {
|
|
174
172
|
return context.workspace.workspaces.ts;
|
|
173
|
+
} : undefined,
|
|
174
|
+
getScriptLanguageId: (fileName) => {
|
|
175
|
+
var _a;
|
|
176
|
+
return (_a = context.workspace.workspaces.documents.data.pathGet(fileName)) === null || _a === void 0 ? void 0 : _a.languageId;
|
|
175
177
|
},
|
|
176
178
|
};
|
|
177
179
|
if (context.workspace.workspaces.initOptions.noProjectReferences) {
|
|
@@ -181,11 +183,6 @@ function createProject(context) {
|
|
|
181
183
|
if (context.workspace.workspaces.tsLocalized) {
|
|
182
184
|
host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
|
|
183
185
|
}
|
|
184
|
-
for (const plugin of context.workspace.workspaces.plugins) {
|
|
185
|
-
if (context.workspace.workspaces.ts && plugin.resolveLanguageServiceHost) {
|
|
186
|
-
host = plugin.resolveLanguageServiceHost(context.workspace.workspaces.ts, sys, context.tsConfig, host);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
186
|
return host;
|
|
190
187
|
function getScriptVersion(fileName) {
|
|
191
188
|
var _a, _b;
|
|
@@ -243,7 +240,7 @@ function createProject(context) {
|
|
|
243
240
|
}
|
|
244
241
|
exports.createProject = createProject;
|
|
245
242
|
function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
246
|
-
const extraFileExtensions = plugins.map(plugin => { var _a; return (_a = plugin.
|
|
243
|
+
const extraFileExtensions = plugins.map(plugin => { var _a; return (_a = plugin.tsconfigExtraFileExtensions) !== null && _a !== void 0 ? _a : []; }).flat();
|
|
247
244
|
if (ts) {
|
|
248
245
|
try {
|
|
249
246
|
let content;
|
|
@@ -271,35 +268,53 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
|
271
268
|
options: {},
|
|
272
269
|
};
|
|
273
270
|
}
|
|
274
|
-
function
|
|
271
|
+
function getDocumentContext(ts, host, rootUri) {
|
|
275
272
|
const documentContext = {
|
|
276
|
-
resolveReference(ref, base) {
|
|
273
|
+
resolveReference: (ref, base) => {
|
|
277
274
|
var _a, _b;
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
dirs.add(path.dirname(failed));
|
|
286
|
-
}
|
|
287
|
-
if (failed.endsWith('.d.ts')) {
|
|
288
|
-
failed = failed.substring(0, failed.length - '.d.ts'.length);
|
|
275
|
+
if (ts && host) { // support tsconfig.json paths
|
|
276
|
+
const isUri = base.indexOf('://') >= 0;
|
|
277
|
+
const resolveResult = ts.resolveModuleName(ref, isUri ? shared.uriToFileName(base) : base, host.getCompilationSettings(), host);
|
|
278
|
+
const failedLookupLocations = typeof resolveResult === 'object' ? resolveResult.failedLookupLocations : [];
|
|
279
|
+
const dirs = new Set();
|
|
280
|
+
if (!failedLookupLocations) {
|
|
281
|
+
console.warn(`[volar] failedLookupLocations not exists, ts: ${ts.version}`);
|
|
289
282
|
}
|
|
290
|
-
|
|
291
|
-
|
|
283
|
+
for (let failed of failedLookupLocations !== null && failedLookupLocations !== void 0 ? failedLookupLocations : []) {
|
|
284
|
+
const fileName = path.basename(failed);
|
|
285
|
+
if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
|
|
286
|
+
dirs.add(path.dirname(failed));
|
|
287
|
+
}
|
|
288
|
+
if (failed.endsWith('.d.ts')) {
|
|
289
|
+
failed = failed.substring(0, failed.length - '.d.ts'.length);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (host.fileExists(failed)) {
|
|
295
|
+
return isUri ? shared.fileNameToUri(failed) : failed;
|
|
296
|
+
}
|
|
292
297
|
}
|
|
293
|
-
|
|
294
|
-
|
|
298
|
+
for (const dir of dirs) {
|
|
299
|
+
if ((_b = (_a = host.directoryExists) === null || _a === void 0 ? void 0 : _a.call(host, dir)) !== null && _b !== void 0 ? _b : true) {
|
|
300
|
+
return isUri ? shared.fileNameToUri(dir) : dir;
|
|
301
|
+
}
|
|
295
302
|
}
|
|
296
303
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
304
|
+
// original html resolveReference
|
|
305
|
+
if (ref.match(/^\w[\w\d+.-]*:/)) {
|
|
306
|
+
// starts with a schema
|
|
307
|
+
return ref;
|
|
308
|
+
}
|
|
309
|
+
if (ref[0] === '/') { // resolve absolute path against the current workspace folder
|
|
310
|
+
const folderUri = rootUri;
|
|
311
|
+
if (folderUri) {
|
|
312
|
+
return folderUri + ref.substr(1);
|
|
300
313
|
}
|
|
301
314
|
}
|
|
302
|
-
|
|
315
|
+
const baseUri = vscode_uri_1.URI.parse(base);
|
|
316
|
+
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
|
|
317
|
+
return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
|
|
303
318
|
},
|
|
304
319
|
};
|
|
305
320
|
return documentContext;
|
package/out/common/server.js
CHANGED
|
@@ -17,6 +17,7 @@ const configurationHost_1 = require("./configurationHost");
|
|
|
17
17
|
const documents_1 = require("./documents");
|
|
18
18
|
const registerFeatures_1 = require("./utils/registerFeatures");
|
|
19
19
|
const workspaces_1 = require("./workspaces");
|
|
20
|
+
const l10n = require("@vscode/l10n");
|
|
20
21
|
function startCommonLanguageServer(context) {
|
|
21
22
|
let initParams;
|
|
22
23
|
let options;
|
|
@@ -27,10 +28,13 @@ function startCommonLanguageServer(context) {
|
|
|
27
28
|
let plugins;
|
|
28
29
|
const documents = (0, documents_1.createDocuments)(context.connection);
|
|
29
30
|
context.connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
var _a, _b, _c;
|
|
31
|
+
var _a, _b, _c, _d;
|
|
31
32
|
initParams = _params;
|
|
32
33
|
options = initParams.initializationOptions;
|
|
33
34
|
plugins = context.plugins.map(plugin => plugin(options));
|
|
35
|
+
if (options.l10n) {
|
|
36
|
+
yield l10n.config({ uri: options.l10n.location });
|
|
37
|
+
}
|
|
34
38
|
if (((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) && initParams.workspaceFolders) {
|
|
35
39
|
roots = initParams.workspaceFolders.map(folder => vscode_uri_1.URI.parse(folder.uri));
|
|
36
40
|
}
|
|
@@ -56,7 +60,10 @@ function startCommonLanguageServer(context) {
|
|
|
56
60
|
version: packageJson.version,
|
|
57
61
|
};
|
|
58
62
|
}
|
|
59
|
-
catch (
|
|
63
|
+
catch (_e) { }
|
|
64
|
+
for (const plugin of plugins) {
|
|
65
|
+
(_d = plugin.onInitialize) === null || _d === void 0 ? void 0 : _d.call(plugin, result);
|
|
66
|
+
}
|
|
60
67
|
return result;
|
|
61
68
|
}));
|
|
62
69
|
context.connection.onInitialized(() => {
|
|
@@ -76,26 +83,25 @@ function startCommonLanguageServer(context) {
|
|
|
76
83
|
if (options.serverMode !== types_1.ServerMode.Syntactic
|
|
77
84
|
&& !options.disableFileWatcher
|
|
78
85
|
&& ((_c = (_b = initParams.capabilities.workspace) === null || _b === void 0 ? void 0 : _b.didChangeWatchedFiles) === null || _c === void 0 ? void 0 : _c.dynamicRegistration)) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
'
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
'jsx',
|
|
90
|
-
'tsx',
|
|
91
|
-
'json',
|
|
92
|
-
...plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.extraFileExtensions) === null || _a === void 0 ? void 0 : _a.map(ext => ext.extension)) !== null && _b !== void 0 ? _b : []; }).flat(),
|
|
93
|
-
].join(',')}}`
|
|
94
|
-
},
|
|
95
|
-
]
|
|
96
|
-
});
|
|
86
|
+
const exts = plugins.map(plugin => { var _a; return (_a = plugin.extensions.fileWatcher) !== null && _a !== void 0 ? _a : []; }).flat();
|
|
87
|
+
if (exts.length) {
|
|
88
|
+
context.connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
|
|
89
|
+
watchers: [
|
|
90
|
+
{
|
|
91
|
+
globPattern: `**/*.{${exts.join(',')}}`
|
|
92
|
+
},
|
|
93
|
+
]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
97
96
|
}
|
|
98
97
|
});
|
|
98
|
+
context.connection.onShutdown(() => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
if (projects) {
|
|
100
|
+
for (const workspace of projects.workspaces) {
|
|
101
|
+
(yield workspace[1]).dispose();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
99
105
|
context.connection.listen();
|
|
100
106
|
function createLanguageServiceHost() {
|
|
101
107
|
var _a;
|
|
@@ -121,9 +127,9 @@ function startCommonLanguageServer(context) {
|
|
|
121
127
|
projects.add(root);
|
|
122
128
|
}
|
|
123
129
|
(yield Promise.resolve().then(() => require('./features/customFeatures'))).register(context.connection, projects);
|
|
124
|
-
(yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(context.connection, projects, initParams, cancelTokenHost, getSemanticTokensLegend());
|
|
130
|
+
(yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(context.connection, projects, initParams, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv);
|
|
125
131
|
for (const plugin of plugins) {
|
|
126
|
-
(_a = plugin.
|
|
132
|
+
(_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService);
|
|
127
133
|
}
|
|
128
134
|
function getLanguageService(uri) {
|
|
129
135
|
var _a;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.isFileInDir = void 0;
|
|
3
|
+
const path = require("typesafe-path");
|
|
4
|
+
function isFileInDir(fileName, dir) {
|
|
5
|
+
const relative = path.relative(dir, fileName);
|
|
6
|
+
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
7
|
+
}
|
|
8
|
+
exports.isFileInDir = isFileInDir;
|
|
9
|
+
//# sourceMappingURL=isFileInDir.js.map
|
|
@@ -66,18 +66,7 @@ function setupCapabilities(params, server, initOptions, plugins, semanticTokensL
|
|
|
66
66
|
}
|
|
67
67
|
if (!initOptions.respectClientCapabilities || ((_s = params.textDocument) === null || _s === void 0 ? void 0 : _s.completion)) {
|
|
68
68
|
server.completionProvider = {
|
|
69
|
-
|
|
70
|
-
// hardcode to fix https://github.com/sublimelsp/LSP-volar/issues/114
|
|
71
|
-
triggerCharacters: [...new Set([
|
|
72
|
-
'/', '-', ':',
|
|
73
|
-
...'>+^*()#.[]$@-{}'.split(''),
|
|
74
|
-
'.', ':', '<', '"', '=', '/',
|
|
75
|
-
'@',
|
|
76
|
-
'"', ':',
|
|
77
|
-
'.', '"', '\'', '`', '/', '<', '@', '#', ' ',
|
|
78
|
-
'*',
|
|
79
|
-
'@', // typescript-comment
|
|
80
|
-
])],
|
|
69
|
+
triggerCharacters: '!@#$%^&*()_+-=`~{}|[]\:";\'<>?,./ '.split(''),
|
|
81
70
|
resolveProvider: true,
|
|
82
71
|
};
|
|
83
72
|
if (initOptions.ignoreTriggerCharacters) {
|
|
@@ -126,53 +115,33 @@ function setupCapabilities(params, server, initOptions, plugins, semanticTokensL
|
|
|
126
115
|
server.inlayHintProvider = true;
|
|
127
116
|
}
|
|
128
117
|
if ((!initOptions.respectClientCapabilities || ((_2 = params.textDocument) === null || _2 === void 0 ? void 0 : _2.diagnostic)) && ((_3 = initOptions.diagnosticModel) !== null && _3 !== void 0 ? _3 : types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
'cts',
|
|
138
|
-
'mts',
|
|
139
|
-
'jsx',
|
|
140
|
-
'tsx',
|
|
141
|
-
// 'json',
|
|
142
|
-
...plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.extraFileExtensions) === null || _a === void 0 ? void 0 : _a.map(ext => ext.extension)) !== null && _b !== void 0 ? _b : []; }).flat(),
|
|
143
|
-
].join(',')}}`
|
|
144
|
-
}
|
|
145
|
-
],
|
|
146
|
-
interFileDependencies: true,
|
|
147
|
-
workspaceDiagnostics: false,
|
|
148
|
-
};
|
|
118
|
+
const selector = plugins.map(plugin => { var _a; return (_a = plugin.diagnosticDocumentSelector) !== null && _a !== void 0 ? _a : []; }).flat();
|
|
119
|
+
if (selector) {
|
|
120
|
+
server.diagnosticProvider = {
|
|
121
|
+
documentSelector: selector,
|
|
122
|
+
interFileDependencies: true,
|
|
123
|
+
workspaceDiagnostics: false,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
149
126
|
}
|
|
150
127
|
// cross file features
|
|
151
128
|
if (!initOptions.respectClientCapabilities || ((_4 = params.workspace) === null || _4 === void 0 ? void 0 : _4.fileOperations)) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
'
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
'jsx',
|
|
166
|
-
'tsx',
|
|
167
|
-
'json',
|
|
168
|
-
...plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.extraFileExtensions) === null || _a === void 0 ? void 0 : _a.map(ext => ext.extension)) !== null && _b !== void 0 ? _b : []; }).flat(),
|
|
169
|
-
].join(',')}}`
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
]
|
|
129
|
+
const exts = plugins.map(plugin => plugin.extensions.fileRenameOperationFilter).flat();
|
|
130
|
+
if (exts.length) {
|
|
131
|
+
server.workspace = {
|
|
132
|
+
fileOperations: {
|
|
133
|
+
willRename: {
|
|
134
|
+
filters: [
|
|
135
|
+
{
|
|
136
|
+
pattern: {
|
|
137
|
+
glob: `**/*.{${exts.join(',')}}`
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
]
|
|
141
|
+
}
|
|
173
142
|
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
176
145
|
}
|
|
177
146
|
if (!initOptions.respectClientCapabilities || ((_5 = params.workspace) === null || _5 === void 0 ? void 0 : _5.symbol)) {
|
|
178
147
|
server.workspaceSymbolProvider = true;
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
plugins?: LanguageServicePlugin[];
|
|
4
|
-
}
|
|
5
|
-
export declare function loadServerConfig(dir: string, configFile: string | undefined): ServerConfig | undefined;
|
|
1
|
+
import { LanguageServiceConfig } from "@volar/language-service";
|
|
2
|
+
export declare function loadConfig(dir: string, configFile: string | undefined): LanguageServiceConfig | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.
|
|
3
|
-
function
|
|
2
|
+
exports.loadConfig = void 0;
|
|
3
|
+
function loadConfig(dir, configFile) {
|
|
4
4
|
let configPath;
|
|
5
5
|
try {
|
|
6
6
|
configPath = require.resolve(configFile !== null && configFile !== void 0 ? configFile : './volar.config.js', { paths: [dir] });
|
|
@@ -17,5 +17,5 @@ function loadServerConfig(dir, configFile) {
|
|
|
17
17
|
console.log(err);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
exports.
|
|
20
|
+
exports.loadConfig = loadConfig;
|
|
21
21
|
//# sourceMappingURL=serverConfig.js.map
|
|
@@ -25,7 +25,7 @@ function createUriMap(map = new Map()) {
|
|
|
25
25
|
}
|
|
26
26
|
function getUriByPath(path) {
|
|
27
27
|
if (!pathToUri.has(path)) {
|
|
28
|
-
pathToUri.set(path, shared.
|
|
28
|
+
pathToUri.set(path, shared.fileNameToUri(path).toLowerCase());
|
|
29
29
|
}
|
|
30
30
|
return pathToUri.get(path);
|
|
31
31
|
}
|
package/out/common/workspace.js
CHANGED
|
@@ -17,27 +17,28 @@ const project_1 = require("./project");
|
|
|
17
17
|
const inferredCompilerOptions_1 = require("./utils/inferredCompilerOptions");
|
|
18
18
|
const serverConfig_1 = require("./utils/serverConfig");
|
|
19
19
|
const uriMap_1 = require("./utils/uriMap");
|
|
20
|
+
const isFileInDir_1 = require("./utils/isFileInDir");
|
|
20
21
|
exports.rootTsConfigNames = ['tsconfig.json', 'jsconfig.json'];
|
|
21
22
|
function createWorkspace(context) {
|
|
22
23
|
var _a, _b, _c;
|
|
23
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
25
|
let inferredProject;
|
|
25
|
-
const serverConfig = (0, serverConfig_1.
|
|
26
|
+
const serverConfig = (0, serverConfig_1.loadConfig)(shared.uriToFileName(context.rootUri.toString()), context.workspaces.initOptions.configFilePath);
|
|
26
27
|
const sys = (_a = context.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.getWorkspaceFileSystem(context.rootUri);
|
|
27
|
-
const documentRegistry = sys ? (_b = context.workspaces.ts) === null || _b === void 0 ? void 0 : _b.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.
|
|
28
|
+
const documentRegistry = sys ? (_b = context.workspaces.ts) === null || _b === void 0 ? void 0 : _b.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.uriToFileName(context.rootUri.toString())) : undefined;
|
|
28
29
|
const projects = (0, uriMap_1.createUriMap)();
|
|
29
|
-
const rootTsConfigs = new Set(sys === null || sys === void 0 ? void 0 : sys.readDirectory(shared.
|
|
30
|
+
const rootTsConfigs = new Set(sys === null || sys === void 0 ? void 0 : sys.readDirectory(shared.uriToFileName(context.rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => shared.normalizeFileName(fileName)));
|
|
30
31
|
const disposeTsConfigWatch = (_c = context.workspaces.fileSystemHost) === null || _c === void 0 ? void 0 : _c.onDidChangeWatchedFiles(({ changes }) => {
|
|
31
32
|
for (const change of changes) {
|
|
32
33
|
if (exports.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1))) {
|
|
33
34
|
if (change.type === vscode.FileChangeType.Created) {
|
|
34
|
-
if (
|
|
35
|
-
rootTsConfigs.add(shared.
|
|
35
|
+
if ((0, isFileInDir_1.isFileInDir)(shared.uriToFileName(change.uri), shared.uriToFileName(context.rootUri.toString()))) {
|
|
36
|
+
rootTsConfigs.add(shared.uriToFileName(change.uri));
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
else if ((change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Deleted) && projects.uriHas(change.uri)) {
|
|
39
40
|
if (change.type === vscode.FileChangeType.Deleted) {
|
|
40
|
-
rootTsConfigs.delete(shared.
|
|
41
|
+
rootTsConfigs.delete(shared.uriToFileName(change.uri));
|
|
41
42
|
}
|
|
42
43
|
const project = projects.uriGet(change.uri);
|
|
43
44
|
projects.uriDelete(change.uri);
|
|
@@ -106,11 +107,11 @@ function createWorkspace(context) {
|
|
|
106
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
108
|
let matches = [];
|
|
108
109
|
for (const rootTsConfig of rootTsConfigs) {
|
|
109
|
-
if (
|
|
110
|
+
if ((0, isFileInDir_1.isFileInDir)(shared.uriToFileName(uri.toString()), path.dirname(rootTsConfig))) {
|
|
110
111
|
matches.push(rootTsConfig);
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
|
-
matches = matches.sort((a, b) => sortTsConfigs(shared.
|
|
114
|
+
matches = matches.sort((a, b) => sortTsConfigs(shared.uriToFileName(uri.toString()), a, b));
|
|
114
115
|
if (matches.length) {
|
|
115
116
|
yield getParsedCommandLine(matches[0]);
|
|
116
117
|
}
|
|
@@ -132,14 +133,14 @@ function createWorkspace(context) {
|
|
|
132
133
|
var _a, _b;
|
|
133
134
|
const project = yield projects.pathGet(tsconfig);
|
|
134
135
|
const ls = project === null || project === void 0 ? void 0 : project.getLanguageServiceDontCreate();
|
|
135
|
-
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(shared.
|
|
136
|
+
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(shared.uriToFileName(uri.toString()));
|
|
136
137
|
return !!validDoc;
|
|
137
138
|
}));
|
|
138
139
|
}
|
|
139
140
|
function findTsconfig(match) {
|
|
140
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
142
|
const checked = new Set();
|
|
142
|
-
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(shared.
|
|
143
|
+
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(shared.uriToFileName(uri.toString()), a, b))) {
|
|
143
144
|
const project = yield projects.pathGet(rootTsConfig);
|
|
144
145
|
if (project) {
|
|
145
146
|
let chains = yield getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
|
|
@@ -214,7 +215,7 @@ function createWorkspace(context) {
|
|
|
214
215
|
project = (0, project_1.createProject)({
|
|
215
216
|
workspace: context,
|
|
216
217
|
serverConfig,
|
|
217
|
-
rootUri: vscode_uri_1.URI.parse(shared.
|
|
218
|
+
rootUri: vscode_uri_1.URI.parse(shared.fileNameToUri(path.dirname(tsConfig))),
|
|
218
219
|
tsConfig,
|
|
219
220
|
documentRegistry,
|
|
220
221
|
});
|
|
@@ -226,8 +227,8 @@ function createWorkspace(context) {
|
|
|
226
227
|
}
|
|
227
228
|
exports.createWorkspace = createWorkspace;
|
|
228
229
|
function sortTsConfigs(file, a, b) {
|
|
229
|
-
const inA =
|
|
230
|
-
const inB =
|
|
230
|
+
const inA = (0, isFileInDir_1.isFileInDir)(file, path.dirname(a));
|
|
231
|
+
const inB = (0, isFileInDir_1.isFileInDir)(file, path.dirname(b));
|
|
231
232
|
if (inA !== inB) {
|
|
232
233
|
const aWeight = inA ? 1 : 0;
|
|
233
234
|
const bWeight = inB ? 1 : 0;
|
package/out/common/workspaces.js
CHANGED
|
@@ -13,6 +13,7 @@ const shared = require("@volar/shared");
|
|
|
13
13
|
const vscode = require("vscode-languageserver");
|
|
14
14
|
const types_1 = require("../types");
|
|
15
15
|
const workspace_1 = require("./workspace");
|
|
16
|
+
const isFileInDir_1 = require("./utils/isFileInDir");
|
|
16
17
|
function createWorkspaces(context) {
|
|
17
18
|
var _a, _b, _c;
|
|
18
19
|
const workspaces = new Map();
|
|
@@ -146,9 +147,9 @@ function createWorkspaces(context) {
|
|
|
146
147
|
function getProjectAndTsConfig(uri) {
|
|
147
148
|
var _a;
|
|
148
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
-
|
|
150
|
-
.filter(rootUri =>
|
|
151
|
-
.sort((a, b) => (0, workspace_1.sortTsConfigs)(shared.
|
|
150
|
+
let rootUris = [...workspaces.keys()]
|
|
151
|
+
.filter(rootUri => (0, isFileInDir_1.isFileInDir)(shared.uriToFileName(uri), shared.uriToFileName(rootUri)))
|
|
152
|
+
.sort((a, b) => (0, workspace_1.sortTsConfigs)(shared.uriToFileName(uri), shared.uriToFileName(a), shared.uriToFileName(b)));
|
|
152
153
|
if (context.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
|
|
153
154
|
for (const rootUri of rootUris) {
|
|
154
155
|
const workspace = yield workspaces.get(rootUri);
|
|
@@ -158,9 +159,12 @@ function createWorkspaces(context) {
|
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
}
|
|
162
|
+
if (!rootUris.length) {
|
|
163
|
+
rootUris = [...workspaces.keys()];
|
|
164
|
+
}
|
|
161
165
|
if (rootUris.length) {
|
|
162
166
|
const project = yield ((_a = (yield workspaces.get(rootUris[0]))) === null || _a === void 0 ? void 0 : _a.getInferredProject());
|
|
163
|
-
project === null || project === void 0 ? void 0 : project.tryAddFile(shared.
|
|
167
|
+
project === null || project === void 0 ? void 0 : project.tryAddFile(shared.uriToFileName(uri));
|
|
164
168
|
return {
|
|
165
169
|
tsconfig: undefined,
|
|
166
170
|
project,
|
package/out/index.d.ts
CHANGED
package/out/index.js
CHANGED
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
__exportStar(require("./protocol"), exports);
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
// only export types of depend packages
|
|
19
|
+
__exportStar(require("vscode-languageserver"), exports);
|
|
19
20
|
__exportStar(require("@volar/language-core/out/types"), exports);
|
|
20
21
|
__exportStar(require("@volar/language-service/out/types"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/out/node/fileSystem.js
CHANGED
|
@@ -51,7 +51,7 @@ function createNodeFileSystemHost(ts, capabilities) {
|
|
|
51
51
|
};
|
|
52
52
|
function createWorkspaceFileSystem(ts, capabilities, rootUri) {
|
|
53
53
|
var _a;
|
|
54
|
-
const rootPath = shared.
|
|
54
|
+
const rootPath = shared.uriToFileName(rootUri.toString());
|
|
55
55
|
const workspaceSys = new Proxy(ts.sys, {
|
|
56
56
|
get(target, prop) {
|
|
57
57
|
const fn = target[prop];
|
package/out/node/index.js
CHANGED
|
@@ -42,6 +42,12 @@ function startLanguageServer(connection, ...plugins) {
|
|
|
42
42
|
plugins,
|
|
43
43
|
connection,
|
|
44
44
|
runtimeEnv: {
|
|
45
|
+
timer: {
|
|
46
|
+
setImmediate(callback, ...args) {
|
|
47
|
+
const handle = setImmediate(callback, ...args);
|
|
48
|
+
return { dispose: () => clearImmediate(handle) };
|
|
49
|
+
},
|
|
50
|
+
},
|
|
45
51
|
loadTypescript(tsdk) {
|
|
46
52
|
for (const name of ['./typescript.js', './tsserverlibrary.js', './tsserver.js']) {
|
|
47
53
|
try {
|
|
@@ -72,7 +78,7 @@ function startLanguageServer(connection, ...plugins) {
|
|
|
72
78
|
fileSystemProvide: {
|
|
73
79
|
stat: (uri) => {
|
|
74
80
|
return new Promise((resolve, reject) => {
|
|
75
|
-
fs.stat(shared.
|
|
81
|
+
fs.stat(shared.uriToFileName(uri), (err, stats) => {
|
|
76
82
|
if (stats) {
|
|
77
83
|
resolve({
|
|
78
84
|
type: stats.isFile() ? html.FileType.File
|
|
@@ -92,7 +98,7 @@ function startLanguageServer(connection, ...plugins) {
|
|
|
92
98
|
},
|
|
93
99
|
readDirectory: (uri) => {
|
|
94
100
|
return new Promise((resolve, reject) => {
|
|
95
|
-
fs.readdir(shared.
|
|
101
|
+
fs.readdir(shared.uriToFileName(uri), (err, files) => {
|
|
96
102
|
if (files) {
|
|
97
103
|
resolve(files.map(file => [file, html.FileType.File]));
|
|
98
104
|
}
|