typescript-svelte-plugin 0.3.17 → 0.3.19
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 +37 -12
- package/dist/src/language-service/completions.d.ts +2 -2
- package/dist/src/language-service/completions.js +101 -25
- package/dist/src/language-service/definition.d.ts +3 -1
- package/dist/src/language-service/definition.js +20 -2
- package/dist/src/language-service/diagnostics.d.ts +1 -1
- package/dist/src/language-service/diagnostics.js +103 -10
- package/dist/src/language-service/hover.d.ts +5 -0
- package/dist/src/language-service/hover.js +35 -0
- package/dist/src/language-service/index.d.ts +1 -1
- package/dist/src/language-service/index.js +10 -6
- package/dist/src/language-service/inlay-hints.d.ts +5 -0
- package/dist/src/language-service/inlay-hints.js +25 -0
- package/dist/src/language-service/sveltekit.d.ts +20 -0
- package/dist/src/language-service/sveltekit.js +634 -0
- package/dist/src/module-loader.js +2 -2
- package/dist/src/source-mapper.js +1 -1
- package/dist/src/utils.d.ts +11 -0
- package/dist/src/utils.js +74 -1
- package/package.json +2 -2
package/dist/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const project_svelte_files_1 = require("./project-svelte-files");
|
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
function init(modules) {
|
|
11
11
|
const configManager = new config_manager_1.ConfigManager();
|
|
12
|
+
let resolvedSvelteTsxFiles;
|
|
12
13
|
function create(info) {
|
|
13
14
|
var _a, _b, _c, _d;
|
|
14
15
|
const logger = new logger_1.Logger(info.project.projectService.logger);
|
|
@@ -86,7 +87,7 @@ function init(modules) {
|
|
|
86
87
|
info.project.updateGraph();
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
|
-
return decorateLanguageServiceDispose((0, language_service_1.decorateLanguageService)(info.languageService, snapshotManager, logger, configManager, modules.typescript), projectSvelteFilesManager !== null && projectSvelteFilesManager !== void 0 ? projectSvelteFilesManager : {
|
|
90
|
+
return decorateLanguageServiceDispose((0, language_service_1.decorateLanguageService)(info.languageService, snapshotManager, logger, configManager, info, modules.typescript), projectSvelteFilesManager !== null && projectSvelteFilesManager !== void 0 ? projectSvelteFilesManager : {
|
|
90
91
|
dispose() { }
|
|
91
92
|
});
|
|
92
93
|
}
|
|
@@ -96,26 +97,31 @@ function init(modules) {
|
|
|
96
97
|
return [];
|
|
97
98
|
}
|
|
98
99
|
// Needed so the ambient definitions are known inside the tsx files
|
|
100
|
+
const svelteTsxFiles = resolveSvelteTsxFiles();
|
|
101
|
+
if (!project.getCompilerOptions().configFilePath) {
|
|
102
|
+
svelteTsxFiles.forEach((file) => {
|
|
103
|
+
openSvelteTsxFileForInferredProject(project, file);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// let ts know project svelte files to do its optimization
|
|
107
|
+
return svelteTsxFiles.concat((_b = (_a = project_svelte_files_1.ProjectSvelteFilesManager.getInstance(project.getProjectName())) === null || _a === void 0 ? void 0 : _a.getFiles()) !== null && _b !== void 0 ? _b : []);
|
|
108
|
+
}
|
|
109
|
+
function resolveSvelteTsxFiles() {
|
|
110
|
+
if (resolvedSvelteTsxFiles) {
|
|
111
|
+
return resolvedSvelteTsxFiles;
|
|
112
|
+
}
|
|
99
113
|
const svelteTsPath = (0, path_1.dirname)(require.resolve('svelte2tsx'));
|
|
100
114
|
const svelteTsxFiles = [
|
|
101
115
|
'./svelte-shims.d.ts',
|
|
102
116
|
'./svelte-jsx.d.ts',
|
|
103
117
|
'./svelte-native-jsx.d.ts'
|
|
104
118
|
].map((f) => modules.typescript.sys.resolvePath((0, path_1.resolve)(svelteTsPath, f)));
|
|
105
|
-
|
|
106
|
-
return svelteTsxFiles
|
|
119
|
+
resolvedSvelteTsxFiles = svelteTsxFiles;
|
|
120
|
+
return svelteTsxFiles;
|
|
107
121
|
}
|
|
108
122
|
function isSvelteProject(compilerOptions) {
|
|
109
123
|
// Add more checks like "no Svelte file found" or "no config file found"?
|
|
110
|
-
|
|
111
|
-
const isSvelteProject = typeof compilerOptions.configFilePath !== 'string' ||
|
|
112
|
-
require.resolve('svelte', { paths: [compilerOptions.configFilePath] });
|
|
113
|
-
return isSvelteProject;
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
// If require.resolve fails, we end up here
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
124
|
+
return (0, utils_1.hasNodeModule)(compilerOptions, 'svelte');
|
|
119
125
|
}
|
|
120
126
|
function onConfigurationChanged(config) {
|
|
121
127
|
configManager.updateConfigFromPluginConfig(config);
|
|
@@ -128,6 +134,25 @@ function init(modules) {
|
|
|
128
134
|
};
|
|
129
135
|
return languageService;
|
|
130
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* TypeScript doesn't load the external files in projects without a config file. So we load it by ourselves.
|
|
139
|
+
* TypeScript also seems to expect files added to the root to be opened by the client in this situation.
|
|
140
|
+
*/
|
|
141
|
+
function openSvelteTsxFileForInferredProject(project, file) {
|
|
142
|
+
const normalizedPath = modules.typescript.server.toNormalizedPath(file);
|
|
143
|
+
if (project.containsFile(normalizedPath)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const scriptInfo = project.projectService.getOrCreateScriptInfoForNormalizedPath(normalizedPath,
|
|
147
|
+
/*openedByClient*/ true, project.readFile(file));
|
|
148
|
+
if (!scriptInfo) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (!project.projectService.openFiles.has(scriptInfo.path)) {
|
|
152
|
+
project.projectService.openFiles.set(scriptInfo.path, undefined);
|
|
153
|
+
}
|
|
154
|
+
project.addRoot(scriptInfo);
|
|
155
|
+
}
|
|
131
156
|
return { create, getExternalFiles, onConfigurationChanged };
|
|
132
157
|
}
|
|
133
158
|
module.exports = init;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type ts from 'typescript';
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
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;
|
|
4
|
+
export declare function decorateCompletions(ls: ts.LanguageService, info: ts.server.PluginCreateInfo, ts: _ts, logger: Logger): void;
|
|
5
5
|
export {};
|
|
@@ -3,20 +3,67 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.decorateCompletions = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
+
const sveltekit_1 = require("./sveltekit");
|
|
6
7
|
const componentPostfix = '__SvelteComponent_';
|
|
7
|
-
function decorateCompletions(ls, ts, logger) {
|
|
8
|
+
function decorateCompletions(ls, info, ts, logger) {
|
|
8
9
|
const getCompletionsAtPosition = ls.getCompletionsAtPosition;
|
|
9
|
-
ls.getCompletionsAtPosition = (fileName, position, options) => {
|
|
10
|
-
var _a, _b, _c, _d;
|
|
11
|
-
|
|
10
|
+
ls.getCompletionsAtPosition = (fileName, position, options, settings) => {
|
|
11
|
+
var _a, _b, _c, _d, _e;
|
|
12
|
+
let completions;
|
|
13
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
14
|
+
if (result) {
|
|
15
|
+
const { languageService, toVirtualPos, toOriginalPos } = result;
|
|
16
|
+
completions = languageService.getCompletionsAtPosition(fileName, toVirtualPos(position), options, settings);
|
|
17
|
+
if (completions) {
|
|
18
|
+
completions.entries = completions.entries.map((c) => {
|
|
19
|
+
if (c.replacementSpan) {
|
|
20
|
+
return {
|
|
21
|
+
...c,
|
|
22
|
+
replacementSpan: {
|
|
23
|
+
...c.replacementSpan,
|
|
24
|
+
start: toOriginalPos(c.replacementSpan.start).pos
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return c;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
completions =
|
|
33
|
+
completions !== null && completions !== void 0 ? completions : getCompletionsAtPosition(fileName, position, options, settings);
|
|
12
34
|
if (!completions) {
|
|
35
|
+
// No completions hints at a top level export in the making
|
|
36
|
+
const source = (_a = ls.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
|
|
37
|
+
const node = source && (0, utils_1.findNodeAtPosition)(source, position);
|
|
38
|
+
if (node && (0, utils_1.isTopLevelExport)(ts, node, source)) {
|
|
39
|
+
return {
|
|
40
|
+
entries: Object.entries(sveltekit_1.kitExports)
|
|
41
|
+
.filter(([, value]) => (0, sveltekit_1.isKitRouteExportAllowedIn)((0, path_1.basename)(fileName), value))
|
|
42
|
+
.map(([key, value]) => ({
|
|
43
|
+
kind: ts.ScriptElementKind.constElement,
|
|
44
|
+
name: key,
|
|
45
|
+
labelDetails: {
|
|
46
|
+
description: value.documentation.map((d) => d.text).join('')
|
|
47
|
+
},
|
|
48
|
+
sortText: '0',
|
|
49
|
+
data: {
|
|
50
|
+
__sveltekit: key,
|
|
51
|
+
exportName: key // TS needs this
|
|
52
|
+
}
|
|
53
|
+
})),
|
|
54
|
+
isGlobalCompletion: false,
|
|
55
|
+
isMemberCompletion: false,
|
|
56
|
+
isNewIdentifierLocation: false,
|
|
57
|
+
isIncomplete: true
|
|
58
|
+
};
|
|
59
|
+
}
|
|
13
60
|
return completions;
|
|
14
61
|
}
|
|
15
62
|
// Add ./$types imports for SvelteKit since TypeScript is bad at it
|
|
16
63
|
if ((0, path_1.basename)(fileName).startsWith('+')) {
|
|
17
64
|
const $typeImports = new Map();
|
|
18
65
|
for (const c of completions.entries) {
|
|
19
|
-
if (((
|
|
66
|
+
if (((_b = c.source) === null || _b === void 0 ? void 0 : _b.includes('.svelte-kit/types')) && c.data) {
|
|
20
67
|
$typeImports.set(c.name, c);
|
|
21
68
|
}
|
|
22
69
|
}
|
|
@@ -24,7 +71,7 @@ function decorateCompletions(ls, ts, logger) {
|
|
|
24
71
|
// resolve path from FileName to svelte-kit/types
|
|
25
72
|
// src/routes/foo/+page.svelte -> .svelte-kit/types/foo/$types.d.ts
|
|
26
73
|
const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
|
|
27
|
-
const relativeFileName = (
|
|
74
|
+
const relativeFileName = (_c = fileName.split(routesFolder)[1]) === null || _c === void 0 ? void 0 : _c.slice(1);
|
|
28
75
|
if (relativeFileName) {
|
|
29
76
|
const relativePath = (0, path_1.dirname)(relativeFileName) === '.' ? '' : `${(0, path_1.dirname)(relativeFileName)}/`;
|
|
30
77
|
const modifiedSource = $typeImport.source.split('.svelte-kit/types')[0] +
|
|
@@ -39,28 +86,14 @@ function decorateCompletions(ls, ts, logger) {
|
|
|
39
86
|
source: modifiedSource,
|
|
40
87
|
data: {
|
|
41
88
|
...$typeImport.data,
|
|
42
|
-
fileName: (
|
|
43
|
-
moduleSpecifier: (
|
|
89
|
+
fileName: (_d = $typeImport.data.fileName) === null || _d === void 0 ? void 0 : _d.replace($typeImport.source, modifiedSource),
|
|
90
|
+
moduleSpecifier: (_e = $typeImport.data.moduleSpecifier) === null || _e === void 0 ? void 0 : _e.replace($typeImport.source, modifiedSource),
|
|
44
91
|
__is_sveltekit$typeImport: true
|
|
45
92
|
}
|
|
46
93
|
});
|
|
47
94
|
}
|
|
48
95
|
}
|
|
49
96
|
}
|
|
50
|
-
if ((0, path_1.basename)(fileName).startsWith('+page') || (0, path_1.basename)(fileName).startsWith('+layout')) {
|
|
51
|
-
if ((0, path_1.extname)(fileName) === '.js') {
|
|
52
|
-
completions.entries.push({
|
|
53
|
-
// TODO doesn't show up for "export" and "load" only at the bottom for "function"
|
|
54
|
-
kind: ts.ScriptElementKind.functionElement,
|
|
55
|
-
name: 'export function load() {}',
|
|
56
|
-
sortText: '-99',
|
|
57
|
-
kindModifiers: ts.ScriptElementKindModifier.exportedModifier,
|
|
58
|
-
insertText: `/** @type {import('./$types').Foo} */\nexport function load() {}`
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
97
|
return {
|
|
65
98
|
...completions,
|
|
66
99
|
entries: completions.entries.map((entry) => {
|
|
@@ -77,12 +110,46 @@ function decorateCompletions(ls, ts, logger) {
|
|
|
77
110
|
};
|
|
78
111
|
const getCompletionEntryDetails = ls.getCompletionEntryDetails;
|
|
79
112
|
ls.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
|
|
80
|
-
var _a;
|
|
113
|
+
var _a, _b;
|
|
114
|
+
if (data === null || data === void 0 ? void 0 : data.__sveltekit) {
|
|
115
|
+
const key = data === null || data === void 0 ? void 0 : data.__sveltekit;
|
|
116
|
+
return {
|
|
117
|
+
name: key,
|
|
118
|
+
kind: ts.ScriptElementKind.constElement,
|
|
119
|
+
kindModifiers: ts.ScriptElementKindModifier.none,
|
|
120
|
+
displayParts: sveltekit_1.kitExports[key].displayParts,
|
|
121
|
+
documentation: sveltekit_1.kitExports[key].documentation
|
|
122
|
+
};
|
|
123
|
+
}
|
|
81
124
|
const is$typeImport = data === null || data === void 0 ? void 0 : data.__is_sveltekit$typeImport;
|
|
82
|
-
|
|
125
|
+
let details;
|
|
126
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
127
|
+
if (result) {
|
|
128
|
+
const { languageService, toVirtualPos, toOriginalPos } = result;
|
|
129
|
+
details = languageService.getCompletionEntryDetails(fileName, toVirtualPos(position), entryName, formatOptions, source, preferences, data);
|
|
130
|
+
if (details) {
|
|
131
|
+
details.codeActions = (_a = details.codeActions) === null || _a === void 0 ? void 0 : _a.map((codeAction) => {
|
|
132
|
+
codeAction.changes = codeAction.changes.map((change) => {
|
|
133
|
+
change.textChanges = change.textChanges.map((textChange) => {
|
|
134
|
+
return {
|
|
135
|
+
...textChange,
|
|
136
|
+
span: {
|
|
137
|
+
...textChange.span,
|
|
138
|
+
start: toOriginalPos(textChange.span.start).pos
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
return change;
|
|
143
|
+
});
|
|
144
|
+
return codeAction;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
details =
|
|
149
|
+
details !== null && details !== void 0 ? details : getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
|
|
83
150
|
if (details) {
|
|
84
151
|
if (is$typeImport) {
|
|
85
|
-
details.codeActions = (
|
|
152
|
+
details.codeActions = (_b = details.codeActions) === null || _b === void 0 ? void 0 : _b.map((codeAction) => {
|
|
86
153
|
codeAction.description = adjustPath(codeAction.description);
|
|
87
154
|
codeAction.changes = codeAction.changes.map((change) => {
|
|
88
155
|
change.textChanges = change.textChanges.map((textChange) => {
|
|
@@ -116,6 +183,15 @@ function decorateCompletions(ls, ts, logger) {
|
|
|
116
183
|
logger.debug('Found Svelte Component import completion details');
|
|
117
184
|
return (0, utils_1.replaceDeep)(svelteDetails, componentPostfix, '');
|
|
118
185
|
};
|
|
186
|
+
const getSignatureHelpItems = ls.getSignatureHelpItems;
|
|
187
|
+
ls.getSignatureHelpItems = (fileName, position, options) => {
|
|
188
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
189
|
+
if (result) {
|
|
190
|
+
const { languageService, toVirtualPos } = result;
|
|
191
|
+
return languageService.getSignatureHelpItems(fileName, toVirtualPos(position), options);
|
|
192
|
+
}
|
|
193
|
+
return getSignatureHelpItems(fileName, position, options);
|
|
194
|
+
};
|
|
119
195
|
}
|
|
120
196
|
exports.decorateCompletions = decorateCompletions;
|
|
121
197
|
function adjustPath(path) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { Logger } from '../logger';
|
|
3
3
|
import { SvelteSnapshotManager } from '../svelte-snapshots';
|
|
4
|
-
|
|
4
|
+
type _ts = typeof ts;
|
|
5
|
+
export declare function decorateGetDefinition(ls: ts.LanguageService, info: ts.server.PluginCreateInfo, ts: _ts, snapshotManager: SvelteSnapshotManager, logger: Logger): void;
|
|
6
|
+
export {};
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decorateGetDefinition = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
5
|
+
const sveltekit_1 = require("./sveltekit");
|
|
6
|
+
function decorateGetDefinition(ls, info, ts, snapshotManager, logger) {
|
|
6
7
|
const getDefinitionAndBoundSpan = ls.getDefinitionAndBoundSpan;
|
|
7
8
|
ls.getDefinitionAndBoundSpan = (fileName, position) => {
|
|
8
9
|
const definition = getDefinitionAndBoundSpan(fileName, position);
|
|
9
10
|
if (!(definition === null || definition === void 0 ? void 0 : definition.definitions)) {
|
|
10
|
-
return
|
|
11
|
+
return getKitDefinitions(ts, info, fileName, position);
|
|
11
12
|
}
|
|
12
13
|
return {
|
|
13
14
|
...definition,
|
|
@@ -38,4 +39,21 @@ function decorateGetDefinition(ls, snapshotManager, logger) {
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
exports.decorateGetDefinition = decorateGetDefinition;
|
|
42
|
+
function getKitDefinitions(ts, info, fileName, position) {
|
|
43
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
44
|
+
if (!result)
|
|
45
|
+
return;
|
|
46
|
+
const { languageService, toOriginalPos, toVirtualPos } = result;
|
|
47
|
+
const virtualPos = toVirtualPos(position);
|
|
48
|
+
const definitions = languageService.getDefinitionAndBoundSpan(fileName, virtualPos);
|
|
49
|
+
if (!definitions)
|
|
50
|
+
return;
|
|
51
|
+
// Assumption: This is only called when the original definitions didn't turn up anything.
|
|
52
|
+
// Therefore we are called on things like export function load ({ fetch }) .
|
|
53
|
+
// This means the textSpan needs conversion but none of the definitions because they are all referencing other files.
|
|
54
|
+
return {
|
|
55
|
+
...definitions,
|
|
56
|
+
textSpan: { ...definitions.textSpan, start: toOriginalPos(definitions.textSpan.start).pos }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
41
59
|
//# sourceMappingURL=definition.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { Logger } from '../logger';
|
|
3
|
-
export declare function decorateDiagnostics(ls: ts.LanguageService, logger: Logger): void;
|
|
3
|
+
export declare function decorateDiagnostics(ls: ts.LanguageService, info: ts.server.PluginCreateInfo, typescript: typeof ts, logger: Logger): void;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.decorateDiagnostics = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const svelte2tsx_1 = require("svelte2tsx");
|
|
4
9
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
const sveltekit_1 = require("./sveltekit");
|
|
11
|
+
function decorateDiagnostics(ls, info, typescript, logger) {
|
|
12
|
+
decorateSyntacticDiagnostics(ls, info, typescript, logger);
|
|
13
|
+
decorateSemanticDiagnostics(ls, info, typescript, logger);
|
|
14
|
+
decorateSuggestionDiagnostics(ls, info, typescript, logger);
|
|
9
15
|
}
|
|
10
16
|
exports.decorateDiagnostics = decorateDiagnostics;
|
|
11
|
-
function decorateSyntacticDiagnostics(ls) {
|
|
17
|
+
function decorateSyntacticDiagnostics(ls, info, typescript, logger) {
|
|
12
18
|
const getSyntacticDiagnostics = ls.getSyntacticDiagnostics;
|
|
13
19
|
ls.getSyntacticDiagnostics = (fileName) => {
|
|
14
20
|
// Diagnostics inside Svelte files are done
|
|
@@ -16,10 +22,11 @@ function decorateSyntacticDiagnostics(ls) {
|
|
|
16
22
|
if ((0, utils_1.isSvelteFilePath)(fileName)) {
|
|
17
23
|
return [];
|
|
18
24
|
}
|
|
19
|
-
|
|
25
|
+
const kitDiagnostics = getKitDiagnostics('getSyntacticDiagnostics', fileName, info, typescript, logger);
|
|
26
|
+
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSyntacticDiagnostics(fileName);
|
|
20
27
|
};
|
|
21
28
|
}
|
|
22
|
-
function decorateSemanticDiagnostics(ls) {
|
|
29
|
+
function decorateSemanticDiagnostics(ls, info, typescript, logger) {
|
|
23
30
|
const getSemanticDiagnostics = ls.getSemanticDiagnostics;
|
|
24
31
|
ls.getSemanticDiagnostics = (fileName) => {
|
|
25
32
|
// Diagnostics inside Svelte files are done
|
|
@@ -27,10 +34,11 @@ function decorateSemanticDiagnostics(ls) {
|
|
|
27
34
|
if ((0, utils_1.isSvelteFilePath)(fileName)) {
|
|
28
35
|
return [];
|
|
29
36
|
}
|
|
30
|
-
|
|
37
|
+
const kitDiagnostics = getKitDiagnostics('getSemanticDiagnostics', fileName, info, typescript, logger);
|
|
38
|
+
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSemanticDiagnostics(fileName);
|
|
31
39
|
};
|
|
32
40
|
}
|
|
33
|
-
function decorateSuggestionDiagnostics(ls) {
|
|
41
|
+
function decorateSuggestionDiagnostics(ls, info, typescript, logger) {
|
|
34
42
|
const getSuggestionDiagnostics = ls.getSuggestionDiagnostics;
|
|
35
43
|
ls.getSuggestionDiagnostics = (fileName) => {
|
|
36
44
|
// Diagnostics inside Svelte files are done
|
|
@@ -38,7 +46,92 @@ function decorateSuggestionDiagnostics(ls) {
|
|
|
38
46
|
if ((0, utils_1.isSvelteFilePath)(fileName)) {
|
|
39
47
|
return [];
|
|
40
48
|
}
|
|
41
|
-
|
|
49
|
+
const kitDiagnostics = getKitDiagnostics('getSuggestionDiagnostics', fileName, info, typescript, logger);
|
|
50
|
+
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSuggestionDiagnostics(fileName);
|
|
42
51
|
};
|
|
43
52
|
}
|
|
53
|
+
function getKitDiagnostics(methodName, fileName, info, ts, logger) {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts, logger);
|
|
56
|
+
if (!result)
|
|
57
|
+
return;
|
|
58
|
+
const { languageService, toOriginalPos } = result;
|
|
59
|
+
const diagnostics = [];
|
|
60
|
+
for (let diagnostic of languageService[methodName](fileName)) {
|
|
61
|
+
if (!diagnostic.start || !diagnostic.length) {
|
|
62
|
+
diagnostics.push(diagnostic);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const mapped = toOriginalPos(diagnostic.start);
|
|
66
|
+
if (mapped.inGenerated) {
|
|
67
|
+
// If not "Cannot find module './$types' .." then filter out
|
|
68
|
+
if (diagnostic.code === 2307) {
|
|
69
|
+
diagnostic = {
|
|
70
|
+
...diagnostic,
|
|
71
|
+
// adjust length so it doesn't spill over to the next line
|
|
72
|
+
length: 1,
|
|
73
|
+
messageText: typeof diagnostic.messageText === 'string' &&
|
|
74
|
+
diagnostic.messageText.includes('./$types')
|
|
75
|
+
? diagnostic.messageText +
|
|
76
|
+
` (this likely means that SvelteKit's type generation didn't run yet - try running it by executing 'npm run dev' or 'npm run build')`
|
|
77
|
+
: diagnostic.messageText
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
else if (diagnostic.code === 2694) {
|
|
81
|
+
diagnostic = {
|
|
82
|
+
...diagnostic,
|
|
83
|
+
// adjust length so it doesn't spill over to the next line
|
|
84
|
+
length: 1,
|
|
85
|
+
messageText: typeof diagnostic.messageText === 'string' &&
|
|
86
|
+
diagnostic.messageText.includes('/$types')
|
|
87
|
+
? diagnostic.messageText +
|
|
88
|
+
` (this likely means that SvelteKit's generated types are out of date - try rerunning it by executing 'npm run dev' or 'npm run build')`
|
|
89
|
+
: diagnostic.messageText
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else if (diagnostic.code === 2355) {
|
|
93
|
+
// A function whose declared type is neither 'void' nor 'any' must return a value
|
|
94
|
+
diagnostic = {
|
|
95
|
+
...diagnostic,
|
|
96
|
+
// adjust length so it doesn't spill over to the next line
|
|
97
|
+
length: 1
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
diagnostic = {
|
|
105
|
+
...diagnostic,
|
|
106
|
+
start: mapped.pos
|
|
107
|
+
};
|
|
108
|
+
diagnostics.push(diagnostic);
|
|
109
|
+
}
|
|
110
|
+
if (methodName === 'getSemanticDiagnostics') {
|
|
111
|
+
// We're in a Svelte file - check top level exports
|
|
112
|
+
// We're using the original file to have the correct position without mapping
|
|
113
|
+
const source = (_a = info.languageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
|
|
114
|
+
const basename = path_1.default.basename(fileName);
|
|
115
|
+
const validExports = Object.keys(sveltekit_1.kitExports).filter((key) => (0, sveltekit_1.isKitRouteExportAllowedIn)(basename, sveltekit_1.kitExports[key]));
|
|
116
|
+
if (source && basename.startsWith('+')) {
|
|
117
|
+
const exports = svelte2tsx_1.internalHelpers.findExports(source, /* irrelevant */ false);
|
|
118
|
+
for (const exportName of exports.keys()) {
|
|
119
|
+
if (!validExports.includes(exportName) && !exportName.startsWith('_')) {
|
|
120
|
+
const node = exports.get(exportName).node;
|
|
121
|
+
const identifier = (_b = (0, utils_1.findIdentifier)(ts, node)) !== null && _b !== void 0 ? _b : node;
|
|
122
|
+
diagnostics.push({
|
|
123
|
+
file: source,
|
|
124
|
+
start: identifier.getStart(),
|
|
125
|
+
length: identifier.getEnd() - identifier.getStart(),
|
|
126
|
+
messageText: `Invalid export '${exportName}' (valid exports are ${validExports.join(', ')}, or anything with a '_' prefix)`,
|
|
127
|
+
category: ts.DiagnosticCategory.Error,
|
|
128
|
+
code: 71001 // arbitrary
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// @ts-ignore TS doesn't get the return type right
|
|
135
|
+
return diagnostics;
|
|
136
|
+
}
|
|
44
137
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorateHover = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const sveltekit_1 = require("./sveltekit");
|
|
6
|
+
function decorateHover(ls, info, ts, logger) {
|
|
7
|
+
const getQuickInfoAtPosition = ls.getQuickInfoAtPosition;
|
|
8
|
+
ls.getQuickInfoAtPosition = (fileName, position) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
11
|
+
if (!result)
|
|
12
|
+
return getQuickInfoAtPosition(fileName, position);
|
|
13
|
+
const { languageService, toOriginalPos, toVirtualPos } = result;
|
|
14
|
+
const virtualPos = toVirtualPos(position);
|
|
15
|
+
const quickInfo = languageService.getQuickInfoAtPosition(fileName, virtualPos);
|
|
16
|
+
if (!quickInfo)
|
|
17
|
+
return quickInfo;
|
|
18
|
+
const source = (_a = languageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
|
|
19
|
+
const node = source && (0, utils_1.findNodeAtPosition)(source, virtualPos);
|
|
20
|
+
if (node && (0, utils_1.isTopLevelExport)(ts, node, source) && ts.isIdentifier(node)) {
|
|
21
|
+
const name = node.text;
|
|
22
|
+
if (name in sveltekit_1.kitExports) {
|
|
23
|
+
quickInfo.documentation = !((_b = quickInfo.documentation) === null || _b === void 0 ? void 0 : _b.length)
|
|
24
|
+
? sveltekit_1.kitExports[name].documentation
|
|
25
|
+
: quickInfo.documentation;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
...quickInfo,
|
|
30
|
+
textSpan: { ...quickInfo.textSpan, start: toOriginalPos(quickInfo.textSpan.start).pos }
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.decorateHover = decorateHover;
|
|
35
|
+
//# sourceMappingURL=hover.js.map
|
|
@@ -3,4 +3,4 @@ import { ConfigManager } from '../config-manager';
|
|
|
3
3
|
import { Logger } from '../logger';
|
|
4
4
|
import { SvelteSnapshotManager } from '../svelte-snapshots';
|
|
5
5
|
export declare function isPatched(ls: ts.LanguageService): boolean;
|
|
6
|
-
export declare function decorateLanguageService(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger, configManager: ConfigManager, typescript: typeof ts): ts.LanguageService;
|
|
6
|
+
export declare function decorateLanguageService(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger, configManager: ConfigManager, info: ts.server.PluginCreateInfo, typescript: typeof ts): ts.LanguageService;
|
|
@@ -7,7 +7,9 @@ const completions_1 = require("./completions");
|
|
|
7
7
|
const definition_1 = require("./definition");
|
|
8
8
|
const diagnostics_1 = require("./diagnostics");
|
|
9
9
|
const find_references_1 = require("./find-references");
|
|
10
|
+
const hover_1 = require("./hover");
|
|
10
11
|
const implementation_1 = require("./implementation");
|
|
12
|
+
const inlay_hints_1 = require("./inlay-hints");
|
|
11
13
|
const rename_1 = require("./rename");
|
|
12
14
|
const update_imports_1 = require("./update-imports");
|
|
13
15
|
const sveltePluginPatchSymbol = Symbol('sveltePluginPatchSymbol');
|
|
@@ -15,24 +17,26 @@ function isPatched(ls) {
|
|
|
15
17
|
return ls[sveltePluginPatchSymbol] === true;
|
|
16
18
|
}
|
|
17
19
|
exports.isPatched = isPatched;
|
|
18
|
-
function decorateLanguageService(ls, snapshotManager, logger, configManager, typescript) {
|
|
20
|
+
function decorateLanguageService(ls, snapshotManager, logger, configManager, info, typescript) {
|
|
19
21
|
// Decorate using a proxy so we can dynamically enable/disable method
|
|
20
22
|
// patches depending on the enabled state of our config
|
|
21
23
|
const proxy = new Proxy(ls, createProxyHandler(configManager));
|
|
22
|
-
decorateLanguageServiceInner(proxy, snapshotManager, logger, typescript);
|
|
24
|
+
decorateLanguageServiceInner(proxy, snapshotManager, logger, info, typescript);
|
|
23
25
|
return proxy;
|
|
24
26
|
}
|
|
25
27
|
exports.decorateLanguageService = decorateLanguageService;
|
|
26
|
-
function decorateLanguageServiceInner(ls, snapshotManager, logger, typescript) {
|
|
28
|
+
function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescript) {
|
|
27
29
|
patchLineColumnOffset(ls, snapshotManager);
|
|
28
30
|
(0, rename_1.decorateRename)(ls, snapshotManager, logger);
|
|
29
|
-
(0, diagnostics_1.decorateDiagnostics)(ls, logger);
|
|
31
|
+
(0, diagnostics_1.decorateDiagnostics)(ls, info, typescript, logger);
|
|
30
32
|
(0, find_references_1.decorateFindReferences)(ls, snapshotManager, logger);
|
|
31
|
-
(0, completions_1.decorateCompletions)(ls, typescript, logger);
|
|
32
|
-
(0, definition_1.decorateGetDefinition)(ls, snapshotManager, logger);
|
|
33
|
+
(0, completions_1.decorateCompletions)(ls, info, typescript, logger);
|
|
34
|
+
(0, definition_1.decorateGetDefinition)(ls, info, typescript, snapshotManager, logger);
|
|
33
35
|
(0, implementation_1.decorateGetImplementation)(ls, snapshotManager, logger);
|
|
34
36
|
(0, update_imports_1.decorateUpdateImports)(ls, snapshotManager, logger);
|
|
35
37
|
(0, call_hierarchy_1.decorateCallHierarchy)(ls, snapshotManager, typescript);
|
|
38
|
+
(0, hover_1.decorateHover)(ls, info, typescript, logger);
|
|
39
|
+
(0, inlay_hints_1.decorateInlayHints)(ls, info, typescript, logger);
|
|
36
40
|
return ls;
|
|
37
41
|
}
|
|
38
42
|
function createProxyHandler(configManager) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorateInlayHints = void 0;
|
|
4
|
+
const sveltekit_1 = require("./sveltekit");
|
|
5
|
+
function decorateInlayHints(ls, info, ts, logger) {
|
|
6
|
+
const provideInlayHints = ls.provideInlayHints;
|
|
7
|
+
ls.provideInlayHints = (fileName, span, preferences) => {
|
|
8
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
9
|
+
if (!result) {
|
|
10
|
+
return provideInlayHints(fileName, span, preferences);
|
|
11
|
+
}
|
|
12
|
+
const { languageService, toVirtualPos, toOriginalPos } = result;
|
|
13
|
+
return languageService
|
|
14
|
+
.provideInlayHints(fileName, {
|
|
15
|
+
start: toVirtualPos(span.start),
|
|
16
|
+
length: span.length
|
|
17
|
+
}, preferences)
|
|
18
|
+
.map((hint) => ({
|
|
19
|
+
...hint,
|
|
20
|
+
position: toOriginalPos(hint.position).pos
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.decorateInlayHints = decorateInlayHints;
|
|
25
|
+
//# sourceMappingURL=inlay-hints.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import { Logger } from '../logger';
|
|
3
|
+
import { InternalHelpers } from 'svelte2tsx';
|
|
4
|
+
type _ts = typeof ts;
|
|
5
|
+
export declare const kitExports: Record<string, {
|
|
6
|
+
displayParts: ts.SymbolDisplayPart[];
|
|
7
|
+
documentation: ts.SymbolDisplayPart[];
|
|
8
|
+
allowedIn: Array<'server' | 'universal' | 'layout' | 'page' | 'api'>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function isKitRouteExportAllowedIn(basename: string, kitExport: typeof kitExports[keyof typeof kitExports]): boolean;
|
|
11
|
+
export declare function getVirtualLS(fileName: string, info: ts.server.PluginCreateInfo, ts: _ts, logger?: Logger): {
|
|
12
|
+
languageService: ts.LanguageService;
|
|
13
|
+
addedCode: InternalHelpers.AddedCode[];
|
|
14
|
+
toVirtualPos: (pos: number) => number;
|
|
15
|
+
toOriginalPos: (pos: number) => {
|
|
16
|
+
pos: number;
|
|
17
|
+
inGenerated: boolean;
|
|
18
|
+
};
|
|
19
|
+
} | undefined;
|
|
20
|
+
export {};
|