From 29ee2e38ea5e5d8043508b1aad09da01a6950827 Mon Sep 17 00:00:00 2001 From: kyklish Date: Fri, 24 May 2024 16:57:19 +0300 Subject: [PATCH 1/5] reset tagDepth in IF-DIRECTIVE --- src/providers/formattingProvider.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/providers/formattingProvider.ts b/src/providers/formattingProvider.ts index 7d89dd6c..a1073501 100644 --- a/src/providers/formattingProvider.ts +++ b/src/providers/formattingProvider.ts @@ -857,6 +857,7 @@ export const internalFormat = ( indentCodeAfterIfDirective ) { depth++; + tagDepth = 0; } // SWITCH-CASE-DEFAULT or LABEL: or HOTKEY:: From 75b0bb93ed936cec09614c2d0fb41a52371c7dec Mon Sep 17 00:00:00 2001 From: kyklish Date: Fri, 24 May 2024 17:15:31 +0300 Subject: [PATCH 2/5] comments --- src/providers/formattingProvider.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/providers/formattingProvider.ts b/src/providers/formattingProvider.ts index a1073501..9e9bbbf5 100644 --- a/src/providers/formattingProvider.ts +++ b/src/providers/formattingProvider.ts @@ -38,21 +38,19 @@ export const internalFormat = ( /** Level of indentation on previous line */ let prevLineDepth = 0; /** - * It's marker for `Return`, `ExitApp`, `#Directive` commands and `Labels`, + * It's marker for `Return`, `ExitApp`, `Hotkeys` and `Labels`, * which allow/disallow for them to be un-indented. * * ------------------------------------------------------------------------- * `tagDepth === 0`: * - * Indentation level was decreased by `Return` or `ExitApp` command, + * Indentation level was decreased by `Return`, `ExitApp`, `#If Directive`, * so they placed on same indentation level as `Label`. * * Decrement of indentation level by `Label` is disallowed (previous * `Label` finished with `Return` or `ExitApp` command and un-indent for * fall-through scenario not needed). * - * Decrement indentation by one level for `#Directive` is allowed. - * * ------------------------------------------------------------------------- * `tagDepth === depth`: * @@ -75,7 +73,7 @@ export const internalFormat = ( * ------------------------------------------------------------------------- * `tagDepth > 0` : * - * `#Directive` allowed to be un-indented by `tagDepth` value (jump + * `#If Directive` allowed to be un-indented by `tagDepth` value (jump * several indentation levels). * * ------------------------------------------------------------------------- @@ -305,8 +303,8 @@ export const internalFormat = ( */ const hotkeySingleLine = /^.+::/; /** - * `#Directive`, that will create context-sensitive hotkeys and hotstrings. - * Example of `#Directives`: + * `#IF Directive`, that will create context-sensitive hotkeys and hotstrings. + * Example of `#If Directives`: * ```ahk * #IfWinActive WinTitle * #IfWinNotActive WinTitle @@ -692,12 +690,12 @@ export const internalFormat = ( } } - // #DIRECTIVE + // #IF DIRECTIVE // #IfWinActive WinTitle1 // Hotkey:: - // #IfWinActive WinTitle2 <-- fall-through scenario for #Directive with - // Hotkey:: parameters - // #If <-- de-indent #Directive without parameters + // #IfWinActive WinTitle2 <-- fall-through scenario for #IF DIRECTIVE + // Hotkey:: with parameters + // #If <-- de-indent #IF DIRECTIVE without parameters if (purifiedLine.match('^' + sharpDirective + '\\b')) { if (tagDepth > 0) { depth -= tagDepth; @@ -849,8 +847,8 @@ export const internalFormat = ( openBraceIndent = false; } - // #DIRECTIVE with parameters - // #If Expression <-- indent next line after '#Directive' + // #IF DIRECTIVE with parameters + // #If Expression <-- indent next line after '#IF DIRECTIVE' // F1:: MsgBox Help if ( purifiedLine.match('^' + sharpDirective + '\\b.+') && From e61cdafdc8d1ab91ce05d67a672f34c952e1f60e Mon Sep 17 00:00:00 2001 From: kyklish Date: Fri, 24 May 2024 17:22:54 +0300 Subject: [PATCH 3/5] add tests --- src/providers/format.test.ts | 1 + ...fall-through-single-line-hotkey-with-if-directive.in.ahk | 6 ++++++ ...all-through-single-line-hotkey-with-if-directive.out.ahk | 6 ++++++ 3 files changed, 13 insertions(+) create mode 100644 src/providers/samples/440-fall-through-single-line-hotkey-with-if-directive.in.ahk create mode 100644 src/providers/samples/440-fall-through-single-line-hotkey-with-if-directive.out.ahk diff --git a/src/providers/format.test.ts b/src/providers/format.test.ts index d80a4154..10a5c3ba 100644 --- a/src/providers/format.test.ts +++ b/src/providers/format.test.ts @@ -71,6 +71,7 @@ const formatTests: FormatTest[] = [ { filenameRoot: '316-if-object-continuation-section' }, { filenameRoot: '429-single-line-hotkey' }, { filenameRoot: '432-label-inside-code-block' }, + { filenameRoot: '440-fall-through-single-line-hotkey-with-if-directive' }, { filenameRoot: 'ahk-explorer' }, { filenameRoot: 'align-assignment' }, { filenameRoot: 'demo' }, diff --git a/src/providers/samples/440-fall-through-single-line-hotkey-with-if-directive.in.ahk b/src/providers/samples/440-fall-through-single-line-hotkey-with-if-directive.in.ahk new file mode 100644 index 00000000..6afecfaa --- /dev/null +++ b/src/providers/samples/440-fall-through-single-line-hotkey-with-if-directive.in.ahk @@ -0,0 +1,6 @@ +; [Issue #440](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/440) +F1:: +F2::code +#IfWinActive, WinTitle +F3::code +#If diff --git a/src/providers/samples/440-fall-through-single-line-hotkey-with-if-directive.out.ahk b/src/providers/samples/440-fall-through-single-line-hotkey-with-if-directive.out.ahk new file mode 100644 index 00000000..dc93de1d --- /dev/null +++ b/src/providers/samples/440-fall-through-single-line-hotkey-with-if-directive.out.ahk @@ -0,0 +1,6 @@ +; [Issue #440](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/440) +F1:: +F2::code +#IfWinActive, WinTitle + F3::code +#If From 973782a26d03f70b94f487016093941855e01825 Mon Sep 17 00:00:00 2001 From: kyklish Date: Fri, 24 May 2024 17:31:11 +0300 Subject: [PATCH 4/5] comments --- src/providers/formattingProvider.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/providers/formattingProvider.ts b/src/providers/formattingProvider.ts index 9e9bbbf5..0241b1df 100644 --- a/src/providers/formattingProvider.ts +++ b/src/providers/formattingProvider.ts @@ -83,6 +83,12 @@ export const internalFormat = ( * * `Case:` and `Default:` must not make syncing to disallow `Return`, * `ExitApp` and `Label` to un-indent inside `Switch-Case` block. + * + * ------------------------------------------------------------------------- + * `tagDepth = 0`: + * + * `Return`, `ExitApp`, `#If Directive` resets `tagDepth` value, when + * they un-indented. */ let tagDepth = 0; From 9a93eba0fe1c880011fcffcd16ca7ffed5432b01 Mon Sep 17 00:00:00 2001 From: kyklish Date: Fri, 24 May 2024 19:42:49 +0300 Subject: [PATCH 5/5] reset tagDepth in single line hotkey --- src/providers/format.test.ts | 1 + src/providers/formattingProvider.ts | 6 ++++-- ...42-fall-through-single-line-hotkey-with-function.in.ahk | 7 +++++++ ...2-fall-through-single-line-hotkey-with-function.out.ahk | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/providers/samples/442-fall-through-single-line-hotkey-with-function.in.ahk create mode 100644 src/providers/samples/442-fall-through-single-line-hotkey-with-function.out.ahk diff --git a/src/providers/format.test.ts b/src/providers/format.test.ts index 10a5c3ba..c804f1fc 100644 --- a/src/providers/format.test.ts +++ b/src/providers/format.test.ts @@ -72,6 +72,7 @@ const formatTests: FormatTest[] = [ { filenameRoot: '429-single-line-hotkey' }, { filenameRoot: '432-label-inside-code-block' }, { filenameRoot: '440-fall-through-single-line-hotkey-with-if-directive' }, + { filenameRoot: '442-fall-through-single-line-hotkey-with-function' }, { filenameRoot: 'ahk-explorer' }, { filenameRoot: 'align-assignment' }, { filenameRoot: 'demo' }, diff --git a/src/providers/formattingProvider.ts b/src/providers/formattingProvider.ts index 0241b1df..0cefdb2b 100644 --- a/src/providers/formattingProvider.ts +++ b/src/providers/formattingProvider.ts @@ -87,8 +87,8 @@ export const internalFormat = ( * ------------------------------------------------------------------------- * `tagDepth = 0`: * - * `Return`, `ExitApp`, `#If Directive` resets `tagDepth` value, when - * they un-indented. + * `Return`, `ExitApp`, `#If Directive`, `HotkeySingleLine` resets + * `tagDepth` value, when they un-indented. */ let tagDepth = 0; @@ -881,6 +881,8 @@ export const internalFormat = ( tagDepth = depth; } } + } else if (purifiedLine.match(hotkeySingleLine)) { + tagDepth = 0; } // CONTINUATION SECTION: Expression, Object diff --git a/src/providers/samples/442-fall-through-single-line-hotkey-with-function.in.ahk b/src/providers/samples/442-fall-through-single-line-hotkey-with-function.in.ahk new file mode 100644 index 00000000..96232598 --- /dev/null +++ b/src/providers/samples/442-fall-through-single-line-hotkey-with-function.in.ahk @@ -0,0 +1,7 @@ +; [Issue #442](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/442) +F1:: +F2::code +foo() { +code +Return +} diff --git a/src/providers/samples/442-fall-through-single-line-hotkey-with-function.out.ahk b/src/providers/samples/442-fall-through-single-line-hotkey-with-function.out.ahk new file mode 100644 index 00000000..d24b7fa1 --- /dev/null +++ b/src/providers/samples/442-fall-through-single-line-hotkey-with-function.out.ahk @@ -0,0 +1,7 @@ +; [Issue #442](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/442) +F1:: +F2::code +foo() { + code + Return +}