Sublime Forum

GoTo Anything fails with jQuery js files

#1

Try the following:

Write some jQuery code with AJAX requests, like this:

[code]function bild_loeschen(id) {
var urldaten = {};
urldaten’action’] = ‘bild_loeschen’;
urldaten’id’] = id;

$.post("index.php", urldaten,
	function (data) {
		$("#bild").html(data);
		bilderloader(oe_id);
	});

}[/code]

Open the GoTo Anything tool and type “@”. It will show you the bild_loeschen() and the function (data) “functions”. I am pretty sure this is not wanted.

0 Likes

Does Jon actually care for bug reports here?
#2

The symbol list is populated based on the syntax scope rules. By default, as JavaScript may have some additional scopes for symbol list, symbol list are populated with entries with the following scopes - entity.name.function, entity.name.type, meta.toc-list. So, it’s more a limitation of the syntax highlighting, rather than of Sublime Text. You can play with the tmLanguage file to add the appropriate scope to that entry (though there isn’t a name, which makes it a bit more tricky to “go to”).

You can use “ctrl+shift+alt+p” (in windows) to view the scope under the cursor. Alternatively, you can use the ScopeHunter plugin.

0 Likes

#3

The editor is responsible for the highlighting, right?

0 Likes

#4

I suppose I worded it wrong, this may not have gotten as much attention because it’s just a syntax highlighting problem. I also misread the problem (which is why my post in your other thread probably seemed odd :smile:), I thought you said it wasn’t appearing. You can edit the Symbol List Function.tmPreferences, and remove the source.js meta.function.js, but this would cause you to lose the “function” “prefix”. So you would have to do a bit more work to get it to only list non anonymous functions.

0 Likes

#5

Rather than removing that entry, you can try replacing that symbol list with

[code]<?xml version="1.0" encoding="UTF-8"?>

name Symbol List Function scope source.js meta.function.js, source.js meta.function.json.js settings showInSymbolList 1 symbolTransformation s/^function\s*\(.*\)//g uuid 3CEA49B2-A5C5-405C-82E2-B8B668877C38 [/code]

Note this is minimally tested, but the regex matches the definition for the anonymous function. All I did was add the “symbolTransformation” entry.

0 Likes

#6

So it would only match anonymous functions then? Not quite what I wanted to achieve.

0 Likes

#7

No it removes them,well technically it just replaces “function (foo)” with an empty string, which is subsequently ignored by the symbol list. The symbol transformation, as far as I understand it, modifies what will be displayed in the symbol list. The actual entries are defined by the scope. So in this case, anonymous functions are replaced with empty strings.

0 Likes

#8

Ah - pretty much what I am looking for, thanks!

Where to store it so an update won’t kill it?

0 Likes

#9

Ignore the built in package “JavaScript” and create your own, essentially a copy paste of the folder, with the changes you want to Symbol List Functions. Downside is if there are any updates to the package, you will have to do this again. This will work on (I believe) ST2 and ST3. I was hoping I could override the tmPreferences file in ST3, by creating it in the packages directory, similar to how you can override snippets. Unfortunately, this didn’t work for me. Though I could have done something wrong, so you may want to try too. If it doesn’t in fact work, perhaps it should be a feature request as that is the behavior I would expect.

0 Likes

#10

I’d just guess as ST3 is still in beta, maybe this is already on the ToDo list.

Thank you, the fix works fine for what it should do. :smile:

0 Likes