This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Running truffle debug with appropriate flag (--vscode) #5684
Open
xhulz
wants to merge
9
commits into
develop
Choose a base branch
from
feat/debug-vscode
base: develop
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
801061f
feat: first version of using debugging in vscode has been implemented
xhulz 60b00a2
fix: a url object was created to replace string url concatenation
xhulz c878daa
chore: new parameter (fetchExternal) has been added to the serch para…
xhulz 19ce332
fix: some comments has been implemented / changed
xhulz eff430c
fix: some comments has been changed
xhulz 889a667
chore: the vs code debug functions have been isolated in a new class
xhulz 17953b6
Merge branch 'develop' into feat/debug-vscode
xhulz 5b8c10a
chore: network parameter has been added to search params on vscode de…
xhulz b7616f1
refactoring: a new method for retrieving the providerUrl was created
xhulz File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ const debug = debugModule("lib:debug:cli"); | |
|
||
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
const childProcess = require("child_process"); | ||
|
||
const Debugger = require("@truffle/debugger"); | ||
const DebugUtils = require("@truffle/debug-utils"); | ||
|
@@ -204,6 +205,42 @@ class CLIDebugger { | |
|
||
return contracts; | ||
} | ||
|
||
/** | ||
* This function is responsible for opening the debugger in vscode. | ||
*/ | ||
async openVSCodeDebug() { | ||
// Sets the URL | ||
const url = new URL("/debug", "vscode://trufflesuite-csi.truffle-vscode"); | ||
|
||
// 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
url.searchParams.set("fetchExternal", this.config.fetchExternal); | ||
|
||
// Opens VSCode based on OS | ||
const openCommand = process.platform === "win32" ? `start ""` : `open`; | ||
const commandLine = `${openCommand} "${url}"`; | ||
|
||
// Defines the options for the child process. An abort signal is used to cancel the process, if necessary. | ||
const controller = new AbortController(); | ||
const { signal } = controller; | ||
|
||
// Executes the command | ||
childProcess.exec(commandLine, { signal }, (stderr, error) => { | ||
if (stderr) { | ||
throw new Error(`Error opening the debug session in VSCode: ${stderr}`); | ||
} | ||
if (error) { | ||
controller.abort(); | ||
throw new Error(`Error opening the debug session in VSCode: ${error}`); | ||
} | ||
}); | ||
|
||
// Sends a message to the user | ||
this.config.logger.log("Opening truffle debugger in VSCode..."); | ||
} | ||
} | ||
|
||
module.exports = { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinbluer for visibility
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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