Skip to content

Commit

Permalink
Fix snippetTextEdits applying to other files
Browse files Browse the repository at this point in the history
vscode.window.visibleTextEditors only contains editors whose contents
are being displayed at the moment, so the previous logic only worked if
the other file for which a snippetTextEdit is being received was visible
in a separate split.

Ported from rust-analyzer: rust-lang/rust-analyzer#5480
  • Loading branch information
TimoFreiberg committed Jul 22, 2020
1 parent 16f789c commit df3035b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rust-analyzer/editors/code/src/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
assert(edit.entries().length === 1, `bad ws edit: ${JSON.stringify(edit)}`);
const [uri, edits] = edit.entries()[0];

if (vscode.window.activeTextEditor?.document.uri !== uri) {
// `vscode.window.visibleTextEditors` only contains editors whose contents are being displayed
await vscode.window.showTextDocument(uri, {});
}
const editor = vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString());
if (!editor) return;
await applySnippetTextEdits(editor, edits);
Expand Down

0 comments on commit df3035b

Please sign in to comment.