Reputation: 3927
I have an issue when trying to play with the debug api
of vscode
. This is the code I'm using:
const vscode = require('vscode');
function activate(context) {
console.log('Congratulations, your extension "helloworld" is now active!');
let disposable = vscode.commands.registerCommand('extension.helloWorld', function () {
// Display a message box to the user
vscode.window.showInformationMessage('Hello World!'); // This works
const session = vscode.debug.activeDebugSession;
console.log(session); // returns undefined
// I have tried this one, and no text is shown
vscode.debug.activeDebugConsole.append("Hello from Debug Console");
if (session) {
session.customRequest("evaluate", {
"expression": "Math.sqrt(10)"
}).then(reply => {
vscode.window.showInformationMessage(`result: ${reply.result}`);
}, error => {
vscode.window.showInformationMessage(`error: ${error.message}`);
});
}
});
context.subscriptions.push(disposable);
}
exports.activate = activate;
function deactivate() {}
module.exports = {
activate,
deactivate
}
To try this I have made the following steps:
"Hello World"
extension with yeoman.extension.js
with the code from above.But const session = vscode.debug.activeDebugSession;
returns undefined
.
Also vscode.debug.activeDebugConsole.append("Hello from Debug Console");
does not shows anything.
I know that if there is no active debug session, the code from above will not work properly. So:
Do I correctly have an active debug session? What I'm doing wrong here?
Upvotes: 2
Views: 793
Reputation: 53
My suggestion: you have to subscribe to vscode.debug.onDidStartDebugSession
and vscode.debug.onDidTerminateDebugSession
to keep track of when a session starts/ends or use onDidChangeActiveDebugSession
when changing. At that point, you can know that a session is active, and your code should run.
Upvotes: 1
Reputation: 3927
I have solved the issue, following these steps:
"Hello World"
extension with yeoman.extension.js
with the code from above.Upvotes: 2