我不完全确定如何在 VS-Code 中使用 QuickInput

I'm not entirely sure how to use QuickInput in VS-Code

我最近问了一个问题 "how do i add custom parameters to a custom command in a custom vs code extension" and realized through some of the comments that you cant enter parameters in the command palette. so i looked for alternate options. one i came across was quickInput which allows the user to enter text into a window. however, being new to typescript, along with having documentation 为我手上更有知识的用户,我不知道如何使用它。请帮忙!

更新:由于找不到“quickInput”,我决定选择“showInputBox”,但不确定如何使用“title”参数。但只是为了测试海豚,我决定测试以下内容:

var info  = vscode.window.showInputBox();
vscode.window.showInformationMessage(info);

但出现错误:

No overload matches this call.
Overload 1 of 4, '(message: string, ...items: string[]); Thenable<string | undefined>', gave the following error.
Argument of type 'Thenable<string | undefined>' is not assignable to the parameter of type 'string'.
Overload 2 of 4, '(message: string, ...items: MessageItem[]); Thenable<MessageItem | undefined>', gave the following error.
Argument of type 'Thenable<string | undefined>' is not assignable to the parameter of type 'string'. ts(2769) [29, 40]

我注意到它只给出了重载 1 和 2,而不是 3 和 4 无论如何,现在我需要知道如何添加:1) 输入框的标题,以及 2) 如何解决该错误!!!

编辑2: 我试过这个来解决变量类型问题:

var info = vscode.window.showInputBox();
if(typeof info === "string") {
    vscode.window.showInformationMessage(info);
}

它没有出现任何错误,但是...它接受了我的输入但没有发送它。

我之前用过的一些示例代码(修改):


let inputBoxOptions = {
  ignoreFocusOut: true,
  title: "your title here"
};

// you can use the above or below ways to specify your inputBoxOptions
// 'command' is a variable I have declared elsewhere I want to use now 

inputBoxOptions.prompt = `Enter an alias for the command: ${ command } . . . . . `;
inputBoxOptions.placeHolder = `Enter an alias(es) for the ${ command } here`;

await vscode.window.showInputBox(inputBoxOptions)
  .then(arg => {
      // run your code using the inputBox 'arg' here
   });
}

您需要await用户的输入。然后在 then 函数中使用它或如下所示:


或文档示例:

export async function showInputBox() {
    const result = await window.showInputBox({
        value: 'abcdef',
        valueSelection: [2, 4],
        placeHolder: 'For example: fedcba. But not: 123',
        validateInput: text => {
            window.showInformationMessage(`Validating: ${text}`);
            return text === '123' ? 'Not 123!' : null;
        }
    });
    window.showInformationMessage(`Got: ${result}`);
}

basic input documentation