在我的 VS 代碼擴展中,我希望在從完成項提供程式提供的串列中選擇一個函式后自動插入左括號和右括號。
添加括號后,我希望擴展程式觸發簽名幫助提供程式(注意當您手動鍵入左括號時,VS Code 會觸發簽名幫助提供程式(。
這是我在provideCompletionItems方法中添加的片段:
myFunctions.forEach((func) => {
const completion = new CompletionItem(func, CompletionItemKind.Function);
completion.detail = func.signature;
completion.documentation = func.description;
completion.insertText = func '(';
...
});
我知道我可以在插入完成后通過添加類似的東西來執行命令
completion.command = ...
VS Code 擴展 API 具有vscode.executeSignatureHelpProvider執行簽名幫助提供程式的內置命令。因此,我會像這樣運行這個命令:
vscode.commands.executeCommand('vscode.executeSignatureHelpProvider', document.uri, position)
但是,我不知道如何將此命令作為command變數的一部分運行,這意味著我做不到
completion.command = vscode.commands.executeCommand('vscode.executeSignatureHelpProvider', document.uri, position)
因為command變數只接受 type Command。
那么,將完成插入編輯器后如何運行命令?
解決方案:
根據下面的答案,我意識到我使用了錯誤的命令來觸發引數提示小部件。相反,我使用了以下editor.action.triggerParameterHints命令:
completion.command = { command: 'editor.action.triggerParameterHints', title: '' };
uj5u.com熱心網友回復:
請嘗試使用該editor.action.triggerParameterHints命令。如果您已經注冊了自己的 SignatureHelpProvider 應該觸發它運行。如果您還沒有注冊自己的,那應該會觸發默認提供程式。
completion.command = "editor.action.triggerParameterHints";
如果您有更多作業要做,您還可以通過以下方式呼叫命令CompletionItem:
newCommand.command = "<your extension name>.selectDigitInCompletion";
newCommand.title = "Select the digit 'n' in completionItem";
newCommand.arguments = [key, replaceRange, position]; // whatever args you want to pass to the command
completion.command = newCommand;
然后該命令在某處注冊 - 它不必位于package.json:
vscode.commands.registerCommand('<your extension name>.selectDigitInCompletion', async (completionText, completionRange, position) => {
// ...
// access your passed-in args `completionText`,`completionRange` and `position` here
// await vscode.commands.executeCommand('vscode.executeSignatureHelpProvider', document.uri, position)
...
}
uj5u.com熱心網友回復:
分配Command物件的一個??實體
completion.command = { command: 'vscode.executeSignatureHelpProvider', title: 'Signature' };
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/431502.html
標籤:javascript 打字稿 视觉工作室代码 vscode 扩展
上一篇:Java代碼未在我的macbook的VS代碼上執行(運行)
下一篇:VScode為隨機線添加一些顏色
