ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
803 stars 54 forks source link

Allow functions to be prefixed with $, Fixes #1 #2

Closed subhaze closed 11 years ago

subhaze commented 11 years ago

Removes the $ prefix from the completion name so that Sublime Text will correctly complete.

marijnh commented 11 years ago

Sublime Text seems to be very confused about the syntactic role of $ in JavaScript. At least for me, it also colors the $ red if I used it in a name. Do you know whether this is something that could be fixed by a better JavaScript mode, or something that's built into ST?

subhaze commented 11 years ago

I think it's a mixture of the two.

For the completions I think it might be something built into ST, not for sure on that and will try and dig more into this, but I've had issues with using a dollar sign infront of completions before.

As for the color issue you describe, that seems to stem from the JavaScript.tmLanguage file. I did some debugging and it seems that it's scoped to source.js keyword.operator.js. So, I decompressed the JavaScript.sublime-package that is shipped and overrode the JavaScript.tmLanguage and removed the $ from the keyword operators list and that fixed the coloring issues but did not help when it came to completions.

Hope that info helps.

subhaze commented 11 years ago

Going to close this pull request as it only solved the prefix issue and not very elegantly...

Looking more into this yesterday, it seems that you need to escape the completion so that Sublime Text handles the $ correctly.

However, doing this solved one issue while creating another. The next issue is that when the completion is triggered ST will not replace the $ correctly since it's default word_separators includes the $. The only work around I know for this would be to ship the plugin with a modified word_separators for JavaScript so that it will replace the $ when triggering the completion.

Otherwise you would end up with something like: $$MyConstructor instead of $MyConstructor.

I have a branch with this setup here: https://github.com/subhaze/tern_for_sublime/commit/35e22bb9d6e378ffff678d155accd70222032c54

marijnh commented 11 years ago

How responsive is Sublime Text upstream usually? Since this rather obviously a bug in the JS mode, I'd think the solution of just getting this fixed in the distribution should be considered. There doesn't appear to be a real bug tracker for ST, unfortunately. Do you want to try and submit a patch on the ST forums?

subhaze commented 11 years ago

I know Jon is pretty responsive if the issue called out on the forum is critical to the application itself, but not sure how responsive on fixing lang issues.

I'll see what I can stir up in the forum this evening after work.

subhaze commented 11 years ago

I've made a post about this here http://www.sublimetext.com/forum/viewtopic.php?f=3&t=12178

marijnh commented 11 years ago

Well, it's fallen off the front page of the forum. I somehow doubt a chaotic forum like this is a very effective way to track bugs.

Do you know how this should be fixed? If so, including a patch might help it get noticed.

subhaze commented 11 years ago

The only workaround I can think of is here https://github.com/subhaze/tern_for_sublime/commit/35e22bb9d6e378ffff678d155accd70222032c54

But that involves changing the default word_separators settings so it wouldn't be 100% reliable...

I've PM'd Jon, not sure if that'll do any good but hopefully I'll get some feedback.

marijnh commented 11 years ago

My understanding of ST isn't all that deep. Would simply putting that JavaScript.sublime-settings file in the plugin fix this problem without having any undesirable side effects? If so, that's probably an acceptable solution.

subhaze commented 11 years ago

You'll also need to re.escape the completion otherwise ST will remove anything to the right of the $ when a completion is triggered.

The JavaScript.sublime-settings addition is so that when the completion is triggered ST will remove the current $ that you've typed.

So with escaping but without the settings file, this: $someVar would complete to $$someVar.

The reason I state that using the settings file wouldn't be 100% reliable is because other plugins could override your settings. I believe they're loaded in A-Z so tern will be low on the list and it's doubtful other plugins would alter this setting but it's definitely worth noting.

marijnh commented 11 years ago

Great. I've merged your patch (51d24eded8a81968c4dc124a3d6a1515fbb9a3f1) and indeed completion works well now. Highlighting is still wonky, but hey, that's not Tern's problem.

subhaze commented 11 years ago

Glad to hear that. Yeah, the highlighting is a whole other story, haha.