VSCode task arguments not passing to custume extension command - Stack Overflow

I'm trying to create a simple VS Code extension that receives arguments from a task, but the argum

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信