gpt4 book ai didi

autocomplete - VS Code 中的自定义语言自动补全

转载 作者:行者123 更新时间:2023-12-01 23:39:36 25 4
gpt4 key购买 nike

所以我想为一些自定义语言自定义 VS Code。我制作了一个带有片段的 .json 文件,这些片段是从我使用这种语言获得的所有 .inc 文件中解析出来的,但我更愿意将它实现到 IntelliSense 中。所以我的问题是,当我拥有包含所有全局变量、函数等的 .inc 文件时,如何创建自定义语言 IntelliSense 支持?我已经研究了几个小时,但找不到任何可以帮助我开始的东西。

最佳答案

您需要创建一个 language server并向其添加代码完成功能。
下面的示例代码向服务器添加了代码完成。它提出了“TypeScript”和“JavaScript”这两个词

// This handler provides the initial list of the completion items.
connection.onCompletion(
(_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
// The pass parameter contains the position of the text document in
// which code complete got requested. For the example we ignore this
// info and always provide the same completion items.
return [
{
label: 'TypeScript',
kind: CompletionItemKind.Text,
data: 1
},
{
label: 'JavaScript',
kind: CompletionItemKind.Text,
data: 2
}
];
}
);

// This handler resolve additional information for the item selected in
// the completion list.
connection.onCompletionResolve(
(item: CompletionItem): CompletionItem => {
if (item.data === 1) {
(item.detail = 'TypeScript details'),
(item.documentation = 'TypeScript documentation');
} else if (item.data === 2) {
(item.detail = 'JavaScript details'),
(item.documentation = 'JavaScript documentation');
}
return item;
}
);

关于autocomplete - VS Code 中的自定义语言自动补全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46145607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com