LSP icon indicating copy to clipboard operation
LSP copied to clipboard

Replace dots in the trigger with a different character that is visually the same

Open ryuukk opened this issue 2 years ago • 1 comments

This helps cases with Sublime Text strips some completion items

Check the following issue for more details: https://github.com/sublimehq/sublime_text/issues/6033

Question:

  1. trigger wont insert anything?
  2. if it inserts something, where would this trick be used instead?

ryuukk avatar Jun 29 '23 16:06 ryuukk

1. trigger wont insert anything?

Correct, as far as I can tell. It will use the original CompletionItem from the language server again, for the inserted text, so we are free to modify the trigger. But it will only have an effect on filtering.


Some observations:

  1. When I try this in a simplified example, it seems like the normal . in the trigger cannot be the single cause of this. The following example seems to work fine for me:
import sublime
import sublime_plugin
from typing import List, Optional


class CompletionsListener(sublime_plugin.ViewEventListener):

    def on_query_completions(self, prefix: str, locations: List[int]) -> Optional[sublime.CompletionList]:
        completion_list = sublime.CompletionList()
        sublime.set_timeout_async(lambda: self._on_query_completions_async(completion_list))
        return completion_list

    def _on_query_completions_async(self, completion_list: sublime.CompletionList) -> None:
        flags = sublime.DYNAMIC_COMPLETIONS | sublime.INHIBIT_REORDER
        trigger = "erro(fmt: string, args: ..any, location := caller_location)"  # unmodified
        # trigger = "erro(fmt: string, args: ꓸꓸany, location := caller_location)"  # U+A4F8
        # trigger = "erro(fmt: string, args: ․․any, location := caller_location)"  # U+2024
        annotation = "rt.erro: proc(fmt: string, args: ..any, location := caller_location)"
        completion = "erro"
        completions = [sublime.CompletionItem(trigger, annotation, completion)]
        sublime.set_timeout(lambda: completion_list.set_completions(completions, flags))

unmodified

So as a first step we should identify the root cause or the combination of factors which makes the completion not work in your example (linked issue). Just to exchange some random symbols might not work in all situations or even possibly make it worse for other examples.

  1. You chose a quite uncommon replacement symbol in this PR (Lisu Letter Tone Mya Ti) https://www.compart.com/en/unicode/U+A4F8 I doubt that many fonts have support for this symbol, and probably use some fallback instead. It doesn't look very good here:

pr

Maybe this one would be a little bit better: https://www.compart.com/en/unicode/U+2024

jwortmann avatar Jun 29 '23 17:06 jwortmann