typescript-svelte-plugin 0.3.15 → 0.3.17
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/index.js +36 -0
- package/dist/src/language-service/completions.d.ts +4 -2
- package/dist/src/language-service/completions.js +3 -7
- package/dist/src/language-service/index.js +1 -1
- package/dist/src/module-loader.js +1 -1
- package/dist/src/svelte-snapshots.js +1 -1
- package/dist/src/svelte-sys.d.ts +4 -2
- package/dist/src/svelte-sys.js +6 -10
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -32,6 +32,42 @@ function init(modules) {
|
|
|
32
32
|
// This call the ConfiguredProject.getParsedCommandLine
|
|
33
33
|
// where it'll try to load the cached version of the parsedCommandLine
|
|
34
34
|
const parsedCommandLine = (_c = (_b = info.languageServiceHost).getParsedCommandLine) === null || _c === void 0 ? void 0 : _c.call(_b, (0, utils_1.getConfigPathForProject)(info.project));
|
|
35
|
+
// For some reason it's no longer enough to patch this at the projectService level, so we do it here, too
|
|
36
|
+
// TODO investigate if we can use the script snapshot for all Svelte files, too, enabling Svelte file
|
|
37
|
+
// updates getting picked up without a file save - move this logic into the snapshot manager then?
|
|
38
|
+
const getScriptSnapshot = info.languageServiceHost.getScriptSnapshot.bind(info.languageServiceHost);
|
|
39
|
+
info.languageServiceHost.getScriptSnapshot = (fileName) => {
|
|
40
|
+
const normalizedPath = fileName.replace(/\\/g, '/');
|
|
41
|
+
if (normalizedPath.endsWith('node_modules/svelte/types/runtime/ambient.d.ts')) {
|
|
42
|
+
return modules.typescript.ScriptSnapshot.fromString('');
|
|
43
|
+
}
|
|
44
|
+
else if (normalizedPath.endsWith('svelte2tsx/svelte-jsx.d.ts')) {
|
|
45
|
+
// Remove the dom lib reference to not load these ambient types in case
|
|
46
|
+
// the user has a tsconfig.json with different lib settings like in
|
|
47
|
+
// https://github.com/sveltejs/language-tools/issues/1733
|
|
48
|
+
const snapshot = getScriptSnapshot(fileName);
|
|
49
|
+
if (snapshot) {
|
|
50
|
+
const originalText = snapshot.getText(0, snapshot.getLength());
|
|
51
|
+
return modules.typescript.ScriptSnapshot.fromString(originalText.replace('/// <reference lib="dom" />', ''));
|
|
52
|
+
}
|
|
53
|
+
return snapshot;
|
|
54
|
+
}
|
|
55
|
+
else if (normalizedPath.endsWith('svelte2tsx/svelte-shims.d.ts')) {
|
|
56
|
+
const snapshot = getScriptSnapshot(fileName);
|
|
57
|
+
if (snapshot) {
|
|
58
|
+
let originalText = snapshot.getText(0, snapshot.getLength());
|
|
59
|
+
if (!originalText.includes('// -- start svelte-ls-remove --')) {
|
|
60
|
+
return snapshot; // uses an older version of svelte2tsx or is already patched
|
|
61
|
+
}
|
|
62
|
+
originalText =
|
|
63
|
+
originalText.substring(0, originalText.indexOf('// -- start svelte-ls-remove --')) +
|
|
64
|
+
originalText.substring(originalText.indexOf('// -- end svelte-ls-remove --'));
|
|
65
|
+
return modules.typescript.ScriptSnapshot.fromString(originalText);
|
|
66
|
+
}
|
|
67
|
+
return snapshot;
|
|
68
|
+
}
|
|
69
|
+
return getScriptSnapshot(fileName);
|
|
70
|
+
};
|
|
35
71
|
const svelteOptions = ((_d = parsedCommandLine === null || parsedCommandLine === void 0 ? void 0 : parsedCommandLine.raw) === null || _d === void 0 ? void 0 : _d.svelteOptions) || { namespace: 'svelteHTML' };
|
|
36
72
|
logger.log('svelteOptions:', svelteOptions);
|
|
37
73
|
logger.debug(parsedCommandLine === null || parsedCommandLine === void 0 ? void 0 : parsedCommandLine.wildcardDirectories);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import ts from 'typescript
|
|
1
|
+
import type ts from 'typescript';
|
|
2
2
|
import { Logger } from '../logger';
|
|
3
|
-
|
|
3
|
+
type _ts = typeof ts;
|
|
4
|
+
export declare function decorateCompletions(ls: ts.LanguageService, ts: _ts, logger: Logger): void;
|
|
5
|
+
export {};
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.decorateCompletions = void 0;
|
|
7
4
|
const path_1 = require("path");
|
|
8
|
-
const tsserverlibrary_1 = __importDefault(require("typescript/lib/tsserverlibrary"));
|
|
9
5
|
const utils_1 = require("../utils");
|
|
10
6
|
const componentPostfix = '__SvelteComponent_';
|
|
11
|
-
function decorateCompletions(ls, logger) {
|
|
7
|
+
function decorateCompletions(ls, ts, logger) {
|
|
12
8
|
const getCompletionsAtPosition = ls.getCompletionsAtPosition;
|
|
13
9
|
ls.getCompletionsAtPosition = (fileName, position, options) => {
|
|
14
10
|
var _a, _b, _c, _d;
|
|
@@ -55,10 +51,10 @@ function decorateCompletions(ls, logger) {
|
|
|
55
51
|
if ((0, path_1.extname)(fileName) === '.js') {
|
|
56
52
|
completions.entries.push({
|
|
57
53
|
// TODO doesn't show up for "export" and "load" only at the bottom for "function"
|
|
58
|
-
kind:
|
|
54
|
+
kind: ts.ScriptElementKind.functionElement,
|
|
59
55
|
name: 'export function load() {}',
|
|
60
56
|
sortText: '-99',
|
|
61
|
-
kindModifiers:
|
|
57
|
+
kindModifiers: ts.ScriptElementKindModifier.exportedModifier,
|
|
62
58
|
insertText: `/** @type {import('./$types').Foo} */\nexport function load() {}`
|
|
63
59
|
});
|
|
64
60
|
}
|
|
@@ -28,7 +28,7 @@ function decorateLanguageServiceInner(ls, snapshotManager, logger, typescript) {
|
|
|
28
28
|
(0, rename_1.decorateRename)(ls, snapshotManager, logger);
|
|
29
29
|
(0, diagnostics_1.decorateDiagnostics)(ls, logger);
|
|
30
30
|
(0, find_references_1.decorateFindReferences)(ls, snapshotManager, logger);
|
|
31
|
-
(0, completions_1.decorateCompletions)(ls, logger);
|
|
31
|
+
(0, completions_1.decorateCompletions)(ls, typescript, logger);
|
|
32
32
|
(0, definition_1.decorateGetDefinition)(ls, snapshotManager, logger);
|
|
33
33
|
(0, implementation_1.decorateGetImplementation)(ls, snapshotManager, logger);
|
|
34
34
|
(0, update_imports_1.decorateUpdateImports)(ls, snapshotManager, logger);
|
|
@@ -58,7 +58,7 @@ class ModuleResolutionCache {
|
|
|
58
58
|
*/
|
|
59
59
|
function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project, configManager) {
|
|
60
60
|
var _a, _b;
|
|
61
|
-
const svelteSys = (0, svelte_sys_1.createSvelteSys)(logger);
|
|
61
|
+
const svelteSys = (0, svelte_sys_1.createSvelteSys)(typescript, logger);
|
|
62
62
|
const moduleCache = new ModuleResolutionCache(project.projectService);
|
|
63
63
|
const origResolveModuleNames = (_a = lsHost.resolveModuleNames) === null || _a === void 0 ? void 0 : _a.bind(lsHost);
|
|
64
64
|
const origResolveModuleNamLiterals = (_b = lsHost.resolveModuleNameLiterals) === null || _b === void 0 ? void 0 : _b.bind(lsHost);
|
|
@@ -84,7 +84,7 @@ class SvelteSnapshot {
|
|
|
84
84
|
}
|
|
85
85
|
setAndPatchScriptInfo(scriptInfo) {
|
|
86
86
|
// @ts-expect-error
|
|
87
|
-
scriptInfo.scriptKind = this.typescript.ScriptKind.
|
|
87
|
+
scriptInfo.scriptKind = this.typescript.ScriptKind.TS;
|
|
88
88
|
const positionToLineOffset = scriptInfo.positionToLineOffset.bind(scriptInfo);
|
|
89
89
|
scriptInfo.positionToLineOffset = (position) => {
|
|
90
90
|
if (this.convertInternalCodePositions) {
|
package/dist/src/svelte-sys.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
1
|
+
import type ts from 'typescript';
|
|
2
2
|
import { Logger } from './logger';
|
|
3
|
+
type _ts = typeof ts;
|
|
3
4
|
/**
|
|
4
5
|
* This should only be accessed by TS svelte module resolution.
|
|
5
6
|
*/
|
|
6
|
-
export declare function createSvelteSys(logger: Logger): ts.System;
|
|
7
|
+
export declare function createSvelteSys(ts: _ts, logger: Logger): ts.System;
|
|
8
|
+
export {};
|
package/dist/src/svelte-sys.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.createSvelteSys = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
8
4
|
const utils_1 = require("./utils");
|
|
9
5
|
/**
|
|
10
6
|
* This should only be accessed by TS svelte module resolution.
|
|
11
7
|
*/
|
|
12
|
-
function createSvelteSys(logger) {
|
|
8
|
+
function createSvelteSys(ts, logger) {
|
|
13
9
|
const svelteSys = {
|
|
14
|
-
...
|
|
10
|
+
...ts.sys,
|
|
15
11
|
fileExists(path) {
|
|
16
|
-
return
|
|
12
|
+
return ts.sys.fileExists((0, utils_1.ensureRealSvelteFilePath)(path));
|
|
17
13
|
},
|
|
18
14
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
19
15
|
const extensionsWithSvelte = (extensions !== null && extensions !== void 0 ? extensions : []).concat('.svelte');
|
|
20
|
-
return
|
|
16
|
+
return ts.sys.readDirectory(path, extensionsWithSvelte, exclude, include, depth);
|
|
21
17
|
}
|
|
22
18
|
};
|
|
23
|
-
if (
|
|
24
|
-
const realpath =
|
|
19
|
+
if (ts.sys.realpath) {
|
|
20
|
+
const realpath = ts.sys.realpath;
|
|
25
21
|
svelteSys.realpath = function (path) {
|
|
26
22
|
if ((0, utils_1.isVirtualSvelteFilePath)(path)) {
|
|
27
23
|
return realpath((0, utils_1.toRealSvelteFilePath)(path)) + '.ts';
|