Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom language autocompletion in VS Code

So I wanted to customize VS Code for some custom language. I made a .json with snippets that I parsed out of all .inc files that I've got with this language but I'd rather want to have it implemented into IntelliSense. So my question is, how to create a custom language IntelliSense support when I have .inc files with all the global variables, functions and so on? I've researched this for a couple of hours now and couldn't find anything that helped me even start.

like image 377
Tomek Avatar asked Sep 10 '17 21:09

Tomek


1 Answers

you need to create a language server and Add code completion feature to it. The example code below adds code completion to the server. It proposes the two words 'TypeScript' and '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;
    }
);
like image 166
Nima Habibollahi Avatar answered Nov 01 '22 09:11

Nima Habibollahi