添加完成项提供程序并保留建议 [英] add completionitemprovider and keep suggestions

查看:34
本文介绍了添加完成项提供程序并保留建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的扩展创建了一个 completionitemprovider,但现在没有显示基于文档中单词的建议.我是否必须提供文档中的每个单词?

I created a completionitemprovider for my extension, but now the suggestions based on words in the document aren't shown. Do I have to provide each word in the document?

export class ScriptViewProvider implements vscode.CompletionItemProvider
...
    extension.context.subscriptions.push(vscode.languages.registerCompletionItemProvider(
            ["language"],
            this));
...
    async provideCompletionItems(document : vscode.TextDocument, position : vscode.Position) : Promise<vscode.CompletionItem[]> {
        let completions : vscode.CompletionItem[] = [];
        let completion = new vscode.CompletionItem("bla", vscode.CompletionItemKind.Field);
        completions.push(completion);
        return completions;
    }

它带来了bla"当我输入b"时,但文档中的其他单词都没有出现.

It brings up "bla" when I type "b", but none of the other words in the document appear.

推荐答案

参见 这个评论是一个开放的 VS Code 问题.

See this comment of an open VS Code issue.

当您的 CompletionProvider 使用比其他提供者更重要的 DocumentSelector 注册并返回至少一个完成项时,其他提供者将被跳过.基于单词的建议提供者不太重要,因此它不会提供任何建议.

When your CompletionProvider was registered using a DocumentSelector that is more significant than that of other providers and returns at least one completion item, the other providers are skipped. The word-based suggestions provider is less significant and so it does not contribute any suggestions.

根据扩展的性质,您可以在注册 CompletionProvider 时尝试定义一个不太具体的 DocumentSelector.如果这是不可能的,我认为除了自己提供所有完成项目(包括基于单词的建议)之外别无选择.

Depending on the nature of your extension you could try to define a less specific DocumentSelector when registering your CompletionProvider. If this is not possible I think there is no other option than to providing all completion items yourself (including word-based suggestions).

这篇关于添加完成项提供程序并保留建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆