From 1cf9e6560da3c8447b813ff568b4a5e3f6759737 Mon Sep 17 00:00:00 2001 From: Phill Wolf Date: Sun, 5 Jan 2025 14:30:09 -0500 Subject: [PATCH] Using getConfigNow instead of getConfig, avoid some async/await related to reformatting --- src/calva-fmt/src/format.ts | 12 ++++++------ src/repl-window/repl-doc.ts | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/calva-fmt/src/format.ts b/src/calva-fmt/src/format.ts index ef1923be8..8cdbc60b0 100644 --- a/src/calva-fmt/src/format.ts +++ b/src/calva-fmt/src/format.ts @@ -49,10 +49,10 @@ export async function indentPosition(position: vscode.Position, document: vscode } } -export async function formatRangeEdits( +export function formatRangeEdits( document: vscode.TextDocument, originalRange: vscode.Range -): Promise { +): vscode.TextEdit[] | undefined { const mirrorDoc = getDocument(document); const startIndex = document.offsetAt(originalRange.start); const cursor = mirrorDoc.getTokenCursor(startIndex); @@ -63,7 +63,7 @@ export async function formatRangeEdits( const trailingWs = originalText.match(/\s*$/)[0]; const missingTexts = cursorDocUtils.getMissingBrackets(originalText); const healedText = `${missingTexts.prepend}${originalText.trim()}${missingTexts.append}`; - const formattedHealedText = await formatCode(healedText, document.eol); + const formattedHealedText = formatCode(healedText, document.eol); const leadingEolPos = leadingWs.lastIndexOf(eol); const startIndent = leadingEolPos === -1 @@ -86,7 +86,7 @@ export async function formatRangeEdits( export async function formatRange(document: vscode.TextDocument, range: vscode.Range) { const wsEdit: vscode.WorkspaceEdit = new vscode.WorkspaceEdit(); - const edits = await formatRangeEdits(document, range); + const edits = formatRangeEdits(document, range); if (isUndefined(edits)) { console.error('formatRangeEdits returned undefined!', cloneDeep({ document, range })); @@ -315,11 +315,11 @@ export function trimWhiteSpacePositionCommand(editor: vscode.TextEditor) { void formatPosition(editor, false, { 'remove-multiple-non-indenting-spaces?': true }); } -export async function formatCode(code: string, eol: number) { +export function formatCode(code: string, eol: number) { const d = { 'range-text': code, eol: _convertEolNumToStringNotation(eol), - config: await config.getConfig(), + config: config.getConfigNow(), }; const result = jsify(formatText(d)); if (!result['error']) { diff --git a/src/repl-window/repl-doc.ts b/src/repl-window/repl-doc.ts index ff02ebb7f..cfe8d5e86 100644 --- a/src/repl-window/repl-doc.ts +++ b/src/repl-window/repl-doc.ts @@ -299,7 +299,7 @@ export function setNamespaceFromCurrentFile() { output.replWindowAppendPrompt(); } -async function appendFormGrabbingSessionAndNS(topLevel: boolean) { +function appendFormGrabbingSessionAndNS(topLevel: boolean): void { const session = replSession.getSession(); const [ns, _] = namespace.getNamespace( util.tryToGetDocument({}), @@ -311,9 +311,9 @@ async function appendFormGrabbingSessionAndNS(topLevel: boolean) { let code = ''; if (selection.isEmpty) { const formSelection = select.getFormSelection(doc, selection.active, topLevel); - code = await formatCode(doc.getText(formSelection), doc.eol); + code = formatCode(doc.getText(formSelection), doc.eol); } else { - code = await formatCode(doc.getText(selection), doc.eol); + code = formatCode(doc.getText(selection), doc.eol); } if (code != '') { setSession(session, ns); @@ -322,11 +322,11 @@ async function appendFormGrabbingSessionAndNS(topLevel: boolean) { } export function appendCurrentForm() { - void appendFormGrabbingSessionAndNS(false); + appendFormGrabbingSessionAndNS(false); } export function appendCurrentTopLevelForm() { - void appendFormGrabbingSessionAndNS(true); + appendFormGrabbingSessionAndNS(true); } export async function lastLineIsEmpty(): Promise {