vscode扩展名自定义完整Initem禁用内置的Intellisense

发布于 2025-02-10 16:47:13 字数 1065 浏览 1 评论 0原文

我正在研究VSCODE扩展程序,以便为代码完成提供自定义片段。

我知道直接使用摘要JSON文件的选项,但是这些选项的限制是无法使用启示弹窗口旁边的图标旁边的InterionItemkind属性。

我的问题:

如果我实现了这样的简单完整启动者:

context.subscriptions.push(
    vscode.languages.registerCompletionItemProvider(
        {scheme:"file",language:"MyLang"},  
        {
            provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
                let item = new vscode.CompletionItem('test');
                item.documentation = 'my test function';
                item.kind = vscode.CompletionItemKind.Function;
                return [item];
            }
        }
    )
)

那么原始的vscode IntelliSense文本建议不再显示,而只显示了我自己。如果我只是返回一种空的回应,例如

provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
    return [null|[]|undefined];
}

建议再次出现。在我看来,与其合并内置的IntelliSense和我自己的提供商的结果,内置的提供商会被简单地覆盖。

问题:

在应用自己的postionIniTems时如何保留内置的Intellisense建议?

vscode版本:v1.68.1 ubuntu

I am working on a VsCode extension in that I want to provide custom snippets for code completion.

I know about the option of using snippet json files directly, however those have the limitation of not being able to utilize the CompletionItemKind property that determines the icon next to the completion suggestion in the pop-up.

My issue:

If I implement a simple CompletionItemProvider like this:

context.subscriptions.push(
    vscode.languages.registerCompletionItemProvider(
        {scheme:"file",language:"MyLang"},  
        {
            provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
                let item = new vscode.CompletionItem('test');
                item.documentation = 'my test function';
                item.kind = vscode.CompletionItemKind.Function;
                return [item];
            }
        }
    )
)

then the original VsCode IntelliSense text suggestions are not shown anymore, only my own. Should I just return a kind of an empty response, like

provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
    return [null|[]|undefined];
}

the suggestions appear again as they should. It seems to me that instead of merging the results of the built-in IntelliSense and my own provider, the built-in ones get simply overridden.

Question:

How can I keep the built-in IntelliSense suggestions while applying my own CompletionItems?

VsCode Version: v1.68.1 Ubuntu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶情人眼里出诗心の 2025-02-17 16:47:13

我似乎已经找到了问题的答案,所以我会回答我的问题。

可以为一种语言注册多个提供商。在这种情况下,提供商进行了分类

按其{@link语言.match分数}和等分等等的组进行顺序要求

完成项目。当一个小组的一个或多个提供者返回A时,该过程停止

结果。

我的提供者似乎提供的结果比Intellisense的评分更高。
由于我没有提供任何触发字符,因此我的完成启动直接与每个按下键内置系统找到的单词并赢得胜利。

我的解决方案是简单地解析并注册单词我自己的文本文章并扩展了我的提供商的结果。如果我愿意,我可能同样可以为他们创建并注册一个新的完整网络培训者,但是我决定为我的项目建立不同的结构。

I seem to have found the answer for my problem, so I will answer my question.

Multiple providers can be registered for a language. In that case providers are sorted

by their {@link languages.match score} and groups of equal score are sequentially asked for

completion items. The process stops when one or many providers of a group return a

result.

My provider seems to provide results that are just higher scored than those of IntelliSense.
Since I didn't provide any trigger characters, my CompletionItems were comteping directly with the words found by the built-in system by every single pressed key and won.

My solution is to simply parse and register the words in my TextDocument myself and extend my provider results by them. I could probably just as well create and register a new CompletionItemProvider for them if I wanted to, however I decided to have a different structure for my project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文