@volar/typescript 2.0.1 → 2.0.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.
|
@@ -421,18 +421,41 @@ function decorateLanguageService(files, languageService) {
|
|
|
421
421
|
languageService.getCompletionsAtPosition = (fileName, position, options, formattingSettings) => {
|
|
422
422
|
const [virtualCode, sourceFile, map] = (0, utils_1.getVirtualFileAndMap)(files, fileName);
|
|
423
423
|
if (virtualCode) {
|
|
424
|
+
let mainResult;
|
|
425
|
+
let additionalResults = [];
|
|
424
426
|
for (const [generateOffset, mapping] of map.getGeneratedOffsets(position)) {
|
|
425
427
|
if ((0, language_core_1.isCompletionEnabled)(mapping.data)) {
|
|
428
|
+
const isAdditional = typeof mapping.data.completion === 'object' && mapping.data.completion.isAdditional;
|
|
429
|
+
if (!isAdditional && mainResult) {
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
426
432
|
const result = getCompletionsAtPosition(fileName, generateOffset + sourceFile.snapshot.getLength(), options, formattingSettings);
|
|
427
433
|
if (result) {
|
|
428
434
|
for (const entry of result.entries) {
|
|
429
435
|
entry.replacementSpan = (0, transform_1.transformSpan)(files, fileName, entry.replacementSpan, language_core_1.isCompletionEnabled)?.textSpan;
|
|
430
436
|
}
|
|
431
437
|
result.optionalReplacementSpan = (0, transform_1.transformSpan)(files, fileName, result.optionalReplacementSpan, language_core_1.isCompletionEnabled)?.textSpan;
|
|
438
|
+
if (isAdditional) {
|
|
439
|
+
additionalResults.push(result);
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
mainResult = result;
|
|
443
|
+
}
|
|
432
444
|
}
|
|
433
|
-
return result;
|
|
434
445
|
}
|
|
435
446
|
}
|
|
447
|
+
if (!mainResult && additionalResults.length) {
|
|
448
|
+
mainResult = additionalResults.shift();
|
|
449
|
+
}
|
|
450
|
+
if (mainResult) {
|
|
451
|
+
return {
|
|
452
|
+
...mainResult,
|
|
453
|
+
entries: [
|
|
454
|
+
...mainResult.entries,
|
|
455
|
+
...additionalResults.map(additionalResult => additionalResult.entries).flat(),
|
|
456
|
+
],
|
|
457
|
+
};
|
|
458
|
+
}
|
|
436
459
|
}
|
|
437
460
|
else {
|
|
438
461
|
return getCompletionsAtPosition(fileName, position, options, formattingSettings);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type FileRegistry } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
export declare function decorateLanguageServiceHost(virtualFiles: FileRegistry, languageServiceHost: ts.LanguageServiceHost, ts: typeof import('typescript')): void;
|
|
4
4
|
export declare function searchExternalFiles(ts: typeof import('typescript'), project: ts.server.Project, exts: string[]): string[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.searchExternalFiles = exports.decorateLanguageServiceHost = void 0;
|
|
4
|
-
const
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
5
|
function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts) {
|
|
6
6
|
let extraProjectVersion = 0;
|
|
7
7
|
const exts = virtualFiles.languagePlugins
|
|
@@ -118,7 +118,7 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts) {
|
|
|
118
118
|
const snapshot = getScriptSnapshot(fileName);
|
|
119
119
|
if (snapshot) {
|
|
120
120
|
extraProjectVersion++;
|
|
121
|
-
const sourceFile = virtualFiles.set(fileName, (0,
|
|
121
|
+
const sourceFile = virtualFiles.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot);
|
|
122
122
|
if (sourceFile.generated) {
|
|
123
123
|
const text = snapshot.getText(0, snapshot.getLength());
|
|
124
124
|
let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n');
|
|
@@ -62,8 +62,9 @@ function createLanguage(ts, sys, languagePlugins, configFileName, projectHost, {
|
|
|
62
62
|
const result = ts.resolveModuleName(moduleName, containingFile, options, {
|
|
63
63
|
...languageServiceHost,
|
|
64
64
|
fileExists(fileName) {
|
|
65
|
-
if (extraFileExtension && fileName.endsWith(
|
|
66
|
-
const patchResult = languageServiceHost.fileExists(fileName.slice(0,
|
|
65
|
+
if (extraFileExtension && fileName.endsWith(`.d.${extraFileExtension}.ts`)) {
|
|
66
|
+
const patchResult = languageServiceHost.fileExists(fileName.slice(0, -`.d.${extraFileExtension}.ts`.length)
|
|
67
|
+
+ `.${extraFileExtension}`);
|
|
67
68
|
if (patchResult) {
|
|
68
69
|
isPatchResult = true;
|
|
69
70
|
return true;
|
|
@@ -73,7 +74,9 @@ function createLanguage(ts, sys, languagePlugins, configFileName, projectHost, {
|
|
|
73
74
|
},
|
|
74
75
|
}, moduleCache, redirectedReference, sourceFile.impliedNodeFormat);
|
|
75
76
|
if (isPatchResult && result.resolvedModule) {
|
|
76
|
-
result.resolvedModule.resolvedFileName = result.resolvedModule.resolvedFileName
|
|
77
|
+
result.resolvedModule.resolvedFileName = result.resolvedModule.resolvedFileName
|
|
78
|
+
.slice(0, -`.d.${extraFileExtension}.ts`.length)
|
|
79
|
+
+ `.${extraFileExtension}`;
|
|
77
80
|
const sourceFile = files.get(fileNameToFileId(result.resolvedModule.resolvedFileName));
|
|
78
81
|
if (sourceFile?.generated) {
|
|
79
82
|
const tsCode = sourceFile.generated.languagePlugin.typescript?.getScript(sourceFile.generated.code);
|
|
@@ -108,10 +111,11 @@ function createLanguage(ts, sys, languagePlugins, configFileName, projectHost, {
|
|
|
108
111
|
getCurrentDirectory: projectHost.getCurrentDirectory,
|
|
109
112
|
getCompilationSettings() {
|
|
110
113
|
const options = projectHost.getCompilationSettings();
|
|
111
|
-
if (languagePlugins.some(language => language.typescript?.extraFileExtensions.length)
|
|
112
|
-
&& !options.allowNonTsExtensions) {
|
|
113
|
-
console.warn('`allowNonTsExtensions` must be `true`.');
|
|
114
|
+
if (languagePlugins.some(language => language.typescript?.extraFileExtensions.length)) {
|
|
114
115
|
options.allowNonTsExtensions ??= true;
|
|
116
|
+
if (!options.allowNonTsExtensions) {
|
|
117
|
+
console.warn('`allowNonTsExtensions` must be `true`.');
|
|
118
|
+
}
|
|
115
119
|
}
|
|
116
120
|
return options;
|
|
117
121
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/typescript",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"directory": "packages/typescript"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "2.0.
|
|
15
|
+
"@volar/language-core": "2.0.3",
|
|
16
16
|
"path-browserify": "^1.0.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "latest",
|
|
20
20
|
"@types/path-browserify": "latest",
|
|
21
|
-
"@volar/language-service": "2.0.
|
|
21
|
+
"@volar/language-service": "2.0.3"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "d8a6dc056d37779ff6486f545f45bc57b22c02e4"
|
|
24
24
|
}
|