Sublime Forum

Auto-complete issues when snippet starts with $

#1

There appear to be a few issues with snippets or completions that start with the $ character. I’m not sure if this has to do with it being the start line regex character or what?

  • Just typing the $ will not open the completions menu automatically like it does for other alphanumeric characters. You must manually hit Ctrl+Space.

  • If I start to type additional characters, the completion menu will open. So for instance, lets say I have a completion like $resource … I type $re and the menu pops open, highlighting $resource. When I press tab, the text that I’ve entered in the editor is eaten.

  • Similarly if I type $, then hit Ctrl+Space and scroll through the menu with the keyboard, select something, then hit tab… the text is eaten.

This is causing a bit of static for an AngularJS package that I put together, because many of the global variables start with $. See the completions here as an example - github.com/EastPoint/Sublime-An … ompletions

github.com/EastPoint/Sublime-An … ompletions

There are a few other issues listed in the README there – but I figured I’d try and draw attention to the issue that’s causing the most difficulty at the moment.

Thanks!

0 Likes

#2

+1

0 Likes

#3

If you edit the default preferences you can remove $ from this setting:

// Characters that are considered to separate words "word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=]{}`~?",

Although it is generally preferable to copy this setting to your own user-preferences file, and edit it there.

0 Likes

#4

Thanks for the suggestion, but that doesn’t work.

0 Likes

#5

Indeed, it doesn’t

0 Likes

#6

The dollar signs in those completions files need to be \escaped as well. Replace

“$anchorScroll”,

with

“$anchorScroll”, etc.

You could do a global replace of $ to $. But, this said, I haven’t tried it yet. It’ll only take you a minute to find out though :smiley:

0 Likes

#7

it is escaped in all of the snippets. It’s not the case here. Thank you though

0 Likes

#8

In snippets (rather than completions-files) dollar-signs need to be double-escaped \ - but I should mention/apologise that I haven’t proven my solution (yet :smile: ).

0 Likes

#9

I was forgetting that you may also need to adapt the following setting in conjunction with my previous advice:

// Additional situations to trigger auto complete "auto_complete_triggers": {"selector": "text.html", "characters": "<"} ],

0 Likes

#10

can you please elaborate, because escaping it with “\” doesn’t change anything.

0 Likes

#11

As an example:

// Additional situations to trigger auto complete "auto_complete_triggers": {"selector": "source.coffee,source.js,source.js.embedded.html", "characters": "$"} ],
would allow $ to trigger completions in coffeescript files, etc. I don’t believe the dollar-sign needs escaping in this setting.

But you might need to read the docs to learn when characters require escaping (or double-escaping) in completions and snippets. ST2 is quite clever though as it (for me) dis-colours the back-slashes if I have the wrong number of them. Edited: Actually, it only does this for me in completions files.]

0 Likes

#12

I think I tried almost everything… doesn’t work

0 Likes

#13

Thanks for the tips… this mostly works.

The completions file has been updated with \$ … and I’ve added the bit to my user prefs.

However, when executing a completion, I end up with, for instance $$resource instead of just $resource.

Any ideas here?

0 Likes