Sublime Forum

Autocompletion suggest doesn't work like expected

#1

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:

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:

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

0 Likes

#2

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

"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() … ?

0 Likes

#3

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”

0 Likes

#4

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. :frowning:

Mario

0 Likes

#5

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]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)[/code]
0 Likes

#6

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”. :wink:

Thanks again

Mario

0 Likes

#7

No problem. :smile: 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 :frowning:

0 Likes

#8

The Sass package i’m using is this: https://github.com/kuroir/SCSS.tmbundle/tree/SublimeText2

0 Likes

#9

Well, I don’t think it would break anything. Have you tried creating this plugin manually and using it?

0 Likes

#10

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.

0 Likes

#11

I removed the SublimeCodeIntel package. Now the autocompletion/suggestion of the variable is working. But now ST doesn’t autocomplete “col” to “color:” but only to “color” (without the “:”) :astonished:

0 Likes

#12

Hmm, well I can’t seem to get it not to show the autocomplete. Though the “code” I am testing with is just something I threw together. Could you post something where it doesn’t work for you. Perhaps I will be able to reproduce it with that.

0 Likes

#13

Maybe i should start again with a fresh ST2 Installation. The more i try, the more it doesn’t work like expected. My installed packages right now are: SCSS, HTML5,Package Control, SFTP, SideBarEnhancements and Theme - Soda.

Here’s a Code Example:

[code]$dunkelrot : #990703;
$logograu : #CCCCCB;

@media screen {

/* force vertical scrollbar */
body {
overflow-y: scroll;
}

/* Layout Module Configuration */
.ym-wrapper {
max-width: 80em;
margin: 0 auto;
}

.ym-wbox {
padding: 1.5em;
color: $dunkelrot;
}
}[/code]

I have the default setting “auto_complete”: true. I type “col” and nothing happens. No suggestions. I’ve to type “color:” completely. After that i type “$” and nothing happens. I’ve to type “$d” to see the suggestion “$dunkelrot”. Strange, isn’t it? :wink:

0 Likes

#14

Hmm odd. The only time I had to type "color: " completely rather than being auto completed properly was if I didn’t properly end the previous statement with a semicolon. That being said, every time I entered “$” the variable names came up fine. Out of curiosity, when you manually entered the colon, did it auto insert a semi colon?

0 Likes