Sublime Forum

on_query_completions prefix does not work when there is @, $, & or { characters after the cursor

#1

I want to build a plugin for that will do auto completion. If characters after the cursor contains A-Z or 0-9 the prefix in on_query_completions works quite nicely. But if there is @, $, & or { characters after the cursor, the prefix is always empty.

When my code looks like this:
def on_query_completions(self, view, prefix, locations): print(prefix)

Example if my file contains:
qwert
and cursor is after the t-character the output in the console will be qwert, which is correct.

But if my file contains:
@
and cursor is after the @-character the output in the console will be empty, but I did expect @ in the console.

  1. Is there a workaround for this issue?
  2. Is a new bug or an existing issue?
  3. Would this issue be fixed in the dev builds?

I am using 3103 build.

-Tatu

0 Likes

#2

@ is considered to be a “word separator” by default, which is why only everything after it is included in the prefix for completion loopup.

Check the respective setting.

1 Like

#3

If I edit the word_separators setting, it works, which is cool. But if I would like to keep $, @ and & as word separators, is there a other workaround?

0 Likes

#4

Why would you need to use them as word separators but still have them appear in your prefix?

0 Likes

#5
  1. Is there a workaround for this issue?

why not just check the character at the position before the relevant cursor?

def on_query_completions(self, view, prefix, locations):
    if view.substr(locations[0] - 1) == '@':
        prefix = '@' + prefix
    print(prefix)
0 Likes

#6

I am building a plugin for a Robot Framework (RF), which is a test automation framework. In RF, variables are declared with @, &, $, { and } characters. Example:
| ${var} = | Set Variable | a string |
And same in Python would be:
var = 'a string'
In RF, @ is a list, & is a dictionary and $ is a scalar.

In RF, I can do this:
| Log | StringWith${var} |
And the variable would be automatically resolved and it would print out:
StringWitha string

0 Likes

#7

Looks like a good proposal and I think I have to keep the @, &, $, { and } as word separators. It will lead to other problems if they aren’t word separators.

Thanks from the tip.

0 Likes

#8

Please elaborate on these “other problems”. I can’t follow you.

As a wild guess: You do know that you can set word_separators on a per-language basis?

0 Likes

#9

Other problems means that because it is valid to write this: StringWith${ and I want word boundary to stop on the $. Because I don’t want to completions to replace StringWith, I only want to complete the ${ part.

And the if there is a variable definition, in the prefix, I want the completion to provide only variables. It shouldn’t provide functions or classes. And if there not variable definition, in the prefix, I want the completion to provide functions and classes.

By @kingkeith example I can check, what other characters there was, beyond the word boundary, and provide correct completions to the user. Or would there be other solution to my problem?

0 Likes

#10

I see now, thanks.

Yes, doing what @kingkeith suggested is the proper way then. I also do this is some of my plugins and you obviously have to do it in order to provide auto-completions.

0 Likes

#11

ugly hacks :stuck_out_tongue:

0 Likes

#12

And thank you both from help.

The solution does work quite nicely, still have few bugs to clear but it doesn’t look like a ugly hack :slight_smile:

0 Likes