typescript-svelte-plugin 0.3.16 → 0.3.18
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 -3
- package/dist/src/language-service/completions.d.ts +4 -2
- package/dist/src/language-service/completions.js +99 -29
- 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 +53 -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 +8 -6
- package/dist/src/language-service/sveltekit.d.ts +135 -0
- package/dist/src/language-service/sveltekit.js +567 -0
- package/dist/src/module-loader.js +3 -3
- package/dist/src/source-mapper.js +1 -1
- package/dist/src/svelte-sys.d.ts +4 -2
- package/dist/src/svelte-sys.js +6 -10
- package/dist/src/utils.d.ts +9 -0
- package/dist/src/utils.js +43 -1
- package/package.json +1 -1
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,14 +97,27 @@ 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"?
|
|
@@ -128,6 +142,25 @@ function init(modules) {
|
|
|
128
142
|
};
|
|
129
143
|
return languageService;
|
|
130
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* TypeScript doesn't load the external files in projects without a config file. So we load it by ourselves.
|
|
147
|
+
* TypeScript also seems to expect files added to the root to be opened by the client in this situation.
|
|
148
|
+
*/
|
|
149
|
+
function openSvelteTsxFileForInferredProject(project, file) {
|
|
150
|
+
const normalizedPath = modules.typescript.server.toNormalizedPath(file);
|
|
151
|
+
if (project.containsFile(normalizedPath)) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const scriptInfo = project.projectService.getOrCreateScriptInfoForNormalizedPath(normalizedPath,
|
|
155
|
+
/*openedByClient*/ true, project.readFile(file));
|
|
156
|
+
if (!scriptInfo) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!project.projectService.openFiles.has(scriptInfo.path)) {
|
|
160
|
+
project.projectService.openFiles.set(scriptInfo.path, undefined);
|
|
161
|
+
}
|
|
162
|
+
project.addRoot(scriptInfo);
|
|
163
|
+
}
|
|
131
164
|
return { create, getExternalFiles, onConfigurationChanged };
|
|
132
165
|
}
|
|
133
166
|
module.exports = init;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import ts from 'typescript/lib/tsserverlibrary';
|
|
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, info: ts.server.PluginCreateInfo, ts: _ts, logger: Logger): void;
|
|
5
|
+
export {};
|
|
@@ -1,26 +1,67 @@
|
|
|
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");
|
|
6
|
+
const sveltekit_1 = require("./sveltekit");
|
|
10
7
|
const componentPostfix = '__SvelteComponent_';
|
|
11
|
-
function decorateCompletions(ls, logger) {
|
|
8
|
+
function decorateCompletions(ls, info, ts, logger) {
|
|
12
9
|
const getCompletionsAtPosition = ls.getCompletionsAtPosition;
|
|
13
|
-
ls.getCompletionsAtPosition = (fileName, position, options) => {
|
|
14
|
-
var _a, _b, _c, _d;
|
|
15
|
-
|
|
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);
|
|
16
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).map(([key, value]) => ({
|
|
41
|
+
kind: ts.ScriptElementKind.constElement,
|
|
42
|
+
name: key,
|
|
43
|
+
labelDetails: {
|
|
44
|
+
description: value.documentation.map((d) => d.text).join('')
|
|
45
|
+
},
|
|
46
|
+
sortText: '0',
|
|
47
|
+
data: {
|
|
48
|
+
__sveltekit: key,
|
|
49
|
+
exportName: key // TS needs this
|
|
50
|
+
}
|
|
51
|
+
})),
|
|
52
|
+
isGlobalCompletion: false,
|
|
53
|
+
isMemberCompletion: false,
|
|
54
|
+
isNewIdentifierLocation: false,
|
|
55
|
+
isIncomplete: true
|
|
56
|
+
};
|
|
57
|
+
}
|
|
17
58
|
return completions;
|
|
18
59
|
}
|
|
19
60
|
// Add ./$types imports for SvelteKit since TypeScript is bad at it
|
|
20
61
|
if ((0, path_1.basename)(fileName).startsWith('+')) {
|
|
21
62
|
const $typeImports = new Map();
|
|
22
63
|
for (const c of completions.entries) {
|
|
23
|
-
if (((
|
|
64
|
+
if (((_b = c.source) === null || _b === void 0 ? void 0 : _b.includes('.svelte-kit/types')) && c.data) {
|
|
24
65
|
$typeImports.set(c.name, c);
|
|
25
66
|
}
|
|
26
67
|
}
|
|
@@ -28,7 +69,7 @@ function decorateCompletions(ls, logger) {
|
|
|
28
69
|
// resolve path from FileName to svelte-kit/types
|
|
29
70
|
// src/routes/foo/+page.svelte -> .svelte-kit/types/foo/$types.d.ts
|
|
30
71
|
const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
|
|
31
|
-
const relativeFileName = (
|
|
72
|
+
const relativeFileName = (_c = fileName.split(routesFolder)[1]) === null || _c === void 0 ? void 0 : _c.slice(1);
|
|
32
73
|
if (relativeFileName) {
|
|
33
74
|
const relativePath = (0, path_1.dirname)(relativeFileName) === '.' ? '' : `${(0, path_1.dirname)(relativeFileName)}/`;
|
|
34
75
|
const modifiedSource = $typeImport.source.split('.svelte-kit/types')[0] +
|
|
@@ -43,28 +84,14 @@ function decorateCompletions(ls, logger) {
|
|
|
43
84
|
source: modifiedSource,
|
|
44
85
|
data: {
|
|
45
86
|
...$typeImport.data,
|
|
46
|
-
fileName: (
|
|
47
|
-
moduleSpecifier: (
|
|
87
|
+
fileName: (_d = $typeImport.data.fileName) === null || _d === void 0 ? void 0 : _d.replace($typeImport.source, modifiedSource),
|
|
88
|
+
moduleSpecifier: (_e = $typeImport.data.moduleSpecifier) === null || _e === void 0 ? void 0 : _e.replace($typeImport.source, modifiedSource),
|
|
48
89
|
__is_sveltekit$typeImport: true
|
|
49
90
|
}
|
|
50
91
|
});
|
|
51
92
|
}
|
|
52
93
|
}
|
|
53
94
|
}
|
|
54
|
-
if ((0, path_1.basename)(fileName).startsWith('+page') || (0, path_1.basename)(fileName).startsWith('+layout')) {
|
|
55
|
-
if ((0, path_1.extname)(fileName) === '.js') {
|
|
56
|
-
completions.entries.push({
|
|
57
|
-
// TODO doesn't show up for "export" and "load" only at the bottom for "function"
|
|
58
|
-
kind: tsserverlibrary_1.default.ScriptElementKind.functionElement,
|
|
59
|
-
name: 'export function load() {}',
|
|
60
|
-
sortText: '-99',
|
|
61
|
-
kindModifiers: tsserverlibrary_1.default.ScriptElementKindModifier.exportedModifier,
|
|
62
|
-
insertText: `/** @type {import('./$types').Foo} */\nexport function load() {}`
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
95
|
return {
|
|
69
96
|
...completions,
|
|
70
97
|
entries: completions.entries.map((entry) => {
|
|
@@ -81,12 +108,46 @@ function decorateCompletions(ls, logger) {
|
|
|
81
108
|
};
|
|
82
109
|
const getCompletionEntryDetails = ls.getCompletionEntryDetails;
|
|
83
110
|
ls.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
|
|
84
|
-
var _a;
|
|
111
|
+
var _a, _b;
|
|
112
|
+
if (data === null || data === void 0 ? void 0 : data.__sveltekit) {
|
|
113
|
+
const key = data === null || data === void 0 ? void 0 : data.__sveltekit;
|
|
114
|
+
return {
|
|
115
|
+
name: key,
|
|
116
|
+
kind: ts.ScriptElementKind.constElement,
|
|
117
|
+
kindModifiers: ts.ScriptElementKindModifier.none,
|
|
118
|
+
displayParts: sveltekit_1.kitExports[key].displayParts,
|
|
119
|
+
documentation: sveltekit_1.kitExports[key].documentation
|
|
120
|
+
};
|
|
121
|
+
}
|
|
85
122
|
const is$typeImport = data === null || data === void 0 ? void 0 : data.__is_sveltekit$typeImport;
|
|
86
|
-
|
|
123
|
+
let details;
|
|
124
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
125
|
+
if (result) {
|
|
126
|
+
const { languageService, toVirtualPos, toOriginalPos } = result;
|
|
127
|
+
details = languageService.getCompletionEntryDetails(fileName, toVirtualPos(position), entryName, formatOptions, source, preferences, data);
|
|
128
|
+
if (details) {
|
|
129
|
+
details.codeActions = (_a = details.codeActions) === null || _a === void 0 ? void 0 : _a.map((codeAction) => {
|
|
130
|
+
codeAction.changes = codeAction.changes.map((change) => {
|
|
131
|
+
change.textChanges = change.textChanges.map((textChange) => {
|
|
132
|
+
return {
|
|
133
|
+
...textChange,
|
|
134
|
+
span: {
|
|
135
|
+
...textChange.span,
|
|
136
|
+
start: toOriginalPos(textChange.span.start).pos
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
return change;
|
|
141
|
+
});
|
|
142
|
+
return codeAction;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
details =
|
|
147
|
+
details !== null && details !== void 0 ? details : getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
|
|
87
148
|
if (details) {
|
|
88
149
|
if (is$typeImport) {
|
|
89
|
-
details.codeActions = (
|
|
150
|
+
details.codeActions = (_b = details.codeActions) === null || _b === void 0 ? void 0 : _b.map((codeAction) => {
|
|
90
151
|
codeAction.description = adjustPath(codeAction.description);
|
|
91
152
|
codeAction.changes = codeAction.changes.map((change) => {
|
|
92
153
|
change.textChanges = change.textChanges.map((textChange) => {
|
|
@@ -120,6 +181,15 @@ function decorateCompletions(ls, logger) {
|
|
|
120
181
|
logger.debug('Found Svelte Component import completion details');
|
|
121
182
|
return (0, utils_1.replaceDeep)(svelteDetails, componentPostfix, '');
|
|
122
183
|
};
|
|
184
|
+
const getSignatureHelpItems = ls.getSignatureHelpItems;
|
|
185
|
+
ls.getSignatureHelpItems = (fileName, position, options) => {
|
|
186
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
187
|
+
if (result) {
|
|
188
|
+
const { languageService, toVirtualPos } = result;
|
|
189
|
+
return languageService.getSignatureHelpItems(fileName, toVirtualPos(position), options);
|
|
190
|
+
}
|
|
191
|
+
return getSignatureHelpItems(fileName, position, options);
|
|
192
|
+
};
|
|
123
193
|
}
|
|
124
194
|
exports.decorateCompletions = decorateCompletions;
|
|
125
195
|
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;
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decorateDiagnostics = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const sveltekit_1 = require("./sveltekit");
|
|
6
|
+
function decorateDiagnostics(ls, info, typescript, logger) {
|
|
7
|
+
decorateSyntacticDiagnostics(ls, info, typescript, logger);
|
|
8
|
+
decorateSemanticDiagnostics(ls, info, typescript, logger);
|
|
9
|
+
decorateSuggestionDiagnostics(ls, info, typescript, logger);
|
|
9
10
|
}
|
|
10
11
|
exports.decorateDiagnostics = decorateDiagnostics;
|
|
11
|
-
function decorateSyntacticDiagnostics(ls) {
|
|
12
|
+
function decorateSyntacticDiagnostics(ls, info, typescript, logger) {
|
|
12
13
|
const getSyntacticDiagnostics = ls.getSyntacticDiagnostics;
|
|
13
14
|
ls.getSyntacticDiagnostics = (fileName) => {
|
|
14
15
|
// Diagnostics inside Svelte files are done
|
|
@@ -16,10 +17,11 @@ function decorateSyntacticDiagnostics(ls) {
|
|
|
16
17
|
if ((0, utils_1.isSvelteFilePath)(fileName)) {
|
|
17
18
|
return [];
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
const kitDiagnostics = getKitDiagnostics('getSyntacticDiagnostics', fileName, info, typescript, logger);
|
|
21
|
+
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSyntacticDiagnostics(fileName);
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
|
-
function decorateSemanticDiagnostics(ls) {
|
|
24
|
+
function decorateSemanticDiagnostics(ls, info, typescript, logger) {
|
|
23
25
|
const getSemanticDiagnostics = ls.getSemanticDiagnostics;
|
|
24
26
|
ls.getSemanticDiagnostics = (fileName) => {
|
|
25
27
|
// Diagnostics inside Svelte files are done
|
|
@@ -27,10 +29,11 @@ function decorateSemanticDiagnostics(ls) {
|
|
|
27
29
|
if ((0, utils_1.isSvelteFilePath)(fileName)) {
|
|
28
30
|
return [];
|
|
29
31
|
}
|
|
30
|
-
|
|
32
|
+
const kitDiagnostics = getKitDiagnostics('getSemanticDiagnostics', fileName, info, typescript, logger);
|
|
33
|
+
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSemanticDiagnostics(fileName);
|
|
31
34
|
};
|
|
32
35
|
}
|
|
33
|
-
function decorateSuggestionDiagnostics(ls) {
|
|
36
|
+
function decorateSuggestionDiagnostics(ls, info, typescript, logger) {
|
|
34
37
|
const getSuggestionDiagnostics = ls.getSuggestionDiagnostics;
|
|
35
38
|
ls.getSuggestionDiagnostics = (fileName) => {
|
|
36
39
|
// Diagnostics inside Svelte files are done
|
|
@@ -38,7 +41,47 @@ function decorateSuggestionDiagnostics(ls) {
|
|
|
38
41
|
if ((0, utils_1.isSvelteFilePath)(fileName)) {
|
|
39
42
|
return [];
|
|
40
43
|
}
|
|
41
|
-
|
|
44
|
+
const kitDiagnostics = getKitDiagnostics('getSuggestionDiagnostics', fileName, info, typescript, logger);
|
|
45
|
+
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSuggestionDiagnostics(fileName);
|
|
42
46
|
};
|
|
43
47
|
}
|
|
48
|
+
function getKitDiagnostics(methodName, fileName, info, ts, logger) {
|
|
49
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts, logger);
|
|
50
|
+
if (!result)
|
|
51
|
+
return;
|
|
52
|
+
const { languageService, toOriginalPos } = result;
|
|
53
|
+
const diagnostics = [];
|
|
54
|
+
for (let diagnostic of languageService[methodName](fileName)) {
|
|
55
|
+
if (!diagnostic.start || !diagnostic.length) {
|
|
56
|
+
diagnostics.push(diagnostic);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const mapped = toOriginalPos(diagnostic.start);
|
|
60
|
+
if (mapped.inGenerated) {
|
|
61
|
+
// If not "Cannot find module './$types' .." then filter out
|
|
62
|
+
if (diagnostic.code !== 2307) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
diagnostic = {
|
|
67
|
+
...diagnostic,
|
|
68
|
+
// adjust length so it doesn't spill over to the next line
|
|
69
|
+
length: 1,
|
|
70
|
+
messageText: typeof diagnostic.messageText === 'string' &&
|
|
71
|
+
diagnostic.messageText.includes('./$types')
|
|
72
|
+
? diagnostic.messageText +
|
|
73
|
+
` (this likely means that SvelteKit's type generation didn't run yet)`
|
|
74
|
+
: diagnostic.messageText
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
diagnostic = {
|
|
79
|
+
...diagnostic,
|
|
80
|
+
start: mapped.pos
|
|
81
|
+
};
|
|
82
|
+
diagnostics.push(diagnostic);
|
|
83
|
+
}
|
|
84
|
+
// @ts-ignore TS doesn't get the return type right
|
|
85
|
+
return diagnostics;
|
|
86
|
+
}
|
|
44
87
|
//# 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,6 +7,7 @@ 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");
|
|
11
12
|
const rename_1 = require("./rename");
|
|
12
13
|
const update_imports_1 = require("./update-imports");
|
|
@@ -15,24 +16,25 @@ function isPatched(ls) {
|
|
|
15
16
|
return ls[sveltePluginPatchSymbol] === true;
|
|
16
17
|
}
|
|
17
18
|
exports.isPatched = isPatched;
|
|
18
|
-
function decorateLanguageService(ls, snapshotManager, logger, configManager, typescript) {
|
|
19
|
+
function decorateLanguageService(ls, snapshotManager, logger, configManager, info, typescript) {
|
|
19
20
|
// Decorate using a proxy so we can dynamically enable/disable method
|
|
20
21
|
// patches depending on the enabled state of our config
|
|
21
22
|
const proxy = new Proxy(ls, createProxyHandler(configManager));
|
|
22
|
-
decorateLanguageServiceInner(proxy, snapshotManager, logger, typescript);
|
|
23
|
+
decorateLanguageServiceInner(proxy, snapshotManager, logger, info, typescript);
|
|
23
24
|
return proxy;
|
|
24
25
|
}
|
|
25
26
|
exports.decorateLanguageService = decorateLanguageService;
|
|
26
|
-
function decorateLanguageServiceInner(ls, snapshotManager, logger, typescript) {
|
|
27
|
+
function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescript) {
|
|
27
28
|
patchLineColumnOffset(ls, snapshotManager);
|
|
28
29
|
(0, rename_1.decorateRename)(ls, snapshotManager, logger);
|
|
29
|
-
(0, diagnostics_1.decorateDiagnostics)(ls, logger);
|
|
30
|
+
(0, diagnostics_1.decorateDiagnostics)(ls, info, typescript, logger);
|
|
30
31
|
(0, find_references_1.decorateFindReferences)(ls, snapshotManager, logger);
|
|
31
|
-
(0, completions_1.decorateCompletions)(ls, logger);
|
|
32
|
-
(0, definition_1.decorateGetDefinition)(ls, snapshotManager, logger);
|
|
32
|
+
(0, completions_1.decorateCompletions)(ls, info, typescript, logger);
|
|
33
|
+
(0, definition_1.decorateGetDefinition)(ls, info, typescript, snapshotManager, logger);
|
|
33
34
|
(0, implementation_1.decorateGetImplementation)(ls, snapshotManager, logger);
|
|
34
35
|
(0, update_imports_1.decorateUpdateImports)(ls, snapshotManager, logger);
|
|
35
36
|
(0, call_hierarchy_1.decorateCallHierarchy)(ls, snapshotManager, typescript);
|
|
37
|
+
(0, hover_1.decorateHover)(ls, info, typescript, logger);
|
|
36
38
|
return ls;
|
|
37
39
|
}
|
|
38
40
|
function createProxyHandler(configManager) {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import { Logger } from '../logger';
|
|
3
|
+
type _ts = typeof ts;
|
|
4
|
+
interface KitSnapshot {
|
|
5
|
+
file: ts.IScriptSnapshot;
|
|
6
|
+
version: string;
|
|
7
|
+
addedCode: Array<{
|
|
8
|
+
generatedPos: number;
|
|
9
|
+
originalPos: number;
|
|
10
|
+
length: number;
|
|
11
|
+
total: number;
|
|
12
|
+
inserted: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export declare const kitExports: {
|
|
16
|
+
prerender: {
|
|
17
|
+
displayParts: {
|
|
18
|
+
text: string;
|
|
19
|
+
kind: string;
|
|
20
|
+
}[];
|
|
21
|
+
documentation: {
|
|
22
|
+
text: string;
|
|
23
|
+
kind: string;
|
|
24
|
+
}[];
|
|
25
|
+
};
|
|
26
|
+
ssr: {
|
|
27
|
+
displayParts: {
|
|
28
|
+
text: string;
|
|
29
|
+
kind: string;
|
|
30
|
+
}[];
|
|
31
|
+
documentation: {
|
|
32
|
+
text: string;
|
|
33
|
+
kind: string;
|
|
34
|
+
}[];
|
|
35
|
+
};
|
|
36
|
+
csr: {
|
|
37
|
+
displayParts: {
|
|
38
|
+
text: string;
|
|
39
|
+
kind: string;
|
|
40
|
+
}[];
|
|
41
|
+
documentation: {
|
|
42
|
+
text: string;
|
|
43
|
+
kind: string;
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
trailingSlash: {
|
|
47
|
+
displayParts: {
|
|
48
|
+
text: string;
|
|
49
|
+
kind: string;
|
|
50
|
+
}[];
|
|
51
|
+
documentation: {
|
|
52
|
+
text: string;
|
|
53
|
+
kind: string;
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
config: {
|
|
57
|
+
displayParts: {
|
|
58
|
+
text: string;
|
|
59
|
+
kind: string;
|
|
60
|
+
}[];
|
|
61
|
+
documentation: {
|
|
62
|
+
text: string;
|
|
63
|
+
kind: string;
|
|
64
|
+
}[];
|
|
65
|
+
};
|
|
66
|
+
actions: {
|
|
67
|
+
displayParts: {
|
|
68
|
+
text: string;
|
|
69
|
+
kind: string;
|
|
70
|
+
}[];
|
|
71
|
+
documentation: {
|
|
72
|
+
text: string;
|
|
73
|
+
kind: string;
|
|
74
|
+
}[];
|
|
75
|
+
};
|
|
76
|
+
load: {
|
|
77
|
+
displayParts: {
|
|
78
|
+
text: string;
|
|
79
|
+
kind: string;
|
|
80
|
+
}[];
|
|
81
|
+
documentation: {
|
|
82
|
+
text: string;
|
|
83
|
+
kind: string;
|
|
84
|
+
}[];
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export declare function getProxiedLanguageService(info: ts.server.PluginCreateInfo, ts: _ts, logger?: Logger): {
|
|
88
|
+
languageService: ts.LanguageService;
|
|
89
|
+
languageServiceHost: ts.LanguageServiceHost & {
|
|
90
|
+
getKitScriptSnapshotIfUpToDate: (fileName: string) => KitSnapshot | undefined;
|
|
91
|
+
upsertKitFile: (fileName: string) => void;
|
|
92
|
+
};
|
|
93
|
+
} | {
|
|
94
|
+
languageService: ts.LanguageService;
|
|
95
|
+
languageServiceHost: {
|
|
96
|
+
files: Record<string, KitSnapshot>;
|
|
97
|
+
log(): void;
|
|
98
|
+
trace(): void;
|
|
99
|
+
error(): void;
|
|
100
|
+
getCompilationSettings(): ts.CompilerOptions;
|
|
101
|
+
getScriptIsOpen(): boolean;
|
|
102
|
+
getCurrentDirectory(): string;
|
|
103
|
+
getDefaultLibFileName(o: any): string;
|
|
104
|
+
resolveModuleNames: ((...args: any[]) => (ts.ResolvedModule | undefined)[]) | undefined;
|
|
105
|
+
resolveModuleNameLiterals: ((...args: any[]) => readonly ts.ResolvedModuleWithFailedLookupLocations[]) | undefined;
|
|
106
|
+
getScriptVersion(fileName: string): string;
|
|
107
|
+
getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined;
|
|
108
|
+
getScriptFileNames(): string[];
|
|
109
|
+
getKitScriptSnapshotIfUpToDate(fileName: string): KitSnapshot | undefined;
|
|
110
|
+
upsertKitFile(fileName: string): KitSnapshot | undefined;
|
|
111
|
+
readFile(fileName: string): string | undefined;
|
|
112
|
+
fileExists(fileName: string): boolean;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export declare function getVirtualLS(fileName: string, info: ts.server.PluginCreateInfo, ts: _ts, logger?: Logger): {
|
|
116
|
+
languageService: ts.LanguageService;
|
|
117
|
+
addedCode: {
|
|
118
|
+
generatedPos: number;
|
|
119
|
+
originalPos: number;
|
|
120
|
+
length: number;
|
|
121
|
+
total: number;
|
|
122
|
+
inserted: string;
|
|
123
|
+
}[];
|
|
124
|
+
toVirtualPos: (pos: number) => number;
|
|
125
|
+
toOriginalPos: (pos: number) => {
|
|
126
|
+
pos: number;
|
|
127
|
+
inGenerated: boolean;
|
|
128
|
+
};
|
|
129
|
+
} | undefined;
|
|
130
|
+
export declare function toVirtualPos(pos: number, addedCode: KitSnapshot['addedCode']): number;
|
|
131
|
+
export declare function toOriginalPos(pos: number, addedCode: KitSnapshot['addedCode']): {
|
|
132
|
+
pos: number;
|
|
133
|
+
inGenerated: boolean;
|
|
134
|
+
};
|
|
135
|
+
export {};
|