typescript-svelte-plugin 0.3.6 → 0.3.7
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,6 +1,7 @@
|
|
|
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) {
|
|
@@ -26,9 +27,49 @@ function decorateCompletions(ls, logger) {
|
|
|
26
27
|
};
|
|
27
28
|
const getCompletionEntryDetails = ls.getCompletionEntryDetails;
|
|
28
29
|
ls.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
|
|
29
|
-
|
|
30
|
+
var _a, _b, _c, _d;
|
|
31
|
+
let is$typeImport = false;
|
|
32
|
+
const originalSource = source;
|
|
33
|
+
const originalData = data ? { ...data } : undefined;
|
|
34
|
+
if ((0, path_1.basename)(fileName).startsWith('+') && (source === null || source === void 0 ? void 0 : source.includes('.svelte-kit/types'))) {
|
|
35
|
+
// resolve path from FileName to svelte-kit/types
|
|
36
|
+
// src/routes/foo/+page.svelte -> .svelte-kit/types/foo/$types.d.ts
|
|
37
|
+
const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
|
|
38
|
+
const relativeFileName = (_a = fileName.split(routesFolder)[1]) === null || _a === void 0 ? void 0 : _a.slice(1);
|
|
39
|
+
if (relativeFileName) {
|
|
40
|
+
is$typeImport = true;
|
|
41
|
+
source =
|
|
42
|
+
source.split('.svelte-kit/types')[0] +
|
|
43
|
+
// note the missing .d.ts at the end - TS wants it that way for some reason
|
|
44
|
+
`.svelte-kit/types/${routesFolder}/${(0, path_1.dirname)(relativeFileName)}/$types`;
|
|
45
|
+
if (data) {
|
|
46
|
+
data.fileName = (_b = data.fileName) === null || _b === void 0 ? void 0 : _b.replace(originalSource, source);
|
|
47
|
+
data.moduleSpecifier = (_c = data.moduleSpecifier) === null || _c === void 0 ? void 0 : _c.replace(originalSource, source);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let details = getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
|
|
52
|
+
if (!details && is$typeImport) {
|
|
53
|
+
// Try again
|
|
54
|
+
is$typeImport = false;
|
|
55
|
+
details = getCompletionEntryDetails(fileName, position, entryName, formatOptions, originalSource, preferences, originalData);
|
|
56
|
+
}
|
|
30
57
|
if (details) {
|
|
31
|
-
if (
|
|
58
|
+
if (is$typeImport) {
|
|
59
|
+
details.codeActions = (_d = details.codeActions) === null || _d === void 0 ? void 0 : _d.map((codeAction) => {
|
|
60
|
+
codeAction.description = adjustPath(codeAction.description);
|
|
61
|
+
codeAction.changes = codeAction.changes.map((change) => {
|
|
62
|
+
change.textChanges = change.textChanges.map((textChange) => {
|
|
63
|
+
textChange.newText = adjustPath(textChange.newText);
|
|
64
|
+
return textChange;
|
|
65
|
+
});
|
|
66
|
+
return change;
|
|
67
|
+
});
|
|
68
|
+
return codeAction;
|
|
69
|
+
});
|
|
70
|
+
return details;
|
|
71
|
+
}
|
|
72
|
+
else if ((0, utils_1.isSvelteFilePath)(source || '')) {
|
|
32
73
|
logger.debug('TS found Svelte Component import completion details');
|
|
33
74
|
return (0, utils_1.replaceDeep)(details, componentPostfix, '');
|
|
34
75
|
}
|
|
@@ -51,4 +92,9 @@ function decorateCompletions(ls, logger) {
|
|
|
51
92
|
};
|
|
52
93
|
}
|
|
53
94
|
exports.decorateCompletions = decorateCompletions;
|
|
95
|
+
function adjustPath(path) {
|
|
96
|
+
return path.replace(/(['"])(.+?)['"]/,
|
|
97
|
+
// .js logic for node16 module resolution
|
|
98
|
+
(_match, quote, path) => `${quote}./$types${path.endsWith('.js') ? '.js' : ''}${quote}`);
|
|
99
|
+
}
|
|
54
100
|
//# sourceMappingURL=completions.js.map
|