-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Running truffle debug with appropriate flag (--vscode) #5684
base: develop
Are you sure you want to change the base?
Changes from all commits
801061f
60b00a2
c878daa
19ce332
eff430c
889a667
17953b6
5b8c10a
b7616f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const { CLIDebugger } = require("./cli"); | ||
const { VSCodeDebugger } = require("./vscode"); | ||
|
||
module.exports = { | ||
CLIDebugger | ||
CLIDebugger, | ||
VSCodeDebugger | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const childProcess = require("child_process"); | ||
|
||
class VSCodeDebugger { | ||
constructor(config, txHash) { | ||
this.config = config; | ||
this.txHash = txHash; | ||
} | ||
|
||
/** | ||
* This function is responsible for opening the debugger in vscode. | ||
*/ | ||
async run() { | ||
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. Given the purpose of this method, I would name it |
||
// Sets the URL | ||
const url = new URL("/debug", "vscode://trufflesuite-csi.truffle-vscode"); | ||
|
||
const disableFetchExternal = this.config.fetchExternal ? false : true; | ||
|
||
// Sets the query parameters | ||
url.searchParams.set("txHash", this.txHash); | ||
url.searchParams.set("workingDirectory", this.config.working_directory); | ||
url.searchParams.set("providerUrl", this.getProviderUrl()); | ||
url.searchParams.set("network", this.config.network); | ||
url.searchParams.set("disableFetchExternal", disableFetchExternal); | ||
|
||
// Opens VSCode based on OS | ||
const openCommand = process.platform === "win32" ? `start ""` : `open`; | ||
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. Does 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. IIRC, |
||
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..."); | ||
} | ||
|
||
/** | ||
* This function is for getting the provider URL. | ||
*/ | ||
getProviderUrl() { | ||
// Checks if the user is using a custom provider | ||
if (this.config.url) { | ||
return this.config.url; | ||
} | ||
|
||
// Checks if there is a provider in the config | ||
if (this.config.provider) { | ||
return this.config.provider.host; | ||
} | ||
|
||
// Creates the provider URL from host and port | ||
if (this.config.network_config) { | ||
return new URL( | ||
`http://${this.config.network_config.host}:${this.config.network_config.port}` | ||
).toString(); | ||
Comment on lines
+64
to
+66
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. Is it worth to do |
||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
VSCodeDebugger | ||
}; |
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.
Just a small detail, the name
VSCodeDebugger
might be a bit misleading. What aboutVSCodeOpenDebugger
orVSCodeDebugAdapter
?