0

I am trying to have language support in VSCode for an assembler targeting a programmable ASIC. So far I have only the TextMate grammar and I am now trying to understand how to implement a language server. I am learning from

https://github.com/Microsoft/vscode-extension-samples/tree/master/lsp-sample

and have come so far as to have my environment up for debugging. Where I am struggling is that I do not understand how the completion mechanism is done in the example.
What I see when debugging is that as soon the first letter (word boundary) is an:

  • j or J a small text popup with a string JavaScript(J highlighted) and details shows so I can select without typing
  • t or T the same but for TypeScript(T highlighted)
  • s or S gives a list of the both previous popups(S highlighted on both) and arrow up/down for selection

The only code covering this, as I understand it, is this section in the server.ts file

// 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 resolves 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;
    }
);

I have tested with more labels and it appears as the Completionparser checks for capital letters in the labels. Added 2 more labels, 'TwoMore' and 'JetBrain' and they behaved in the same way, e.g. m/M or b/B also gave a popup.

What is not obvious is why this is so?

Gama11
  • 31,714
  • 9
  • 78
  • 100
IgorLopez
  • 157
  • 1
  • 1
  • 10
  • I'm not sure I understand the question. You're confused about how the filtering / fuzzy matching of completion item works...? – Gama11 Aug 18 '19 at 17:49
  • Yes exactly, my assumption is that it had to do with the capital letters, TypeScript will get matched on T and S but that is my assumption no knowledge. – IgorLopez Aug 19 '19 at 16:51

0 Answers0