@volar/typescript 2.4.23 → 2.4.24
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/index.d.ts +2 -2
- package/index.js +1 -1
- package/lib/common.js +18 -9
- package/lib/node/decorateLanguageServiceHost.js +15 -7
- package/lib/node/proxyCreateProgram.d.ts +1 -1
- package/lib/node/proxyCreateProgram.js +18 -10
- package/lib/node/proxyLanguageService.d.ts +1 -1
- package/lib/node/proxyLanguageService.js +77 -40
- package/lib/node/transform.d.ts +1 -1
- package/lib/node/transform.js +5 -4
- package/lib/node/utils.d.ts +2 -0
- package/lib/node/utils.js +14 -0
- package/lib/protocol/createProject.d.ts +1 -1
- package/lib/protocol/createProject.js +27 -17
- package/lib/protocol/createSys.d.ts +1 -1
- package/lib/protocol/createSys.js +21 -19
- package/lib/quickstart/languageServicePluginCommon.d.ts +1 -1
- package/lib/quickstart/runTsc.d.ts +1 -1
- package/lib/quickstart/runTsc.js +1 -1
- package/lib/typescript/core.d.ts +1 -1
- package/lib/typescript/core.js +12 -8
- package/lib/typescript/corePublic.d.ts +2 -2
- package/lib/typescript/corePublic.js +17 -9
- package/lib/typescript/path.d.ts +1 -1
- package/lib/typescript/path.js +28 -26
- package/lib/typescript/utilities.js +38 -35
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export * from './lib/common';
|
|
2
|
-
export * from './lib/node/proxyLanguageService';
|
|
3
2
|
export * from './lib/node/decorateLanguageServiceHost';
|
|
4
3
|
export * from './lib/node/decorateProgram';
|
|
5
4
|
export * from './lib/node/proxyCreateProgram';
|
|
5
|
+
export * from './lib/node/proxyLanguageService';
|
|
6
6
|
export * from './lib/protocol/createProject';
|
|
7
7
|
export * from './lib/protocol/createSys';
|
|
8
8
|
import type { VirtualCode } from '@volar/language-core';
|
|
9
9
|
import type * as ts from 'typescript';
|
|
10
|
-
import { URI } from 'vscode-uri';
|
|
10
|
+
import { type URI } from 'vscode-uri';
|
|
11
11
|
declare module '@volar/language-service' {
|
|
12
12
|
interface ProjectContext {
|
|
13
13
|
typescript?: {
|
package/index.js
CHANGED
|
@@ -15,10 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./lib/common"), exports);
|
|
18
|
-
__exportStar(require("./lib/node/proxyLanguageService"), exports);
|
|
19
18
|
__exportStar(require("./lib/node/decorateLanguageServiceHost"), exports);
|
|
20
19
|
__exportStar(require("./lib/node/decorateProgram"), exports);
|
|
21
20
|
__exportStar(require("./lib/node/proxyCreateProgram"), exports);
|
|
21
|
+
__exportStar(require("./lib/node/proxyLanguageService"), exports);
|
|
22
22
|
__exportStar(require("./lib/protocol/createProject"), exports);
|
|
23
23
|
__exportStar(require("./lib/protocol/createSys"), exports);
|
|
24
24
|
//# sourceMappingURL=index.js.map
|
package/lib/common.js
CHANGED
|
@@ -4,15 +4,24 @@ exports.resolveFileLanguageId = resolveFileLanguageId;
|
|
|
4
4
|
function resolveFileLanguageId(path) {
|
|
5
5
|
const ext = path.split('.').pop();
|
|
6
6
|
switch (ext) {
|
|
7
|
-
case 'js':
|
|
8
|
-
|
|
9
|
-
case '
|
|
10
|
-
|
|
11
|
-
case '
|
|
12
|
-
|
|
13
|
-
case '
|
|
14
|
-
|
|
15
|
-
case '
|
|
7
|
+
case 'js':
|
|
8
|
+
return 'javascript';
|
|
9
|
+
case 'cjs':
|
|
10
|
+
return 'javascript';
|
|
11
|
+
case 'mjs':
|
|
12
|
+
return 'javascript';
|
|
13
|
+
case 'ts':
|
|
14
|
+
return 'typescript';
|
|
15
|
+
case 'cts':
|
|
16
|
+
return 'typescript';
|
|
17
|
+
case 'mts':
|
|
18
|
+
return 'typescript';
|
|
19
|
+
case 'jsx':
|
|
20
|
+
return 'javascriptreact';
|
|
21
|
+
case 'tsx':
|
|
22
|
+
return 'typescriptreact';
|
|
23
|
+
case 'json':
|
|
24
|
+
return 'json';
|
|
16
25
|
}
|
|
17
26
|
}
|
|
18
27
|
//# sourceMappingURL=common.js.map
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.decorateLanguageServiceHost = decorateLanguageServiceHost;
|
|
4
4
|
exports.searchExternalFiles = searchExternalFiles;
|
|
5
5
|
const resolveModuleName_1 = require("../resolveModuleName");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
6
7
|
function decorateLanguageServiceHost(ts, language, languageServiceHost) {
|
|
7
8
|
const pluginExtensions = language.plugins
|
|
8
9
|
.map(plugin => plugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? [])
|
|
@@ -35,13 +36,19 @@ function decorateLanguageServiceHost(ts, language, languageServiceHost) {
|
|
|
35
36
|
const moduleResolutionCache = ts.createModuleResolutionCache(languageServiceHost.getCurrentDirectory(), getCanonicalFileName, languageServiceHost.getCompilationSettings());
|
|
36
37
|
if (resolveModuleNameLiterals) {
|
|
37
38
|
languageServiceHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, ...rest) => {
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const disposeFixup = (0, utils_1.fixupImpliedNodeFormatForFile)(ts, pluginExtensions, containingSourceFile, moduleResolutionCache.getPackageJsonInfoCache(), languageServiceHost, options);
|
|
40
|
+
try {
|
|
41
|
+
if (moduleLiterals.every(name => !pluginExtensions.some(ext => name.text.endsWith(ext)))) {
|
|
42
|
+
return resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, ...rest);
|
|
43
|
+
}
|
|
44
|
+
return moduleLiterals.map(moduleLiteral => {
|
|
45
|
+
const mode = ts.getModeForUsageLocation(containingSourceFile, moduleLiteral, options);
|
|
46
|
+
return resolveModuleName(moduleLiteral.text, containingFile, options, moduleResolutionCache, redirectedReference, mode);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
disposeFixup?.();
|
|
40
51
|
}
|
|
41
|
-
return moduleLiterals.map(moduleLiteral => {
|
|
42
|
-
const mode = ts.getModeForUsageLocation(containingSourceFile, moduleLiteral, options);
|
|
43
|
-
return resolveModuleName(moduleLiteral.text, containingFile, options, moduleResolutionCache, redirectedReference, mode);
|
|
44
|
-
});
|
|
45
52
|
};
|
|
46
53
|
}
|
|
47
54
|
if (resolveModuleNames) {
|
|
@@ -50,7 +57,8 @@ function decorateLanguageServiceHost(ts, language, languageServiceHost) {
|
|
|
50
57
|
return resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, options, containingSourceFile);
|
|
51
58
|
}
|
|
52
59
|
return moduleNames.map(moduleName => {
|
|
53
|
-
return resolveModuleName(moduleName, containingFile, options, moduleResolutionCache, redirectedReference)
|
|
60
|
+
return resolveModuleName(moduleName, containingFile, options, moduleResolutionCache, redirectedReference)
|
|
61
|
+
.resolvedModule;
|
|
54
62
|
});
|
|
55
63
|
};
|
|
56
64
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Language, LanguagePlugin } from '@volar/language-core';
|
|
1
|
+
import { type Language, type LanguagePlugin } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
export declare function proxyCreateProgram(ts: typeof import('typescript'), original: typeof ts['createProgram'], create: (ts: typeof import('typescript'), options: ts.CreateProgramOptions) => LanguagePlugin<string>[] | {
|
|
4
4
|
languagePlugins: LanguagePlugin<string>[];
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.proxyCreateProgram = proxyCreateProgram;
|
|
4
4
|
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const common_1 = require("../common");
|
|
5
6
|
const resolveModuleName_1 = require("../resolveModuleName");
|
|
6
7
|
const decorateProgram_1 = require("./decorateProgram");
|
|
7
|
-
const
|
|
8
|
+
const utils_1 = require("./utils");
|
|
8
9
|
const arrayEqual = (a, b) => {
|
|
9
10
|
if (a.length !== b.length) {
|
|
10
11
|
return false;
|
|
@@ -90,7 +91,7 @@ function proxyCreateProgram(ts, original, create) {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
const originalHost = options.host;
|
|
93
|
-
const
|
|
94
|
+
const pluginExtensions = languagePlugins
|
|
94
95
|
.map(plugin => plugin.typescript?.extraFileExtensions.map(({ extension }) => `.${extension}`) ?? [])
|
|
95
96
|
.flat();
|
|
96
97
|
options.host = { ...originalHost };
|
|
@@ -146,22 +147,29 @@ function proxyCreateProgram(ts, original, create) {
|
|
|
146
147
|
}
|
|
147
148
|
return parsedSourceFiles.get(originalSourceFile) ?? originalSourceFile;
|
|
148
149
|
};
|
|
149
|
-
if (
|
|
150
|
+
if (pluginExtensions.length) {
|
|
150
151
|
options.options.allowArbitraryExtensions = true;
|
|
151
152
|
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, ts.sys.getFileSize, originalHost, language.plugins, fileName => language.scripts.get(fileName));
|
|
152
153
|
const resolveModuleNameLiterals = originalHost.resolveModuleNameLiterals;
|
|
153
154
|
const resolveModuleNames = originalHost.resolveModuleNames;
|
|
154
155
|
options.host.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, compilerOptions, containingSourceFile, ...rest) => {
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
const disposeFixup = (0, utils_1.fixupImpliedNodeFormatForFile)(ts, pluginExtensions, containingSourceFile, moduleResolutionCache.getPackageJsonInfoCache(), originalHost, compilerOptions);
|
|
157
|
+
try {
|
|
158
|
+
if (resolveModuleNameLiterals
|
|
159
|
+
&& moduleLiterals.every(name => !pluginExtensions.some(ext => name.text.endsWith(ext)))) {
|
|
160
|
+
return resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, compilerOptions, containingSourceFile, ...rest);
|
|
161
|
+
}
|
|
162
|
+
return moduleLiterals.map(moduleLiteral => {
|
|
163
|
+
const mode = ts.getModeForUsageLocation(containingSourceFile, moduleLiteral, compilerOptions);
|
|
164
|
+
return resolveModuleName(moduleLiteral.text, containingFile, compilerOptions, moduleResolutionCache, redirectedReference, mode);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
disposeFixup?.();
|
|
157
169
|
}
|
|
158
|
-
return moduleLiterals.map(moduleLiteral => {
|
|
159
|
-
const mode = ts.getModeForUsageLocation(containingSourceFile, moduleLiteral, compilerOptions);
|
|
160
|
-
return resolveModuleName(moduleLiteral.text, containingFile, compilerOptions, moduleResolutionCache, redirectedReference, mode);
|
|
161
|
-
});
|
|
162
170
|
};
|
|
163
171
|
options.host.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile) => {
|
|
164
|
-
if (resolveModuleNames && moduleNames.every(name => !
|
|
172
|
+
if (resolveModuleNames && moduleNames.every(name => !pluginExtensions.some(ext => name.endsWith(ext)))) {
|
|
165
173
|
return resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile);
|
|
166
174
|
}
|
|
167
175
|
return moduleNames.map(moduleName => {
|
|
@@ -25,41 +25,76 @@ function createProxyLanguageService(languageService) {
|
|
|
25
25
|
initialize(language) {
|
|
26
26
|
getProxyMethod = (target, p) => {
|
|
27
27
|
switch (p) {
|
|
28
|
-
case 'getNavigationTree':
|
|
29
|
-
|
|
30
|
-
case '
|
|
31
|
-
|
|
32
|
-
case '
|
|
33
|
-
|
|
34
|
-
case '
|
|
35
|
-
|
|
36
|
-
case '
|
|
37
|
-
|
|
38
|
-
case '
|
|
39
|
-
|
|
40
|
-
case '
|
|
41
|
-
|
|
42
|
-
case '
|
|
43
|
-
|
|
44
|
-
case '
|
|
45
|
-
|
|
46
|
-
case '
|
|
47
|
-
|
|
48
|
-
case '
|
|
49
|
-
|
|
50
|
-
case '
|
|
51
|
-
|
|
52
|
-
case '
|
|
53
|
-
|
|
54
|
-
case '
|
|
55
|
-
|
|
56
|
-
case '
|
|
57
|
-
|
|
58
|
-
case '
|
|
59
|
-
|
|
60
|
-
case '
|
|
61
|
-
|
|
62
|
-
case '
|
|
28
|
+
case 'getNavigationTree':
|
|
29
|
+
return getNavigationTree(language, target[p]);
|
|
30
|
+
case 'getOutliningSpans':
|
|
31
|
+
return getOutliningSpans(language, target[p]);
|
|
32
|
+
case 'getFormattingEditsForDocument':
|
|
33
|
+
return getFormattingEditsForDocument(language, target[p]);
|
|
34
|
+
case 'getFormattingEditsForRange':
|
|
35
|
+
return getFormattingEditsForRange(language, target[p]);
|
|
36
|
+
case 'getFormattingEditsAfterKeystroke':
|
|
37
|
+
return getFormattingEditsAfterKeystroke(language, target[p]);
|
|
38
|
+
case 'getEditsForFileRename':
|
|
39
|
+
return getEditsForFileRename(language, target[p]);
|
|
40
|
+
case 'getLinkedEditingRangeAtPosition':
|
|
41
|
+
return getLinkedEditingRangeAtPosition(language, target[p]);
|
|
42
|
+
case 'prepareCallHierarchy':
|
|
43
|
+
return prepareCallHierarchy(language, target[p]);
|
|
44
|
+
case 'provideCallHierarchyIncomingCalls':
|
|
45
|
+
return provideCallHierarchyIncomingCalls(language, target[p]);
|
|
46
|
+
case 'provideCallHierarchyOutgoingCalls':
|
|
47
|
+
return provideCallHierarchyOutgoingCalls(language, target[p]);
|
|
48
|
+
case 'organizeImports':
|
|
49
|
+
return organizeImports(language, target[p]);
|
|
50
|
+
case 'getQuickInfoAtPosition':
|
|
51
|
+
return getQuickInfoAtPosition(language, target[p]);
|
|
52
|
+
case 'getSignatureHelpItems':
|
|
53
|
+
return getSignatureHelpItems(language, target[p]);
|
|
54
|
+
case 'getDocumentHighlights':
|
|
55
|
+
return getDocumentHighlights(language, target[p]);
|
|
56
|
+
case 'getApplicableRefactors':
|
|
57
|
+
return getApplicableRefactors(language, target[p]);
|
|
58
|
+
case 'getEditsForRefactor':
|
|
59
|
+
return getEditsForRefactor(language, target[p]);
|
|
60
|
+
case 'getCombinedCodeFix':
|
|
61
|
+
return getCombinedCodeFix(language, target[p]);
|
|
62
|
+
case 'getRenameInfo':
|
|
63
|
+
return getRenameInfo(language, target[p]);
|
|
64
|
+
case 'getCodeFixesAtPosition':
|
|
65
|
+
return getCodeFixesAtPosition(language, target[p]);
|
|
66
|
+
case 'getEncodedSemanticClassifications':
|
|
67
|
+
return getEncodedSemanticClassifications(language, target[p]);
|
|
68
|
+
case 'getSyntacticDiagnostics':
|
|
69
|
+
return getSyntacticDiagnostics(language, languageService, target[p]);
|
|
70
|
+
case 'getSemanticDiagnostics':
|
|
71
|
+
return getSemanticDiagnostics(language, languageService, target[p]);
|
|
72
|
+
case 'getSuggestionDiagnostics':
|
|
73
|
+
return getSuggestionDiagnostics(language, languageService, target[p]);
|
|
74
|
+
case 'getDefinitionAndBoundSpan':
|
|
75
|
+
return getDefinitionAndBoundSpan(language, target[p]);
|
|
76
|
+
case 'findReferences':
|
|
77
|
+
return findReferences(language, target[p]);
|
|
78
|
+
case 'getDefinitionAtPosition':
|
|
79
|
+
return getDefinitionAtPosition(language, target[p]);
|
|
80
|
+
case 'getTypeDefinitionAtPosition':
|
|
81
|
+
return getTypeDefinitionAtPosition(language, target[p]);
|
|
82
|
+
case 'getImplementationAtPosition':
|
|
83
|
+
return getImplementationAtPosition(language, target[p]);
|
|
84
|
+
case 'findRenameLocations':
|
|
85
|
+
return findRenameLocations(language, target[p]);
|
|
86
|
+
case 'getReferencesAtPosition':
|
|
87
|
+
return getReferencesAtPosition(language, target[p]);
|
|
88
|
+
case 'getCompletionsAtPosition':
|
|
89
|
+
return getCompletionsAtPosition(language, target[p]);
|
|
90
|
+
case 'getCompletionEntryDetails':
|
|
91
|
+
return getCompletionEntryDetails(language, target[p]);
|
|
92
|
+
case 'provideInlayHints':
|
|
93
|
+
return provideInlayHints(language, target[p]);
|
|
94
|
+
case 'getFileReferences':
|
|
95
|
+
return getFileReferences(language, target[p]);
|
|
96
|
+
case 'getNavigateToItems':
|
|
97
|
+
return getNavigateToItems(language, target[p]);
|
|
63
98
|
}
|
|
64
99
|
};
|
|
65
100
|
},
|
|
@@ -413,7 +448,8 @@ function getDocumentHighlights(language, getDocumentHighlights) {
|
|
|
413
448
|
...highlights,
|
|
414
449
|
highlightSpans: highlights.highlightSpans
|
|
415
450
|
.map(span => {
|
|
416
|
-
const { textSpan } = (0, transform_1.transformSpan)(language, span.fileName ?? highlights.fileName, span.textSpan, false, language_core_1.isHighlightEnabled)
|
|
451
|
+
const { textSpan } = (0, transform_1.transformSpan)(language, span.fileName ?? highlights.fileName, span.textSpan, false, language_core_1.isHighlightEnabled)
|
|
452
|
+
?? {};
|
|
417
453
|
if (textSpan) {
|
|
418
454
|
return {
|
|
419
455
|
...span,
|
|
@@ -498,7 +534,7 @@ function getRenameInfo(language, getRenameInfo) {
|
|
|
498
534
|
if (targetScript?.associatedOnly) {
|
|
499
535
|
return {
|
|
500
536
|
canRename: false,
|
|
501
|
-
localizedErrorMessage:
|
|
537
|
+
localizedErrorMessage: 'Cannot rename',
|
|
502
538
|
};
|
|
503
539
|
}
|
|
504
540
|
if (serviceScript) {
|
|
@@ -560,7 +596,7 @@ function getEncodedSemanticClassifications(language, getEncodedSemanticClassific
|
|
|
560
596
|
if (targetScript?.associatedOnly) {
|
|
561
597
|
return {
|
|
562
598
|
spans: [],
|
|
563
|
-
endOfLineState: 0
|
|
599
|
+
endOfLineState: 0,
|
|
564
600
|
};
|
|
565
601
|
}
|
|
566
602
|
if (serviceScript) {
|
|
@@ -569,7 +605,7 @@ function getEncodedSemanticClassifications(language, getEncodedSemanticClassific
|
|
|
569
605
|
if (!mapped) {
|
|
570
606
|
return {
|
|
571
607
|
spans: [],
|
|
572
|
-
endOfLineState: 0
|
|
608
|
+
endOfLineState: 0,
|
|
573
609
|
};
|
|
574
610
|
}
|
|
575
611
|
const mappingOffset = (0, transform_1.getMappingOffset)(language, serviceScript);
|
|
@@ -778,7 +814,8 @@ function getCompletionsAtPosition(language, getCompletionsAtPosition) {
|
|
|
778
814
|
result.entries = result.entries.filter(entry => !!entry.sourceDisplay);
|
|
779
815
|
}
|
|
780
816
|
for (const entry of result.entries) {
|
|
781
|
-
entry.replacementSpan = entry.replacementSpan
|
|
817
|
+
entry.replacementSpan = entry.replacementSpan
|
|
818
|
+
&& (0, transform_1.transformTextSpan)(sourceScript, language, serviceScript, entry.replacementSpan, false, language_core_1.isCompletionEnabled)?.[1];
|
|
782
819
|
}
|
|
783
820
|
result.optionalReplacementSpan = result.optionalReplacementSpan
|
|
784
821
|
&& (0, transform_1.transformTextSpan)(sourceScript, language, serviceScript, result.optionalReplacementSpan, false, language_core_1.isCompletionEnabled)?.[1];
|
package/lib/node/transform.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CodeInformation, SourceScript } from '@volar/language-core';
|
|
2
|
-
import { Language } from '@volar/language-core';
|
|
2
|
+
import { type Language } from '@volar/language-core';
|
|
3
3
|
import type * as ts from 'typescript';
|
|
4
4
|
import type { TypeScriptServiceScript } from '../..';
|
|
5
5
|
/**
|
package/lib/node/transform.js
CHANGED
|
@@ -52,7 +52,7 @@ function transformDiagnostic(language, diagnostic, program, isTsc) {
|
|
|
52
52
|
if (serviceScript) {
|
|
53
53
|
const [sourceSpanFileName, sourceSpan] = transformTextSpan(undefined, language, serviceScript, {
|
|
54
54
|
start: diagnostic.start,
|
|
55
|
-
length: diagnostic.length
|
|
55
|
+
length: diagnostic.length,
|
|
56
56
|
}, true, data => (0, language_core_1.shouldReportDiagnostics)(data, String(diagnostic.source), String(diagnostic.code))) ?? [];
|
|
57
57
|
const actualDiagnosticFile = sourceSpanFileName
|
|
58
58
|
? diagnostic.file.fileName === sourceSpanFileName
|
|
@@ -101,14 +101,15 @@ function transformFileTextChanges(language, changes, fallbackToAnyMatch, filter)
|
|
|
101
101
|
const [_, source] = (0, utils_1.getServiceScript)(language, fileChanges.fileName);
|
|
102
102
|
if (source) {
|
|
103
103
|
fileChanges.textChanges.forEach(c => {
|
|
104
|
-
const { fileName, textSpan } = transformSpan(language, fileChanges.fileName, c.span, fallbackToAnyMatch, filter)
|
|
104
|
+
const { fileName, textSpan } = transformSpan(language, fileChanges.fileName, c.span, fallbackToAnyMatch, filter)
|
|
105
|
+
?? {};
|
|
105
106
|
if (fileName && textSpan) {
|
|
106
107
|
(changesPerFile[fileName] ?? (changesPerFile[fileName] = [])).push({ ...c, span: textSpan });
|
|
107
108
|
}
|
|
108
109
|
});
|
|
109
110
|
}
|
|
110
111
|
else {
|
|
111
|
-
const list =
|
|
112
|
+
const list = changesPerFile[fileChanges.fileName] ?? (changesPerFile[fileChanges.fileName] = []);
|
|
112
113
|
fileChanges.textChanges.forEach(c => {
|
|
113
114
|
list.push(c);
|
|
114
115
|
});
|
|
@@ -122,7 +123,7 @@ function transformFileTextChanges(language, changes, fallbackToAnyMatch, filter)
|
|
|
122
123
|
result.push({
|
|
123
124
|
fileName,
|
|
124
125
|
isNewFile: newFiles.has(fileName),
|
|
125
|
-
textChanges: changesPerFile[fileName]
|
|
126
|
+
textChanges: changesPerFile[fileName],
|
|
126
127
|
});
|
|
127
128
|
}
|
|
128
129
|
return result;
|
package/lib/node/utils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Language, SourceScript } from '@volar/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
2
3
|
import type { TypeScriptServiceScript } from '../..';
|
|
3
4
|
export declare function getServiceScript(language: Language<string>, fileName: string): [serviceScript: TypeScriptServiceScript, targetScript: SourceScript<string>, sourceScript: SourceScript<string>] | [serviceScript: undefined, sourceScript: SourceScript<string>, sourceScript: SourceScript<string>] | [serviceScript: undefined, sourceScript: undefined, targetScript: undefined];
|
|
5
|
+
export declare function fixupImpliedNodeFormatForFile(ts: typeof import('typescript'), pluginExtensions: string[], sourceFile: ts.SourceFile, packageJsonInfoCache: ts.PackageJsonInfoCache, host: ts.ModuleResolutionHost, options: ts.CompilerOptions): (() => undefined) | undefined;
|
package/lib/node/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getServiceScript = getServiceScript;
|
|
4
|
+
exports.fixupImpliedNodeFormatForFile = fixupImpliedNodeFormatForFile;
|
|
4
5
|
function getServiceScript(language, fileName) {
|
|
5
6
|
const sourceScript = language.scripts.get(fileName);
|
|
6
7
|
if (sourceScript?.targetIds.size) {
|
|
@@ -25,4 +26,17 @@ function getServiceScript(language, fileName) {
|
|
|
25
26
|
}
|
|
26
27
|
return [undefined, undefined, undefined];
|
|
27
28
|
}
|
|
29
|
+
function fixupImpliedNodeFormatForFile(ts, pluginExtensions, sourceFile, packageJsonInfoCache, host, options) {
|
|
30
|
+
if (sourceFile.impliedNodeFormat !== undefined || !pluginExtensions.some(ext => sourceFile.fileName.endsWith(ext))) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// https://github.com/microsoft/TypeScript/blob/669c25c091ad4d32298d0f33b0e4e681d46de3ea/src/compiler/program.ts#L1354
|
|
34
|
+
const validExts = [ts.Extension.Dts, ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Js, ts.Extension.Jsx];
|
|
35
|
+
if (validExts.some(ext => sourceFile.fileName.endsWith(ext))) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const asTs = sourceFile.fileName + ts.Extension.Ts;
|
|
39
|
+
sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile?.(asTs, packageJsonInfoCache, host, options);
|
|
40
|
+
return () => sourceFile.impliedNodeFormat = undefined;
|
|
41
|
+
}
|
|
28
42
|
//# sourceMappingURL=utils.js.map
|
|
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createLanguageServiceHost = createLanguageServiceHost;
|
|
4
4
|
const language_core_1 = require("@volar/language-core");
|
|
5
5
|
const path = require("path-browserify");
|
|
6
|
+
const utils_1 = require("../node/utils");
|
|
6
7
|
const resolveModuleName_1 = require("../resolveModuleName");
|
|
7
8
|
function createLanguageServiceHost(ts, sys, language, asScriptId, projectHost) {
|
|
9
|
+
const pluginExtensions = language.plugins
|
|
10
|
+
.map(plugin => plugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? [])
|
|
11
|
+
.flat();
|
|
8
12
|
const scriptVersions = new language_core_1.FileMap(sys.useCaseSensitiveFileNames);
|
|
9
13
|
let lastProjectVersion;
|
|
10
14
|
let tsProjectVersion = 0;
|
|
@@ -32,17 +36,15 @@ function createLanguageServiceHost(ts, sys, language, asScriptId, projectHost) {
|
|
|
32
36
|
},
|
|
33
37
|
readDirectory(dirName, extensions, excludes, includes, depth) {
|
|
34
38
|
const exts = new Set(extensions);
|
|
35
|
-
for (const
|
|
36
|
-
|
|
37
|
-
exts.add('.' + ext.extension);
|
|
38
|
-
}
|
|
39
|
+
for (const ext of pluginExtensions) {
|
|
40
|
+
exts.add(ext);
|
|
39
41
|
}
|
|
40
42
|
extensions = [...exts];
|
|
41
43
|
return sys.readDirectory(dirName, extensions, excludes, includes, depth);
|
|
42
44
|
},
|
|
43
45
|
getCompilationSettings() {
|
|
44
46
|
const options = projectHost.getCompilationSettings();
|
|
45
|
-
if (
|
|
47
|
+
if (pluginExtensions.length) {
|
|
46
48
|
options.allowNonTsExtensions ??= true;
|
|
47
49
|
if (!options.allowNonTsExtensions) {
|
|
48
50
|
console.warn('`allowNonTsExtensions` must be `true`.');
|
|
@@ -124,30 +126,38 @@ function createLanguageServiceHost(ts, sys, language, asScriptId, projectHost) {
|
|
|
124
126
|
languageServiceHost = plugin.typescript.resolveLanguageServiceHost(languageServiceHost);
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
|
-
if (
|
|
129
|
+
if (pluginExtensions.length) {
|
|
128
130
|
// TODO: can this share between monorepo packages?
|
|
129
|
-
const
|
|
131
|
+
const moduleResolutionCache = ts.createModuleResolutionCache(languageServiceHost.getCurrentDirectory(), languageServiceHost.useCaseSensitiveFileNames?.() ? s => s : s => s.toLowerCase(), languageServiceHost.getCompilationSettings());
|
|
130
132
|
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, sys.getFileSize, languageServiceHost, language.plugins, fileName => language.scripts.get(asScriptId(fileName)));
|
|
131
133
|
let lastSysVersion = 'version' in sys ? sys.version : undefined;
|
|
132
|
-
languageServiceHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
languageServiceHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, containingSourceFile) => {
|
|
135
|
+
const disposeFixup = (0, utils_1.fixupImpliedNodeFormatForFile)(ts, pluginExtensions, containingSourceFile, moduleResolutionCache.getPackageJsonInfoCache(), languageServiceHost, options);
|
|
136
|
+
try {
|
|
137
|
+
if ('version' in sys && lastSysVersion !== sys.version) {
|
|
138
|
+
lastSysVersion = sys.version;
|
|
139
|
+
moduleResolutionCache.clear();
|
|
140
|
+
}
|
|
141
|
+
return moduleLiterals.map(moduleLiteral => {
|
|
142
|
+
const mode = ts.getModeForUsageLocation(containingSourceFile, moduleLiteral, options);
|
|
143
|
+
return resolveModuleName(moduleLiteral.text, containingFile, options, moduleResolutionCache, redirectedReference, mode);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
disposeFixup?.();
|
|
136
148
|
}
|
|
137
|
-
return moduleLiterals.map(moduleLiteral => {
|
|
138
|
-
return resolveModuleName(moduleLiteral.text, containingFile, options, moduleCache, redirectedReference, sourceFile.impliedNodeFormat);
|
|
139
|
-
});
|
|
140
149
|
};
|
|
141
150
|
languageServiceHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options) => {
|
|
142
151
|
if ('version' in sys && lastSysVersion !== sys.version) {
|
|
143
152
|
lastSysVersion = sys.version;
|
|
144
|
-
|
|
153
|
+
moduleResolutionCache.clear();
|
|
145
154
|
}
|
|
146
155
|
return moduleNames.map(moduleName => {
|
|
147
|
-
return resolveModuleName(moduleName, containingFile, options,
|
|
156
|
+
return resolveModuleName(moduleName, containingFile, options, moduleResolutionCache, redirectedReference)
|
|
157
|
+
.resolvedModule;
|
|
148
158
|
});
|
|
149
159
|
};
|
|
150
|
-
languageServiceHost.getModuleResolutionCache = () =>
|
|
160
|
+
languageServiceHost.getModuleResolutionCache = () => moduleResolutionCache;
|
|
151
161
|
}
|
|
152
162
|
return {
|
|
153
163
|
languageServiceHost,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Disposable, LanguageServiceEnvironment } from '@volar/language-service';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import { URI } from 'vscode-uri';
|
|
4
4
|
export declare function createSys(sys: ts.System | undefined, env: Pick<LanguageServiceEnvironment, 'onDidChangeWatchedFiles' | 'fs'>, getCurrentDirectory: () => string, uriConverter: {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSys = createSys;
|
|
4
4
|
const path = require("path-browserify");
|
|
5
|
-
const utilities_1 = require("../typescript/utilities");
|
|
6
5
|
const vscode_uri_1 = require("vscode-uri");
|
|
6
|
+
const utilities_1 = require("../typescript/utilities");
|
|
7
7
|
let currentCwd = '';
|
|
8
8
|
function createSys(sys, env, getCurrentDirectory, uriConverter) {
|
|
9
9
|
let version = 0;
|
|
@@ -25,23 +25,25 @@ function createSys(sys, env, getCurrentDirectory, uriConverter) {
|
|
|
25
25
|
const fileExists = change.type === 1
|
|
26
26
|
|| change.type === 2;
|
|
27
27
|
const dir = getDir(dirName, fileExists);
|
|
28
|
-
dir.files.set(normalizeFileId(baseName), fileExists
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
dir.files.set(normalizeFileId(baseName), fileExists
|
|
29
|
+
? {
|
|
30
|
+
name: baseName,
|
|
31
|
+
stat: {
|
|
32
|
+
type: 1,
|
|
33
|
+
ctime: Date.now(),
|
|
34
|
+
mtime: Date.now(),
|
|
35
|
+
size: -1,
|
|
36
|
+
},
|
|
37
|
+
requestedStat: false,
|
|
38
|
+
requestedText: false,
|
|
39
|
+
}
|
|
40
|
+
: {
|
|
41
|
+
name: baseName,
|
|
42
|
+
stat: undefined,
|
|
43
|
+
text: undefined,
|
|
44
|
+
requestedStat: true,
|
|
45
|
+
requestedText: true,
|
|
46
|
+
});
|
|
45
47
|
}
|
|
46
48
|
});
|
|
47
49
|
return {
|
|
@@ -133,7 +135,7 @@ function createSys(sys, env, getCurrentDirectory, uriConverter) {
|
|
|
133
135
|
file.requestedStat = true;
|
|
134
136
|
handleStat(fileName, file);
|
|
135
137
|
}
|
|
136
|
-
return file.stat ? new Date(file.stat.mtime) : new Date(
|
|
138
|
+
return file.stat ? new Date(file.stat.mtime) : new Date(-1);
|
|
137
139
|
}
|
|
138
140
|
function fileExists(fileName) {
|
|
139
141
|
fileName = resolvePath(fileName);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Language, LanguagePlugin } from '@volar/language-core/lib/types';
|
|
1
|
+
import { type Language, type LanguagePlugin } from '@volar/language-core/lib/types';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
export declare const externalFiles: WeakMap<ts.server.Project, string[]>;
|
|
4
4
|
export declare const projectExternalFileExtensions: WeakMap<ts.server.Project, string[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
1
|
import type { Language, LanguagePlugin } from '@volar/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
3
|
export declare let getLanguagePlugins: (ts: typeof import('typescript'), options: ts.CreateProgramOptions) => LanguagePlugin<string>[] | {
|
|
4
4
|
languagePlugins: LanguagePlugin<string>[];
|
|
5
5
|
setup?(language: Language<string>): void;
|
package/lib/quickstart/runTsc.js
CHANGED
|
@@ -95,7 +95,7 @@ function transformTscContent(tsc, proxyApiPath, extraSupportedExtensions, extraE
|
|
|
95
95
|
+ s.replace('createProgram', '_createProgram'));
|
|
96
96
|
return tsc;
|
|
97
97
|
}
|
|
98
|
-
function replace(text,
|
|
98
|
+
function replace(text, search, replace) {
|
|
99
99
|
const before = text;
|
|
100
100
|
text = text.replace(search, replace);
|
|
101
101
|
const after = text;
|
package/lib/typescript/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Comparer, Comparison, SortedReadonlyArray } from
|
|
1
|
+
import { type Comparer, Comparison, type SortedReadonlyArray } from './corePublic';
|
|
2
2
|
/**
|
|
3
3
|
* Iterates through `array` by index and performs the callback on each element of array until the callback
|
|
4
4
|
* returns a falsey value, then returns false.
|
package/lib/typescript/core.js
CHANGED
|
@@ -232,9 +232,9 @@ const fileNameLowerCaseRegExp = /[^\u0130\u0131\u00DFa-z0-9\\/:\-_\. ]+/g;
|
|
|
232
232
|
* So for this function purpose, we go ahead and assume character I with dot on top it as case sensitive since its very unlikely to use lower case form of that special character
|
|
233
233
|
*/
|
|
234
234
|
function toFileNameLowerCase(x) {
|
|
235
|
-
return fileNameLowerCaseRegExp.test(x)
|
|
236
|
-
x.replace(fileNameLowerCaseRegExp, toLowerCase)
|
|
237
|
-
x;
|
|
235
|
+
return fileNameLowerCaseRegExp.test(x)
|
|
236
|
+
? x.replace(fileNameLowerCaseRegExp, toLowerCase)
|
|
237
|
+
: x;
|
|
238
238
|
}
|
|
239
239
|
function equateValues(a, b) {
|
|
240
240
|
return a === b;
|
|
@@ -263,11 +263,15 @@ function equateStringsCaseSensitive(a, b) {
|
|
|
263
263
|
return equateValues(a, b);
|
|
264
264
|
}
|
|
265
265
|
function compareComparableValues(a, b) {
|
|
266
|
-
return a === b
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
266
|
+
return a === b
|
|
267
|
+
? 0 /* Comparison.EqualTo */
|
|
268
|
+
: a === undefined
|
|
269
|
+
? -1 /* Comparison.LessThan */
|
|
270
|
+
: b === undefined
|
|
271
|
+
? 1 /* Comparison.GreaterThan */
|
|
272
|
+
: a < b
|
|
273
|
+
? -1 /* Comparison.LessThan */
|
|
274
|
+
: 1 /* Comparison.GreaterThan */;
|
|
271
275
|
}
|
|
272
276
|
/**
|
|
273
277
|
* Compare two strings using a case-insensitive ordinal comparison.
|
|
@@ -10,10 +10,10 @@ export interface MapLike<T> {
|
|
|
10
10
|
[index: string]: T;
|
|
11
11
|
}
|
|
12
12
|
export interface SortedReadonlyArray<T> extends ReadonlyArray<T> {
|
|
13
|
-
|
|
13
|
+
' __sortedArrayBrand': any;
|
|
14
14
|
}
|
|
15
15
|
export interface SortedArray<T> extends Array<T> {
|
|
16
|
-
|
|
16
|
+
' __sortedArrayBrand': any;
|
|
17
17
|
}
|
|
18
18
|
/** Common read methods for ES6 Map/Set. */
|
|
19
19
|
export interface ReadonlyCollection<K> {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Set = exports.Map = exports.version = exports.versionMajorMinor = void 0;
|
|
4
4
|
// WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
|
|
5
5
|
// If changing the text in this section, be sure to test `configurePrerelease` too.
|
|
6
|
-
exports.versionMajorMinor =
|
|
6
|
+
exports.versionMajorMinor = '4.9';
|
|
7
7
|
// The following is baselined as a literal template type without intervention
|
|
8
8
|
/** The version of the TypeScript compiler release */
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
@@ -11,11 +11,15 @@ exports.version = `${exports.versionMajorMinor}.0-dev`;
|
|
|
11
11
|
/* @internal */
|
|
12
12
|
var NativeCollections;
|
|
13
13
|
(function (NativeCollections) {
|
|
14
|
-
const globals = typeof globalThis !==
|
|
14
|
+
const globals = typeof globalThis !== 'undefined'
|
|
15
|
+
? globalThis
|
|
15
16
|
// @ts-ignore node global
|
|
16
|
-
typeof global !==
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
: typeof global !== 'undefined'
|
|
18
|
+
// @ts-ignore node global
|
|
19
|
+
? global
|
|
20
|
+
: typeof self !== 'undefined'
|
|
21
|
+
? self
|
|
22
|
+
: undefined;
|
|
19
23
|
/**
|
|
20
24
|
* Returns the native Map implementation if it is available and compatible (i.e. supports iteration).
|
|
21
25
|
*/
|
|
@@ -23,9 +27,11 @@ var NativeCollections;
|
|
|
23
27
|
// Internet Explorer's Map doesn't support iteration, so don't use it.
|
|
24
28
|
const gMap = globals?.Map;
|
|
25
29
|
// eslint-disable-next-line local/no-in-operator
|
|
26
|
-
const constructor = typeof gMap !==
|
|
30
|
+
const constructor = typeof gMap !== 'undefined' && 'entries' in gMap.prototype && new gMap([[0, 0]]).size === 1
|
|
31
|
+
? gMap
|
|
32
|
+
: undefined;
|
|
27
33
|
if (!constructor) {
|
|
28
|
-
throw new Error(
|
|
34
|
+
throw new Error('No compatible Map implementation found.');
|
|
29
35
|
}
|
|
30
36
|
return constructor;
|
|
31
37
|
}
|
|
@@ -37,9 +43,11 @@ var NativeCollections;
|
|
|
37
43
|
// Internet Explorer's Set doesn't support iteration, so don't use it.
|
|
38
44
|
const gSet = globals?.Set;
|
|
39
45
|
// eslint-disable-next-line local/no-in-operator
|
|
40
|
-
const constructor = typeof gSet !==
|
|
46
|
+
const constructor = typeof gSet !== 'undefined' && 'entries' in gSet.prototype && new gSet([0]).size === 1
|
|
47
|
+
? gSet
|
|
48
|
+
: undefined;
|
|
41
49
|
if (!constructor) {
|
|
42
|
-
throw new Error(
|
|
50
|
+
throw new Error('No compatible Set implementation found.');
|
|
43
51
|
}
|
|
44
52
|
return constructor;
|
|
45
53
|
}
|
package/lib/typescript/path.d.ts
CHANGED
package/lib/typescript/path.js
CHANGED
|
@@ -16,9 +16,9 @@ const core_1 = require("./core");
|
|
|
16
16
|
* When we make system calls (eg: LanguageServiceHost.getDirectory()),
|
|
17
17
|
* we expect the host to correctly handle paths in our specified format.
|
|
18
18
|
*/
|
|
19
|
-
exports.directorySeparator =
|
|
20
|
-
const altDirectorySeparator =
|
|
21
|
-
const urlSchemeSeparator =
|
|
19
|
+
exports.directorySeparator = '/';
|
|
20
|
+
const altDirectorySeparator = '\\';
|
|
21
|
+
const urlSchemeSeparator = '://';
|
|
22
22
|
const backslashRegExp = /\\/g;
|
|
23
23
|
//// Path Tests
|
|
24
24
|
/**
|
|
@@ -35,7 +35,7 @@ function isRootedDiskPath(path) {
|
|
|
35
35
|
return getEncodedRootLength(path) > 0;
|
|
36
36
|
}
|
|
37
37
|
function hasExtension(fileName) {
|
|
38
|
-
return (0, core_1.stringContains)(getBaseFileName(fileName),
|
|
38
|
+
return (0, core_1.stringContains)(getBaseFileName(fileName), '.');
|
|
39
39
|
}
|
|
40
40
|
function fileExtensionIs(path, extension) {
|
|
41
41
|
return path.length > extension.length && (0, core_1.endsWith)(path, extension);
|
|
@@ -56,8 +56,8 @@ function hasTrailingDirectorySeparator(path) {
|
|
|
56
56
|
}
|
|
57
57
|
//// Path Parsing
|
|
58
58
|
function isVolumeCharacter(charCode) {
|
|
59
|
-
return (charCode >= 97 /* CharacterCodes.a */ && charCode <= 122 /* CharacterCodes.z */)
|
|
60
|
-
(charCode >= 65 /* CharacterCodes.A */ && charCode <= 90 /* CharacterCodes.Z */);
|
|
59
|
+
return (charCode >= 97 /* CharacterCodes.a */ && charCode <= 122 /* CharacterCodes.z */)
|
|
60
|
+
|| (charCode >= 65 /* CharacterCodes.A */ && charCode <= 90 /* CharacterCodes.Z */);
|
|
61
61
|
}
|
|
62
62
|
function getFileUrlVolumeSeparatorEnd(url, start) {
|
|
63
63
|
const ch0 = url.charCodeAt(start);
|
|
@@ -113,8 +113,8 @@ function getEncodedRootLength(path) {
|
|
|
113
113
|
// special case interpreted as "the machine from which the URL is being interpreted".
|
|
114
114
|
const scheme = path.slice(0, schemeEnd);
|
|
115
115
|
const authority = path.slice(authorityStart, authorityEnd);
|
|
116
|
-
if (scheme ===
|
|
117
|
-
isVolumeCharacter(path.charCodeAt(authorityEnd + 1))) {
|
|
116
|
+
if (scheme === 'file' && (authority === '' || authority === 'localhost')
|
|
117
|
+
&& isVolumeCharacter(path.charCodeAt(authorityEnd + 1))) {
|
|
118
118
|
const volumeSeparatorEnd = getFileUrlVolumeSeparatorEnd(path, authorityEnd + 2);
|
|
119
119
|
if (volumeSeparatorEnd !== -1) {
|
|
120
120
|
if (path.charCodeAt(volumeSeparatorEnd) === 47 /* CharacterCodes.slash */) {
|
|
@@ -181,18 +181,20 @@ function getBaseFileName(path, extensions, ignoreCase) {
|
|
|
181
181
|
// if the path provided is itself the root, then it has not file name.
|
|
182
182
|
const rootLength = getRootLength(path);
|
|
183
183
|
if (rootLength === path.length) {
|
|
184
|
-
return
|
|
184
|
+
return '';
|
|
185
185
|
}
|
|
186
186
|
// return the trailing portion of the path starting after the last (non-terminal) directory
|
|
187
187
|
// separator but not including any trailing directory separator.
|
|
188
188
|
path = removeTrailingDirectorySeparator(path);
|
|
189
189
|
const name = path.slice(Math.max(getRootLength(path), path.lastIndexOf(exports.directorySeparator) + 1));
|
|
190
|
-
const extension = extensions !== undefined && ignoreCase !== undefined
|
|
190
|
+
const extension = extensions !== undefined && ignoreCase !== undefined
|
|
191
|
+
? getAnyExtensionFromPath(name, extensions, ignoreCase)
|
|
192
|
+
: undefined;
|
|
191
193
|
return extension ? name.slice(0, name.length - extension.length) : name;
|
|
192
194
|
}
|
|
193
195
|
function tryGetExtensionFromPath(path, extension, stringEqualityComparer) {
|
|
194
|
-
if (!(0, core_1.startsWith)(extension,
|
|
195
|
-
extension =
|
|
196
|
+
if (!(0, core_1.startsWith)(extension, '.')) {
|
|
197
|
+
extension = '.' + extension;
|
|
196
198
|
}
|
|
197
199
|
if (path.length >= extension.length && path.charCodeAt(path.length - extension.length) === 46 /* CharacterCodes.dot */) {
|
|
198
200
|
const pathExtension = path.slice(path.length - extension.length);
|
|
@@ -202,8 +204,8 @@ function tryGetExtensionFromPath(path, extension, stringEqualityComparer) {
|
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
206
|
function getAnyExtensionFromPathWorker(path, extensions, stringEqualityComparer) {
|
|
205
|
-
if (typeof extensions ===
|
|
206
|
-
return tryGetExtensionFromPath(path, extensions, stringEqualityComparer) ||
|
|
207
|
+
if (typeof extensions === 'string') {
|
|
208
|
+
return tryGetExtensionFromPath(path, extensions, stringEqualityComparer) || '';
|
|
207
209
|
}
|
|
208
210
|
for (const extension of extensions) {
|
|
209
211
|
const result = tryGetExtensionFromPath(path, extension, stringEqualityComparer);
|
|
@@ -211,7 +213,7 @@ function getAnyExtensionFromPathWorker(path, extensions, stringEqualityComparer)
|
|
|
211
213
|
return result;
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
|
-
return
|
|
216
|
+
return '';
|
|
215
217
|
}
|
|
216
218
|
function getAnyExtensionFromPath(path, extensions, ignoreCase) {
|
|
217
219
|
// Retrieves any string from the final "." onwards from a base file name.
|
|
@@ -220,11 +222,11 @@ function getAnyExtensionFromPath(path, extensions, ignoreCase) {
|
|
|
220
222
|
return getAnyExtensionFromPathWorker(removeTrailingDirectorySeparator(path), extensions, ignoreCase ? core_1.equateStringsCaseInsensitive : core_1.equateStringsCaseSensitive);
|
|
221
223
|
}
|
|
222
224
|
const baseFileName = getBaseFileName(path);
|
|
223
|
-
const extensionIndex = baseFileName.lastIndexOf(
|
|
225
|
+
const extensionIndex = baseFileName.lastIndexOf('.');
|
|
224
226
|
if (extensionIndex >= 0) {
|
|
225
227
|
return baseFileName.substring(extensionIndex);
|
|
226
228
|
}
|
|
227
|
-
return
|
|
229
|
+
return '';
|
|
228
230
|
}
|
|
229
231
|
function pathComponents(path, rootLength) {
|
|
230
232
|
const root = path.substring(0, rootLength);
|
|
@@ -264,7 +266,7 @@ function pathComponents(path, rootLength) {
|
|
|
264
266
|
* getPathComponents("file:///") === ["file:///"]
|
|
265
267
|
* getPathComponents("file://") === ["file://"]
|
|
266
268
|
*/
|
|
267
|
-
function getPathComponents(path, currentDirectory =
|
|
269
|
+
function getPathComponents(path, currentDirectory = '') {
|
|
268
270
|
path = combinePaths(currentDirectory, path);
|
|
269
271
|
return pathComponents(path, getRootLength(path));
|
|
270
272
|
}
|
|
@@ -279,7 +281,7 @@ function getPathComponents(path, currentDirectory = "") {
|
|
|
279
281
|
*/
|
|
280
282
|
function getPathFromPathComponents(pathComponents) {
|
|
281
283
|
if (pathComponents.length === 0) {
|
|
282
|
-
return
|
|
284
|
+
return '';
|
|
283
285
|
}
|
|
284
286
|
const root = pathComponents[0] && ensureTrailingDirectorySeparator(pathComponents[0]);
|
|
285
287
|
return root + pathComponents.slice(1).join(exports.directorySeparator);
|
|
@@ -289,7 +291,7 @@ function getPathFromPathComponents(pathComponents) {
|
|
|
289
291
|
* Normalize path separators, converting `\` into `/`.
|
|
290
292
|
*/
|
|
291
293
|
function normalizeSlashes(path) {
|
|
292
|
-
return path.indexOf(
|
|
294
|
+
return path.indexOf('\\') !== -1
|
|
293
295
|
? path.replace(backslashRegExp, exports.directorySeparator)
|
|
294
296
|
: path;
|
|
295
297
|
}
|
|
@@ -307,12 +309,12 @@ function reducePathComponents(components) {
|
|
|
307
309
|
if (!component) {
|
|
308
310
|
continue;
|
|
309
311
|
}
|
|
310
|
-
if (component ===
|
|
312
|
+
if (component === '.') {
|
|
311
313
|
continue;
|
|
312
314
|
}
|
|
313
|
-
if (component ===
|
|
315
|
+
if (component === '..') {
|
|
314
316
|
if (reduced.length > 1) {
|
|
315
|
-
if (reduced[reduced.length - 1] !==
|
|
317
|
+
if (reduced[reduced.length - 1] !== '..') {
|
|
316
318
|
reduced.pop();
|
|
317
319
|
continue;
|
|
318
320
|
}
|
|
@@ -381,7 +383,7 @@ function normalizePath(path) {
|
|
|
381
383
|
return path;
|
|
382
384
|
}
|
|
383
385
|
// Some paths only require cleanup of `/./` or leading `./`
|
|
384
|
-
const simplified = path.replace(/\/\.\//g,
|
|
386
|
+
const simplified = path.replace(/\/\.\//g, '/').replace(/^\.\//, '');
|
|
385
387
|
if (simplified !== path) {
|
|
386
388
|
path = simplified;
|
|
387
389
|
if (!relativePathSegmentRegExp.test(path)) {
|
|
@@ -408,11 +410,11 @@ function ensureTrailingDirectorySeparator(path) {
|
|
|
408
410
|
// check path for these segments: '', '.'. '..'
|
|
409
411
|
const relativePathSegmentRegExp = /(?:\/\/)|(?:^|\/)\.\.?(?:$|\/)/;
|
|
410
412
|
function containsPath(parent, child, currentDirectory, ignoreCase) {
|
|
411
|
-
if (typeof currentDirectory ===
|
|
413
|
+
if (typeof currentDirectory === 'string') {
|
|
412
414
|
parent = combinePaths(currentDirectory, parent);
|
|
413
415
|
child = combinePaths(currentDirectory, child);
|
|
414
416
|
}
|
|
415
|
-
else if (typeof currentDirectory ===
|
|
417
|
+
else if (typeof currentDirectory === 'boolean') {
|
|
416
418
|
ignoreCase = currentDirectory;
|
|
417
419
|
}
|
|
418
420
|
if (parent === undefined || child === undefined) {
|
|
@@ -10,8 +10,8 @@ const path_1 = require("./path");
|
|
|
10
10
|
// proof.
|
|
11
11
|
const reservedCharacterPattern = /[^\w\s\/]/g;
|
|
12
12
|
const wildcardCharCodes = [42 /* CharacterCodes.asterisk */, 63 /* CharacterCodes.question */];
|
|
13
|
-
const commonPackageFolders = [
|
|
14
|
-
const implicitExcludePathRegexPattern = `(?!(${commonPackageFolders.join(
|
|
13
|
+
const commonPackageFolders = ['node_modules', 'bower_components', 'jspm_packages'];
|
|
14
|
+
const implicitExcludePathRegexPattern = `(?!(${commonPackageFolders.join('|')})(/|$))`;
|
|
15
15
|
const filesMatcher = {
|
|
16
16
|
/**
|
|
17
17
|
* Matches any single directory segment unless it is the last segment and a .min.js file
|
|
@@ -19,41 +19,41 @@ const filesMatcher = {
|
|
|
19
19
|
* [^./] # matches everything up to the first . character (excluding directory separators)
|
|
20
20
|
* (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension
|
|
21
21
|
*/
|
|
22
|
-
singleAsteriskRegexFragment:
|
|
22
|
+
singleAsteriskRegexFragment: '([^./]|(\\.(?!min\\.js$))?)*',
|
|
23
23
|
/**
|
|
24
24
|
* Regex for the ** wildcard. Matches any number of subdirectories. When used for including
|
|
25
25
|
* files or directories, does not match subdirectories that start with a . character
|
|
26
26
|
*/
|
|
27
27
|
doubleAsteriskRegexFragment: `(/${implicitExcludePathRegexPattern}[^/.][^/]*)*?`,
|
|
28
|
-
replaceWildcardCharacter: match => replaceWildcardCharacter(match, filesMatcher.singleAsteriskRegexFragment)
|
|
28
|
+
replaceWildcardCharacter: match => replaceWildcardCharacter(match, filesMatcher.singleAsteriskRegexFragment),
|
|
29
29
|
};
|
|
30
30
|
const directoriesMatcher = {
|
|
31
|
-
singleAsteriskRegexFragment:
|
|
31
|
+
singleAsteriskRegexFragment: '[^/]*',
|
|
32
32
|
/**
|
|
33
33
|
* Regex for the ** wildcard. Matches any number of subdirectories. When used for including
|
|
34
34
|
* files or directories, does not match subdirectories that start with a . character
|
|
35
35
|
*/
|
|
36
36
|
doubleAsteriskRegexFragment: `(/${implicitExcludePathRegexPattern}[^/.][^/]*)*?`,
|
|
37
|
-
replaceWildcardCharacter: match => replaceWildcardCharacter(match, directoriesMatcher.singleAsteriskRegexFragment)
|
|
37
|
+
replaceWildcardCharacter: match => replaceWildcardCharacter(match, directoriesMatcher.singleAsteriskRegexFragment),
|
|
38
38
|
};
|
|
39
39
|
const excludeMatcher = {
|
|
40
|
-
singleAsteriskRegexFragment:
|
|
41
|
-
doubleAsteriskRegexFragment:
|
|
42
|
-
replaceWildcardCharacter: match => replaceWildcardCharacter(match, excludeMatcher.singleAsteriskRegexFragment)
|
|
40
|
+
singleAsteriskRegexFragment: '[^/]*',
|
|
41
|
+
doubleAsteriskRegexFragment: '(/.+?)?',
|
|
42
|
+
replaceWildcardCharacter: match => replaceWildcardCharacter(match, excludeMatcher.singleAsteriskRegexFragment),
|
|
43
43
|
};
|
|
44
44
|
const wildcardMatchers = {
|
|
45
45
|
files: filesMatcher,
|
|
46
46
|
directories: directoriesMatcher,
|
|
47
|
-
exclude: excludeMatcher
|
|
47
|
+
exclude: excludeMatcher,
|
|
48
48
|
};
|
|
49
49
|
function getRegularExpressionForWildcard(specs, basePath, usage) {
|
|
50
50
|
const patterns = getRegularExpressionsForWildcards(specs, basePath, usage);
|
|
51
51
|
if (!patterns || !patterns.length) {
|
|
52
52
|
return undefined;
|
|
53
53
|
}
|
|
54
|
-
const pattern = patterns.map(pattern => `(${pattern})`).join(
|
|
54
|
+
const pattern = patterns.map(pattern => `(${pattern})`).join('|');
|
|
55
55
|
// If excluding, match "foo/bar/baz...", but if including, only allow "foo".
|
|
56
|
-
const terminator = usage ===
|
|
56
|
+
const terminator = usage === 'exclude' ? '($|/)' : '$';
|
|
57
57
|
return `^(${pattern})${terminator}`;
|
|
58
58
|
}
|
|
59
59
|
function getRegularExpressionsForWildcards(specs, basePath, usage) {
|
|
@@ -70,43 +70,43 @@ function isImplicitGlob(lastPathComponent) {
|
|
|
70
70
|
return !/[.*?]/.test(lastPathComponent);
|
|
71
71
|
}
|
|
72
72
|
function getSubPatternFromSpec(spec, basePath, usage, { singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }) {
|
|
73
|
-
let subpattern =
|
|
73
|
+
let subpattern = '';
|
|
74
74
|
let hasWrittenComponent = false;
|
|
75
75
|
const components = (0, path_1.getNormalizedPathComponents)(spec, basePath);
|
|
76
76
|
const lastComponent = (0, core_1.last)(components);
|
|
77
|
-
if (usage !==
|
|
77
|
+
if (usage !== 'exclude' && lastComponent === '**') {
|
|
78
78
|
return undefined;
|
|
79
79
|
}
|
|
80
80
|
// getNormalizedPathComponents includes the separator for the root component.
|
|
81
81
|
// We need to remove to create our regex correctly.
|
|
82
82
|
components[0] = (0, path_1.removeTrailingDirectorySeparator)(components[0]);
|
|
83
83
|
if (isImplicitGlob(lastComponent)) {
|
|
84
|
-
components.push(
|
|
84
|
+
components.push('**', '*');
|
|
85
85
|
}
|
|
86
86
|
let optionalCount = 0;
|
|
87
87
|
for (let component of components) {
|
|
88
|
-
if (component ===
|
|
88
|
+
if (component === '**') {
|
|
89
89
|
subpattern += doubleAsteriskRegexFragment;
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
|
-
if (usage ===
|
|
93
|
-
subpattern +=
|
|
92
|
+
if (usage === 'directories') {
|
|
93
|
+
subpattern += '(';
|
|
94
94
|
optionalCount++;
|
|
95
95
|
}
|
|
96
96
|
if (hasWrittenComponent) {
|
|
97
97
|
subpattern += path_1.directorySeparator;
|
|
98
98
|
}
|
|
99
|
-
if (usage !==
|
|
100
|
-
let componentPattern =
|
|
99
|
+
if (usage !== 'exclude') {
|
|
100
|
+
let componentPattern = '';
|
|
101
101
|
// The * and ? wildcards should not match directories or files that start with . if they
|
|
102
102
|
// appear first in a component. Dotted directories and files can be included explicitly
|
|
103
103
|
// like so: **/.*/.*
|
|
104
104
|
if (component.charCodeAt(0) === 42 /* CharacterCodes.asterisk */) {
|
|
105
|
-
componentPattern +=
|
|
105
|
+
componentPattern += '([^./]' + singleAsteriskRegexFragment + ')?';
|
|
106
106
|
component = component.substr(1);
|
|
107
107
|
}
|
|
108
108
|
else if (component.charCodeAt(0) === 63 /* CharacterCodes.question */) {
|
|
109
|
-
componentPattern +=
|
|
109
|
+
componentPattern += '[^./]';
|
|
110
110
|
component = component.substr(1);
|
|
111
111
|
}
|
|
112
112
|
componentPattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
|
|
@@ -128,13 +128,13 @@ function getSubPatternFromSpec(spec, basePath, usage, { singleAsteriskRegexFragm
|
|
|
128
128
|
hasWrittenComponent = true;
|
|
129
129
|
}
|
|
130
130
|
while (optionalCount > 0) {
|
|
131
|
-
subpattern +=
|
|
131
|
+
subpattern += ')?';
|
|
132
132
|
optionalCount--;
|
|
133
133
|
}
|
|
134
134
|
return subpattern;
|
|
135
135
|
}
|
|
136
136
|
function replaceWildcardCharacter(match, singleAsteriskRegexFragment) {
|
|
137
|
-
return match ===
|
|
137
|
+
return match === '*' ? singleAsteriskRegexFragment : match === '?' ? '[^/]' : '\\' + match;
|
|
138
138
|
}
|
|
139
139
|
/** @param path directory of the tsconfig.json */
|
|
140
140
|
function getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory) {
|
|
@@ -142,24 +142,27 @@ function getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNa
|
|
|
142
142
|
currentDirectory = (0, path_1.normalizePath)(currentDirectory);
|
|
143
143
|
const absolutePath = (0, path_1.combinePaths)(currentDirectory, path);
|
|
144
144
|
return {
|
|
145
|
-
includeFilePatterns: (0, core_1.map)(getRegularExpressionsForWildcards(includes, absolutePath,
|
|
146
|
-
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath,
|
|
147
|
-
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath,
|
|
148
|
-
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath,
|
|
149
|
-
basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames)
|
|
145
|
+
includeFilePatterns: (0, core_1.map)(getRegularExpressionsForWildcards(includes, absolutePath, 'files'), pattern => `^${pattern}$`),
|
|
146
|
+
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, 'files'),
|
|
147
|
+
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, 'directories'),
|
|
148
|
+
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, 'exclude'),
|
|
149
|
+
basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames),
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
function getRegexFromPattern(pattern, useCaseSensitiveFileNames) {
|
|
153
|
-
return new RegExp(pattern, useCaseSensitiveFileNames ?
|
|
153
|
+
return new RegExp(pattern, useCaseSensitiveFileNames ? '' : 'i');
|
|
154
154
|
}
|
|
155
155
|
/** @param path directory of the tsconfig.json */
|
|
156
156
|
function matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath) {
|
|
157
157
|
path = (0, path_1.normalizePath)(path);
|
|
158
158
|
currentDirectory = (0, path_1.normalizePath)(currentDirectory);
|
|
159
159
|
const patterns = getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory);
|
|
160
|
-
const includeFileRegexes = patterns.includeFilePatterns
|
|
161
|
-
|
|
162
|
-
const
|
|
160
|
+
const includeFileRegexes = patterns.includeFilePatterns
|
|
161
|
+
&& patterns.includeFilePatterns.map(pattern => getRegexFromPattern(pattern, useCaseSensitiveFileNames));
|
|
162
|
+
const includeDirectoryRegex = patterns.includeDirectoryPattern
|
|
163
|
+
&& getRegexFromPattern(patterns.includeDirectoryPattern, useCaseSensitiveFileNames);
|
|
164
|
+
const excludeRegex = patterns.excludePattern
|
|
165
|
+
&& getRegexFromPattern(patterns.excludePattern, useCaseSensitiveFileNames);
|
|
163
166
|
// Associate an array of results with each include regex. This keeps results in order of the "include" order.
|
|
164
167
|
// If there are no "includes", then just put everything in results[0].
|
|
165
168
|
const results = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]];
|
|
@@ -204,8 +207,8 @@ function matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNa
|
|
|
204
207
|
for (const current of (0, core_1.sort)(directories, core_1.compareStringsCaseSensitive)) {
|
|
205
208
|
const name = (0, path_1.combinePaths)(path, current);
|
|
206
209
|
const absoluteName = (0, path_1.combinePaths)(absolutePath, current);
|
|
207
|
-
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName))
|
|
208
|
-
(!excludeRegex || !excludeRegex.test(absoluteName))) {
|
|
210
|
+
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName))
|
|
211
|
+
&& (!excludeRegex || !excludeRegex.test(absoluteName))) {
|
|
209
212
|
visitDirectory(name, absoluteName, depth);
|
|
210
213
|
}
|
|
211
214
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/typescript",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"directory": "packages/typescript"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "2.4.
|
|
15
|
+
"@volar/language-core": "2.4.24",
|
|
16
16
|
"path-browserify": "^1.0.1",
|
|
17
17
|
"vscode-uri": "^3.0.8"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "latest",
|
|
21
21
|
"@types/path-browserify": "latest",
|
|
22
|
-
"@volar/language-service": "2.4.
|
|
22
|
+
"@volar/language-service": "2.4.24"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "a5c7cf5d1afa5c3780a48866d17680c223891e42"
|
|
25
25
|
}
|