5480: Fix snippetTextEdits applying to other files r=matklad a=TimoFreiberg

Fixes #4551
`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.

I feel that this is a hacky approach, so feel free to reject it for something nicer :)

Co-authored-by: Timo Freiberg <timo.freiberg@gmail.com>
This commit is contained in:
bors[bot] 2020-07-23 12:33:24 +00:00 committed by GitHub
commit 85532e2df3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,10 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
assert(edit.entries().length === 1, `bad ws edit: ${JSON.stringify(edit)}`); assert(edit.entries().length === 1, `bad ws edit: ${JSON.stringify(edit)}`);
const [uri, edits] = edit.entries()[0]; 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()); const editor = vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString());
if (!editor) return; if (!editor) return;
await applySnippetTextEdits(editor, edits); await applySnippetTextEdits(editor, edits);