Sublime Forum

SourcePawn Symbol List Possible?

#1

I want to create a tmLanguage file that will capture functions in SourcePawn files and add them to the symbol list.

The problem I’m having is that Pawn has no keyword to denote a function definition and semicolons are optional. Therefore I can’t seem to find a way to match function definitions using the single-line regex that Sublime uses and I can’t figure out how to make a begin/end work.

Take this code for example (formatting purposely inconsistent):

 1. public Action:RoundEnd(Handle:event, const String:name], bool:dontBroadcast)
 2. {
 3.     CheckWinCondition(true);
 4. }
 5. 
 6. CheckWinCondition(bool:round_end = false)
 7. {
 8.     // ...
 9.     if (!round_end)
10.     {
11.         SetVariantInt(TEAM_BLU)
12.         AcceptEntityInput(master_cp, "SetWinner")
13.     }
14. }
15. 
16. StartBeacon(client) {
17.     // ...
18. }

Using this begin/end

<dict>
    <key>begin</key>
    <string>\w+\s*\(^)]*\)</string>
    <key>name</key>
    <string>support.function.sourcepawn</string>
    <key>end</key>
    <string>{</string>
</dict>

doesn’t work because it also captures function calls and consumes everything between the function call and the next ‘{’. So, it will capture everything between lines 3 and 7 and lines 11 and 16.

Is there any way to make this work? I’m currently generating completions using a plugin, but there is no API to allow a plugin to populate the symbol list so there is no way to easily navigate to function definitions.

0 Likes

#2

What plugin you are using for completions?

To add the source pawn symbols to the list, you need to create a configuration file like this named SourcePawn.tmPreferences:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Symbol List</string>
	<key>scope</key>
	<string>(source.SourcePawn) &amp; (function.definition | variable.definition)</string>
	<key>settings</key>
	<dict>
		<key>showInSymbolList</key>
		<integer>1</integer>
		<key>showInIndexedSymbolList</key>
		<integer>1</integer>
	</dict>
</dict>
</plist>

Where function.definition and variable.definition are the scopes associated for the variables keywords on your sublime-syntax file. For AmxxPawn see this.

Find out scopes for your theme you may use these:

  1. https://github.com/yaworsw/Sublime-ScopeAlways
  2. https://github.com/facelessuser/ScopeHunter
0 Likes