Filtering and code completion do not work when '#' character is used

88 Views Asked by At

I've reproduced the problem in lsp-sample (description of my original post moved below).

The code completion does not work with # character. How to make it work?

Added CompletionItem for #1000:

connection.onCompletion(
    (_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
        return [
            {
                label: 'TypeScript',
                kind: CompletionItemKind.Text,
                data: 1,
            },
            {
                label: 'JavaScript',
                kind: CompletionItemKind.Text,
                data: 2,
            },
            {
                label: '#1000',
                kind: CompletionItemKind.Text,
                data: 3,
            },
        ];
    }
);

Now typing # or #1 does not show/filter the completion list. Choosing #1000 from the list does not completes properly, i.e. makes ##1000.

For filtering tried adding filterText: '#[0-9]+', or filterText: '#', to no avail.

For completion tried below but it does not work when there is something before #1 in the same line:

textEdit: InsertReplaceEdit.create(
                    '#1000',
                    Range.create(
                        Position.create(_textDocumentPosition.position.line, 0),
                        _textDocumentPosition.position
                    ),
                    Range.create(
                        Position.create(_textDocumentPosition.position.line, 0),
                        _textDocumentPosition.position
                    )
                ),

=================(My previous post)=======================

I have the following code completion list defined:

[
    {
        "jsonrpc": "2.0",
        "id": 6,
        "result": [
            {
                "label": "G253",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 106
            },
            {
                "label": "G254",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 107
            },
            {
                "label": "G255",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 108
            },
            {
                "label": "#3000",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 215
            },
            {
                "label": "#3001",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 216
            },
            {
                "label": "#3002",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 217
            },
            {
                "label": "#3003",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 218
            },
            {
                "label": "#3004",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 219
            }
        ]
    }
]

When typing # and triggering code completion, further typing #3 does not make the list filtered. Then selecting for example #3002 from the list inserts double hash: ##3002. What am I missing here?

However there is no problem if I use other character than #, for example G. Then everything works with no problem - proper completion list filtering and inserting, for example G254.

0

There are 0 best solutions below