Skip to content

Commit

Permalink
Add: #75
Browse files Browse the repository at this point in the history
Support custom context menu for data inspection
  • Loading branch information
zero-plusplus committed Oct 13, 2021
1 parent 73381e8 commit 673cd82
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Also want to check the development status, check the [commit history](https://gi
## [Released]
## [1.10.0] - 2021-xx-xx
### Added
* [#75](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/75) Add some context menus to copy the value of a variable in data inspection
* [#88](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/88) Support `variableCategories` attribute in launch.json
* [#142](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/142) Support `suppressAnnounce` attribute in launch.json
* [#142](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/142) Support `useOutputDebug` attribute in launch.json
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ This extension is a debugger adapter for [VSCode](https://code.visualstudio.com/
### Important Notices
* Much of the README content has been migrated to the [Github wiki](https://github.com/zero-plusplus/vscode-autohotkey-debug/wiki). If you want to see the description of each feature, please refer to there

* The required version of VSCode has been raised from [1.45.0](https://code.visualstudio.com/updates/v1_45) to [1.49.0](https://code.visualstudio.com/updates/v1_49).

* Since `1.10.0` is a relatively large update with additions and fixes, there may be new bugs. If you find any, please report them in [Issues](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues)

### Update
* `1.10.0` - 2021-xx-xx
* Added: [#75](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/75) Add some context menus to copy the value of a variable in data inspection
* Added: [#88](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/88) Support `variableCategories` attribute in launch.json
* Added: [#142](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/142) Support `suppressAnnounce` attribute in launch.json
* [#142](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/142) Support `useOutputDebug` attribute in launch.json
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 53 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"publisher": "zero-plusplus",
"engines": {
"vscode": "^1.45.0"
"vscode": "^1.49.0"
},
"icon": "image/icon.png",
"keywords": [
Expand Down Expand Up @@ -53,6 +53,57 @@
"language": "ah2"
}
],
"commands": [
{
"command": "vscode-autohotkey-debug.variables-view.copyAsText",
"title": "Copy as Text"
},
{
"command": "vscode-autohotkey-debug.variables-view.copyAsDecimal",
"title": "Copy as Decimal"
},
{
"command": "vscode-autohotkey-debug.variables-view.copyAsBinary",
"title": "Copy as Binary"
},
{
"command": "vscode-autohotkey-debug.variables-view.copyAsHex",
"title": "Copy as Hex"
},
{
"command": "vscode-autohotkey-debug.variables-view.copyAsScientificNotation",
"title": "Copy as Scientific Notation"
}
],
"menus": {
"debug/variables/context": [
{
"command": "vscode-autohotkey-debug.variables-view.copyAsText",
"when": "debugConfigurationType == 'autohotkey'",
"group": "5_cutcopypaste"
},
{
"command": "vscode-autohotkey-debug.variables-view.copyAsDecimal",
"when": "debugConfigurationType == 'autohotkey'",
"group": "5_cutcopypaste"
},
{
"command": "vscode-autohotkey-debug.variables-view.copyAsBinary",
"when": "debugConfigurationType == 'autohotkey'",
"group": "5_cutcopypaste"
},
{
"command": "vscode-autohotkey-debug.variables-view.copyAsHex",
"when": "debugConfigurationType == 'autohotkey'",
"group": "5_cutcopypaste"
},
{
"command": "vscode-autohotkey-debug.variables-view.copyAsScientificNotation",
"when": "debugConfigurationType == 'autohotkey'",
"group": "5_cutcopypaste"
}
]
},
"debuggers": [
{
"type": "autohotkey",
Expand Down Expand Up @@ -775,7 +826,7 @@
"@types/parsimmon": "^1.10.1",
"@types/underscore": "^1.9.4",
"@types/underscore.string": "^0.0.38",
"@types/vscode": "^1.45.0",
"@types/vscode": "^1.49.0",
"@types/webpack": "^4.41.25",
"@types/webpack-merge": "^4.1.5",
"@zero-plusplus/eslint-my-rules": "^1.0.28",
Expand Down
2 changes: 2 additions & 0 deletions src/ahkDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
matchers: MatcherData[];
}>;
suppressAnnounce: boolean;
// The following is not a configuration, but is set to pass data to the debug adapter.
cancelReason?: string;
extensionContext: vscode.ExtensionContext;
}

type LogCategory = 'console' | 'stdout' | 'stderr';
Expand Down
34 changes: 34 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
ExtensionContext,
ProviderResult,
WorkspaceFolder,
commands,
debug,
env,
languages,
window,
workspace,
Expand All @@ -28,6 +30,7 @@ import { getRunningAhkScriptList } from './util/getRunningAhkScriptList';
// eslint-disable-next-line @typescript-eslint/no-require-imports
import normalizeToUnix = require('normalize-path');
import * as glob from 'fast-glob';
import { unescapeAhk } from './util/VariableManager';

const ahkPathResolve = (filePath: string, cwd?: string): string => {
let _filePath = filePath;
Expand Down Expand Up @@ -76,6 +79,7 @@ class AhkConfigurationProvider implements DebugConfigurationProvider {
useUIAVersion: false,
suppressAnnounce: false,
trace: false,
// The following is not a configuration, but is set to pass data to the debug adapter.
cancelReason: undefined,
});

Expand Down Expand Up @@ -456,6 +460,36 @@ class InlineDebugAdapterFactory implements DebugAdapterDescriptorFactory {
export const activate = (context: ExtensionContext): void => {
const provider = new AhkConfigurationProvider();

context.subscriptions.push(commands.registerCommand('vscode-autohotkey-debug.variables-view.copyAsText', async(param): Promise<void> => {
const value = param.variable.value as string;
const text = unescapeAhk(value.replace(/(^"|"$)/gu, ''));
await env.clipboard.writeText(text);
}));
context.subscriptions.push(commands.registerCommand('vscode-autohotkey-debug.variables-view.copyAsDecimal', async(param): Promise<void> => {
const value = param.variable.value as string;
const text = value.replace(/(^"|"$)/gu, '');
const decimal = Number(text).toString(10);
await env.clipboard.writeText(decimal);
}));
context.subscriptions.push(commands.registerCommand('vscode-autohotkey-debug.variables-view.copyAsBinary', async(param): Promise<void> => {
const value = param.variable.value as string;
const text = value.replace(/(^"|"$)/gu, '');
const binary = Number(text).toString(2);
await env.clipboard.writeText(binary);
}));
context.subscriptions.push(commands.registerCommand('vscode-autohotkey-debug.variables-view.copyAsHex', async(param): Promise<void> => {
const value = param.variable.value as string;
const text = value.replace(/(^"|"$)/gu, '');
const hex = Number(text).toString(16);
await env.clipboard.writeText(hex.startsWith('-') ? `-0x${hex.substr(1)}` : `0x${hex}`);
}));
context.subscriptions.push(commands.registerCommand('vscode-autohotkey-debug.variables-view.copyAsScientificNotation', async(param): Promise<void> => {
const value = param.variable.value as string;
const text = value.replace(/(^"|"$)/gu, '');
const scientificNotation = Number(text).toExponential();
await env.clipboard.writeText(scientificNotation);
}));

context.subscriptions.push(debug.registerDebugConfigurationProvider('ahk', provider));
context.subscriptions.push(debug.registerDebugConfigurationProvider('autohotkey', provider));
context.subscriptions.push(debug.registerDebugAdapterDescriptorFactory('autohotkey', new InlineDebugAdapterFactory()));
Expand Down
11 changes: 11 additions & 0 deletions src/util/VariableManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ export const escapeAhk = (str: string, ahkVersion?: AhkVersion): string => {
.replace(/[\x07]/gu, '`a')
.replace(/\f/gu, '`f');
};
export const unescapeAhk = (str: string, ahkVersion?: AhkVersion): string => {
return str
.replace(ahkVersion?.mejor === 2 ? /`"/gu : /""/gu, '"')
.replace(/`r`n/gu, '\r\n')
.replace(/`n/gu, '\n')
.replace(/`r/gu, '\r')
.replace(/`b/gu, '\b')
.replace(/`t/gu, '\t')
.replace(/`v/gu, '\v')
.replace(/`f/gu, '\f');
};
export const formatProperty = (property: dbgp.Property, ahkVersion?: AhkVersion): string => {
const formatPrimitiveProperty = (property: dbgp.PrimitiveProperty): string => {
if (property.type === 'string') {
Expand Down

0 comments on commit 673cd82

Please sign in to comment.