Adding a keybinding to make ‘.’ open the autocomplete list is easy enough, but then the ‘.’ doesn’t actually get inserted into the document. Is there a way to specify a keybinding which executes some command and also inserts those keys into the document?
If your autocomplete function returns results after a dot and you have
activateOnTyping enabled, this should just work.
Hmmm, that’s not quite the behavior I’m describing, since that would mean it also always opens on any other keypress as well. I think I’ve described poorly what I’m trying to achieve. The more root issue is that ‘.’ is interpreted as the end of the word, so the suggestion list closes when a period is typed. Instead, the suggestion list should stay open through the ‘.’ character. I’ve been looking through the autocomplete documentation, but I can’t figure out where word separators are configured.
What does your autocompleter work like? And when exactly would you like it to run? There’s no concept of a ‘word’ in the interface—the completer is called every time a character is typed, or the current completions are preserved if the added text matches the result’s
My autocomplete is currently running on every single keystroke, since I’m not currently providing the span field in the results. Since engine gets results from a server, I’d like to avoid sending a request on every keystroke, so I want to start supplying the
My first attempt was to set it to the regexp
current_substring + ".*" where
current_substring is specified by the autocomplete engine. I’m imagining this will cause the engine to never send a request, except on the first character, since after that it will always match the regexp. Indeed, this is pretty much the behavior I see, except that thing like ‘.’ and ‘space’ make autocompletion quit until re-activated.
I just checked again, and I that the behavior without
span is to not quit, even when ‘space’ is pressed, which is also not what I want. Also, this all probably isn’t that big of a deal, so if there isn’t a way to do this, that should probably be fine.
span indicates the shape of token that the current set of completions applies to. So if you make that match an identifier, and return all identifiers that match in the current context, the completer will keep filtering that list as long as the user is typing more letters. When they type a ‘.’, that doesn’t match the span anymore, so your completion source is queried again and can figure out what set of properties to complete for that ‘.’, again with an identifier span so that editing the properties doesn’t cause further queries. I.e. the general idea is not to make the span match the ‘.’, because in almost all situations (unless you include sub-completions containing periods right away), you’ll want to re-query when it is typed.
@marijn I’d also like to know how this works, but I am having trouble visualizing what you are describing, I’d appreciate a code example.