Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Running truffle debug with appropriate flag (--vscode) #5684

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

xhulz
Copy link

@xhulz xhulz commented Nov 9, 2022

PR description

This PR allows the user to debug a transaction using VSCode.

Testing instructions

1. Download and Unzip the Truffle extension VSIX (local version is 2.3.5): truffle-vscode-2.3.5.vsix.zip

2. To install:

  • 2.1 Open the VSCode.
  • 2.2 Click on the Extensions Tab on the left menu.
  • 2.3 Click on the 3 dots at the top of the menu.
  • 2.4 Choose the option: Install from VSIX.

Screenshot 2022-11-22 at 10 17 07

3. To prevent VSCode from updating the Truffle extension version choose the option Ignore updates:

Screenshot 2022-11-22 at 10 19 33

4. To debug using VSCode, just type in your terminal: truffle debug {your tx} --vscode

5. If you want to use the fetchExternal option, just add the flag: truffle debug {your tx} --vscode --fetchExternal`

7. To debug using VSCode, just type: truffle debug {your tx} --vscode

Reminder: VSCode will ask if you want to allow debugging,](reminder: VSCode will ask if you want to allow opening the url for debugging. To continue, click open.

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if documentation updates are required.

Breaking changes and new features

  • I have added any needed breaking-change and new-feature labels for the appropriate packages.


// Checks if the user wants to open the debugger in vscode
if (config.vscode) {
await cliDebugger.openVSCodeDebug();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this method not be part of the thing called the "CLI" debugger? Seems better to keep the CLIDebugger just for the CLI and push this VS Code logic elsewhere.

Copy link
Author

@xhulz xhulz Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gnidan, Thank you for that

What would be the best place (package/class) to put this code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinbluer for visibility

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up @xhulz! Also sounds like we've got a way forward for this from our earlier conversation 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe just have a VSCodeDebugger class?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @gnidan @kevinbluer

I just moved all the vscode debug function to a new class called VSCodeDebugger.

Thank you all again

// Sets the query parameters
url.searchParams.set("txHash", this.txHash);
url.searchParams.set("workingDirectory", this.config.working_directory);
url.searchParams.set("providerUrl", this.config.provider.host);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is brittle, since we can't always rely on being able to get a URL from a provider

Copy link

@acuarica acuarica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, although please keep in mind that my review is mostly about style rather than correctness, since I'm not that familiar with Truffle codebase.

url.searchParams.set("disableFetchExternal", disableFetchExternal);

// Opens VSCode based on OS
const openCommand = process.platform === "win32" ? `start ""` : `open`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does open also works in Linux?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, win32: start, osX: open, and *nix is xdg-open or similar resource openers mimeopen, mimeo, linopen, handlr etc.

Comment on lines +64 to +66
return new URL(
`http://${this.config.network_config.host}:${this.config.network_config.port}`
).toString();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth to do new URL(string).toString()? In other words, what's the issue with returning just http://[...]?

/**
* This function is responsible for opening the debugger in vscode.
*/
async run() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the purpose of this method, I would name it open instead of run.

@@ -0,0 +1,73 @@
const childProcess = require("child_process");

class VSCodeDebugger {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small detail, the name VSCodeDebugger might be a bit misleading. What about VSCodeOpenDebugger or VSCodeDebugAdapter?

@xhulz
Copy link
Author

xhulz commented Nov 22, 2022

Hey @acuarica, thank you for you review!

Your suggestions make sense. I'll wait for the other reviews to implement them all at once.

Thank you!

Copy link
Member

@cds-amal cds-amal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review, I didn't get a chance to run this yet.

url.searchParams.set("disableFetchExternal", disableFetchExternal);

// Opens VSCode based on OS
const openCommand = process.platform === "win32" ? `start ""` : `open`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, win32: start, osX: open, and *nix is xdg-open or similar resource openers mimeopen, mimeo, linopen, handlr etc.

@eggplantzzz
Copy link
Contributor

Sorry for neglecting this for so long, I didn't know that you were waiting on a review for me!

It looks like there is some kind of problem when importing truffle/console. I get this when executing debug with --vscode:
Screenshot 2023-01-17 at 3 16 47 PM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants