Skip to content

Commit

Permalink
FIX: label inside code block breaks return indentation (#434)
Browse files Browse the repository at this point in the history
* fix wrong behavior of the LABEL

* Update package.json

---------

Co-authored-by: Mark Wiemer <7833360+mark-wiemer@users.noreply.github.com>
  • Loading branch information
kyklish and mark-wiemer authored May 24, 2024
1 parent 09d90b9 commit 01689f8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/providers/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
7 changes: 5 additions & 2 deletions src/providers/formattingProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/providers/samples/432-label-inside-code-block.in.ahk
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions src/providers/samples/432-label-inside-code-block.out.ahk
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions src/providers/samples/ahk-explorer.out.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 01689f8

Please sign in to comment.