Home Download Buy Blog Forum Support

Autocompletion suggest doesn't work like expected

Autocompletion suggest doesn't work like expected

Postby electricarts on Wed Mar 20, 2013 1:38 pm

Hi,

i'm new to ST2 (came from Coda and Espresso) and have a few questions about settings in ST2. I didn't find something, so i'm asking here.

I installed the Sass package. When i type "text" the autocompletion automatically shows me all possible entries like "text-shadow", "text-transform" and so on. When i choose an entry i expect the next window with possible entries like "lowercase", "uppercase" and ... But nothing happens. Until i type something. Here is what it looks like in Coda:

Image

And when i'm using variables i was expecting ST2 to show me the already defined variables. But the same here. I have to type a few paragraphs to see suggestions. But what when i didn't remember the variables i've already defined? Again a screenshot of how Codas handles this (colors in this example). I just type "$" and Coda shows me all available variables:

Image

I'm sure, there are preferences for ST2 to have the same behavior, but i don't know what to do. Could someone help me with this?


Mario
electricarts
 
Posts: 22
Joined: Wed Mar 20, 2013 1:01 pm
Location: Germany

Re: Autocompletion suggest doesn't work like expected

Postby electricarts on Fri Mar 22, 2013 10:34 am

Ok, i discovered the "auto_complete_triggers" pref and set it like this:

Code: Select all
"auto_complete_triggers": [ {"selector": "source.scss", "characters": " "} ]


Now when i hit tab it shows the available completions in the pop-up. Fine.

But i can't find a solution for the autocompletion of variables. Is there a way to show the defined variables and not only rgb(), hsl() ... ?
electricarts
 
Posts: 22
Joined: Wed Mar 20, 2013 1:01 pm
Location: Germany

Re: Autocompletion suggest doesn't work like expected

Postby skuroda on Fri Mar 22, 2013 7:33 pm

The $ is, by default, defined as a word separator. You can create a syntax specific setting with that removed and it should trigger the autocomplete menu.

The setting you are looking for in the default to use as a base is "word_separators"
skuroda
 
Posts: 677
Joined: Fri Oct 05, 2012 8:11 am

Re: Autocompletion suggest doesn't work like expected

Postby electricarts on Sat Mar 23, 2013 11:21 am

Hi skuroda,

thanks for your reply! I removed the $ in the syntax sprecific setting. But i don't wanna trigger the autocompletion generally with that "$". I wanted to have a trigger that shows me only the defined variables (something like "$darkgrey" or "$bluesky") when i type "$" and not all the possible properties like "rgb", "hsl" and so on.

I was thinking, that this would be useful for many web developers when working with Sass or Less. It seems like that ist's not so easy to find a pref for ST to act like that. :(

Mario
electricarts
 
Posts: 22
Joined: Wed Mar 20, 2013 1:01 pm
Location: Germany

Re: Autocompletion suggest doesn't work like expected

Postby skuroda on Sat Mar 23, 2013 6:24 pm

Yup, you want some intelligence built into the auto completion with isn't built into the editor (yet?). But you can modify the autocomplete list with a plugin. I put something together rather quickly and minimally tested it, so your mileage may vary. You still need to keep "$" out of the word separator list.

Code: Select all
import sublime_plugin

class EventListener(sublime_plugin.EventListener):
        def on_query_completions(self, view, prefix, locations):
        if prefix.startswith("$"):
            find_regions = view.find_all(r"\$[A-Za-z]+")

            text = set()
            for region in find_regions:
                if region == view.word(view.sel()[0]):
                    continue
                text.add(view.substr(region))
            auto_complete = [(x, x.replace("$", "\\$")) for x in text]
            return (auto_complete, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
skuroda
 
Posts: 677
Joined: Fri Oct 05, 2012 8:11 am

Re: Autocompletion suggest doesn't work like expected

Postby electricarts on Sun Mar 24, 2013 12:11 pm

Wow skuroda,

much thanks for the work you've done! But i don't know where to put in your code. There is already a autocomplete plugin in the scss_compltions.py. And i'm not able to put it together with yours. Thats the incapability of a "design guy". ;)

Thanks again

Mario
electricarts
 
Posts: 22
Joined: Wed Mar 20, 2013 1:01 pm
Location: Germany

Re: Autocompletion suggest doesn't work like expected

Postby skuroda on Sun Mar 24, 2013 6:47 pm

No problem. :) Go to "Tools -> New Plugin". Copy paste the code and save it as something like "SASS Autocomplete.py" or something (the actual name of the file doesn't matter. It should work immediately, but you can always try restarting ST. I don't know if this is something that would want to be integrated into whatever SASS package you are using. I'd be happy to take a quick look to make sure it doesn't conflict with whatever completions SASS does if you can point me to the package you are using. I did a quick google search and to my dismay...there are many listed :(
skuroda
 
Posts: 677
Joined: Fri Oct 05, 2012 8:11 am

Re: Autocompletion suggest doesn't work like expected

Postby electricarts on Sun Mar 24, 2013 7:00 pm

electricarts
 
Posts: 22
Joined: Wed Mar 20, 2013 1:01 pm
Location: Germany

Re: Autocompletion suggest doesn't work like expected

Postby skuroda on Sun Mar 24, 2013 9:18 pm

Well, I don't think it would break anything. Have you tried creating this plugin manually and using it?
skuroda
 
Posts: 677
Joined: Fri Oct 05, 2012 8:11 am

Re: Autocompletion suggest doesn't work like expected

Postby electricarts on Mon Mar 25, 2013 7:40 am

It seems so. But some Key Bindings are driving me nuts. Using the Backspace key on a english Mac keyboard triggers some sort of toggling. I type "col" , hit tab and "color:" is there. Fine. I type "$" and ST shows me the recently used (in that opened file) color variables. But when i hit backspace and type "$" again nothing happens (just the "$" is shown - no suggestion). When i now hit backspace the 2nd time (to delete the "$") and type "$" again the variables are shown.

I'll search the default Key Bindings to see what happens here.
electricarts
 
Posts: 22
Joined: Wed Mar 20, 2013 1:01 pm
Location: Germany

Next

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 13 guests