Sublime Forum

Help to Goto Definition

#1

A simplified example:
in .tmLanguage, I define scope tidea.symbol = :.+:
in .tmPreference, I assign: scope = tidea.symbol showInSymbolList = 1
The source code has this example text:Define :Plist: is Property List blah blah What is Plist
Goto Symbol does show up :Plist:
However, when placing cusor on the 2nd Plist and Goto Definition, nothing happens ?!
Please help

P.S In the same file, whichever text assigned with scope “entity.name.function” is included in Goto Symbol list while my .tm Preference doesn’t mention entity.name.function at all. Why?

0 Likes

#2

In your syntax definition you are includeing the : characters as part of the function name. Sublime thinks your function name is now “:Plist:” not “Plist” which is what you are expecting. If you tried the following I think it would work based on your current syntax.

blah blah
What is :Plist:

To get around that I would use “captures” in your syntax. The following is in Plist format so you may need to convert it to match the way you are creating your syntax but this works:

<key>patterns</key>
	<array>
		<dict>
			<key>captures</key>
			<dict>
				<key>1</key>
				<dict>
					<key>name</key>
					<string>meta.language.4gl</string>
				</dict>
				<key>2</key>
				<dict>
					<key>name</key>
					<string>entity.name.function.4gl</string>
				</dict>
				<key>3</key>
				<dict>
					<key>name</key>
					<string>meta.language.4gl</string>
				</dict>
			</dict>
			<key>match</key>
			<string>(:)(.+)(:)</string>
		</dict>
	</array>

Everything between ( and ) will be a group. I am assigning each group a different name which will tell sublime that in order for your function names to be “Defined” you need to start with a “:” followed by something and end with another “:”. But since each group has its own name, only the part between the : will be treated as the function name which will allow sublime to find the definition using your examples.

I hope that was helpful and clear.

-Nick

0 Likes

#3

Thanks Nick, I tried your method and did make the Goto Symbol list only show “Plist” without the colon
However, when I place cursor on the 2nd Plist and choose Goto Definition, still no thing happens.
I guess that I need symbolTransformation to match both :Plist: and Plist(). Then the 2nd Plist should be entered as Plist() to make it work? But I don’t know how to use symbolTransformation

0 Likes

#4

Here is the tmLanguage file I created to get mine to work. Since everything is in the same file and the function defintion is in the frame it doesn’t look like anything happens, but my cursor is jumping up to the function definition. Also if I create a second file with the Plist function in the text it will correctly jump to the file with the definition.

I have seen some odd things when developing syntax files. Try closing Sublime and reopening to release any cached version of the syntax that may be in use. I am also including my entire tmLanguage file for you to compare against.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>fileTypes</key>
	<array>
		<string>tid</string>
	</array>
	<key>name</key>
	<string>Tidea</string>
	<key>patterns</key>
	<array>
		<dict>
			<key>captures</key>
			<dict>
				<key>1</key>
				<dict>
					<key>name</key>
					<string>meta.language.4gl</string>
				</dict>
				<key>2</key>
				<dict>
					<key>name</key>
					<string>entity.name.function.4gl</string>
				</dict>
				<key>3</key>
				<dict>
					<key>name</key>
					<string>meta.language.4gl</string>
				</dict>
			</dict>
			<key>match</key>
			<string>(:)(.+)(:)</string>
		</dict>
	</array>
	<key>scopeName</key>
	<string>source.tidea</string>
	<key>uuid</key>
	<string>8647ca7c-8f33-4c93-b413-dab16f94d3c4</string>
</dict>
</plist>

Here is the file I was using to test just so you have everything I was working with when I did my testing.

Define :Plist: 
is Property List

blah blah
What is Plist
0 Likes

#5

I should also note that I do not have a tmPreference file in use for this syntax.

0 Likes

#6

Your file works because (as I said in 1st post) the scope name is entity.name.function
Argh, now I suspect that it’s a special scope name that ST use with Goto Definition
User cannot create a different name

0 Likes

#7

Sorry, I completely missed the last part of your original post.

Don’t quote me, but I believe there are some things that are documented in the tmLanguage documentation that Sublime does not support. I think you may have found one of those items. Another item that does not seem to work in Sublime is the code folding begin/end entries.

As you stated, I do believe Sublime is expecting your symbols to be added under the entity.name.function scope in order to be indexed for goto definition.

0 Likes

#8

I doubt that there’re more special scope names like that because JavaScript’s “Symbol List Function.tmPreferences” has this:
source.js meta.function.js, source.js meta.function.json.js

anyway, my question now is how to highlight all symbols in project (i.e: all Plist)?
My plan is: Well there’re a lot of the word Plist scattering and I need to highlight to reader that this word is defined before

0 Likes

#9

So what you would like to do is highlight the names of the symbols that have been defined? I am just trying to fully understand what you would like to see. Something like this?:

Define : Plist: this is a Plist (there should be no space between : and P)
Define :Tester: testing…

Some test goes here. We may have a Plist or we could have a Tester.

Something like this can be done for individual files, but the color highlighting would probably need to be done through regions in the view. I don’t think there is a way to get a full list of the indexed project symbols. Right now the only API’s that I can see only allow you to pass in a symbol and get the information for that single symbol.

0 Likes

#10

If you want background highlighting of certain scopes, the best idea would be to edit your color scheme.

Here is what the Tubnil color scheme looks like (defines background color for entity.name.function and entity.name.class): fichtefoll.taiga-san.net/screens … -theme.png

That sounds weird. It shouldn’t happen and I haven’t experienced this before. I don’t have the time currently to test this myself, though.

0 Likes

#11

I can add scope to symbol definition such as :stuck_out_tongue:list:
But when I reuse Plist later in many other files, that’s a normal text, without any scope.
The problem is how to highlight all instance of Plist without any scope, just rely on list of Indexed_Symbol_in_Project

0 Likes