Skip to content

Commit

Permalink
fix: update imports on file move not working
Browse files Browse the repository at this point in the history
close #1599
  • Loading branch information
johnsoncodehk committed Jul 19, 2022
1 parent ecd9a63 commit 662ee29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
@@ -1,6 +1,7 @@
import type { LanguageServiceRuntimeContext } from '../types';
import { embeddedEditToSourceEdit } from './rename';
import type * as _ from 'vscode-languageserver-protocol';
import * as dedupe from '../utils/dedupe';

export function register(context: LanguageServiceRuntimeContext) {

Expand All @@ -23,10 +24,17 @@ export function register(context: LanguageServiceRuntimeContext) {
const workspaceEdit = await plugin.doFileRename(oldUri, newUri);

if (workspaceEdit) {
return embeddedEditToSourceEdit(

const result = embeddedEditToSourceEdit(
workspaceEdit,
context.vueDocuments,
);

if (result?.documentChanges) {
result.documentChanges = dedupe.withDocumentChanges(result.documentChanges);
}

return result;
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions packages/vue-language-service/src/utils/dedupe.ts
Expand Up @@ -43,6 +43,9 @@ export function withTextEdits<T extends vscode.TextEdit>(items: T[]): T[] {
item.newText,
].join(':'));
}
export function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>) {
return dedupe(items, item => JSON.stringify(item)); // TODO: improve this
}
export function withDiagnostics<T extends vscode.Diagnostic>(items: T[]): T[] {
return dedupe(items, item => [
item.range.start.line,
Expand Down

0 comments on commit 662ee29

Please sign in to comment.