Skip to content

Commit 4862c8d

Browse files
authored
(fix) only update imports when ts/js/svelte/json file path changed
#641
1 parent bd3fb8a commit 4862c8d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/svelte-vscode/src/extension.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function activate(context: ExtensionContext) {
123123
});
124124

125125
workspace.onDidSaveTextDocument(async (doc) => {
126-
const parts = doc.uri.toString().split(/\/|\\/);
126+
const parts = doc.uri.toString(true).split(/\/|\\/);
127127
if (['tsconfig.json', 'jsconfig.json'].includes(parts[parts.length - 1])) {
128128
await restartLS(false);
129129
}
@@ -225,6 +225,11 @@ export function activate(context: ExtensionContext) {
225225

226226
function addRenameFileListener(getLS: () => LanguageClient) {
227227
workspace.onDidRenameFiles(async (evt) => {
228+
const oldUri = evt.files[0].oldUri.toString(true);
229+
if (!['.ts', '.js', '.json', '.svelte'].some((ending) => oldUri.endsWith(ending))) {
230+
return;
231+
}
232+
228233
window.withProgress(
229234
{ location: ProgressLocation.Window, title: 'Updating Imports..' },
230235
async () => {
@@ -236,7 +241,7 @@ function addRenameFileListener(getLS: () => LanguageClient) {
236241
// In the meantime, just assume it's a single entry and simplify the
237242
// rest of the logic that way.
238243
{
239-
oldUri: evt.files[0].oldUri.toString(true),
244+
oldUri: oldUri,
240245
newUri: evt.files[0].newUri.toString(true)
241246
}
242247
);

0 commit comments

Comments
 (0)