how to use vscode CompletionItemProvider by keybinding

一世执手 提交于 2020-02-07 01:59:07

问题


I tried to write an extension to vscode to help me import lib by keyboard shortcuts I've tried many things, but two questions remain unanswered

1.How to use CompletionItemProvider by shortcut key

Normally, CompletionItemProvider is triggered by a character,But I want to be able to use the shortcut to bind commands.Ideally, I could press the shortcut to display the CompletionItems directly.But the only thing I know so far is through vscode.com command.excute('trugger suggest'), which can be cluttered with other CompletionItems

2.How to hide other CompletionItems

When trigger the CompletionItemProvider,other options appear . They should come from other extensions .What should I do to display only my own extension options

code:

export function activate(context: vscode.ExtensionContext) {
    const provider = vscode.languages.registerCompletionItemProvider({
        scheme:"file",
        language:"typescript"
    }, {
        provideCompletionItems(doc, pos) {
            return [
                new vscode.CompletionItem("1.foo"),
                new vscode.CompletionItem("2.bar"),
                new vscode.CompletionItem("3.baz")
            ]
        }
    })

    context.subscriptions.push(provider);
}

result:out of the red box are unnecessary options

来源:https://stackoverflow.com/questions/59941508/how-to-use-vscode-completionitemprovider-by-keybinding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!