Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_query_completions behavior with leading spaces #2394

Open
rwols opened this issue Jul 29, 2018 · 1 comment
Open

on_query_completions behavior with leading spaces #2394

rwols opened this issue Jul 29, 2018 · 1 comment

Comments

@rwols
Copy link

rwols commented Jul 29, 2018

I'm unsure if this is intended behavior, but I find it undesirable behavior.

Summary

When the unicode string of the completion trigger has a leading space, the inserted text eats the space to the left of the cursor.

However, when there is no space to the left of the cursor, that character remains intact.

Expected behavior

Trim leading spaces of the completion trigger before processing it.

Actual behavior

The completion trigger including its leading spaces are used to replace text to the left of the cursor.

Steps to reproduce

  1. Copy this python script to Packages/User:
import sublime_plugin


class SpacesBehavior(sublime_plugin.EventListener):
    def on_query_completions(self, _, __, ___):
        return ([[' space', '${1:suddenly my space to the left is gone}']], 0)
  1. Save it.
  2. Indent the cursor a little bit.
  3. Type the word "space".
  4. Select this completion.
  5. A space character to the left is now removed.

To showcase another situation:

  1. Type the word foo.
  2. Type a dot . as if you're accessing a member of the structure foo.
  3. Select the space completion.
  4. Observe that the space in front of the completion trigger is ignored now.

Environment

Mac OS 10.13, Build 3175, 64 bit

Related: sublimelsp/LSP#368

@FichteFoll
Copy link
Collaborator

This seems okay-ish to me. The space character in the completion is seemingly considered part of the prefix when completions are queried. In the first case, the prefix space is there, so it will be removed upon selecting the completion. In the second case, the prefix space is not there, but through fuzzy matching the completion can be matched anyway and the entire matched prefix is replaced with the completion.

Now, you could argue that special characters (e.g. word separators) should never be part of the prefix, because they perform badly with it anyway, but then you they could never be matched in the tab trigger as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants