Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: for #433 PR (single line hotkey fall-through scenario) #441

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/providers/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ 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: '442-fall-through-single-line-hotkey-with-function' },
{ filenameRoot: 'ahk-explorer' },
{ filenameRoot: 'align-assignment' },
{ filenameRoot: 'demo' },
Expand Down
33 changes: 20 additions & 13 deletions src/providers/formattingProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
*
Expand All @@ -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).
*
* -------------------------------------------------------------------------
Expand All @@ -85,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`, `HotkeySingleLine` resets
* `tagDepth` value, when they un-indented.
*/
let tagDepth = 0;

Expand Down Expand Up @@ -305,8 +309,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
Expand Down Expand Up @@ -692,12 +696,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;
Expand Down Expand Up @@ -849,14 +853,15 @@ 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.+') &&
indentCodeAfterIfDirective
) {
depth++;
tagDepth = 0;
}

// SWITCH-CASE-DEFAULT or LABEL: or HOTKEY::
Expand All @@ -876,6 +881,8 @@ export const internalFormat = (
tagDepth = depth;
}
}
} else if (purifiedLine.match(hotkeySingleLine)) {
tagDepth = 0;
}

// CONTINUATION SECTION: Expression, Object
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; [Issue #442](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/442)
F1::
F2::code
foo() {
code
Return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; [Issue #442](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/442)
F1::
F2::code
foo() {
code
Return
}
Loading