From 01689f83a3b4e845a75b12ae26b991e39f696b8a Mon Sep 17 00:00:00 2001 From: Kyklish Date: Fri, 24 May 2024 08:05:13 +0300 Subject: [PATCH] `FIX`: `label` inside code block breaks `return` indentation (#434) * fix wrong behavior of the LABEL * Update package.json --------- Co-authored-by: Mark Wiemer <7833360+mark-wiemer@users.noreply.github.com> --- package.json | 2 +- src/providers/format.test.ts | 1 + src/providers/formattingProvider.ts | 7 +++++-- .../samples/432-label-inside-code-block.in.ahk | 9 +++++++++ .../samples/432-label-inside-code-block.out.ahk | 9 +++++++++ src/providers/samples/ahk-explorer.out.ahk | 10 +++++----- 6 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 src/providers/samples/432-label-inside-code-block.in.ahk create mode 100644 src/providers/samples/432-label-inside-code-block.out.ahk diff --git a/package.json b/package.json index ef7ec5c1..246c3244 100644 --- a/package.json +++ b/package.json @@ -168,7 +168,7 @@ "ahk++.formatter.indentCodeAfterLabel": { "type": "boolean", "default": true, - "description": "Indent code after label. Only applies to AHK v1." + "description": "Indent code after hotkeys and labels in top-level code blocks. Only applies to AHK v1." }, "ahk++.formatter.indentCodeAfterIfDirective": { "type": "boolean", diff --git a/src/providers/format.test.ts b/src/providers/format.test.ts index 539f6bdb..3ca6d86c 100644 --- a/src/providers/format.test.ts +++ b/src/providers/format.test.ts @@ -69,6 +69,7 @@ const formatTests: FormatTest[] = [ { filenameRoot: '290-ifmsgbox' }, { filenameRoot: '291-single-line-comment' }, { filenameRoot: '316-if-object-continuation-section' }, + { filenameRoot: '432-label-inside-code-block' }, { filenameRoot: 'ahk-explorer' }, { filenameRoot: 'align-assignment' }, { filenameRoot: 'demo' }, diff --git a/src/providers/formattingProvider.ts b/src/providers/formattingProvider.ts index 31ca8927..572f1363 100644 --- a/src/providers/formattingProvider.ts +++ b/src/providers/formattingProvider.ts @@ -857,8 +857,11 @@ export const internalFormat = ( if (indentCodeAfterLabel) { // Label: or Hotkey:: <-- indent next line // code - depth++; - tagDepth = depth; + // Do this only if the LABEL is not inside a nested code + if (focDepth.depth.length === 1) { + depth++; + tagDepth = depth; + } } } diff --git a/src/providers/samples/432-label-inside-code-block.in.ahk b/src/providers/samples/432-label-inside-code-block.in.ahk new file mode 100644 index 00000000..8f311aa3 --- /dev/null +++ b/src/providers/samples/432-label-inside-code-block.in.ahk @@ -0,0 +1,9 @@ +; [Issue #432](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/432) +F1:: +if (var) { +LABEL: +code +return +} +code +return diff --git a/src/providers/samples/432-label-inside-code-block.out.ahk b/src/providers/samples/432-label-inside-code-block.out.ahk new file mode 100644 index 00000000..1badfe73 --- /dev/null +++ b/src/providers/samples/432-label-inside-code-block.out.ahk @@ -0,0 +1,9 @@ +; [Issue #432](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/432) +F1:: + if (var) { + LABEL: + code + return + } + code +return diff --git a/src/providers/samples/ahk-explorer.out.ahk b/src/providers/samples/ahk-explorer.out.ahk index 156ed06d..57a7444a 100644 --- a/src/providers/samples/ahk-explorer.out.ahk +++ b/src/providers/samples/ahk-explorer.out.ahk @@ -2848,11 +2848,11 @@ ShellContextMenu(folderPath, files, win_hwnd = 0 ) DllCall("GlobalFree", "Ptr", DllCall("SetWindowLongPtr", "Ptr", win_hwnd, "int", -4, "Ptr", WPOld,"UPtr")) DllCall("DestroyMenu", "Ptr", hMenu) StopContextMenu: - ObjRelease(pIContextMenu3) - ObjRelease(pIContextMenu2) - ObjRelease(pIContextMenu) - pIContextMenu2:=pIContextMenu3:=WPOld:=0 - Gui,SHELL_CONTEXT:Destroy + ObjRelease(pIContextMenu3) + ObjRelease(pIContextMenu2) + ObjRelease(pIContextMenu) + pIContextMenu2:=pIContextMenu3:=WPOld:=0 + Gui,SHELL_CONTEXT:Destroy return idn } WindowProc(hWnd, nMsg, wParam, lParam)