typescript-svelte-plugin 0.3.35 → 0.3.37
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/language-service/completions.js +7 -0
- package/dist/src/language-service/diagnostics.js +2 -1
- package/dist/src/language-service/hover.js +2 -4
- package/dist/src/language-service/index.js +2 -0
- package/dist/src/language-service/move-to-file.d.ts +2 -0
- package/dist/src/language-service/move-to-file.js +24 -0
- package/dist/src/language-service/sveltekit.js +54 -55
- package/package.json +3 -3
|
@@ -26,6 +26,12 @@ function decorateCompletions(ls, info, ts, logger) {
|
|
|
26
26
|
}
|
|
27
27
|
return c;
|
|
28
28
|
});
|
|
29
|
+
if (completions.optionalReplacementSpan) {
|
|
30
|
+
completions.optionalReplacementSpan = {
|
|
31
|
+
...completions.optionalReplacementSpan,
|
|
32
|
+
start: toOriginalPos(completions.optionalReplacementSpan.start).pos
|
|
33
|
+
};
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
completions =
|
|
@@ -102,6 +108,7 @@ function decorateCompletions(ls, info, ts, logger) {
|
|
|
102
108
|
}
|
|
103
109
|
return {
|
|
104
110
|
...entry,
|
|
111
|
+
insertText: entry.insertText?.replace(componentPostfix, ''),
|
|
105
112
|
name: entry.name.slice(0, -componentPostfix.length)
|
|
106
113
|
};
|
|
107
114
|
})
|
|
@@ -123,7 +123,8 @@ function getKitDiagnostics(methodName, fileName, info, ts, logger) {
|
|
|
123
123
|
start: identifier.getStart(),
|
|
124
124
|
length: identifier.getEnd() - identifier.getStart(),
|
|
125
125
|
messageText: `Invalid export '${exportName}' (valid exports are ${validExports.join(', ')}, or anything with a '_' prefix)`,
|
|
126
|
-
|
|
126
|
+
// make it a warning in case people are stuck on old versions and new exports are added to SvelteKit
|
|
127
|
+
category: ts.DiagnosticCategory.Warning,
|
|
127
128
|
code: 71001 // arbitrary
|
|
128
129
|
});
|
|
129
130
|
}
|
|
@@ -18,10 +18,8 @@ function decorateHover(ls, info, ts, logger) {
|
|
|
18
18
|
const node = source && (0, utils_1.findNodeAtPosition)(source, virtualPos);
|
|
19
19
|
if (node && (0, utils_1.isTopLevelExport)(ts, node, source) && ts.isIdentifier(node)) {
|
|
20
20
|
const name = node.text;
|
|
21
|
-
if (name in sveltekit_1.kitExports) {
|
|
22
|
-
quickInfo.documentation =
|
|
23
|
-
? sveltekit_1.kitExports[name].documentation
|
|
24
|
-
: quickInfo.documentation;
|
|
21
|
+
if (name in sveltekit_1.kitExports && !quickInfo.documentation?.length) {
|
|
22
|
+
quickInfo.documentation = sveltekit_1.kitExports[name].documentation;
|
|
25
23
|
}
|
|
26
24
|
}
|
|
27
25
|
return {
|
|
@@ -15,6 +15,7 @@ const update_imports_1 = require("./update-imports");
|
|
|
15
15
|
const host_1 = require("./host");
|
|
16
16
|
const navigate_to_items_1 = require("./navigate-to-items");
|
|
17
17
|
const file_references_1 = require("./file-references");
|
|
18
|
+
const move_to_file_1 = require("./move-to-file");
|
|
18
19
|
const patchedProject = new Set();
|
|
19
20
|
function isPatched(project) {
|
|
20
21
|
return patchedProject.has(project.getProjectName());
|
|
@@ -44,6 +45,7 @@ function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescr
|
|
|
44
45
|
(0, inlay_hints_1.decorateInlayHints)(ls, info, typescript, logger);
|
|
45
46
|
(0, navigate_to_items_1.decorateNavigateToItems)(ls, snapshotManager);
|
|
46
47
|
(0, file_references_1.decorateFileReferences)(ls, snapshotManager);
|
|
48
|
+
(0, move_to_file_1.decorateMoveToRefactoringFileSuggestions)(ls);
|
|
47
49
|
decorateDispose(ls, info.project, onDispose);
|
|
48
50
|
return ls;
|
|
49
51
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorateMoveToRefactoringFileSuggestions = void 0;
|
|
4
|
+
function decorateMoveToRefactoringFileSuggestions(ls) {
|
|
5
|
+
const getMoveToRefactoringFileSuggestions = ls.getMoveToRefactoringFileSuggestions;
|
|
6
|
+
ls.getMoveToRefactoringFileSuggestions = (fileName, positionOrRange, preferences, triggerReason, kind) => {
|
|
7
|
+
const program = ls.getProgram();
|
|
8
|
+
if (!program) {
|
|
9
|
+
return getMoveToRefactoringFileSuggestions(fileName, positionOrRange, preferences, triggerReason, kind);
|
|
10
|
+
}
|
|
11
|
+
const getSourceFiles = program.getSourceFiles;
|
|
12
|
+
try {
|
|
13
|
+
// typescript currently only allows js/ts files to be moved to.
|
|
14
|
+
// Once there isn't a restriction anymore, we can remove this.
|
|
15
|
+
program.getSourceFiles = () => getSourceFiles().filter((file) => !file.fileName.endsWith('.svelte'));
|
|
16
|
+
return getMoveToRefactoringFileSuggestions(fileName, positionOrRange, preferences, triggerReason, kind);
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
program.getSourceFiles = getSourceFiles;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.decorateMoveToRefactoringFileSuggestions = decorateMoveToRefactoringFileSuggestions;
|
|
24
|
+
//# sourceMappingURL=move-to-file.js.map
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.getVirtualLS = exports.isKitRouteExportAllowedIn = exports.kitExports = void 0;
|
|
27
4
|
const utils_1 = require("../utils");
|
|
@@ -470,6 +447,18 @@ exports.kitExports = {
|
|
|
470
447
|
kind: 'text'
|
|
471
448
|
}
|
|
472
449
|
]
|
|
450
|
+
},
|
|
451
|
+
reroute: {
|
|
452
|
+
allowedIn: [],
|
|
453
|
+
displayParts: [],
|
|
454
|
+
documentation: [
|
|
455
|
+
{
|
|
456
|
+
text: `This function allows you to change how URLs are translated into routes. ` +
|
|
457
|
+
`The returned pathname (which defaults to url.pathname) is used to select the route and its parameters. ` +
|
|
458
|
+
`More info: https://kit.svelte.dev/docs/hooks#universal-hooks-reroute`,
|
|
459
|
+
kind: 'text'
|
|
460
|
+
}
|
|
461
|
+
]
|
|
473
462
|
}
|
|
474
463
|
};
|
|
475
464
|
const FORCE_UPDATE_VERSION = 'FORCE_UPDATE_VERSION';
|
|
@@ -488,6 +477,12 @@ function isKitRouteExportAllowedIn(basename, kitExport) {
|
|
|
488
477
|
: allowedIn.includes('universal')));
|
|
489
478
|
}
|
|
490
479
|
exports.isKitRouteExportAllowedIn = isKitRouteExportAllowedIn;
|
|
480
|
+
const kitFilesSettings = {
|
|
481
|
+
paramsPath: 'src/params',
|
|
482
|
+
clientHooksPath: 'src/hooks.client',
|
|
483
|
+
serverHooksPath: 'src/hooks.server',
|
|
484
|
+
universalHooksPath: 'src/hooks'
|
|
485
|
+
};
|
|
491
486
|
function getProxiedLanguageService(info, ts, logger) {
|
|
492
487
|
const cachedProxiedLanguageService = cache.get(info);
|
|
493
488
|
if (cachedProxiedLanguageService !== undefined) {
|
|
@@ -502,9 +497,6 @@ function getProxiedLanguageService(info, ts, logger) {
|
|
|
502
497
|
class ProxiedLanguageServiceHost {
|
|
503
498
|
constructor() {
|
|
504
499
|
this.files = {};
|
|
505
|
-
this.paramsPath = 'src/params';
|
|
506
|
-
this.serverHooksPath = 'src/hooks.server';
|
|
507
|
-
this.clientHooksPath = 'src/hooks.client';
|
|
508
500
|
this.resolveModuleNames = originalLanguageServiceHost.resolveModuleNames
|
|
509
501
|
? (...args) => {
|
|
510
502
|
return originalLanguageServiceHost.resolveModuleNames(
|
|
@@ -542,29 +534,40 @@ function getProxiedLanguageService(info, ts, logger) {
|
|
|
542
534
|
this.realpath = originalLanguageServiceHost.realpath
|
|
543
535
|
? (...args) => originalLanguageServiceHost.realpath(...args)
|
|
544
536
|
: undefined;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
537
|
+
// This never worked due to configPath being the wrong format and due to https://github.com/microsoft/TypeScript/issues/43329 .
|
|
538
|
+
// Noone has complained about this not working, so this is commented out for now, revisit if it ever comes up.
|
|
539
|
+
// const configPath = info.project.getCurrentDirectory() + '/svelte.config.js';
|
|
540
|
+
// (import(configPath)) as Promise<any>)
|
|
541
|
+
// .then((module) => {
|
|
542
|
+
// const config = module.default;
|
|
543
|
+
// if (config.kit && config.kit.files) {
|
|
544
|
+
// if (config.kit.files.params) {
|
|
545
|
+
// this.paramsPath = config.kit.files.params;
|
|
546
|
+
// }
|
|
547
|
+
// if (config.kit.files.hooks) {
|
|
548
|
+
// this.serverHooksPath ||= config.kit.files.hooks.server;
|
|
549
|
+
// this.clientHooksPath ||= config.kit.files.hooks.client;
|
|
550
|
+
// this.universalHooksPath ||= config.kit.files.hooks.universal;
|
|
551
|
+
// }
|
|
552
|
+
// logger?.log(
|
|
553
|
+
// `Using SvelteKit files config: ${JSON.stringify(
|
|
554
|
+
// config.kit.files.hooks
|
|
555
|
+
// )}`
|
|
556
|
+
// );
|
|
557
|
+
// // We could be more sophisticated with only removing the files that are actually
|
|
558
|
+
// // wrong but this is good enough given how rare it is that this setting is used
|
|
559
|
+
// Object.keys(this.files)
|
|
560
|
+
// .filter((name) => {
|
|
561
|
+
// return !name.includes('src/hooks') && !name.includes('src/params');
|
|
562
|
+
// })
|
|
563
|
+
// .forEach((name) => {
|
|
564
|
+
// delete this.files[name];
|
|
565
|
+
// });
|
|
566
|
+
// }
|
|
567
|
+
// })
|
|
568
|
+
// .catch((e) => {
|
|
569
|
+
// logger?.log('error loading SvelteKit file', e);
|
|
570
|
+
// });
|
|
568
571
|
}
|
|
569
572
|
log() { }
|
|
570
573
|
trace() { }
|
|
@@ -608,11 +611,7 @@ function getProxiedLanguageService(info, ts, logger) {
|
|
|
608
611
|
return this.files[fileName];
|
|
609
612
|
}
|
|
610
613
|
upsertKitFile(fileName) {
|
|
611
|
-
const result = svelte2tsx_1.internalHelpers.upsertKitFile(ts, fileName,
|
|
612
|
-
clientHooksPath: this.clientHooksPath,
|
|
613
|
-
paramsPath: this.paramsPath,
|
|
614
|
-
serverHooksPath: this.serverHooksPath
|
|
615
|
-
}, () => info.languageService.getProgram()?.getSourceFile(fileName));
|
|
614
|
+
const result = svelte2tsx_1.internalHelpers.upsertKitFile(ts, fileName, kitFilesSettings, () => info.languageService.getProgram()?.getSourceFile(fileName));
|
|
616
615
|
if (!result) {
|
|
617
616
|
return;
|
|
618
617
|
}
|
|
@@ -646,7 +645,7 @@ function getProxiedLanguageService(info, ts, logger) {
|
|
|
646
645
|
// Ideally we'd create a full Proxy of the language service, but that seems to have cache issues
|
|
647
646
|
// with diagnostics, which makes positions go out of sync.
|
|
648
647
|
const languageServiceHost = new ProxiedLanguageServiceHost();
|
|
649
|
-
const languageService = ts.createLanguageService(languageServiceHost, createProxyRegistry(ts, originalLanguageServiceHost,
|
|
648
|
+
const languageService = ts.createLanguageService(languageServiceHost, createProxyRegistry(ts, originalLanguageServiceHost, kitFilesSettings));
|
|
650
649
|
cache.set(info, { languageService, languageServiceHost });
|
|
651
650
|
return {
|
|
652
651
|
languageService,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-svelte-plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.37",
|
|
4
4
|
"description": "A TypeScript Plugin providing Svelte intellisense",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@types/node": "^16.0.0",
|
|
16
|
-
"typescript": "^5.
|
|
16
|
+
"typescript": "^5.3.2"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@jridgewell/sourcemap-codec": "^1.4.14",
|
|
20
|
-
"svelte2tsx": "~0.
|
|
20
|
+
"svelte2tsx": "~0.7.0"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsc -p ./",
|