typescript-svelte-plugin 0.3.6 → 0.3.9
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.
|
@@ -1,15 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decorateCompletions = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
4
5
|
const utils_1 = require("../utils");
|
|
5
6
|
const componentPostfix = '__SvelteComponent_';
|
|
6
7
|
function decorateCompletions(ls, logger) {
|
|
7
8
|
const getCompletionsAtPosition = ls.getCompletionsAtPosition;
|
|
8
9
|
ls.getCompletionsAtPosition = (fileName, position, options) => {
|
|
10
|
+
var _a, _b, _c, _d;
|
|
9
11
|
const completions = getCompletionsAtPosition(fileName, position, options);
|
|
10
12
|
if (!completions) {
|
|
11
13
|
return completions;
|
|
12
14
|
}
|
|
15
|
+
// Add ./$types imports for SvelteKit since TypeScript is bad at it
|
|
16
|
+
if ((0, path_1.basename)(fileName).startsWith('+')) {
|
|
17
|
+
const $typeImports = new Map();
|
|
18
|
+
for (const c of completions.entries) {
|
|
19
|
+
if (((_a = c.source) === null || _a === void 0 ? void 0 : _a.includes('.svelte-kit/types')) && c.data) {
|
|
20
|
+
$typeImports.set(c.name, c);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
for (const $typeImport of $typeImports.values()) {
|
|
24
|
+
// resolve path from FileName to svelte-kit/types
|
|
25
|
+
// src/routes/foo/+page.svelte -> .svelte-kit/types/foo/$types.d.ts
|
|
26
|
+
const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
|
|
27
|
+
const relativeFileName = (_b = fileName.split(routesFolder)[1]) === null || _b === void 0 ? void 0 : _b.slice(1);
|
|
28
|
+
if (relativeFileName) {
|
|
29
|
+
const modifiedSource = $typeImport.source.split('.svelte-kit/types')[0] +
|
|
30
|
+
// note the missing .d.ts at the end - TS wants it that way for some reason
|
|
31
|
+
`.svelte-kit/types/${routesFolder}/${(0, path_1.dirname)(relativeFileName)}/$types`;
|
|
32
|
+
completions.entries.push({
|
|
33
|
+
...$typeImport,
|
|
34
|
+
// Ensure it's sorted above the other imports
|
|
35
|
+
sortText: !isNaN(Number($typeImport.sortText))
|
|
36
|
+
? String(Number($typeImport.sortText) - 1)
|
|
37
|
+
: $typeImport.sortText,
|
|
38
|
+
source: modifiedSource,
|
|
39
|
+
data: {
|
|
40
|
+
...$typeImport.data,
|
|
41
|
+
fileName: (_c = $typeImport.data.fileName) === null || _c === void 0 ? void 0 : _c.replace($typeImport.source, modifiedSource),
|
|
42
|
+
moduleSpecifier: (_d = $typeImport.data.moduleSpecifier) === null || _d === void 0 ? void 0 : _d.replace($typeImport.source, modifiedSource),
|
|
43
|
+
__is_sveltekit$typeImport: true
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
13
49
|
return {
|
|
14
50
|
...completions,
|
|
15
51
|
entries: completions.entries.map((entry) => {
|
|
@@ -26,9 +62,25 @@ function decorateCompletions(ls, logger) {
|
|
|
26
62
|
};
|
|
27
63
|
const getCompletionEntryDetails = ls.getCompletionEntryDetails;
|
|
28
64
|
ls.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
|
|
65
|
+
var _a;
|
|
66
|
+
const is$typeImport = data === null || data === void 0 ? void 0 : data.__is_sveltekit$typeImport;
|
|
29
67
|
const details = getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
|
|
30
68
|
if (details) {
|
|
31
|
-
if (
|
|
69
|
+
if (is$typeImport) {
|
|
70
|
+
details.codeActions = (_a = details.codeActions) === null || _a === void 0 ? void 0 : _a.map((codeAction) => {
|
|
71
|
+
codeAction.description = adjustPath(codeAction.description);
|
|
72
|
+
codeAction.changes = codeAction.changes.map((change) => {
|
|
73
|
+
change.textChanges = change.textChanges.map((textChange) => {
|
|
74
|
+
textChange.newText = adjustPath(textChange.newText);
|
|
75
|
+
return textChange;
|
|
76
|
+
});
|
|
77
|
+
return change;
|
|
78
|
+
});
|
|
79
|
+
return codeAction;
|
|
80
|
+
});
|
|
81
|
+
return details;
|
|
82
|
+
}
|
|
83
|
+
else if ((0, utils_1.isSvelteFilePath)(source || '')) {
|
|
32
84
|
logger.debug('TS found Svelte Component import completion details');
|
|
33
85
|
return (0, utils_1.replaceDeep)(details, componentPostfix, '');
|
|
34
86
|
}
|
|
@@ -51,4 +103,9 @@ function decorateCompletions(ls, logger) {
|
|
|
51
103
|
};
|
|
52
104
|
}
|
|
53
105
|
exports.decorateCompletions = decorateCompletions;
|
|
106
|
+
function adjustPath(path) {
|
|
107
|
+
return path.replace(/(['"])(.+?)['"]/,
|
|
108
|
+
// .js logic for node16 module resolution
|
|
109
|
+
(_match, quote, path) => `${quote}./$types${path.endsWith('.js') ? '.js' : ''}${quote}`);
|
|
110
|
+
}
|
|
54
111
|
//# sourceMappingURL=completions.js.map
|