From df3035b1e49a1b3b2be0b08f3696179692a17ae7 Mon Sep 17 00:00:00 2001 From: Timo Freiberg Date: Wed, 22 Jul 2020 17:44:02 +0200 Subject: [PATCH] Fix snippetTextEdits applying to other files 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: https://github.com/rust-analyzer/rust-analyzer/pull/5480 --- rust-analyzer/editors/code/src/snippets.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rust-analyzer/editors/code/src/snippets.ts b/rust-analyzer/editors/code/src/snippets.ts index bcb3f2cc..258b4998 100644 --- a/rust-analyzer/editors/code/src/snippets.ts +++ b/rust-analyzer/editors/code/src/snippets.ts @@ -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);