所以我想为某些自定义语言自定义VS Code。我创建了一个带有片段的.json,我解析了我用这种语言获得的所有.inc文件,但我宁愿将它实现到IntelliSense中。所以我的问题是,当我的.inc文件包含所有全局变量,函数等时,如何创建自定义语言IntelliSense支持?我已经研究了几个小时,现在找不到任何帮助我开始的东西。
答案 0 :(得分:2)
您需要创建一个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;
}
);