From 01a05ba18635a50a89609edce1addafd9b260d6a Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Thu, 12 Feb 2026 13:51:29 -0800 Subject: [PATCH] skip indented lines in add missing cases --- newt-vscode/src/extension.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/newt-vscode/src/extension.ts b/newt-vscode/src/extension.ts index e442686..b0a7ed7 100644 --- a/newt-vscode/src/extension.ts +++ b/newt-vscode/src/extension.ts @@ -18,11 +18,16 @@ interface TopData { context: TopEntry[]; } +function getIndent(text: string) { + return text.match(/\S/)?.index ?? 0 +} + export function activate(context: vscode.ExtensionContext) { let topData: undefined | TopData; const diagnosticCollection = vscode.languages.createDiagnosticCollection("newt"); + vscode.workspace.onDidChangeTextDocument((event) => { const editor = vscode.window.activeTextEditor; if (!editor || event.document !== editor.document) return; @@ -294,8 +299,11 @@ export function activate(context: vscode.ExtensionContext) { if (m) { // A lot of this logic would also apply to case split. let cons = m[1].split(', '); - const line = range.start.line; - const lineText = document.lineAt(line).text; + let line = range.start.line; + let lineText = document.lineAt(line).text; + // this isn't going to work for let. + // and I think I relaxed the indent for `|` + const indent = getIndent(lineText) let m2 = lineText.match(/(.*=>?)/); if (!m2) continue; let s = range.start.character; @@ -312,8 +320,13 @@ export function activate(context: vscode.ExtensionContext) { vscode.CodeActionKind.QuickFix ); fix.edit = new vscode.WorkspaceEdit(); - // TODO - we should skip over subsequent lines that are indented more than the current. - const insertPos = new vscode.Position(line + 1, 0); + // skip indented lines + while (1) { + line = line + 1 + lineText = document.lineAt(line).text + if (!lineText.trim() || getIndent(lineText) <= indent) break + } + const insertPos = new vscode.Position(line, 0); let text = lines.join('\n') + '\n'; if (insertPos.line === document.lineCount) { text = "\n" + text;