I'm trying to create a simple VS Code extension that receives arguments from a task, but the arguments aren't being passed through. Here's my setup: Extension Code (extension.ts):
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
let disposable = vscodemands.registerCommand('testExtension.sendMessage', (...args) => {
console.log('Received arguments:', args);
const terminal = vscode.window.createTerminal('Test Extension');
terminal.show();
if (args && args.length > 0) {
const message = args.join(' ');
terminal.sendText(`echo "Received message: ${message}"`);
} else {
terminal.sendText('echo "No message received"');
}
});
context.subscriptions.push(disposable);
}
package.json related sections:
"activationEvents": [
"onCommand:testExtension.sendMessage"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "testExtension.sendMessage",
"title": "Test Extension: Send Message"
}
]
},
this is the tasks.json in nother vscode instance:
{
"version": "2.0.0",
"tasks": [
{
"label": "Send Message",
"type": "shell",
"command": "${command:testExtension.sendMessage}",
"args": [
"hello world"
],
"runOptions": {
"reevaluateOnRerun": true
}
}
]
}
When I run the task, it always outputs "No message received". The arguments specified in tasks.json ("hello world") are not being passed to the extension command. I've Tried:
"args": ["hello", "world"]
"args": {
"message": "hello world"
}
None of these attempts worked - the arguments from tasks.json never reach the extension command.
How can I properly pass arguments from a VS Code task to an extension command? Is there a specific format or method I need to use to make this work?
Environment:
VS Code Version: 1.94.0
OS: Windows 10
Any help would be appreciated!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745658820a4638709.html
评论列表(0条)