typescript-svelte-plugin 0.3.2 → 0.3.5
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/dist/src/config-manager.js +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/language-service/completions.js +1 -0
- package/dist/src/language-service/definition.js +1 -0
- package/dist/src/language-service/diagnostics.js +1 -0
- package/dist/src/language-service/find-references.js +37 -10
- package/dist/src/language-service/implementation.js +1 -0
- package/dist/src/language-service/index.js +3 -0
- package/dist/src/language-service/rename.js +39 -13
- package/dist/src/language-service/update-imports.d.ts +4 -0
- package/dist/src/language-service/update-imports.js +22 -0
- package/dist/src/logger.js +1 -0
- package/dist/src/module-loader.js +8 -5
- package/dist/src/project-svelte-files.js +1 -0
- package/dist/src/source-mapper.js +1 -0
- package/dist/src/svelte-snapshots.d.ts +1 -1
- package/dist/src/svelte-snapshots.js +1 -0
- package/dist/src/svelte-sys.js +1 -0
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.js +11 -1
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -9,12 +9,19 @@ function decorateFindReferences(ls, snapshotManager, logger) {
|
|
|
9
9
|
exports.decorateFindReferences = decorateFindReferences;
|
|
10
10
|
function _decorateFindReferences(ls, snapshotManager, logger) {
|
|
11
11
|
const findReferences = ls.findReferences;
|
|
12
|
+
const getReferences = (fileName, position) => {
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = findReferences(fileName, position)) === null || _a === void 0 ? void 0 : _a.reduce((acc, curr) => acc.concat(curr.references), []);
|
|
15
|
+
};
|
|
12
16
|
ls.findReferences = (fileName, position) => {
|
|
13
17
|
const references = findReferences(fileName, position);
|
|
14
18
|
return references === null || references === void 0 ? void 0 : references.map((reference) => {
|
|
15
19
|
const snapshot = snapshotManager.get(reference.definition.fileName);
|
|
16
20
|
if (!(0, utils_1.isSvelteFilePath)(reference.definition.fileName) || !snapshot) {
|
|
17
|
-
return
|
|
21
|
+
return {
|
|
22
|
+
...reference,
|
|
23
|
+
references: mapReferences(reference.references, snapshotManager, logger, getReferences)
|
|
24
|
+
};
|
|
18
25
|
}
|
|
19
26
|
const textSpan = snapshot.getOriginalTextSpan(reference.definition.textSpan);
|
|
20
27
|
if (!textSpan) {
|
|
@@ -27,7 +34,7 @@ function _decorateFindReferences(ls, snapshotManager, logger) {
|
|
|
27
34
|
// Spare the work for now
|
|
28
35
|
originalTextSpan: undefined
|
|
29
36
|
},
|
|
30
|
-
references: mapReferences(reference.references, snapshotManager, logger)
|
|
37
|
+
references: mapReferences(reference.references, snapshotManager, logger, getReferences)
|
|
31
38
|
};
|
|
32
39
|
}).filter(utils_1.isNotNullOrUndefined);
|
|
33
40
|
};
|
|
@@ -36,20 +43,40 @@ function decorateGetReferencesAtPosition(ls, snapshotManager, logger) {
|
|
|
36
43
|
const getReferencesAtPosition = ls.getReferencesAtPosition;
|
|
37
44
|
ls.getReferencesAtPosition = (fileName, position) => {
|
|
38
45
|
const references = getReferencesAtPosition(fileName, position);
|
|
39
|
-
return references &&
|
|
46
|
+
return (references &&
|
|
47
|
+
mapReferences(references, snapshotManager, logger, getReferencesAtPosition));
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
|
-
function mapReferences(references, snapshotManager, logger) {
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
function mapReferences(references, snapshotManager, logger, getReferences) {
|
|
51
|
+
const additionalStoreReferences = [];
|
|
52
|
+
const mappedReferences = [];
|
|
53
|
+
for (const reference of references) {
|
|
45
54
|
const snapshot = snapshotManager.get(reference.fileName);
|
|
46
55
|
if (!(0, utils_1.isSvelteFilePath)(reference.fileName) || !snapshot) {
|
|
47
|
-
|
|
56
|
+
mappedReferences.push(reference);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const textSpan = snapshot.getOriginalTextSpan(reference.textSpan);
|
|
60
|
+
if (textSpan) {
|
|
61
|
+
mappedReferences.push(mapReference(reference, textSpan));
|
|
48
62
|
}
|
|
63
|
+
else {
|
|
64
|
+
if ((0, utils_1.isStoreVariableIn$storeDeclaration)(snapshot.getText(), reference.textSpan.start)) {
|
|
65
|
+
additionalStoreReferences.push(...(getReferences(reference.fileName, (0, utils_1.get$storeOffsetOf$storeDeclaration)(snapshot.getText(), reference.textSpan.start)) || []));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const reference of additionalStoreReferences) {
|
|
70
|
+
// We know these are Svelte files
|
|
71
|
+
const snapshot = snapshotManager.get(reference.fileName);
|
|
49
72
|
const textSpan = snapshot.getOriginalTextSpan(reference.textSpan);
|
|
50
73
|
if (!textSpan) {
|
|
51
|
-
|
|
74
|
+
continue;
|
|
52
75
|
}
|
|
76
|
+
mappedReferences.push(mapReference(reference, textSpan));
|
|
77
|
+
}
|
|
78
|
+
return mappedReferences;
|
|
79
|
+
function mapReference(reference, textSpan) {
|
|
53
80
|
logger.debug('Find references; map textSpan: changed', reference.textSpan, 'to', textSpan);
|
|
54
81
|
return {
|
|
55
82
|
...reference,
|
|
@@ -59,6 +86,6 @@ function mapReferences(references, snapshotManager, logger) {
|
|
|
59
86
|
originalTextSpan: undefined,
|
|
60
87
|
originalContextSpan: undefined
|
|
61
88
|
};
|
|
62
|
-
}
|
|
63
|
-
.filter(utils_1.isNotNullOrUndefined);
|
|
89
|
+
}
|
|
64
90
|
}
|
|
91
|
+
//# sourceMappingURL=find-references.js.map
|
|
@@ -8,6 +8,7 @@ const diagnostics_1 = require("./diagnostics");
|
|
|
8
8
|
const find_references_1 = require("./find-references");
|
|
9
9
|
const implementation_1 = require("./implementation");
|
|
10
10
|
const rename_1 = require("./rename");
|
|
11
|
+
const update_imports_1 = require("./update-imports");
|
|
11
12
|
const sveltePluginPatchSymbol = Symbol('sveltePluginPatchSymbol');
|
|
12
13
|
function isPatched(ls) {
|
|
13
14
|
return ls[sveltePluginPatchSymbol] === true;
|
|
@@ -29,6 +30,7 @@ function decorateLanguageServiceInner(ls, snapshotManager, logger) {
|
|
|
29
30
|
(0, completions_1.decorateCompletions)(ls, logger);
|
|
30
31
|
(0, definition_1.decorateGetDefinition)(ls, snapshotManager, logger);
|
|
31
32
|
(0, implementation_1.decorateGetImplementation)(ls, snapshotManager, logger);
|
|
33
|
+
(0, update_imports_1.decorateUpdateImports)(ls, snapshotManager, logger);
|
|
32
34
|
return ls;
|
|
33
35
|
}
|
|
34
36
|
function createProxyHandler(configManager) {
|
|
@@ -67,3 +69,4 @@ function patchLineColumnOffset(ls, snapshotManager) {
|
|
|
67
69
|
return toLineColumnOffset(fileName, position);
|
|
68
70
|
};
|
|
69
71
|
}
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -6,27 +6,53 @@ function decorateRename(ls, snapshotManager, logger) {
|
|
|
6
6
|
const findRenameLocations = ls.findRenameLocations;
|
|
7
7
|
ls.findRenameLocations = (fileName, position, findInStrings, findInComments, providePrefixAndSuffixTextForRename) => {
|
|
8
8
|
const renameLocations = findRenameLocations(fileName, position, findInStrings, findInComments, providePrefixAndSuffixTextForRename);
|
|
9
|
-
|
|
9
|
+
if (!renameLocations) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const convertedRenameLocations = [];
|
|
13
|
+
const additionalStoreRenameLocations = [];
|
|
14
|
+
for (const renameLocation of renameLocations) {
|
|
10
15
|
const snapshot = snapshotManager.get(renameLocation.fileName);
|
|
11
16
|
if (!(0, utils_1.isSvelteFilePath)(renameLocation.fileName) || !snapshot) {
|
|
12
|
-
|
|
17
|
+
convertedRenameLocations.push(renameLocation);
|
|
18
|
+
continue;
|
|
13
19
|
}
|
|
14
20
|
// TODO more needed to filter invalid locations, see RenameProvider
|
|
15
21
|
const textSpan = snapshot.getOriginalTextSpan(renameLocation.textSpan);
|
|
16
22
|
if (!textSpan) {
|
|
17
|
-
|
|
23
|
+
if ((0, utils_1.isStoreVariableIn$storeDeclaration)(snapshot.getText(), renameLocation.textSpan.start)) {
|
|
24
|
+
additionalStoreRenameLocations.push(...findRenameLocations(renameLocation.fileName, (0, utils_1.get$storeOffsetOf$storeDeclaration)(snapshot.getText(), renameLocation.textSpan.start), false, false, false));
|
|
25
|
+
}
|
|
26
|
+
continue;
|
|
18
27
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
convertedRenameLocations.push(convert(renameLocation, textSpan));
|
|
29
|
+
}
|
|
30
|
+
for (const renameLocation of additionalStoreRenameLocations) {
|
|
31
|
+
// We know these are Svelte files
|
|
32
|
+
const snapshot = snapshotManager.get(renameLocation.fileName);
|
|
33
|
+
const textSpan = snapshot.getOriginalTextSpan(renameLocation.textSpan);
|
|
34
|
+
if (!textSpan) {
|
|
35
|
+
continue;
|
|
26
36
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
// |$store| would be renamed, make it $|store|
|
|
38
|
+
textSpan.start += 1;
|
|
39
|
+
textSpan.length -= 1;
|
|
40
|
+
convertedRenameLocations.push(convert(renameLocation, textSpan));
|
|
41
|
+
}
|
|
42
|
+
return convertedRenameLocations;
|
|
30
43
|
};
|
|
44
|
+
function convert(renameLocation, textSpan) {
|
|
45
|
+
const converted = {
|
|
46
|
+
...renameLocation,
|
|
47
|
+
textSpan
|
|
48
|
+
};
|
|
49
|
+
if (converted.contextSpan) {
|
|
50
|
+
// Not important, spare the work
|
|
51
|
+
converted.contextSpan = undefined;
|
|
52
|
+
}
|
|
53
|
+
logger.debug('Converted rename location ', converted);
|
|
54
|
+
return converted;
|
|
55
|
+
}
|
|
31
56
|
}
|
|
32
57
|
exports.decorateRename = decorateRename;
|
|
58
|
+
//# sourceMappingURL=rename.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import { Logger } from '../logger';
|
|
3
|
+
import { SvelteSnapshotManager } from '../svelte-snapshots';
|
|
4
|
+
export declare function decorateUpdateImports(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorateUpdateImports = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
function decorateUpdateImports(ls, snapshotManager, logger) {
|
|
6
|
+
const getEditsForFileRename = ls.getEditsForFileRename;
|
|
7
|
+
ls.getEditsForFileRename = (oldFilePath, newFilePath, formatOptions, preferences) => {
|
|
8
|
+
const renameLocations = getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences);
|
|
9
|
+
// If a file move/rename of a TS/JS file results a Svelte file change,
|
|
10
|
+
// the Svelte extension will notice that, too, and adjusts the same imports.
|
|
11
|
+
// This results in duplicate adjustments or race conditions with conflicting text spans
|
|
12
|
+
// which can break imports in some cases.
|
|
13
|
+
// Therefore don't do any updates of Svelte files and and also no updates of mixed TS files
|
|
14
|
+
// and let the Svelte extension handle that.
|
|
15
|
+
return renameLocations === null || renameLocations === void 0 ? void 0 : renameLocations.filter((renameLocation) => {
|
|
16
|
+
return (!(0, utils_1.isSvelteFilePath)(renameLocation.fileName) &&
|
|
17
|
+
!renameLocation.textChanges.some((change) => change.newText.endsWith('.svelte')));
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.decorateUpdateImports = decorateUpdateImports;
|
|
22
|
+
//# sourceMappingURL=update-imports.js.map
|
package/dist/src/logger.js
CHANGED
|
@@ -67,13 +67,13 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
67
67
|
configManager.onConfigurationChanged(() => {
|
|
68
68
|
moduleCache.clear();
|
|
69
69
|
});
|
|
70
|
-
function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions) {
|
|
70
|
+
function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile) {
|
|
71
71
|
logger.log('Resolving modules names for ' + containingFile);
|
|
72
72
|
// Try resolving all module names with the original method first.
|
|
73
73
|
// The ones that are undefined will be re-checked if they are a
|
|
74
74
|
// Svelte file and if so, are resolved, too. This way we can defer
|
|
75
75
|
// all module resolving logic except for Svelte files to TypeScript.
|
|
76
|
-
const resolved = (origResolveModuleNames === null || origResolveModuleNames === void 0 ? void 0 : origResolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions)) || Array.from(Array(moduleNames.length));
|
|
76
|
+
const resolved = (origResolveModuleNames === null || origResolveModuleNames === void 0 ? void 0 : origResolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile)) || Array.from(Array(moduleNames.length));
|
|
77
77
|
if (!configManager.getConfig().enable) {
|
|
78
78
|
return resolved;
|
|
79
79
|
}
|
|
@@ -86,13 +86,15 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
86
86
|
if (cachedModule) {
|
|
87
87
|
return cachedModule;
|
|
88
88
|
}
|
|
89
|
-
const resolvedModule =
|
|
89
|
+
const resolvedModule = resolveSvelteModuleName(fileName, containingFile, compilerOptions);
|
|
90
90
|
moduleCache.set(fileName, containingFile, resolvedModule);
|
|
91
91
|
return resolvedModule;
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
const svelteResolvedModule = typescript.resolveModuleName(name, containingFile, compilerOptions, svelteSys
|
|
94
|
+
function resolveSvelteModuleName(name, containingFile, compilerOptions) {
|
|
95
|
+
const svelteResolvedModule = typescript.resolveModuleName(name, containingFile, compilerOptions, svelteSys
|
|
96
|
+
// don't set mode or else .svelte imports couldn't be resolved
|
|
97
|
+
).resolvedModule;
|
|
96
98
|
if (!svelteResolvedModule ||
|
|
97
99
|
!(0, utils_1.isVirtualSvelteFilePath)(svelteResolvedModule.resolvedFileName)) {
|
|
98
100
|
return svelteResolvedModule;
|
|
@@ -111,3 +113,4 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
exports.patchModuleLoader = patchModuleLoader;
|
|
116
|
+
//# sourceMappingURL=module-loader.js.map
|
package/dist/src/svelte-sys.js
CHANGED
package/dist/src/utils.d.ts
CHANGED
|
@@ -19,3 +19,5 @@ export declare function isNoTextSpanInGeneratedCode(text: string, span: ts.TextS
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function replaceDeep<T extends Record<string, any>>(obj: T, searchStr: string | RegExp, replacementStr: string): T;
|
|
21
21
|
export declare function getConfigPathForProject(project: ts.server.Project): ts.server.NormalizedPath;
|
|
22
|
+
export declare function isStoreVariableIn$storeDeclaration(text: string, varStart: number): boolean;
|
|
23
|
+
export declare function get$storeOffsetOf$storeDeclaration(text: string, storePosition: number): number;
|
package/dist/src/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfigPathForProject = exports.replaceDeep = exports.isNoTextSpanInGeneratedCode = exports.isInGeneratedCode = exports.isNotNullOrUndefined = exports.ensureRealSvelteFilePath = exports.toRealSvelteFilePath = exports.isVirtualSvelteFilePath = exports.isSvelteFilePath = void 0;
|
|
3
|
+
exports.get$storeOffsetOf$storeDeclaration = exports.isStoreVariableIn$storeDeclaration = exports.getConfigPathForProject = exports.replaceDeep = exports.isNoTextSpanInGeneratedCode = exports.isInGeneratedCode = exports.isNotNullOrUndefined = exports.ensureRealSvelteFilePath = exports.toRealSvelteFilePath = exports.isVirtualSvelteFilePath = exports.isSvelteFilePath = void 0;
|
|
4
4
|
function isSvelteFilePath(filePath) {
|
|
5
5
|
return filePath.endsWith('.svelte');
|
|
6
6
|
}
|
|
@@ -68,3 +68,13 @@ function getConfigPathForProject(project) {
|
|
|
68
68
|
return ((_a = project.canonicalConfigFilePath) !== null && _a !== void 0 ? _a : project.getCompilerOptions().configFilePath);
|
|
69
69
|
}
|
|
70
70
|
exports.getConfigPathForProject = getConfigPathForProject;
|
|
71
|
+
function isStoreVariableIn$storeDeclaration(text, varStart) {
|
|
72
|
+
return (text.lastIndexOf('__sveltets_1_store_get(', varStart) ===
|
|
73
|
+
varStart - '__sveltets_1_store_get('.length);
|
|
74
|
+
}
|
|
75
|
+
exports.isStoreVariableIn$storeDeclaration = isStoreVariableIn$storeDeclaration;
|
|
76
|
+
function get$storeOffsetOf$storeDeclaration(text, storePosition) {
|
|
77
|
+
return text.lastIndexOf(' =', storePosition) - 1;
|
|
78
|
+
}
|
|
79
|
+
exports.get$storeOffsetOf$storeDeclaration = get$storeOffsetOf$storeDeclaration;
|
|
80
|
+
//# sourceMappingURL=utils.js.map
|