admin管理员组文章数量:1026989
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!
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!
本文标签: VSCode task arguments not passing to custume extension commandStack Overflow
版权声明:本文标题:VSCode task arguments not passing to custume extension command - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745658818a2161763.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论