typescript-svelte-plugin 0.3.3 → 0.3.6
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 +34 -10
- package/dist/src/language-service/implementation.js +1 -0
- package/dist/src/language-service/index.js +1 -0
- package/dist/src/language-service/rename.js +39 -13
- package/dist/src/language-service/update-imports.js +1 -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 +7 -3
- 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,6 +9,10 @@ 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) => {
|
|
@@ -16,7 +20,7 @@ function _decorateFindReferences(ls, snapshotManager, logger) {
|
|
|
16
20
|
if (!(0, utils_1.isSvelteFilePath)(reference.definition.fileName) || !snapshot) {
|
|
17
21
|
return {
|
|
18
22
|
...reference,
|
|
19
|
-
references: mapReferences(reference.references, snapshotManager, logger)
|
|
23
|
+
references: mapReferences(reference.references, snapshotManager, logger, getReferences)
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
26
|
const textSpan = snapshot.getOriginalTextSpan(reference.definition.textSpan);
|
|
@@ -30,7 +34,7 @@ function _decorateFindReferences(ls, snapshotManager, logger) {
|
|
|
30
34
|
// Spare the work for now
|
|
31
35
|
originalTextSpan: undefined
|
|
32
36
|
},
|
|
33
|
-
references: mapReferences(reference.references, snapshotManager, logger)
|
|
37
|
+
references: mapReferences(reference.references, snapshotManager, logger, getReferences)
|
|
34
38
|
};
|
|
35
39
|
}).filter(utils_1.isNotNullOrUndefined);
|
|
36
40
|
};
|
|
@@ -39,20 +43,40 @@ function decorateGetReferencesAtPosition(ls, snapshotManager, logger) {
|
|
|
39
43
|
const getReferencesAtPosition = ls.getReferencesAtPosition;
|
|
40
44
|
ls.getReferencesAtPosition = (fileName, position) => {
|
|
41
45
|
const references = getReferencesAtPosition(fileName, position);
|
|
42
|
-
return references &&
|
|
46
|
+
return (references &&
|
|
47
|
+
mapReferences(references, snapshotManager, logger, getReferencesAtPosition));
|
|
43
48
|
};
|
|
44
49
|
}
|
|
45
|
-
function mapReferences(references, snapshotManager, logger) {
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
function mapReferences(references, snapshotManager, logger, getReferences) {
|
|
51
|
+
const additionalStoreReferences = [];
|
|
52
|
+
const mappedReferences = [];
|
|
53
|
+
for (const reference of references) {
|
|
48
54
|
const snapshot = snapshotManager.get(reference.fileName);
|
|
49
55
|
if (!(0, utils_1.isSvelteFilePath)(reference.fileName) || !snapshot) {
|
|
50
|
-
|
|
56
|
+
mappedReferences.push(reference);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const textSpan = snapshot.getOriginalTextSpan(reference.textSpan);
|
|
60
|
+
if (textSpan) {
|
|
61
|
+
mappedReferences.push(mapReference(reference, textSpan));
|
|
51
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);
|
|
52
72
|
const textSpan = snapshot.getOriginalTextSpan(reference.textSpan);
|
|
53
73
|
if (!textSpan) {
|
|
54
|
-
|
|
74
|
+
continue;
|
|
55
75
|
}
|
|
76
|
+
mappedReferences.push(mapReference(reference, textSpan));
|
|
77
|
+
}
|
|
78
|
+
return mappedReferences;
|
|
79
|
+
function mapReference(reference, textSpan) {
|
|
56
80
|
logger.debug('Find references; map textSpan: changed', reference.textSpan, 'to', textSpan);
|
|
57
81
|
return {
|
|
58
82
|
...reference,
|
|
@@ -62,6 +86,6 @@ function mapReferences(references, snapshotManager, logger) {
|
|
|
62
86
|
originalTextSpan: undefined,
|
|
63
87
|
originalContextSpan: undefined
|
|
64
88
|
};
|
|
65
|
-
}
|
|
66
|
-
.filter(utils_1.isNotNullOrUndefined);
|
|
89
|
+
}
|
|
67
90
|
}
|
|
91
|
+
//# sourceMappingURL=find-references.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
|
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
|
|
@@ -228,7 +228,10 @@ class SvelteSnapshotManager {
|
|
|
228
228
|
}
|
|
229
229
|
patchProjectServiceReadFile() {
|
|
230
230
|
const readFile = this.projectService.host.readFile;
|
|
231
|
-
this.projectService.host.readFile = (path) => {
|
|
231
|
+
this.projectService.host.readFile = (path, encoding) => {
|
|
232
|
+
if (!this.configManager.getConfig().enable) {
|
|
233
|
+
return readFile(path, encoding);
|
|
234
|
+
}
|
|
232
235
|
// The following (very hacky) first two checks make sure that the ambient module definitions
|
|
233
236
|
// that tell TS "every import ending with .svelte is a valid module" are removed.
|
|
234
237
|
// They exist in svelte2tsx and svelte to make sure that people don't
|
|
@@ -249,7 +252,7 @@ class SvelteSnapshotManager {
|
|
|
249
252
|
originalText.substring(originalText.indexOf('// -- end svelte-ls-remove --'));
|
|
250
253
|
return originalText;
|
|
251
254
|
}
|
|
252
|
-
else if ((0, utils_1.isSvelteFilePath)(path)
|
|
255
|
+
else if ((0, utils_1.isSvelteFilePath)(path)) {
|
|
253
256
|
this.logger.debug('Read Svelte file:', path);
|
|
254
257
|
const svelteCode = readFile(path) || '';
|
|
255
258
|
try {
|
|
@@ -279,9 +282,10 @@ class SvelteSnapshotManager {
|
|
|
279
282
|
}
|
|
280
283
|
}
|
|
281
284
|
else {
|
|
282
|
-
return readFile(path);
|
|
285
|
+
return readFile(path, encoding);
|
|
283
286
|
}
|
|
284
287
|
};
|
|
285
288
|
}
|
|
286
289
|
}
|
|
287
290
|
exports.SvelteSnapshotManager = SvelteSnapshotManager;
|
|
291
|
+
//# sourceMappingURL=svelte-snapshots.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
|