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

Improve startup logic & code refactor #10

Merged
merged 2 commits into from
Nov 6, 2023
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
17 changes: 11 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@
"preLaunchTask": "npm: compile"
},
{
"name": "Tests",
"name": "Debug Mocha Tests",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": ["-u", "tdd", "--timeout", "999999", "--colors", "./out/tests/"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "npm: compile"
"program": "${workspaceFolder}/node_modules/ts-mocha/bin/ts-mocha",
"args": [
"-p",
"tsconfig.json",
"tests/*test.ts",
"--timeout",
"30s",
"--diff",
"false"
]
}
],
"compounds": [
Expand Down
8 changes: 1 addition & 7 deletions package-lock.json

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

102 changes: 14 additions & 88 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,50 +108,7 @@
"configuration": "./teal-language-configuration.json"
}
],
"menus": {
"editor/title/run": [
{
"command": "extension.teal-debug.runEditorContents",
"when": "resourceLangId == 'markdown' || resourceLangId == 'teal'",
"group": "navigation@1"
},
{
"command": "extension.teal-debug.debugEditorContents",
"when": "resourceLangId == 'markdown' || resourceLangId == 'teal'",
"group": "navigation@2"
}
],
"commandPalette": [
{
"command": "extension.teal-debug.debugEditorContents",
"when": "resourceLangId == 'markdown' || resourceLangId == 'teal'"
},
{
"command": "extension.teal-debug.runEditorContents",
"when": "resourceLangId == 'markdown' || resourceLangId == 'teal'"
}
]
},
"commands": [
{
"command": "extension.teal-debug.debugEditorContents",
"title": "Debug File",
"category": "TEAL Debug",
"enablement": "!inDebugMode",
"icon": "$(debug-alt)"
},
{
"command": "extension.teal-debug.runEditorContents",
"title": "Run File",
"category": "TEAL Debug",
"enablement": "!inDebugMode",
"icon": "$(play)"
}
],
"breakpoints": [
{
"language": "markdown"
},
{
"language": "teal"
}
Expand All @@ -160,7 +117,6 @@
{
"type": "teal",
"languages": [
"markdown",
"teal"
],
"label": "TEAL Debug",
Expand All @@ -169,48 +125,20 @@
"configurationAttributes": {
"launch": {
"properties": {
"debuggerPath": {
"type": "string",
"description": "Path to Algorand txn-group debugger that take in both simulate trace file and txn-group app source description file."
},
"simulationTraceFile": {
"simulateTraceFile": {
"type": "string",
"description": "Transaction group simulation response with execution trace.",
"default": ""
},
"appSourceDescriptionFile": {
"type": "string",
"description": "Description file for TEAL sources of apps appearing in transaction group.",
"default": ""
"default": "${workspaceFolder}/path/to/simulateTraceFile.json"
},
"program": {
"programSourcesDescriptionFile": {
"type": "string",
"description": "Absolute path to a text file.",
"default": "${workspaceFolder}/${command:AskForProgramName}"
"description": "Description file for sources of programs appearing in transaction group.",
"default": "${workspaceFolder}/path/to/programSourcesDescriptionFile.json"
},
"stopOnEntry": {
"type": "boolean",
"description": "Automatically stop after launch.",
"default": true
},
"trace": {
"type": "boolean",
"description": "Enable logging of the Debug Adapter Protocol.",
"default": true
},
"compileError": {
"type": "string",
"description": "Simulates a compile error in 'launch' request.",
"enum": [
"default",
"show",
"hide"
],
"enumDescriptions": [
"default: show fake compile error to user",
"show fake compile error to user",
"do not show fake compile error to user"
]
}
}
}
Expand All @@ -219,23 +147,22 @@
{
"type": "teal",
"request": "launch",
"appSourceDescriptionFile": "launch.json",
"simulationTraceFile": "launch.json",
"debuggerPath": "yo-a-path-for-deal",
"name": "Ask for file name",
"program": "${workspaceFolder}/${command:AskForProgramName}",
"name": "Debug AVM Transactions",
"simulateTraceFile": "${workspaceFolder}/path/to/simulateTraceFile.json",
"programSourcesDescriptionFile": "${workspaceFolder}/path/to/programSourcesDescriptionFile.json",
"stopOnEntry": true
}
],
"configurationSnippets": [
{
"label": "TEAL Debug: Launch",
"description": "A new configuration for 'debugging' a user selected markdown file.",
"label": "AVM Debug",
"description": "A new configuration for replaying and debugging a Algorand transactions.",
"body": {
"type": "teal",
"request": "launch",
"name": "Ask for file name",
"program": "^\"\\${workspaceFolder}/\\${command:AskForProgramName}\"",
"name": "Debug AVM Transactions",
"simulateTraceFile": "^\"\\${workspaceFolder}/path/to/simulateTraceFile.json\"",
"programSourcesDescriptionFile": "^\"\\${workspaceFolder}/path/to/programSourcesDescriptionFile.json\"",
"stopOnEntry": true
}
}
Expand All @@ -245,7 +172,6 @@
},
"dependencies": {
"algosdk": "github:jasonpaulos/js-algorand-sdk#teal-source-map-improvements",
"json-bigint": "^1.0.0",
"lodash": "^4.17.21"
"json-bigint": "^1.0.0"
}
}
15 changes: 4 additions & 11 deletions sampleWorkspace/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@
{
"type": "teal",
"request": "launch",
"name": "Debug Transaction Group",
"debuggerPath": "stuff-to-deal",
"name": "Debug Slot Machine",

// "program": "${workspaceFolder}/stepping-test/simulate-response.json",
// "simulationTraceFile": "${workspaceFolder}/stepping-test/simulate-response.json",
// "appSourceDescriptionFile": "${workspaceFolder}/stepping-test/sources.json",
"simulateTraceFile": "${workspaceFolder}/slot-machine/simulate-response.json",
"programSourcesDescriptionFile": "${workspaceFolder}/slot-machine/sources.json",

"program": "${workspaceFolder}/slot-machine/simulate-response.json",
"simulationTraceFile": "${workspaceFolder}/slot-machine/simulate-response.json",
"appSourceDescriptionFile": "${workspaceFolder}/slot-machine/sources.json",

"stopOnEntry": true,
"trace": false
"stopOnEntry": true
}
]
}
92 changes: 1 addition & 91 deletions src/activateMockDebug.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,13 @@
'use strict';

import * as vscode from 'vscode';
import { FileAccessor } from './debugAdapter/utils';
import { TEALDebugAdapterDescriptorFactory } from './extension';
import { TEALDebugAdapterDescriptorFactory } from './descriptorFactory';
import { TealDebugConfigProvider } from './configuration';

export function activateTealDebug(
context: vscode.ExtensionContext,
factory: TEALDebugAdapterDescriptorFactory,
config: vscode.DebugConfiguration,
) {
context.subscriptions.push(
vscode.commands.registerCommand(
'extension.teal-debug.runEditorContents',
(resource: vscode.Uri) => {
let targetResource = resource;
if (!targetResource && vscode.window.activeTextEditor) {
targetResource = vscode.window.activeTextEditor.document.uri;
}
if (targetResource) {
vscode.debug.startDebugging(
undefined,
{
...config,
name: 'Run File',
program: targetResource.fsPath,
},
{ noDebug: true },
);
}
},
),
vscode.commands.registerCommand(
'extension.teal-debug.debugEditorContents',
(resource: vscode.Uri) => {
let targetResource = resource;
if (!targetResource && vscode.window.activeTextEditor) {
targetResource = vscode.window.activeTextEditor.document.uri;
}
if (targetResource) {
vscode.debug.startDebugging(undefined, {
...config,
name: 'Debug File',
program: targetResource.fsPath,
});
}
},
),
);

// register a configuration provider for 'teal' debug type
const provider = new TealDebugConfigProvider();
context.subscriptions.push(
Expand All @@ -61,53 +20,4 @@ export function activateTealDebug(
// https://vscode-docs.readthedocs.io/en/stable/extensions/patterns-and-principles/#events
// see events, by the end of subscription, call `dispose()` to release resource.
context.subscriptions.push(factory);

// override VS Code's default implementation of the debug hover
// here we match only Mock "variables", that are words starting with an '$'
context.subscriptions.push(
vscode.languages.registerEvaluatableExpressionProvider('markdown', {
provideEvaluatableExpression(
document: vscode.TextDocument,
position: vscode.Position,
): vscode.ProviderResult<vscode.EvaluatableExpression> {
const VARIABLE_REGEXP = /\$[a-z][a-z0-9]*/gi;
const line = document.lineAt(position.line).text;

let m: RegExpExecArray | null;
while ((m = VARIABLE_REGEXP.exec(line))) {
const varRange = new vscode.Range(
position.line,
m.index,
position.line,
m.index + m[0].length,
);

if (varRange.contains(position)) {
return new vscode.EvaluatableExpression(varRange);
}
}
return undefined;
},
}),
);
}

export const workspaceFileAccessor: FileAccessor = {
isWindows: typeof process !== 'undefined' && process.platform === 'win32',
async readFile(path: string): Promise<Uint8Array> {
const uri = pathToUri(path);
return await vscode.workspace.fs.readFile(uri);
},
async writeFile(path: string, contents: Uint8Array) {
const uri = pathToUri(path);
await vscode.workspace.fs.writeFile(uri, contents);
},
};

function pathToUri(path: string) {
try {
return vscode.Uri.file(path);
} catch (e) {
return vscode.Uri.parse(path, true);
}
}
29 changes: 10 additions & 19 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,21 @@
resolveDebugConfiguration(
_folder: WorkspaceFolder | undefined,
config: DebugConfiguration,
_token?: CancellationToken,

Check warning on line 21 in src/configuration.ts

View workflow job for this annotation

GitHub Actions / test (18)

'_token' is defined but never used

Check warning on line 21 in src/configuration.ts

View workflow job for this annotation

GitHub Actions / test (18)

'_token' is defined but never used
): ProviderResult<DebugConfiguration> {
// NOTE: log the overloaded config to window
vscode.window.showInformationMessage(JSON.stringify(config));

// Check necessary part, we do need these 2 files for debug
if (!config.simulationTraceFile) {
return vscode.window
.showInformationMessage(
'missing critical part: simulationTraceFile in launch.json',
)
.then((_) => {
return undefined;
});
if (!config.simulateTraceFile) {
vscode.window.showErrorMessage(
'Missing property "simulateTraceFile" in debug config',
);
return null;
}

if (!config.appSourceDescriptionFile) {
return vscode.window
.showInformationMessage(
'missing critical part: appSourceDescriptionFile in launch.json',
)
.then((_) => {
return undefined;
});
if (!config.programSourcesDescriptionFile) {
vscode.window.showErrorMessage(
'Missing property "programSourcesDescriptionFile" in debug config',
);
return null;
}

return config;
Expand Down
Loading