Sublime Forum

jQuery autocomplete/code intelligence?

#1

Surely this must be simple. I’m looking for a way to have Sublime allow jQuery auto completion as well as code intelligence (knowing parameters for jQuery methods, etc). Is this doable?

Thanks.

0 Likes

#2

A quick google reveals a number of plug-ins for jQuery, including this one.

The Package Control plug-in will probably help you to install a jQuery plug-in. Otherwise, you could create a folder named ‘jQuery’ (in your ‘Packages’ folder) and copy a number of files/snippets to it.

The jQuery snippets/completions will probably display for any .js file, but I suppose if you’re using jQuery you’re likely to be using it most of the time anyway :wink:

0 Likes

#3

Wait, I’m confused. I have this jQuery folder in ~/.config/sublime-text-2/Packages. It has all the autocompletes, etc. I just don’t know how to activate it.

0 Likes

#4

Mmmm… not sure. Check your File Settings - Default for:

[code] // When enabled, pressing tab will insert the best matching completion.
// When disabled, tab will only trigger snippets or insert a tab.
// Shift+tab can be used to insert an explicit tab when tab_completion is
// enabled.
“tab_completion”: true,

// Enable auto complete to be triggered automatically when typing.
"auto_complete": true,[/code]

Try pressing Ctrl-Space to see if this displays completions for you. Perhaps check the completions file itself to see if it has a line like:

"scope": "source.js -string -comment -constant",
0 Likes

#5

I have this plug in too, but no auto-complete for even simple things like .click.

0 Likes

#6

From looking over the plugin, it provides a syntax file for jQuery and a bunch of snippets. I do not see a .sublime-completions file, which is what I believe is used to power the autocomplete functionality.

0 Likes

#7

Well, ST2 does add snippets to the autocompletion, but that could hardly be comparable to code intelligence.

0 Likes

#8

Ok, looks like there is sort of completion. If I do $.getJSON then hit tab, it fills out the possible parameters which is nice. But it doesn’t have the same level of autocomplete as you’re typing, like it does in PHP which is quite extensive, i.e., as I’m typing $.getJ… it doesn’t pop up a list of possible methods.

Needs work. This is the mrmartineau jQuery package BTW.

0 Likes

#9

Coda has a great plug in that auto completes nearly everything jQuery. I want to like Sublime. I do. But it seems like I am repeatedly going back to Coda for the features I need and want…

0 Likes

#10

I’m trying to accomplish this too. I did the package control thing and got jquery with the TONS of snippets, but it has no code completion while typing, so typing $().add should bring up the white menu showing me .addClass(), without me having to do anything, then I could press tab to select that autocomplete choice

From reading above, it looks like there needs to be a .sublime-completion file, and without that file for jquery, it wont work?
I thought that downloading the jquery snippets pack from package control would add those to the “autocomplete that pops up while typing”.

Hitting ctrl+space to bring up the white autocomplete box just slows the whole process down.

0 Likes

#11

Creating a completions file for jQuery is fairly straight-forward, although I think I discovered one on the interweb that just needs updating - I’ll have to look again.

The basic structure is like this, saved as jQuery.sublime-completions:

[code]{
“scope”: “source.js -string -comment -constant”,

"completions": 
	{ "trigger": ".add()", "contents": ".add($1)$0" },
	{ "trigger": ".slideToggle()", "contents": ".slideToggle(${1:duration}, ${2:easing}${3:, callback]})$0" }
]

}[/code]
The add version would allow you to tab into the brackets. slideToggle would allow tabbing between the arguments, and I generally leave the square brackets , and an extra comma] to indicate that it’s optional. This means that, when tabbing, I can either press Delete or re-enter the comma and space (and the argument), before tabbing out.

It would also require creating the setting to allow the dot as a trigger-character, assuming this is required:

// Additional situations to trigger auto complete "auto_complete_triggers": {"selector": "source.js", "characters": "."} ] // or \.
I might try and find the page I mentioned, or perhaps someone has discovered a web-page that lists the jQuery methods in a table column that I can copy? But I won’t be doing this for a few days as I’m otherwise occupied.

Andy.

0 Likes