Skip to content

Commit

Permalink
Fix formatter removing extra spaces in v1 strings (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-wiemer authored Oct 19, 2024
1 parent 37e89e8 commit f0f75c7
Show file tree
Hide file tree
Showing 12 changed files with 2,062 additions and 2,026 deletions.
13 changes: 11 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## 6.3.0 - unreleased 🕳️

- Rename extension to `AHK++ (AutoHotkey Plus Plus)` to provide a clear short name while retaining previous brand
- In 6.2.0, only the settings were renamed. This release renames the extension display name on registries as well.
### New features

- Rewrite AutoHotkey v2 definition files using [GroggyOtter](https://github.com/GroggyOtter/ahkv2_definition_rewrite)'s syntaxes ([#521](https://github.com/mark-wiemer-org/ahkpp/issues/521))
- Add exclude setting ([#488](https://github.com/mark-wiemer-org/ahkpp/issues/488))
- Excluded files are not included in IntelliSense completion suggestions, even when they're added via `#include`
Expand All @@ -12,8 +12,17 @@
- Changes to this setting take effect immediately, no need to restart your IDE (different than thqby's extension)
- v2 will exclude excluded files from suggestions even if they're opened in the IDE (different than thqby's extension)
- v1 no longer automatically ignores files with `out`, `target`, or `node_modules` in their name

### Fixes

- Fixup output channel names: "AHK++ (v1)" and "AHK++ (v2)" instead of "AHK" and "AHK++" respectively
- Fix duplicate output channels
- Fix formatter removing extra spaces in v1 strings ([#411](https://github.com/mark-wiemer-org/ahkpp/issues/411))

### Other

- Rename extension to `AHK++ (AutoHotkey Plus Plus)` to provide a clear short name while retaining previous brand
- In 6.2.0, only the settings were renamed. This release renames the extension display name on registries as well.

## 6.2.3 - 2024-10-08 📖

Expand Down
1 change: 1 addition & 0 deletions demos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sandbox.ah*
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,16 @@
},
"trimExtraSpaces": {
"type": "boolean",
"default": true,
"description": "Trim extra spaces between words."
"default": false,
"description": "%ahk++.config.v1.formatter.trimExtraSpaces%"
}
},
"default": {
"allowedNumberOfEmptyLines": 1,
"indentCodeAfterIfDirective": true,
"indentCodeAfterLabel": true,
"preserveIndent": false,
"trimExtraSpaces": true
"trimExtraSpaces": false
},
"additionalProperties": {
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"ahk++.command.setV2Interpreter": "Set AHK v2 Interpreter",
"ahk++.command.stop": "Stop AHK Script",
"ahk++.command.updateVersionInfo": "Update File Version Info",
"ahk++.config.exclude": "[Glob patterns](<https://en.wikipedia.org/wiki/Glob_(programming)>) for excluding files and folders from completion suggestions. Applies even when files are opened.",
"ahk++.config.general.showOutput": "Automatically show output view when running a script. View can always be toggled with F1 > 'View: Toggle Output' (`Ctrl+Shift+U`)",
"ahk++.config.general.showOutput.always": "Always open the output view when running a script",
"ahk++.config.general.showOutput.never": "Never automatically show the output view",
"ahk++.config.v1.formatter.trimExtraSpaces": "Trim extra spaces between words and symbols",
"ahk++.config.v2.actionWhenV1Detected": "Action when v1 script is detected",
"ahk++.config.v2.commentTagRegex": "The regular expression for custom symbols to appear in the breadcrumb and elsewhere. Default matches any line that starts with `;;`. Changes take effect after restart.",
"ahk++.config.v2.completionCommitCharacters": "Characters which commit auto-completion",
Expand All @@ -22,7 +24,6 @@
"ahk++.config.v2.diagnostics.classNonDynamicMemberCheck": "Check whether non-dynamic members of a class exist",
"ahk++.config.v2.diagnostics.paramsCheck": "Check that the function call has the correct number of arguments",
"ahk++.config.v2.file.interpreterPath": "Path to the `AutoHotkey.exe` executable file for AHK v2.",
"ahk++.config.exclude": "[Glob patterns](<https://en.wikipedia.org/wiki/Glob_(programming)>) for excluding files and folders from completion suggestions. Applies even when files are opened.",
"ahk++.config.v2.file.maxScanDepth": "Depth of folders to scan for IntelliSense. Negative values mean infinite depth.",
"ahk++.config.v2.librarySuggestions": "Which libraries to suggest functions from, if any. In case of issues, restart your IDE.",
"ahk++.config.v2.symbolFoldingFromOpenBrace": "Fold parameter lists separately from definitions.",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"ahk++.config.general.showOutput": "运行脚本时自动显示输出视图。可通过 F1 > '视图.切换输出' (`Ctrl+Shift+U`)随时切换视图: Toggle Output' (`Ctrl+Shift+U`)",
"ahk++.config.general.showOutput.always": "运行脚本时始终打开输出视图",
"ahk++.config.general.showOutput.never": "从不自动显示输出视图",
"ahk++.config.v1.formatter.trimExtraSpaces": "删除单词和符号之间多余的空格",
"ahk++.config.v2.actionWhenV1Detected": "检测到v1脚本时的行为",
"ahk++.config.v2.commentTagRegex": "用来从注释中提取命名标记的正则表达式, 并生成模块符号",
"ahk++.config.v2.completeFunctionCalls": "当右侧不存在`(`或`[`时, 给函数补全添加括号; 否则向右移动光标",
Expand Down
112 changes: 3 additions & 109 deletions src/providers/formattingProvider.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import * as assert from 'assert';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as vscode from 'vscode';
import { FormatProvider, internalFormat } from './formattingProvider';
import { FormatProvider } from './formattingProvider';
import { FormatOptions } from './formattingProvider.types';

const inFilenameSuffix = '.in.ahk';
const outFilenameSuffix = '.out.ahk';

interface FormatTest {
/** Name of the file, excluding the suffix (@see inFilenameSuffix, @see outFilenameSuffix) */
filenameRoot: string;
// Any properties not provided will use `defaultOptions` below
options?: Partial<FormatOptions>;
}

/** Default formatting options, meant to match default extension settings */
const defaultOptions = {
tabSize: 4,
Expand All @@ -24,87 +26,6 @@ const defaultOptions = {
preserveIndent: false,
trimExtraSpaces: true,
};
const formatTests: FormatTest[] = [
{ filenameRoot: '25-multiline-string' },
{ filenameRoot: '28-switch-case' },
{ filenameRoot: '40-command-inside-text' },
{ filenameRoot: '55-if-directive' },
{ filenameRoot: '56-return-command-after-label' },
{ filenameRoot: '58-parentheses-indentation' },
{ filenameRoot: '59-one-command-indentation' },
{ filenameRoot: '72-paren-hotkey' },
{ filenameRoot: '119-semicolon-inside-string' },
{ filenameRoot: '161-colon-on-last-position' },
{ filenameRoot: '180-if-else-braces' },
{
filenameRoot: '182-multiple-newlines',
options: { allowedNumberOfEmptyLines: 2 },
},
{ filenameRoot: '184-continuation-section-expression' },
{ filenameRoot: '184-continuation-section-object' },
{ filenameRoot: '184-continuation-section-text' },
{ filenameRoot: '185-block-comment' },
{
filenameRoot: '187-comments-at-end-of-line',
options: { trimExtraSpaces: false },
},
{ filenameRoot: '188-one-command-code-in-text' },
{ filenameRoot: '189-space-at-end-of-line' },
{
filenameRoot: '192-preserve-indent-true',
options: { preserveIndent: true },
},
{ filenameRoot: '255-close-brace' },
{ filenameRoot: '255-else-if' },
{ filenameRoot: '255-if-loop-mix' },
{ filenameRoot: '255-return-function' },
{ filenameRoot: '255-return-label' },
{ filenameRoot: '255-style-allman' },
{ filenameRoot: '255-style-k-and-r' },
{ filenameRoot: '255-style-mix' },
{ filenameRoot: '255-style-one-true-brace' },
{ filenameRoot: '290-ifmsgbox' },
{ filenameRoot: '291-single-line-comment' },
{ 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' },
{
filenameRoot: 'indent-code-after-if-directive-false',
options: { indentCodeAfterIfDirective: false },
},
{
filenameRoot: 'indent-code-after-if-directive-true',
options: { indentCodeAfterIfDirective: true },
},
{
filenameRoot: 'indent-code-after-label-false',
options: { indentCodeAfterLabel: false },
},
{
filenameRoot: 'indent-code-after-label-true',
options: { indentCodeAfterLabel: true },
},
{
filenameRoot: 'insert-spaces-false',
options: { insertSpaces: false },
},
{ filenameRoot: 'legacy-text-if-directive' },
{ filenameRoot: 'label-colon' },
{ filenameRoot: 'label-combination' },
{ filenameRoot: 'label-fall-through' },
{ filenameRoot: 'label-specific-name' },
{ filenameRoot: 'return-exit-exitapp' },
{ filenameRoot: 'single-line-comment' },
{
filenameRoot: 'tab-size-2',
options: { tabSize: 2 },
},
];

// Currently in `out` folder, need to get back to main `src` folder
const filesParentPath = path.join(
Expand All @@ -117,33 +38,6 @@ const filesParentPath = path.join(
'samples', // ./src/providers/samples
);

const fileToString = (path: string): string => fs.readFileSync(path).toString();

suite('Internal formatter', () => {
formatTests.forEach((formatTest) => {
test(`${formatTest.filenameRoot} internal format`, async () => {
// Arrange
const inFilePath = path.join(
filesParentPath,
`${formatTest.filenameRoot}${inFilenameSuffix}`,
);
const inFileString = fileToString(inFilePath);
const outFilePath = path.join(
filesParentPath,
`${formatTest.filenameRoot}${outFilenameSuffix}`,
);
const outFileString = fileToString(outFilePath);
const options = { ...defaultOptions, ...formatTest.options };

// Act
const actual = internalFormat(inFileString, options);

// Assert
assert.strictEqual(actual, outFileString);
});
});
});

suite('External formatter', () => {
// test external formatter a few times to make sure the connection is working
// advanced tests are for internal formatter only
Expand Down
Loading

0 comments on commit f0f75c7

Please sign in to comment.