Home Download Buy Blog Forum Support

completions[] + auto_complete

completions[] + auto_complete

Postby atomi on Wed May 23, 2012 4:45 pm

I'm new to python so this might be a basic/stupid question but,

when using run_command auto_complete is it possible to display the completion similar to sublime-completions files.
ie: completions.append("MyCompletion\tSpecial Completions","MyCompletion") # which isn't working of course (different type error)
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: completions[] + auto_complete

Postby C0D312 on Wed May 23, 2012 4:59 pm

run_command auto_complete

Are you referring to triggering the auto_completion within a textCommand? Or do you mean
def on_query_completions(self, view, prefix, locations):



What do you mean by "similar to sublime-completions files"? Do you mean how you can have helper in grey on the popup?

Either way, on_query_completions is expecting a list of tuples. Append only accepts one parameter and will not automatically create a tuple for you. So you could do:

Code: Select all
sometuple = ("MyCompletion\thelper text","MyCompletion")
completions.append(sometuple)
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: completions[] + auto_complete

Postby atomi on Wed May 23, 2012 5:17 pm

Are you referring to triggering the auto_completion within a textCommand?


Yeah, self.view.run_command('auto_complete')...


Do you mean how you can have helper in grey on the popup?


Exactly that. I want to add the helper text like in sublime-completions files but to the auto_complete using run_command in a textCommand plugin.

completions.append() isn't taking tuples I get:
Code: Select all
TypeError: No registered converter was able to produce a C++ rvalue of type class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > from this Python object of type tuple


Appending plain strings works as expected, but I'd love to add helper text as well.
Edit: Apologies for the PM, I hope that was cool. ;)
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: completions[] + auto_complete

Postby C0D312 on Wed May 23, 2012 5:24 pm

Unless I'm missing something, you can't add autocompletions via a textCommand. You need to add them with on_query_completions. You can send completions from a textCommand to on_query_completions though.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: completions[] + auto_complete

Postby atomi on Wed May 23, 2012 5:26 pm

C0D312 wrote:Unless I'm missing something, you can't add autocompletions via a textCommand. You need to add them with on_query_completions. You can send completions from a textCommand to on_query_completions though.


Really? I learned to use it by looking at your DisplayFunctions plugin (for Java) on GitHub which has the following in a textCommand:

Code: Select all
        self.view.run_command('auto_complete', {
                'disable_auto_insert': True,
                'api_completions_only': True,
                'next_competion_if_showing': True
                })
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: completions[] + auto_complete

Postby C0D312 on Wed May 23, 2012 5:37 pm

That triggers the autocompletion popup to appear. It's doing the same job as control+space. However, it doesn't add anything to the completions. In that plugin, I have a global variable "completions." The textCommand adds completions to the variable. Then, because it's global, the method on_query_completions has access to it. On_query_completions then returns a list of tuples for the autocompletion.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: completions[] + auto_complete

Postby atomi on Wed May 23, 2012 5:48 pm

C0D312 wrote:That triggers the autocompletion popup to appear. It's doing the same job as control+space. However, it doesn't add anything to the completions. In that plugin, I have a global variable "completions." The textCommand adds completions to the variable. Then, because it's global, the method on_query_completions has access to it. On_query_completions then returns a list of tuples for the autocompletion.


That makes sense. Does that mean we aren't able add helper text to the global completions variable?
Is it perhaps possible to edit the list of tuples in on_query_completions method so we can add helper text?
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: completions[] + auto_complete

Postby C0D312 on Wed May 23, 2012 6:09 pm

C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: completions[] + auto_complete

Postby atomi on Wed May 23, 2012 6:13 pm

C0D312 wrote:https://github.com/BoundInCode/SMART-Snippets/blob/master/smartsnippets.py#L223


Brilliant work @COD312. Thanks again for sharing it.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: completions[] + auto_complete

Postby C0D312 on Wed May 23, 2012 7:14 pm

Did you get it working? Let me know if you need help.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Next

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 13 guests