SublimeAllAutocomplete icon indicating copy to clipboard operation
SublimeAllAutocomplete copied to clipboard

Autocomplete for Sass variables (and CSS classes) with dashes doesn't work

Open woerndl opened this issue 11 years ago • 32 comments

We've split our Sass into multiple files; one of the files contains all our variables. The variables look like this $variable-name-example. Unfortunately dashes seam to be a problem currently.

Testcase:

$button-color-secondary: #f00 /* will auto complete only the word $button */
$button_color_main: #0f0 /* works as expected */

Thank you for your plugin, Adrian. Keep up the good work.

woerndl avatar Jul 30 '13 08:07 woerndl

I can confirm the problem: removed dash from word_separators preference, tested with version 2.0.2, build 2221. As you reported, the word never shows up in the autocomplete list of another view.

Unfortunately, this is a bug in the Sublime API implementation (extract_completions method).

It's also weird that I sometimes do get a completion in the same view. But if I try again it doesn't show up anymore. However, I always get a completion if I type past the first dash, i.e., "$button-". So, it seems not only the API is broken but also the built in autocomplete is behaving strangely with words containing dashes (and probably other chars).

NB, best thing you can probably do is open a bug report for Sublime, but I don't know what the chances are that it gets fixed (someone reported a related problem some time ago but it didn't even get a response...).

alienhard avatar Aug 01 '13 17:08 alienhard

Done: http://sublimetext.userecho.com/topic/222861-/

woerndl avatar Aug 01 '13 20:08 woerndl

thanks

On Thu, Aug 1, 2013 at 1:13 PM, wrndl [email protected] wrote:

Done: http://sublimetext.userecho.com/topic/222861-/

— Reply to this email directly or view it on GitHubhttps://github.com/alienhard/SublimeAllAutocomplete/issues/18#issuecomment-21966223 .


www.adrian-lienhard.ch

twitter.com/adrianlienhard

alienhard avatar Aug 01 '13 21:08 alienhard

Just created temporary hack to make possible dash separated suggestions usage: https://github.com/andruhon/SublimeAllAutocomplete

andruhon avatar Nov 05 '13 01:11 andruhon

I can confirm that bug

We'll we see solution in original master branch?

Thanks

ArmorDarks avatar Nov 13 '13 10:11 ArmorDarks

I've just experienced the same thing and written it up on the forum:

http://www.sublimetext.com/forum/viewtopic.php?f=3&t=14773

Was a little confused that this fix didn't seem to have landed until I realised this is a fork and needs installing seperately. For anyone else landing here, see the install instructions: https://github.com/andruhon/SublimeAllAutocomplete

Thank you so much for the fix!

charlesroper avatar Nov 27 '13 15:11 charlesroper

I'm still having an issue surrounding this matter. It works when auto completing a class from CSS into HTML, but when you try it the other way around; auto completing a class name from HTML to CSS it doesn't work? I've tried adding "source.html" to "apply_with_dash_hack_syntaxes" with no luck.

Thanks for all the work done to date!

dentz avatar Jan 10 '14 01:01 dentz

@dntz ,to fix that because ST is ridiculously DUMB

  • the html source is "text.html" even if source.html works in snippets scops.

ctf0 avatar Sep 24 '14 22:09 ctf0

Thanks for your help @ctf0, when I bring up the autocomplete box using Ctrl+Space outside a rule set, the classes from my HTML document are now visible. Is there any way to display this autocomplete box automatically? Similar to how it works for properties and values within declarations.

dentz avatar Oct 29 '14 11:10 dentz

if i understand u right ,i believe what u r after is that u want the same trick but for css ,well its the same thing ,open any css,less,sass ,etc.. and go to settings-more > syntax specific and add the same thing u add to the html.

ctf0 avatar Oct 29 '14 14:10 ctf0

I also don't see this working for SCSS variables. I create a variable in one file that is open:

$myVariable: 'Helvetica', sans-serif;

and in another SCSS file that is open, $myVariable does not show up as an auto complete word.

It simply doesn't work at all.

Jakobud avatar Dec 18 '14 22:12 Jakobud

Any update on this? I also found that SCSS variables don't work (in that it only suggests the first part of the name and clips off the dash):

Example: $one-two-three (expected) $one (actual)

Both the "-" and "$" have been removed form word_separators.

ghost avatar Feb 26 '15 23:02 ghost

Seems like this is still an issue with ST3

tsi avatar Jun 28 '15 07:06 tsi

+1 doesn't work with hyphens in ST3. But, @andruhon fork seems to work. @alienhard please merge this hack into your version?

importnil avatar Aug 12 '15 03:08 importnil

Same problem here, Brackets do that and even show the variable value on the suggested options

RAFA3L avatar Sep 13 '15 04:09 RAFA3L

any updates here? @andruhon solution not working for me...

iturdikulov avatar Mar 04 '16 23:03 iturdikulov

hey guys, I solved it for me based on hacked version https://github.com/petermac-/SublimeAllAutocomplete repo

https://github.com/inomoz/SublimeAllAutocomplete - fixed for me

changed only word_regions variable

if DEBUG: print("SAA: extracting words with dashes") word_regions = v.find_all("\\" + prefix + "\w+(-\w+)+",0)

iturdikulov avatar Mar 05 '16 00:03 iturdikulov

wow, thx @inomoz , you save my life.

jackyon avatar Jun 07 '16 14:06 jackyon

@inomoz looks like this not working after I upgrade to the newest sublime version.

jackyon avatar Jun 14 '16 03:06 jackyon

@inomoz, your repo works for me, but I had to remove - and $ from the word separators.

This is using Sublime Text 3, build 3114.

Since the instructions are kind of all over the place, here are the steps I went through (this is on a Mac, so keystrokes might be different on your machine).

  1. CMD + SHIFT + P to open Command Palette and type "Package Control: Add Repository" and select it.

  2. Paste in "https://github.com/inomoz/SublimeAllAutocomplete" in the input box at the bottom and press Enter.

  3. Again, CMD + SHIFT + P and enter "Package Control: Install Package".

  4. Start typing "All Autocomplete" and look for the one that specifically mentions the repo we just linked, aka, inomoz/SublimeAllAutocomplete. Select that one to install.

  5. After installation, open any Sass file (I use the SCSS extension), and navigate to Preferences > Settings - More > Syntax Specific - User. In my case, this opened up a new file titled SCSS.sublime-settings.

  6. I copied the default word_separators from Preferences > Settings - Default and removed the - and $ characters. So at the end of the day, my SCSS.sublime-settings file looked like:

    {
        "word_separators": "./\\()\"':,.;<>~!@#%^&*|+=[]{}`~?"
    }
    
  7. Save that file, quit and relaunch Sublime. Everything worked after that!

You may have to do this twice if you use both .scss and .sass, and your final .sublime-settings file may be different if you have further settings set within that file. Either way, the instructions should be close.

romellem avatar Jul 07 '16 15:07 romellem

@romellem { "word_separators": "./()"':,.;<>~!@#%^&*|+=[]{}`~?" }

wow~ this works for me, thx!

jackyon avatar Jul 13 '16 07:07 jackyon

@inomoz this doesn't work any more with the latest build v3120 , any chance u can update ur fork ? here are the settings

{
    "apply_with_dash_hack_syntaxes": [
        "source.scss",
        "source.sass",
        "source.css",
        "text.html.basic",
        "text.blade",
        "source.php",
        "embedding.php",
        "source.js",
        "source.json"
    ],
    "return_nothing_on_empty_prefix": true,
    "do_not_search_in_current_view": false
}

user-setting

{"word_separators": "./\()\"':,.;<>~!@#%^&*|+=[]{}`~?"}

ctf0 avatar Aug 07 '16 10:08 ctf0

I use standard version of ST3 build 3114 with word_separators preference mentioned above and it fixed the problem for me.

mahish avatar Aug 17 '16 08:08 mahish

@mahish only in the same view, not across open files.

ctf0 avatar Aug 17 '16 10:08 ctf0

Using build 3131, not seeing this in action. I don't see any SCSS completions with variables.

ronilaukkarinen avatar Apr 26 '17 15:04 ronilaukkarinen

I have 3126 build, word seperator: "word_separators": "./\\()\"'-:,.;<>~!@#%^&*|+=[]{}~?",` plugin All Autocomplete from PackageControl then, if scss file with variables open, autocomplete FROM IT in other files is working

iturdikulov avatar Apr 26 '17 18:04 iturdikulov

offtop: in Jetbrains IDE autocomplete working even if files not opened (I tried use ctags & plugins for this feature, no success...)

iturdikulov avatar Apr 26 '17 18:04 iturdikulov

Based on this issue discussion, for some reason didn't get this in the right place. So if someone misread the whole thing like I did, here's what I did to bypass this problem.

In Preferences > Settings, add on any line:

"word_separators": "./\\()\"':,.;<>~!@#%^&*|+=[]{}`~?",

After this, it works.

ronilaukkarinen avatar Apr 28 '17 06:04 ronilaukkarinen

Thanks @ronilaukkarinen, works great!

kjunggithub avatar Jul 08 '17 01:07 kjunggithub

Thanks guys, @ronilaukkarinen instruction works great :)

The repo linked above is offline by now.

simonvomeyser avatar Oct 05 '17 14:10 simonvomeyser