typescript-svelte-plugin 0.3.24 → 0.3.26
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/LICENSE +7 -0
- package/dist/src/index.js +17 -28
- package/dist/src/language-service/call-hierarchy.js +16 -21
- package/dist/src/language-service/completions.js +13 -14
- package/dist/src/language-service/definition.js +4 -4
- package/dist/src/language-service/diagnostics.js +5 -6
- package/dist/src/language-service/find-references.js +5 -6
- package/dist/src/language-service/host.js +1 -2
- package/dist/src/language-service/hover.js +2 -3
- package/dist/src/language-service/implementation.js +7 -5
- package/dist/src/language-service/index.d.ts +2 -2
- package/dist/src/language-service/index.js +20 -13
- package/dist/src/language-service/sveltekit.js +7 -7
- package/dist/src/language-service/update-imports.js +4 -2
- package/dist/src/module-loader.js +7 -8
- package/dist/src/project-svelte-files.d.ts +4 -2
- package/dist/src/project-svelte-files.js +34 -21
- package/dist/src/svelte-snapshots.js +1 -2
- package/dist/src/svelte-sys.js +1 -1
- package/dist/src/utils.js +4 -5
- package/package.json +7 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2020-Present [these people](https://github.com/sveltejs/language-tools/graphs/contributors)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/src/index.js
CHANGED
|
@@ -11,15 +11,14 @@ function init(modules) {
|
|
|
11
11
|
const configManager = new config_manager_1.ConfigManager();
|
|
12
12
|
let resolvedSvelteTsxFiles;
|
|
13
13
|
function create(info) {
|
|
14
|
-
var _a, _b, _c, _d;
|
|
15
14
|
const logger = new logger_1.Logger(info.project.projectService.logger);
|
|
16
15
|
if (!isSvelteProject(info.project.getCompilerOptions())) {
|
|
17
16
|
logger.log('Detected that this is not a Svelte project, abort patching TypeScript');
|
|
18
17
|
return info.languageService;
|
|
19
18
|
}
|
|
20
|
-
if ((0, language_service_1.isPatched)(info.
|
|
19
|
+
if ((0, language_service_1.isPatched)(info.project)) {
|
|
21
20
|
logger.log('Already patched. Checking tsconfig updates.');
|
|
22
|
-
|
|
21
|
+
project_svelte_files_1.ProjectSvelteFilesManager.getInstance(info.project.getProjectName())?.updateProjectConfig(info.languageServiceHost);
|
|
23
22
|
return info.languageService;
|
|
24
23
|
}
|
|
25
24
|
configManager.updateConfigFromPluginConfig(info.config);
|
|
@@ -32,7 +31,7 @@ function init(modules) {
|
|
|
32
31
|
}
|
|
33
32
|
// This call the ConfiguredProject.getParsedCommandLine
|
|
34
33
|
// where it'll try to load the cached version of the parsedCommandLine
|
|
35
|
-
const parsedCommandLine =
|
|
34
|
+
const parsedCommandLine = info.languageServiceHost.getParsedCommandLine?.((0, utils_1.getConfigPathForProject)(info.project));
|
|
36
35
|
// For some reason it's no longer enough to patch this at the projectService level, so we do it here, too
|
|
37
36
|
// TODO investigate if we can use the script snapshot for all Svelte files, too, enabling Svelte file
|
|
38
37
|
// updates getting picked up without a file save - move this logic into the snapshot manager then?
|
|
@@ -73,12 +72,12 @@ function init(modules) {
|
|
|
73
72
|
}
|
|
74
73
|
return getScriptSnapshot(fileName);
|
|
75
74
|
};
|
|
76
|
-
const svelteOptions =
|
|
75
|
+
const svelteOptions = parsedCommandLine?.raw?.svelteOptions || { namespace: 'svelteHTML' };
|
|
77
76
|
logger.log('svelteOptions:', svelteOptions);
|
|
78
|
-
logger.debug(parsedCommandLine
|
|
77
|
+
logger.debug(parsedCommandLine?.wildcardDirectories);
|
|
79
78
|
const snapshotManager = new svelte_snapshots_1.SvelteSnapshotManager(modules.typescript, info.project.projectService, svelteOptions, logger, configManager);
|
|
80
79
|
const projectSvelteFilesManager = parsedCommandLine
|
|
81
|
-
? new project_svelte_files_1.ProjectSvelteFilesManager(modules.typescript, info.project, info.serverHost, snapshotManager, parsedCommandLine, configManager)
|
|
80
|
+
? new project_svelte_files_1.ProjectSvelteFilesManager(modules.typescript, info.project, info.serverHost, snapshotManager, logger, parsedCommandLine, configManager)
|
|
82
81
|
: undefined;
|
|
83
82
|
(0, module_loader_1.patchModuleLoader)(logger, snapshotManager, modules.typescript, info.languageServiceHost, info.project, configManager);
|
|
84
83
|
configManager.onConfigurationChanged(() => {
|
|
@@ -91,35 +90,33 @@ function init(modules) {
|
|
|
91
90
|
info.project.updateGraph();
|
|
92
91
|
}
|
|
93
92
|
});
|
|
94
|
-
return
|
|
95
|
-
dispose() { }
|
|
96
|
-
});
|
|
93
|
+
return (0, language_service_1.decorateLanguageService)(info.languageService, snapshotManager, logger, configManager, info, modules.typescript, () => projectSvelteFilesManager?.dispose());
|
|
97
94
|
}
|
|
98
95
|
function getExternalFiles(project) {
|
|
99
|
-
var _a, _b;
|
|
100
96
|
if (!isSvelteProject(project.getCompilerOptions()) || !configManager.getConfig().enable) {
|
|
101
97
|
return [];
|
|
102
98
|
}
|
|
99
|
+
const configFilePath = project.getCompilerOptions().configFilePath;
|
|
103
100
|
// Needed so the ambient definitions are known inside the tsx files
|
|
104
|
-
const svelteTsxFiles = resolveSvelteTsxFiles();
|
|
105
|
-
if (!
|
|
101
|
+
const svelteTsxFiles = resolveSvelteTsxFiles(typeof configFilePath === 'string' ? configFilePath : undefined);
|
|
102
|
+
if (!configFilePath) {
|
|
106
103
|
svelteTsxFiles.forEach((file) => {
|
|
107
104
|
openSvelteTsxFileForInferredProject(project, file);
|
|
108
105
|
});
|
|
109
106
|
}
|
|
110
107
|
// let ts know project svelte files to do its optimization
|
|
111
|
-
return svelteTsxFiles.concat(
|
|
108
|
+
return svelteTsxFiles.concat(project_svelte_files_1.ProjectSvelteFilesManager.getInstance(project.getProjectName())?.getFiles() ?? []);
|
|
112
109
|
}
|
|
113
|
-
function resolveSvelteTsxFiles() {
|
|
110
|
+
function resolveSvelteTsxFiles(configFilePath) {
|
|
114
111
|
if (resolvedSvelteTsxFiles) {
|
|
115
112
|
return resolvedSvelteTsxFiles;
|
|
116
113
|
}
|
|
117
114
|
const svelteTsPath = (0, path_1.dirname)(require.resolve('svelte2tsx'));
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
'./svelte-native-jsx.d.ts'
|
|
122
|
-
|
|
115
|
+
const sveltePath = require.resolve('svelte/compiler', configFilePath ? { paths: [configFilePath] } : undefined);
|
|
116
|
+
const VERSION = require(sveltePath).VERSION;
|
|
117
|
+
const svelteTsxFiles = (VERSION.split('.')[0] === '3'
|
|
118
|
+
? ['./svelte-shims.d.ts', './svelte-jsx.d.ts', './svelte-native-jsx.d.ts']
|
|
119
|
+
: ['./svelte-shims-v4.d.ts', './svelte-jsx-v4.d.ts', './svelte-native-jsx.d.ts']).map((f) => modules.typescript.sys.resolvePath((0, path_1.resolve)(svelteTsPath, f)));
|
|
123
120
|
resolvedSvelteTsxFiles = svelteTsxFiles;
|
|
124
121
|
return svelteTsxFiles;
|
|
125
122
|
}
|
|
@@ -130,14 +127,6 @@ function init(modules) {
|
|
|
130
127
|
function onConfigurationChanged(config) {
|
|
131
128
|
configManager.updateConfigFromPluginConfig(config);
|
|
132
129
|
}
|
|
133
|
-
function decorateLanguageServiceDispose(languageService, disposable) {
|
|
134
|
-
const dispose = languageService.dispose;
|
|
135
|
-
languageService.dispose = () => {
|
|
136
|
-
disposable.dispose();
|
|
137
|
-
dispose();
|
|
138
|
-
};
|
|
139
|
-
return languageService;
|
|
140
|
-
}
|
|
141
130
|
/**
|
|
142
131
|
* TypeScript doesn't load the external files in projects without a config file. So we load it by ourselves.
|
|
143
132
|
* TypeScript also seems to expect files added to the root to be opened by the client in this situation.
|
|
@@ -9,7 +9,6 @@ function decorateCallHierarchy(ls, snapshotManager, typescript) {
|
|
|
9
9
|
const provideCallHierarchyIncomingCalls = ls.provideCallHierarchyIncomingCalls;
|
|
10
10
|
const provideCallHierarchyOutgoingCalls = ls.provideCallHierarchyOutgoingCalls;
|
|
11
11
|
ls.provideCallHierarchyIncomingCalls = (fileName, position) => {
|
|
12
|
-
var _a;
|
|
13
12
|
const program = ls.getProgram();
|
|
14
13
|
// probably won't happen
|
|
15
14
|
if (!program) {
|
|
@@ -39,24 +38,21 @@ function decorateCallHierarchy(ls, snapshotManager, typescript) {
|
|
|
39
38
|
fromSpans: fromSpans
|
|
40
39
|
};
|
|
41
40
|
})
|
|
42
|
-
.concat(
|
|
41
|
+
.concat(getInComingCallsForComponent(ls, program, fileName, redirectedPosition) ?? [])
|
|
43
42
|
.filter(utils_1.isNotNullOrUndefined);
|
|
44
43
|
};
|
|
45
44
|
ls.provideCallHierarchyOutgoingCalls = (fileName, position) => {
|
|
46
|
-
var _a, _b, _c;
|
|
47
45
|
const program = ls.getProgram();
|
|
48
46
|
// probably won't happen
|
|
49
47
|
if (!program) {
|
|
50
48
|
return provideCallHierarchyOutgoingCalls(fileName, position);
|
|
51
49
|
}
|
|
52
|
-
const sourceFile = program
|
|
50
|
+
const sourceFile = program?.getSourceFile(fileName);
|
|
53
51
|
const renderFunctionOffset = isComponentModulePosition(fileName, position) && sourceFile
|
|
54
|
-
?
|
|
55
|
-
.find((statement) =>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
((_a = statement.name) === null || _a === void 0 ? void 0 : _a.getText()) === 'render';
|
|
59
|
-
})) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.getStart()
|
|
52
|
+
? sourceFile.statements
|
|
53
|
+
.find((statement) => typescript.isFunctionDeclaration(statement) &&
|
|
54
|
+
statement.name?.getText() === 'render')
|
|
55
|
+
?.name?.getStart()
|
|
60
56
|
: -1;
|
|
61
57
|
const offset = renderFunctionOffset != null && renderFunctionOffset >= 0
|
|
62
58
|
? renderFunctionOffset
|
|
@@ -64,7 +60,7 @@ function decorateCallHierarchy(ls, snapshotManager, typescript) {
|
|
|
64
60
|
const snapshot = snapshotManager.get(fileName);
|
|
65
61
|
return provideCallHierarchyOutgoingCalls(fileName, offset)
|
|
66
62
|
.concat(program && sourceFile && isComponentModulePosition(fileName, position)
|
|
67
|
-
?
|
|
63
|
+
? getOutgoingCallsForComponent(program, sourceFile) ?? []
|
|
68
64
|
: [])
|
|
69
65
|
.map((item) => {
|
|
70
66
|
const to = convertSvelteCallHierarchyItem(item.to, program);
|
|
@@ -146,12 +142,13 @@ function decorateCallHierarchy(ls, snapshotManager, typescript) {
|
|
|
146
142
|
};
|
|
147
143
|
}
|
|
148
144
|
function getInComingCallsForComponent(ls, program, fileName, position) {
|
|
149
|
-
var _a, _b;
|
|
150
145
|
if (!(0, utils_1.isSvelteFilePath)(fileName)) {
|
|
151
146
|
return null;
|
|
152
147
|
}
|
|
153
|
-
return (
|
|
154
|
-
.findReferences(fileName, position)
|
|
148
|
+
return (ls
|
|
149
|
+
.findReferences(fileName, position)
|
|
150
|
+
?.map((ref) => componentRefToIncomingCall(ref, program))
|
|
151
|
+
.filter(utils_1.isNotNullOrUndefined) ?? null);
|
|
155
152
|
}
|
|
156
153
|
function componentRefToIncomingCall(ref, program) {
|
|
157
154
|
const snapshot = (0, utils_1.isSvelteFilePath)(ref.definition.fileName) &&
|
|
@@ -189,14 +186,13 @@ function decorateCallHierarchy(ls, snapshotManager, typescript) {
|
|
|
189
186
|
node === node.parent.arguments[0]);
|
|
190
187
|
}
|
|
191
188
|
function getOutgoingCallsForComponent(program, sourceFile) {
|
|
192
|
-
var _a, _b, _c, _d;
|
|
193
189
|
const groups = new Map();
|
|
194
190
|
const startTags = (0, utils_1.gatherDescendants)(sourceFile, isComponentStartTag);
|
|
195
191
|
const typeChecker = program.getTypeChecker();
|
|
196
192
|
for (const startTag of startTags) {
|
|
197
193
|
const type = typeChecker.getTypeAtLocation(startTag);
|
|
198
|
-
const symbol =
|
|
199
|
-
const declaration =
|
|
194
|
+
const symbol = type.aliasSymbol ?? type.symbol;
|
|
195
|
+
const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
|
|
200
196
|
if (!declaration || !typescript.isClassDeclaration(declaration)) {
|
|
201
197
|
continue;
|
|
202
198
|
}
|
|
@@ -207,10 +203,9 @@ function decorateCallHierarchy(ls, snapshotManager, typescript) {
|
|
|
207
203
|
}
|
|
208
204
|
group.push({ start: startTag.getStart(), length: startTag.getWidth() });
|
|
209
205
|
}
|
|
210
|
-
return (
|
|
211
|
-
var _a, _b;
|
|
206
|
+
return (Array.from(groups).map(([declaration, group]) => {
|
|
212
207
|
const file = declaration.getSourceFile().fileName;
|
|
213
|
-
const name =
|
|
208
|
+
const name = declaration.name?.getText() ?? file.slice(file.lastIndexOf('.'));
|
|
214
209
|
const span = { start: declaration.getStart(), length: declaration.getWidth() };
|
|
215
210
|
const selectionSpan = declaration.name
|
|
216
211
|
? { start: declaration.name.getStart(), length: declaration.name.getWidth() }
|
|
@@ -225,7 +220,7 @@ function decorateCallHierarchy(ls, snapshotManager, typescript) {
|
|
|
225
220
|
},
|
|
226
221
|
fromSpans: group
|
|
227
222
|
};
|
|
228
|
-
})
|
|
223
|
+
}) ?? null);
|
|
229
224
|
}
|
|
230
225
|
}
|
|
231
226
|
exports.decorateCallHierarchy = decorateCallHierarchy;
|
|
@@ -8,7 +8,6 @@ const componentPostfix = '__SvelteComponent_';
|
|
|
8
8
|
function decorateCompletions(ls, info, ts, logger) {
|
|
9
9
|
const getCompletionsAtPosition = ls.getCompletionsAtPosition;
|
|
10
10
|
ls.getCompletionsAtPosition = (fileName, position, options, settings) => {
|
|
11
|
-
var _a, _b, _c, _d, _e;
|
|
12
11
|
let completions;
|
|
13
12
|
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
14
13
|
if (result) {
|
|
@@ -30,10 +29,10 @@ function decorateCompletions(ls, info, ts, logger) {
|
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
completions =
|
|
33
|
-
completions
|
|
32
|
+
completions ?? getCompletionsAtPosition(fileName, position, options, settings);
|
|
34
33
|
if (!completions) {
|
|
35
34
|
// No completions hints at a top level export in the making
|
|
36
|
-
const source =
|
|
35
|
+
const source = ls.getProgram()?.getSourceFile(fileName);
|
|
37
36
|
const node = source && (0, utils_1.findNodeAtPosition)(source, position);
|
|
38
37
|
if (node && (0, utils_1.isTopLevelExport)(ts, node, source)) {
|
|
39
38
|
return {
|
|
@@ -63,7 +62,7 @@ function decorateCompletions(ls, info, ts, logger) {
|
|
|
63
62
|
if ((0, path_1.basename)(fileName).startsWith('+')) {
|
|
64
63
|
const $typeImports = new Map();
|
|
65
64
|
for (const c of completions.entries) {
|
|
66
|
-
if (
|
|
65
|
+
if (c.source?.includes('.svelte-kit/types') && c.data) {
|
|
67
66
|
$typeImports.set(c.name, c);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
@@ -71,7 +70,7 @@ function decorateCompletions(ls, info, ts, logger) {
|
|
|
71
70
|
// resolve path from FileName to svelte-kit/types
|
|
72
71
|
// src/routes/foo/+page.svelte -> .svelte-kit/types/foo/$types.d.ts
|
|
73
72
|
const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
|
|
74
|
-
const relativeFileName =
|
|
73
|
+
const relativeFileName = fileName.split(routesFolder)[1]?.slice(1);
|
|
75
74
|
if (relativeFileName) {
|
|
76
75
|
const relativePath = (0, path_1.dirname)(relativeFileName) === '.' ? '' : `${(0, path_1.dirname)(relativeFileName)}/`;
|
|
77
76
|
const modifiedSource = $typeImport.source.split('.svelte-kit/types')[0] +
|
|
@@ -86,8 +85,8 @@ function decorateCompletions(ls, info, ts, logger) {
|
|
|
86
85
|
source: modifiedSource,
|
|
87
86
|
data: {
|
|
88
87
|
...$typeImport.data,
|
|
89
|
-
fileName:
|
|
90
|
-
moduleSpecifier:
|
|
88
|
+
fileName: $typeImport.data.fileName?.replace($typeImport.source, modifiedSource),
|
|
89
|
+
moduleSpecifier: $typeImport.data.moduleSpecifier?.replace($typeImport.source, modifiedSource),
|
|
91
90
|
__is_sveltekit$typeImport: true
|
|
92
91
|
}
|
|
93
92
|
});
|
|
@@ -110,9 +109,8 @@ function decorateCompletions(ls, info, ts, logger) {
|
|
|
110
109
|
};
|
|
111
110
|
const getCompletionEntryDetails = ls.getCompletionEntryDetails;
|
|
112
111
|
ls.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const key = data === null || data === void 0 ? void 0 : data.__sveltekit;
|
|
112
|
+
if (data?.__sveltekit) {
|
|
113
|
+
const key = data?.__sveltekit;
|
|
116
114
|
return {
|
|
117
115
|
name: key,
|
|
118
116
|
kind: ts.ScriptElementKind.constElement,
|
|
@@ -121,14 +119,14 @@ function decorateCompletions(ls, info, ts, logger) {
|
|
|
121
119
|
documentation: sveltekit_1.kitExports[key].documentation
|
|
122
120
|
};
|
|
123
121
|
}
|
|
124
|
-
const is$typeImport = data
|
|
122
|
+
const is$typeImport = data?.__is_sveltekit$typeImport;
|
|
125
123
|
let details;
|
|
126
124
|
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
127
125
|
if (result) {
|
|
128
126
|
const { languageService, toVirtualPos, toOriginalPos } = result;
|
|
129
127
|
details = languageService.getCompletionEntryDetails(fileName, toVirtualPos(position), entryName, formatOptions, source, preferences, data);
|
|
130
128
|
if (details) {
|
|
131
|
-
details.codeActions =
|
|
129
|
+
details.codeActions = details.codeActions?.map((codeAction) => {
|
|
132
130
|
codeAction.changes = codeAction.changes.map((change) => {
|
|
133
131
|
change.textChanges = change.textChanges.map((textChange) => {
|
|
134
132
|
return {
|
|
@@ -146,10 +144,11 @@ function decorateCompletions(ls, info, ts, logger) {
|
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
146
|
details =
|
|
149
|
-
details
|
|
147
|
+
details ??
|
|
148
|
+
getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
|
|
150
149
|
if (details) {
|
|
151
150
|
if (is$typeImport) {
|
|
152
|
-
details.codeActions =
|
|
151
|
+
details.codeActions = details.codeActions?.map((codeAction) => {
|
|
153
152
|
codeAction.description = adjustPath(codeAction.description);
|
|
154
153
|
codeAction.changes = codeAction.changes.map((change) => {
|
|
155
154
|
change.textChanges = change.textChanges.map((textChange) => {
|
|
@@ -7,19 +7,19 @@ function decorateGetDefinition(ls, info, ts, snapshotManager, logger) {
|
|
|
7
7
|
const getDefinitionAndBoundSpan = ls.getDefinitionAndBoundSpan;
|
|
8
8
|
ls.getDefinitionAndBoundSpan = (fileName, position) => {
|
|
9
9
|
const definition = getDefinitionAndBoundSpan(fileName, position);
|
|
10
|
-
if (!
|
|
10
|
+
if (!definition?.definitions) {
|
|
11
11
|
return getKitDefinitions(ts, info, fileName, position);
|
|
12
12
|
}
|
|
13
13
|
return {
|
|
14
14
|
...definition,
|
|
15
15
|
definitions: definition.definitions
|
|
16
16
|
.map((def) => {
|
|
17
|
-
var _a;
|
|
18
17
|
if (!(0, utils_1.isSvelteFilePath)(def.fileName)) {
|
|
19
18
|
return def;
|
|
20
19
|
}
|
|
21
|
-
let textSpan =
|
|
22
|
-
.get(def.fileName)
|
|
20
|
+
let textSpan = snapshotManager
|
|
21
|
+
.get(def.fileName)
|
|
22
|
+
?.getOriginalTextSpan(def.textSpan);
|
|
23
23
|
if (!textSpan) {
|
|
24
24
|
// Unmapped positions are for example the default export.
|
|
25
25
|
// Fall back to the start of the file to at least go to the correct file.
|
|
@@ -23,7 +23,7 @@ function decorateSyntacticDiagnostics(ls, info, typescript, logger) {
|
|
|
23
23
|
return [];
|
|
24
24
|
}
|
|
25
25
|
const kitDiagnostics = getKitDiagnostics('getSyntacticDiagnostics', fileName, info, typescript, logger);
|
|
26
|
-
return kitDiagnostics
|
|
26
|
+
return kitDiagnostics ?? getSyntacticDiagnostics(fileName);
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
function decorateSemanticDiagnostics(ls, info, typescript, logger) {
|
|
@@ -35,7 +35,7 @@ function decorateSemanticDiagnostics(ls, info, typescript, logger) {
|
|
|
35
35
|
return [];
|
|
36
36
|
}
|
|
37
37
|
const kitDiagnostics = getKitDiagnostics('getSemanticDiagnostics', fileName, info, typescript, logger);
|
|
38
|
-
return kitDiagnostics
|
|
38
|
+
return kitDiagnostics ?? getSemanticDiagnostics(fileName);
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
function decorateSuggestionDiagnostics(ls, info, typescript, logger) {
|
|
@@ -47,11 +47,10 @@ function decorateSuggestionDiagnostics(ls, info, typescript, logger) {
|
|
|
47
47
|
return [];
|
|
48
48
|
}
|
|
49
49
|
const kitDiagnostics = getKitDiagnostics('getSuggestionDiagnostics', fileName, info, typescript, logger);
|
|
50
|
-
return kitDiagnostics
|
|
50
|
+
return kitDiagnostics ?? getSuggestionDiagnostics(fileName);
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
function getKitDiagnostics(methodName, fileName, info, ts, logger) {
|
|
54
|
-
var _a, _b;
|
|
55
54
|
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts, logger);
|
|
56
55
|
if (!result)
|
|
57
56
|
return;
|
|
@@ -110,7 +109,7 @@ function getKitDiagnostics(methodName, fileName, info, ts, logger) {
|
|
|
110
109
|
if (methodName === 'getSemanticDiagnostics') {
|
|
111
110
|
// We're in a Svelte file - check top level exports
|
|
112
111
|
// We're using the original file to have the correct position without mapping
|
|
113
|
-
const source =
|
|
112
|
+
const source = info.languageService.getProgram()?.getSourceFile(fileName);
|
|
114
113
|
const basename = path_1.default.basename(fileName);
|
|
115
114
|
const validExports = Object.keys(sveltekit_1.kitExports).filter((key) => (0, sveltekit_1.isKitRouteExportAllowedIn)(basename, sveltekit_1.kitExports[key]));
|
|
116
115
|
if (source && basename.startsWith('+')) {
|
|
@@ -118,7 +117,7 @@ function getKitDiagnostics(methodName, fileName, info, ts, logger) {
|
|
|
118
117
|
for (const exportName of exports.keys()) {
|
|
119
118
|
if (!validExports.includes(exportName) && !exportName.startsWith('_')) {
|
|
120
119
|
const node = exports.get(exportName).node;
|
|
121
|
-
const identifier = (
|
|
120
|
+
const identifier = (0, utils_1.findIdentifier)(ts, node) ?? node;
|
|
122
121
|
diagnostics.push({
|
|
123
122
|
file: source,
|
|
124
123
|
start: identifier.getStart(),
|
|
@@ -9,13 +9,11 @@ function decorateFindReferences(ls, snapshotManager, logger) {
|
|
|
9
9
|
exports.decorateFindReferences = decorateFindReferences;
|
|
10
10
|
function _decorateFindReferences(ls, snapshotManager, logger) {
|
|
11
11
|
const findReferences = ls.findReferences;
|
|
12
|
-
const getReferences = (fileName, position) =>
|
|
13
|
-
var _a;
|
|
14
|
-
return (_a = findReferences(fileName, position)) === null || _a === void 0 ? void 0 : _a.reduce((acc, curr) => acc.concat(curr.references), []);
|
|
15
|
-
};
|
|
12
|
+
const getReferences = (fileName, position) => findReferences(fileName, position)?.reduce((acc, curr) => acc.concat(curr.references), []);
|
|
16
13
|
ls.findReferences = (fileName, position) => {
|
|
17
14
|
const references = findReferences(fileName, position);
|
|
18
|
-
return references
|
|
15
|
+
return references
|
|
16
|
+
?.map((reference) => {
|
|
19
17
|
const snapshot = snapshotManager.get(reference.definition.fileName);
|
|
20
18
|
if (!(0, utils_1.isSvelteFilePath)(reference.definition.fileName) || !snapshot) {
|
|
21
19
|
return {
|
|
@@ -36,7 +34,8 @@ function _decorateFindReferences(ls, snapshotManager, logger) {
|
|
|
36
34
|
},
|
|
37
35
|
references: mapReferences(reference.references, snapshotManager, logger, getReferences)
|
|
38
36
|
};
|
|
39
|
-
})
|
|
37
|
+
})
|
|
38
|
+
.filter(utils_1.isNotNullOrUndefined);
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
function decorateGetReferencesAtPosition(ls, snapshotManager, logger) {
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decorateLanguageServiceHost = void 0;
|
|
4
4
|
function decorateLanguageServiceHost(host) {
|
|
5
|
-
|
|
6
|
-
const originalReadDirectory = (_a = host.readDirectory) === null || _a === void 0 ? void 0 : _a.bind(host);
|
|
5
|
+
const originalReadDirectory = host.readDirectory?.bind(host);
|
|
7
6
|
host.readDirectory = originalReadDirectory
|
|
8
7
|
? (path, extensions, exclude, include, depth) => {
|
|
9
8
|
const extensionsWithSvelte = extensions ? [...extensions, '.svelte'] : undefined;
|
|
@@ -6,7 +6,6 @@ const sveltekit_1 = require("./sveltekit");
|
|
|
6
6
|
function decorateHover(ls, info, ts, logger) {
|
|
7
7
|
const getQuickInfoAtPosition = ls.getQuickInfoAtPosition;
|
|
8
8
|
ls.getQuickInfoAtPosition = (fileName, position) => {
|
|
9
|
-
var _a, _b;
|
|
10
9
|
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
11
10
|
if (!result)
|
|
12
11
|
return getQuickInfoAtPosition(fileName, position);
|
|
@@ -15,12 +14,12 @@ function decorateHover(ls, info, ts, logger) {
|
|
|
15
14
|
const quickInfo = languageService.getQuickInfoAtPosition(fileName, virtualPos);
|
|
16
15
|
if (!quickInfo)
|
|
17
16
|
return quickInfo;
|
|
18
|
-
const source =
|
|
17
|
+
const source = languageService.getProgram()?.getSourceFile(fileName);
|
|
19
18
|
const node = source && (0, utils_1.findNodeAtPosition)(source, virtualPos);
|
|
20
19
|
if (node && (0, utils_1.isTopLevelExport)(ts, node, source) && ts.isIdentifier(node)) {
|
|
21
20
|
const name = node.text;
|
|
22
21
|
if (name in sveltekit_1.kitExports) {
|
|
23
|
-
quickInfo.documentation = !
|
|
22
|
+
quickInfo.documentation = !quickInfo.documentation?.length
|
|
24
23
|
? sveltekit_1.kitExports[name].documentation
|
|
25
24
|
: quickInfo.documentation;
|
|
26
25
|
}
|
|
@@ -6,13 +6,14 @@ function decorateGetImplementation(ls, snapshotManager, logger) {
|
|
|
6
6
|
const getImplementationAtPosition = ls.getImplementationAtPosition;
|
|
7
7
|
ls.getImplementationAtPosition = (fileName, position) => {
|
|
8
8
|
const implementation = getImplementationAtPosition(fileName, position);
|
|
9
|
-
return implementation
|
|
10
|
-
|
|
9
|
+
return implementation
|
|
10
|
+
?.map((impl) => {
|
|
11
11
|
if (!(0, utils_1.isSvelteFilePath)(impl.fileName)) {
|
|
12
12
|
return impl;
|
|
13
13
|
}
|
|
14
|
-
const textSpan =
|
|
15
|
-
.get(impl.fileName)
|
|
14
|
+
const textSpan = snapshotManager
|
|
15
|
+
.get(impl.fileName)
|
|
16
|
+
?.getOriginalTextSpan(impl.textSpan);
|
|
16
17
|
if (!textSpan) {
|
|
17
18
|
return undefined;
|
|
18
19
|
}
|
|
@@ -24,7 +25,8 @@ function decorateGetImplementation(ls, snapshotManager, logger) {
|
|
|
24
25
|
originalTextSpan: undefined,
|
|
25
26
|
originalContextSpan: undefined
|
|
26
27
|
};
|
|
27
|
-
})
|
|
28
|
+
})
|
|
29
|
+
.filter(utils_1.isNotNullOrUndefined);
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
exports.decorateGetImplementation = decorateGetImplementation;
|
|
@@ -2,5 +2,5 @@ import type ts from 'typescript/lib/tsserverlibrary';
|
|
|
2
2
|
import { ConfigManager } from '../config-manager';
|
|
3
3
|
import { Logger } from '../logger';
|
|
4
4
|
import { SvelteSnapshotManager } from '../svelte-snapshots';
|
|
5
|
-
export declare function isPatched(
|
|
6
|
-
export declare function decorateLanguageService(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger, configManager: ConfigManager, info: ts.server.PluginCreateInfo, typescript: typeof ts): ts.LanguageService;
|
|
5
|
+
export declare function isPatched(project: ts.server.Project): boolean;
|
|
6
|
+
export declare function decorateLanguageService(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger, configManager: ConfigManager, info: ts.server.PluginCreateInfo, typescript: typeof ts, onDispose: () => void): ts.LanguageService;
|
|
@@ -13,21 +13,22 @@ const inlay_hints_1 = require("./inlay-hints");
|
|
|
13
13
|
const rename_1 = require("./rename");
|
|
14
14
|
const update_imports_1 = require("./update-imports");
|
|
15
15
|
const host_1 = require("./host");
|
|
16
|
-
const
|
|
17
|
-
function isPatched(
|
|
18
|
-
return
|
|
16
|
+
const patchedProject = new Set();
|
|
17
|
+
function isPatched(project) {
|
|
18
|
+
return patchedProject.has(project.getProjectName());
|
|
19
19
|
}
|
|
20
20
|
exports.isPatched = isPatched;
|
|
21
|
-
function decorateLanguageService(ls, snapshotManager, logger, configManager, info, typescript) {
|
|
21
|
+
function decorateLanguageService(ls, snapshotManager, logger, configManager, info, typescript, onDispose) {
|
|
22
|
+
patchedProject.add(info.project.getProjectName());
|
|
22
23
|
// Decorate using a proxy so we can dynamically enable/disable method
|
|
23
24
|
// patches depending on the enabled state of our config
|
|
24
25
|
const proxy = new Proxy(ls, createProxyHandler(configManager));
|
|
25
26
|
(0, host_1.decorateLanguageServiceHost)(info.languageServiceHost);
|
|
26
|
-
decorateLanguageServiceInner(proxy, snapshotManager, logger, info, typescript);
|
|
27
|
+
decorateLanguageServiceInner(proxy, snapshotManager, logger, info, typescript, onDispose);
|
|
27
28
|
return proxy;
|
|
28
29
|
}
|
|
29
30
|
exports.decorateLanguageService = decorateLanguageService;
|
|
30
|
-
function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescript) {
|
|
31
|
+
function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescript, onDispose) {
|
|
31
32
|
patchLineColumnOffset(ls, snapshotManager);
|
|
32
33
|
(0, rename_1.decorateRename)(ls, snapshotManager, logger);
|
|
33
34
|
(0, diagnostics_1.decorateDiagnostics)(ls, info, typescript, logger);
|
|
@@ -39,21 +40,18 @@ function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescr
|
|
|
39
40
|
(0, call_hierarchy_1.decorateCallHierarchy)(ls, snapshotManager, typescript);
|
|
40
41
|
(0, hover_1.decorateHover)(ls, info, typescript, logger);
|
|
41
42
|
(0, inlay_hints_1.decorateInlayHints)(ls, info, typescript, logger);
|
|
43
|
+
decorateDispose(ls, info.project, onDispose);
|
|
42
44
|
return ls;
|
|
43
45
|
}
|
|
44
46
|
function createProxyHandler(configManager) {
|
|
45
47
|
const decorated = {};
|
|
46
48
|
return {
|
|
47
49
|
get(target, p) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (p === sveltePluginPatchSymbol) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
if (!configManager.getConfig().enable || p === 'dispose') {
|
|
50
|
+
// always check for decorated dispose
|
|
51
|
+
if (!configManager.getConfig().enable && p !== 'dispose') {
|
|
54
52
|
return target[p];
|
|
55
53
|
}
|
|
56
|
-
return (
|
|
54
|
+
return (decorated[p] ?? target[p]);
|
|
57
55
|
},
|
|
58
56
|
set(_, p, value) {
|
|
59
57
|
decorated[p] = value;
|
|
@@ -77,4 +75,13 @@ function patchLineColumnOffset(ls, snapshotManager) {
|
|
|
77
75
|
return toLineColumnOffset(fileName, position);
|
|
78
76
|
};
|
|
79
77
|
}
|
|
78
|
+
function decorateDispose(ls, project, onDispose) {
|
|
79
|
+
const dispose = ls.dispose;
|
|
80
|
+
ls.dispose = () => {
|
|
81
|
+
patchedProject.delete(project.getProjectName());
|
|
82
|
+
onDispose();
|
|
83
|
+
dispose();
|
|
84
|
+
};
|
|
85
|
+
return ls;
|
|
86
|
+
}
|
|
80
87
|
//# sourceMappingURL=index.js.map
|
|
@@ -378,7 +378,7 @@ exports.kitExports = {
|
|
|
378
378
|
]
|
|
379
379
|
},
|
|
380
380
|
entries: {
|
|
381
|
-
allowedIn: ['api', '
|
|
381
|
+
allowedIn: ['api', 'page', 'server', 'universal'],
|
|
382
382
|
displayParts: [
|
|
383
383
|
{
|
|
384
384
|
text: 'export',
|
|
@@ -488,7 +488,7 @@ exports.isKitRouteExportAllowedIn = isKitRouteExportAllowedIn;
|
|
|
488
488
|
function getProxiedLanguageService(info, ts, logger) {
|
|
489
489
|
const cachedProxiedLanguageService = cache.get(info);
|
|
490
490
|
if (cachedProxiedLanguageService !== undefined) {
|
|
491
|
-
return cachedProxiedLanguageService
|
|
491
|
+
return cachedProxiedLanguageService ?? undefined;
|
|
492
492
|
}
|
|
493
493
|
if (!(0, utils_1.hasNodeModule)(info.project.getCompilerOptions(), '@sveltejs/kit')) {
|
|
494
494
|
// Not a SvelteKit project, do nothing
|
|
@@ -547,8 +547,8 @@ function getProxiedLanguageService(info, ts, logger) {
|
|
|
547
547
|
this.paramsPath = config.kit.files.params;
|
|
548
548
|
}
|
|
549
549
|
if (config.kit.files.hooks) {
|
|
550
|
-
this.serverHooksPath
|
|
551
|
-
this.clientHooksPath
|
|
550
|
+
this.serverHooksPath ||= config.kit.files.hooks.server;
|
|
551
|
+
this.clientHooksPath ||= config.kit.files.hooks.client;
|
|
552
552
|
}
|
|
553
553
|
// We could be more sophisticated with only removing the files that are actually
|
|
554
554
|
// wrong but this is good enough given how rare it is that this setting is used
|
|
@@ -608,7 +608,7 @@ function getProxiedLanguageService(info, ts, logger) {
|
|
|
608
608
|
clientHooksPath: this.clientHooksPath,
|
|
609
609
|
paramsPath: this.paramsPath,
|
|
610
610
|
serverHooksPath: this.serverHooksPath
|
|
611
|
-
}, () =>
|
|
611
|
+
}, () => info.languageService.getProgram()?.getSourceFile(fileName));
|
|
612
612
|
if (!result) {
|
|
613
613
|
return;
|
|
614
614
|
}
|
|
@@ -721,12 +721,12 @@ function createProxyRegistry(ts, originalLanguageServiceHost, options) {
|
|
|
721
721
|
// return proxyRegistry;
|
|
722
722
|
}
|
|
723
723
|
function getVirtualLS(fileName, info, ts, logger) {
|
|
724
|
-
var _a;
|
|
725
724
|
const proxy = getProxiedLanguageService(info, ts, logger);
|
|
726
725
|
if (!proxy) {
|
|
727
726
|
return;
|
|
728
727
|
}
|
|
729
|
-
const result =
|
|
728
|
+
const result = proxy.languageServiceHost.getKitScriptSnapshotIfUpToDate(fileName) ??
|
|
729
|
+
proxy.languageServiceHost.upsertKitFile(fileName);
|
|
730
730
|
if (result) {
|
|
731
731
|
return {
|
|
732
732
|
languageService: proxy.languageService,
|
|
@@ -10,7 +10,8 @@ function decorateUpdateImports(ls, snapshotManager, logger) {
|
|
|
10
10
|
const getEditsForFileRename = ls.getEditsForFileRename;
|
|
11
11
|
ls.getEditsForFileRename = (oldFilePath, newFilePath, formatOptions, preferences) => {
|
|
12
12
|
const renameLocations = getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences);
|
|
13
|
-
return renameLocations
|
|
13
|
+
return renameLocations
|
|
14
|
+
?.filter((renameLocation) => {
|
|
14
15
|
// If a file move/rename of a TS/JS file results a Svelte file change,
|
|
15
16
|
// the Svelte extension will notice that, too, and adjusts the same imports.
|
|
16
17
|
// This results in duplicate adjustments or race conditions with conflicting text spans
|
|
@@ -19,7 +20,8 @@ function decorateUpdateImports(ls, snapshotManager, logger) {
|
|
|
19
20
|
// and let the Svelte extension handle that.
|
|
20
21
|
return (!(0, utils_1.isSvelteFilePath)(renameLocation.fileName) &&
|
|
21
22
|
!renameLocation.textChanges.some((change) => change.newText.endsWith('.svelte')));
|
|
22
|
-
})
|
|
23
|
+
})
|
|
24
|
+
.map((renameLocation) => {
|
|
23
25
|
if (path_1.default.basename(renameLocation.fileName).startsWith('+')) {
|
|
24
26
|
// Filter out changes to './$type' imports for Kit route files,
|
|
25
27
|
// you'll likely want these to stay as-is
|
|
@@ -57,11 +57,10 @@ class ModuleResolutionCache {
|
|
|
57
57
|
* In order to fix this, we need to wrap typescript's module resolution and reroute all `.svelte.ts` file lookups to .svelte.
|
|
58
58
|
*/
|
|
59
59
|
function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project, configManager) {
|
|
60
|
-
var _a, _b;
|
|
61
60
|
const svelteSys = (0, svelte_sys_1.createSvelteSys)(typescript, logger);
|
|
62
61
|
const moduleCache = new ModuleResolutionCache(project.projectService);
|
|
63
|
-
const origResolveModuleNames =
|
|
64
|
-
const origResolveModuleNamLiterals =
|
|
62
|
+
const origResolveModuleNames = lsHost.resolveModuleNames?.bind(lsHost);
|
|
63
|
+
const origResolveModuleNamLiterals = lsHost.resolveModuleNameLiterals?.bind(lsHost);
|
|
65
64
|
if (lsHost.resolveModuleNameLiterals) {
|
|
66
65
|
lsHost.resolveModuleNameLiterals = resolveModuleNameLiterals;
|
|
67
66
|
}
|
|
@@ -83,7 +82,7 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
83
82
|
// The ones that are undefined will be re-checked if they are a
|
|
84
83
|
// Svelte file and if so, are resolved, too. This way we can defer
|
|
85
84
|
// all module resolving logic except for Svelte files to TypeScript.
|
|
86
|
-
const resolved =
|
|
85
|
+
const resolved = origResolveModuleNames?.(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile) || Array.from(Array(moduleNames.length));
|
|
87
86
|
if (!configManager.getConfig().enable) {
|
|
88
87
|
return resolved;
|
|
89
88
|
}
|
|
@@ -118,15 +117,15 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
118
117
|
return resolvedSvelteModule;
|
|
119
118
|
}
|
|
120
119
|
function resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
|
|
121
|
-
var _a;
|
|
122
120
|
logger.debug('Resolving modules names for ' + containingFile);
|
|
123
121
|
// Try resolving all module names with the original method first.
|
|
124
122
|
// The ones that are undefined will be re-checked if they are a
|
|
125
123
|
// Svelte file and if so, are resolved, too. This way we can defer
|
|
126
124
|
// all module resolving logic except for Svelte files to TypeScript.
|
|
127
|
-
const resolved =
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
const resolved = origResolveModuleNamLiterals?.(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) ??
|
|
126
|
+
moduleLiterals.map(() => ({
|
|
127
|
+
resolvedModule: undefined
|
|
128
|
+
}));
|
|
130
129
|
if (!configManager.getConfig().enable) {
|
|
131
130
|
return resolved;
|
|
132
131
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { ConfigManager } from './config-manager';
|
|
3
3
|
import { SvelteSnapshotManager } from './svelte-snapshots';
|
|
4
|
+
import { Logger } from './logger';
|
|
4
5
|
export interface TsFilesSpec {
|
|
5
6
|
include?: readonly string[];
|
|
6
7
|
exclude?: readonly string[];
|
|
@@ -10,12 +11,13 @@ export declare class ProjectSvelteFilesManager {
|
|
|
10
11
|
private readonly project;
|
|
11
12
|
private readonly serverHost;
|
|
12
13
|
private readonly snapshotManager;
|
|
14
|
+
private readonly logger;
|
|
13
15
|
private parsedCommandLine;
|
|
14
|
-
private
|
|
16
|
+
private projectFileToOriginalCasing;
|
|
15
17
|
private directoryWatchers;
|
|
16
18
|
private static instances;
|
|
17
19
|
static getInstance(projectName: string): ProjectSvelteFilesManager | undefined;
|
|
18
|
-
constructor(typescript: typeof ts, project: ts.server.Project, serverHost: ts.server.ServerHost, snapshotManager: SvelteSnapshotManager, parsedCommandLine: ts.ParsedCommandLine, configManager: ConfigManager);
|
|
20
|
+
constructor(typescript: typeof ts, project: ts.server.Project, serverHost: ts.server.ServerHost, snapshotManager: SvelteSnapshotManager, logger: Logger, parsedCommandLine: ts.ParsedCommandLine, configManager: ConfigManager);
|
|
19
21
|
updateProjectConfig(serviceHost: ts.LanguageServiceHost): void;
|
|
20
22
|
getFiles(): string[];
|
|
21
23
|
/**
|
|
@@ -6,13 +6,14 @@ class ProjectSvelteFilesManager {
|
|
|
6
6
|
static getInstance(projectName) {
|
|
7
7
|
return this.instances.get(projectName);
|
|
8
8
|
}
|
|
9
|
-
constructor(typescript, project, serverHost, snapshotManager, parsedCommandLine, configManager) {
|
|
9
|
+
constructor(typescript, project, serverHost, snapshotManager, logger, parsedCommandLine, configManager) {
|
|
10
10
|
this.typescript = typescript;
|
|
11
11
|
this.project = project;
|
|
12
12
|
this.serverHost = serverHost;
|
|
13
13
|
this.snapshotManager = snapshotManager;
|
|
14
|
+
this.logger = logger;
|
|
14
15
|
this.parsedCommandLine = parsedCommandLine;
|
|
15
|
-
this.
|
|
16
|
+
this.projectFileToOriginalCasing = new Map();
|
|
16
17
|
this.directoryWatchers = new Set();
|
|
17
18
|
if (configManager.getConfig().enable) {
|
|
18
19
|
this.setupWatchers();
|
|
@@ -22,8 +23,7 @@ class ProjectSvelteFilesManager {
|
|
|
22
23
|
ProjectSvelteFilesManager.instances.set(project.getProjectName(), this);
|
|
23
24
|
}
|
|
24
25
|
updateProjectConfig(serviceHost) {
|
|
25
|
-
|
|
26
|
-
const parsedCommandLine = (_a = serviceHost.getParsedCommandLine) === null || _a === void 0 ? void 0 : _a.call(serviceHost, (0, utils_1.getConfigPathForProject)(this.project));
|
|
26
|
+
const parsedCommandLine = serviceHost.getParsedCommandLine?.((0, utils_1.getConfigPathForProject)(this.project));
|
|
27
27
|
if (!parsedCommandLine) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
@@ -33,7 +33,7 @@ class ProjectSvelteFilesManager {
|
|
|
33
33
|
this.updateProjectSvelteFiles();
|
|
34
34
|
}
|
|
35
35
|
getFiles() {
|
|
36
|
-
return Array.from(this.
|
|
36
|
+
return Array.from(this.projectFileToOriginalCasing.values());
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Create directory watcher for include and exclude
|
|
@@ -60,35 +60,48 @@ class ProjectSvelteFilesManager {
|
|
|
60
60
|
this.updateProjectSvelteFiles();
|
|
61
61
|
}
|
|
62
62
|
updateProjectSvelteFiles() {
|
|
63
|
-
const fileNamesAfter = this.readProjectSvelteFilesFromFs()
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
const fileNamesAfter = this.readProjectSvelteFilesFromFs().map((file) => ({
|
|
64
|
+
originalCasing: file,
|
|
65
|
+
canonicalFileName: this.project.projectService.toCanonicalFileName(file)
|
|
66
|
+
}));
|
|
67
|
+
const removedFiles = new Set(this.projectFileToOriginalCasing.keys());
|
|
68
|
+
const newFiles = [];
|
|
69
|
+
for (const file of fileNamesAfter) {
|
|
70
|
+
const existingFile = this.projectFileToOriginalCasing.get(file.canonicalFileName);
|
|
71
|
+
if (!existingFile) {
|
|
72
|
+
newFiles.push(file);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
removedFiles.delete(file.canonicalFileName);
|
|
76
|
+
if (existingFile !== file.originalCasing) {
|
|
77
|
+
this.projectFileToOriginalCasing.set(file.canonicalFileName, file.originalCasing);
|
|
69
78
|
}
|
|
70
|
-
|
|
71
|
-
});
|
|
79
|
+
}
|
|
72
80
|
for (const newFile of newFiles) {
|
|
73
|
-
this.addFileToProject(newFile);
|
|
74
|
-
this.
|
|
81
|
+
this.addFileToProject(newFile.originalCasing);
|
|
82
|
+
this.projectFileToOriginalCasing.set(newFile.canonicalFileName, newFile.originalCasing);
|
|
75
83
|
}
|
|
76
84
|
for (const removedFile of removedFiles) {
|
|
77
85
|
this.removeFileFromProject(removedFile, false);
|
|
78
|
-
this.
|
|
86
|
+
this.projectFileToOriginalCasing.delete(removedFile);
|
|
79
87
|
}
|
|
80
88
|
}
|
|
81
89
|
addFileToProject(newFile) {
|
|
82
90
|
this.snapshotManager.create(newFile);
|
|
83
91
|
const snapshot = this.project.projectService.getScriptInfo(newFile);
|
|
84
|
-
if (snapshot) {
|
|
85
|
-
|
|
92
|
+
if (!snapshot) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (this.project.isRoot(snapshot)) {
|
|
96
|
+
this.logger.debug(`File ${newFile} is already in root`);
|
|
97
|
+
return;
|
|
86
98
|
}
|
|
99
|
+
this.project.addRoot(snapshot);
|
|
87
100
|
}
|
|
88
101
|
readProjectSvelteFilesFromFs() {
|
|
89
102
|
const fileSpec = this.parsedCommandLine.raw;
|
|
90
103
|
const { include, exclude } = fileSpec;
|
|
91
|
-
if (
|
|
104
|
+
if (include?.length === 0) {
|
|
92
105
|
return [];
|
|
93
106
|
}
|
|
94
107
|
return this.typescript.sys
|
|
@@ -111,8 +124,8 @@ class ProjectSvelteFilesManager {
|
|
|
111
124
|
disposeWatchersAndFiles() {
|
|
112
125
|
this.directoryWatchers.forEach((watcher) => watcher.close());
|
|
113
126
|
this.directoryWatchers.clear();
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
127
|
+
this.projectFileToOriginalCasing.forEach((file) => this.removeFileFromProject(file));
|
|
128
|
+
this.projectFileToOriginalCasing.clear();
|
|
116
129
|
}
|
|
117
130
|
dispose() {
|
|
118
131
|
this.disposeWatchersAndFiles();
|
|
@@ -208,8 +208,7 @@ class SvelteSnapshot {
|
|
|
208
208
|
this.convertInternalCodePositions = convertInternalCodePositions;
|
|
209
209
|
}
|
|
210
210
|
getText() {
|
|
211
|
-
|
|
212
|
-
const snapshot = (_a = this.scriptInfo) === null || _a === void 0 ? void 0 : _a.getSnapshot();
|
|
211
|
+
const snapshot = this.scriptInfo?.getSnapshot();
|
|
213
212
|
if (!snapshot) {
|
|
214
213
|
return '';
|
|
215
214
|
}
|
package/dist/src/svelte-sys.js
CHANGED
|
@@ -12,7 +12,7 @@ function createSvelteSys(ts, logger) {
|
|
|
12
12
|
return ts.sys.fileExists((0, utils_1.ensureRealSvelteFilePath)(path));
|
|
13
13
|
},
|
|
14
14
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
15
|
-
const extensionsWithSvelte = (extensions
|
|
15
|
+
const extensionsWithSvelte = (extensions ?? []).concat('.svelte');
|
|
16
16
|
return ts.sys.readDirectory(path, extensionsWithSvelte, exclude, include, depth);
|
|
17
17
|
}
|
|
18
18
|
};
|
package/dist/src/utils.js
CHANGED
|
@@ -64,8 +64,8 @@ function replaceDeep(obj, searchStr, replacementStr) {
|
|
|
64
64
|
}
|
|
65
65
|
exports.replaceDeep = replaceDeep;
|
|
66
66
|
function getConfigPathForProject(project) {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
return (project.canonicalConfigFilePath ??
|
|
68
|
+
project.getCompilerOptions().configFilePath);
|
|
69
69
|
}
|
|
70
70
|
exports.getConfigPathForProject = getConfigPathForProject;
|
|
71
71
|
function isStoreVariableIn$storeDeclaration(text, varStart) {
|
|
@@ -137,12 +137,11 @@ exports.findNodeAtPosition = findNodeAtPosition;
|
|
|
137
137
|
* True if is `export const/let/function`
|
|
138
138
|
*/
|
|
139
139
|
function isTopLevelExport(ts, node, source) {
|
|
140
|
-
var _a, _b;
|
|
141
140
|
return ((ts.isVariableStatement(node) && source.statements.includes(node)) ||
|
|
142
141
|
(ts.isIdentifier(node) &&
|
|
143
142
|
node.parent &&
|
|
144
143
|
ts.isVariableDeclaration(node.parent) &&
|
|
145
|
-
source.statements.includes(
|
|
144
|
+
source.statements.includes(node.parent?.parent?.parent)) ||
|
|
146
145
|
(ts.isIdentifier(node) &&
|
|
147
146
|
node.parent &&
|
|
148
147
|
ts.isFunctionDeclaration(node.parent) &&
|
|
@@ -197,7 +196,7 @@ function hasNodeModule(compilerOptions, module) {
|
|
|
197
196
|
catch (e) {
|
|
198
197
|
// If require.resolve fails, we end up here, which can be either because the package is not found,
|
|
199
198
|
// or (in case of things like SvelteKit) the package is found but the package.json is not exported.
|
|
200
|
-
return
|
|
199
|
+
return e?.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED';
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
exports.hasNodeModule = hasNodeModule;
|
package/package.json
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-svelte-plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.26",
|
|
4
4
|
"description": "A TypeScript Plugin providing Svelte intellisense",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "tsc -p ./",
|
|
8
|
-
"watch": "tsc -w -p ./",
|
|
9
|
-
"test": "echo 'NOOP'",
|
|
10
|
-
"prepublishOnly": "npm run build"
|
|
11
|
-
},
|
|
12
6
|
"keywords": [
|
|
13
7
|
"svelte",
|
|
14
8
|
"typescript",
|
|
@@ -25,5 +19,10 @@
|
|
|
25
19
|
"dependencies": {
|
|
26
20
|
"@jridgewell/sourcemap-codec": "^1.4.14",
|
|
27
21
|
"svelte2tsx": "~0.6.8"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p ./",
|
|
25
|
+
"watch": "tsc -w -p ./",
|
|
26
|
+
"test": "echo 'NOOP'"
|
|
28
27
|
}
|
|
29
|
-
}
|
|
28
|
+
}
|