question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

Autocomplete with non-alphabetic characters not triggering and replacing properly

See original GitHub issue

We are trying to create a kind of namespaced-based autocomplete provider behind the / prefix. For example, we would want /test and /foo to be displayed when the user enters โ€˜/โ€™ in their Monaco editor. There are two issues:

  • Simply entering / is not triggering the autocomplete In the recording below, I would expect /test to show up as a suggestion when entering /, but it wonโ€™t match until /t is entered. (0:00 - 0:05)
  • Typing /t and confirming the autocomplete choice does not replace the / prefix. In the recording below, you can see that /test is replaced by /test test test, when we want it to be test test test. (0:06 - 0:10)

Iโ€™ve attached a recording below to highlight the issues:

https://user-images.githubusercontent.com/79662144/122108045-66257a80-cde1-11eb-9170-0b1ab725d84c.mov

This seems to reproduce with a variety of non-alphabet characters (I also can repro with 1 and . as a prefix)

monaco-editor version: 0.43.0 Browser: Chrome Playground code that reproduces the issue:

function createDependencyProposals(range) {
    // returning a static list of proposals, not even looking at the prefix (filtering is done by the Monaco editor),
    // here you could do a server side lookup
    return [
        {
            label: '/test',
            kind: monaco.languages.CompletionItemKind.Function,
            insertText: 'test test test',
            range: range
        },
    ];
}


monaco.languages.registerCompletionItemProvider('javascript', {
    provideCompletionItems: function(model, position) {
        var word = model.getWordUntilPosition(position);
        var range = {
            startLineNumber: position.lineNumber,
            endLineNumber: position.lineNumber,
            startColumn: word.startColumn,
            endColumn: word.endColumn
        };
        console.log(createDependencyProposals(range))
        return {
            suggestions: createDependencyProposals(range)
        };
    }
});

monaco.editor.create(document.getElementById("container"), {
    value: "",
    language: "javascript"
});

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rcjsuencommented, Jun 15, 2021

@alan-codaio Try using triggerCharacters.

function createDependencyProposals(range) {
    // returning a static list of proposals, not even looking at the prefix (filtering is done by the Monaco editor),
    // here you could do a server side lookup
    return [
        {
            label: '/test',
            kind: monaco.languages.CompletionItemKind.Function,
            insertText: 'test test test',
            range: range
        },
    ];
}


monaco.languages.registerCompletionItemProvider('javascript', {
    provideCompletionItems: function(model, position) {
        var word = model.getWordUntilPosition(position);
        var range = {
            startLineNumber: position.lineNumber,
            endLineNumber: position.lineNumber,
            startColumn: word.startColumn,
            endColumn: word.endColumn
        };
        console.log(createDependencyProposals(range))
        return {
            suggestions: createDependencyProposals(range)
        };
    },

    triggerCharacters: ["/"]
});

monaco.editor.create(document.getElementById("container"), {
    value: "",
    language: "javascript"
});
0reactions
medihackcommented, Sep 4, 2022

I also stumbled over this. For a custom language, I want autocompletion for variables that always begin with $ (e.g. $foo). By default, neither filtering works with typing a $ character (the list is not filtered with all variables that begin with $), nor does accepting the auto-completion work correctly (I end up with $$foo). An option would be nice to also respect special characters.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery UI Autocomplete ignore non alphanumeric letters
You should strip the non alpha-numeric characters from both the input and the term that you're matching. Try calling something like this onย ......
Read more >
Auto-completion - Notepad++ User Manual
If you want to include special characters in the retVal or descr attributes and have it render properly in the call tip popup,...
Read more >
Accent Folding for Auto-Complete - A List Apart
One byte equaled one character, no exceptions, and you could only load one language's alphabet at a time. This was fine because it...
Read more >
Password containing non-alphanumeric characters doesn't work
And to be clear, 1Password does not AutoFill. Rather, 1Password will fill your credentials when you manually select a login. If you're seeing...
Read more >
AutoCompleteTextView - Android Developers
android:digits, If set, specifies that this TextView has a numeric input method and that these specific characters are the ones that it will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found