Skip to content

Commit

Permalink
Merge branch '#307' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zero-plusplus committed Dec 3, 2023
2 parents 6f2a6cc + 9402f7d commit fab1112
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Also want to check the development status, check the [commit history](https://gi
* [#275](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/275) Change the syntax of debug directive
* [#288](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/288) Change the labelling process when outputting objects to the log
* [#293](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/293) Change to allow child element to be retrieved even in bracketed notation
* [#307](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/307) Change so that if a file name without extension is specified in the `runtime` attribute of launch.json, it finds the file in the directory registered in the environment variable before finding the AutoHotkey installation directory

### Fixed
* [#207](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/207) Attach fails if file path contains multibyte strings
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This extension is a debugger adapter for [VSCode](https://code.visualstudio.com/
* Changed: [#275](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/275) Change the syntax of debug directive
* Changed: [#288](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/288) Change the labelling process when outputting objects to the log
* Changed: [#293](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/293) Change to allow child element to be retrieved even in bracketed notation

* Changed: [#307](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/307) Change so that if a file name without extension is specified in the `runtime` attribute of launch.json, it finds the file in the directory registered in the environment variable before finding the AutoHotkey installation directory
* Fixed: [#207](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/207) Attach fails if file path contains multibyte strings
* Fixed: [#212](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/212) Some errors were not detected and raw error messages were output. This caused `useAutoJumpToError` to not work in some cases
* Fixed: [#215](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/215) The list of running AutoHotkey processes displayed before attaching does not display correctly when it contains multibyte strings
Expand Down
8 changes: 8 additions & 0 deletions demo/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
"useAnnounce": "develop",
"variableCategories": "recommend"
},
{
"name": "Runtime tests in directories registered in environment variables",
"type": "autohotkey",
"request": "launch",
"runtime": "autohotkey",
"program": "${file}",
"args": []
},
{
"name": "pinnedFile Test",
"type": "autohotkey",
Expand Down
23 changes: 16 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import normalizeToUnix from 'normalize-path';
import glob from 'fast-glob';
import { enableRunToEndOfFunction, registerCommands, setEnableRunToEndOfFunction } from './commands';
import { AhkVersion } from '@zero-plusplus/autohotkey-utilities';
import { isDirectory, reverseSearchPair, searchPair, timeoutPromise, toArray } from './util/util';
import { isDirectory, isValidFileName, reverseSearchPair, searchPair, timeoutPromise, toArray, whereCommand } from './util/util';
import { equalsIgnoreCase } from './util/stringUtils';
import { ExpressionExtractor } from './util/ExpressionExtractor';
import { LaunchInfo, defaultAutoHotkeyInstallDir, getAhkVersion, getAutohotkeyUxRuntimePath, getLaunchInfoByLauncher } from './util/AutoHotkeyLuncher';
Expand All @@ -24,14 +24,23 @@ import * as dbgp from './dbgpSession';
import { sync as pathExistsSync } from 'path-exists';

const ahkPathResolve = (filePath: string, autohotkeyInstallDir?: string): string => {
let _filePath = filePath;
if (!path.isAbsolute(filePath)) {
_filePath = path.resolve(autohotkeyInstallDir ?? `${String(process.env.PROGRAMFILES)}/AutoHotkey`, filePath);
let resolvedFilePath = filePath;

// Search for exe files in directories registered in the environment path
if (isValidFileName(resolvedFilePath)) {
const runtimePath = whereCommand(resolvedFilePath);
if (runtimePath) {
resolvedFilePath = runtimePath;
}
}

if (!path.isAbsolute(resolvedFilePath)) {
resolvedFilePath = path.resolve(autohotkeyInstallDir ?? `${String(process.env.PROGRAMFILES)}/AutoHotkey`, resolvedFilePath);
}
if (path.extname(_filePath) === '') {
_filePath += '.exe';
if (path.extname(resolvedFilePath) === '') {
resolvedFilePath += '.exe';
}
return _filePath;
return resolvedFilePath;
};
const normalizePath = (filePath: string): string => (filePath ? path.normalize(filePath) : filePath); // If pass in an empty string, path.normalize returns '.'
const normalizeCategories = (categories?: CategoriesData): CategoryData[] | undefined => {
Expand Down
26 changes: 26 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AhkVersion } from '@zero-plusplus/autohotkey-utilities';
import { range } from 'lodash';
import tcpPortUsed from 'tcp-port-used';
import { URI } from 'vscode-uri';
import { spawnSync } from 'child_process';
import { CaseInsensitiveMap } from './CaseInsensitiveMap';

export const isDirectory = (dirPath: string): boolean => {
Expand Down Expand Up @@ -255,3 +256,28 @@ export const reverseSearchPair = (text: string, open: string, close: string, ini
}
return text.length - index;
};
export const isValidFileName = (name: string): boolean => {
const regex = /^[^\\/:*?"<>|]+$/u;
return regex.test(name);
};
export const whereCommand = (name: string): string | undefined => {
if (!isValidFileName(name)) {
return undefined;
}

const result = spawnSync(`where`, [ name ]);
if (result.error) {
return undefined;
}

const filePathList = result.stdout.toString().split('\r\n');
if (filePathList.length === 0) {
return undefined;
}

const filePath = filePathList[0];
if (path.isAbsolute(filePath)) {
return path.resolve(filePath);
}
return undefined;
};

0 comments on commit fab1112

Please sign in to comment.