Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'editors/code/src/snippets.ts')
-rw-r--r--editors/code/src/snippets.ts16
1 files changed, 10 insertions, 6 deletions
diff --git a/editors/code/src/snippets.ts b/editors/code/src/snippets.ts
index 299d29c27e..d81765649f 100644
--- a/editors/code/src/snippets.ts
+++ b/editors/code/src/snippets.ts
@@ -1,10 +1,11 @@
import * as vscode from "vscode";
import { assert } from "./util";
+import { unwrapUndefinable } from "./undefinable";
export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
if (edit.entries().length === 1) {
- const [uri, edits] = edit.entries()[0];
+ const [uri, edits] = unwrapUndefinable(edit.entries()[0]);
const editor = await editorFromUri(uri);
if (editor) await applySnippetTextEdits(editor, edits);
return;
@@ -16,7 +17,9 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
for (const indel of edits) {
assert(
!parseSnippet(indel.newText),
- `bad ws edit: snippet received with multiple edits: ${JSON.stringify(edit)}`
+ `bad ws edit: snippet received with multiple edits: ${JSON.stringify(
+ edit,
+ )}`,
);
builder.replace(indel.range, indel.newText);
}
@@ -31,7 +34,7 @@ async function editorFromUri(uri: vscode.Uri): Promise<vscode.TextEditor | undef
await vscode.window.showTextDocument(uri, {});
}
return vscode.window.visibleTextEditors.find(
- (it) => it.document.uri.toString() === uri.toString()
+ (it) => it.document.uri.toString() === uri.toString(),
);
}
@@ -55,8 +58,8 @@ export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vs
selections.push(
new vscode.Selection(
new vscode.Position(startLine, startColumn),
- new vscode.Position(startLine, endColumn)
- )
+ new vscode.Position(startLine, endColumn),
+ ),
);
builder.replace(indel.range, newText);
} else {
@@ -68,7 +71,8 @@ export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vs
});
if (selections.length > 0) editor.selections = selections;
if (selections.length === 1) {
- editor.revealRange(selections[0], vscode.TextEditorRevealType.InCenterIfOutsideViewport);
+ const selection = unwrapUndefinable(selections[0]);
+ editor.revealRange(selection, vscode.TextEditorRevealType.InCenterIfOutsideViewport);
}
}