Sublime Forum

How would I turn console error output into "Links" to files?

#1

Hey there, I’ve been using ST2 for a while now and it’s by far the best application around! I know how amazingly customisable it is so I was wondering if this was possible and how to go about it.

So when I compile code (Using the Pawn compiler) I get errors/warnings that look like this:

E:\Games\Projects\SA-MP\ScavengeSurvive\gamemodes\../scripts/Items/timebomb.pwn(3) : error <error number>: <error name>

Or

<directory>(<line number>) : <error number> : <error description>

And I was wondering, could I somehow turn that first part (I’m sure I could isolate/identify the first part with something like SSCANF or RegEx) into a link to that file? So I can just double or single click that part of the error to jump straight to that file (“E:\Games\Projects\SA-MP\ScavengeSurvive\gamemodes…/scripts/Items/timebomb.pwn”) and that line (3)?

My files are included using “…/scripts/Folder/File” so I assume the “…/” would work fine with opening files etc. I can easily change to using backslashes too if need be.

How would I go about this? I haven’t really delved into plugin development for this application yet but I would give it a try if someone would let me know what kind of level of difficulty something like this would be :stuck_out_tongue: (I’ve been coding C/Pawn for about 3 years)

Thanks in advance for any help! :smile:

0 Likes

#2

I would also be interested in the correct way to do this (particularly in Sublime Text 3). I’m trying to update the Cscope plugin to be compatible with Sublime Text 3. It generates output that sure looks like the “Find Results” window, but the file links aren’t followed. What special work do I need to do to generate text in a new window view that will allow me to click on the file references and have them opened in Sublime?

The original Cscope plugin is here and I haven’t changed much in the way it formats it’s output. I hope to submit my changes (once working) to the original author:
https://github.com/ameyp/CscopeSublime

The output is formatted like so:

In folder C:\path\to\project
Found 2 matches for C symbol: schwankyRoutine
--------------------------------------------------


.\api\schwanky_api.h:
   944 [scope: <global>] extern int schwankyRoutine(int *thing,

.\src\schwanky.c:
  2413 [scope: k] int k(int *thing,

Do I need complete paths? Is the “scope:…” throwing it off? I couldn’t find any documentation on how that is supposed to work.

0 Likes

#3

you can set result_file_regex setting of view or output_panel as fallows

view.settings().set(“result_file_regex”,"^(…^:]):([0-9]+):?([0-9]+)?:? (.)$")

and you can change the regex by yourself

0 Likes

#4

If you are using a build system (which you should) than you can just modify it to include a “file_regex” setting which does the same as @waterup proposed but without a plugin. See docs.sublimetext.info/en/latest/ … ml#options.

0 Likes

#5

Thanks for the replies, I’m using SublimeText2 right now.

I’ve looked at the “file_regex” and it’s almost working, I’ve never used RegEx before though (been meaning to learn for ages)

How would I “regex-ify” the error string?

All I need is the path and line number from this:

E:\Games\Projects\SA-MP\ScavengeSurvive\gamemodes\../scripts/SSS/Char/Animations.pwn(15) : error 017: undefined symbol "symbol"

“E:\Games\Projects\SA-MP\ScavengeSurvive\gamemodes…/scripts/SSS/Char/Animations.pwn” being the path and (15) being the line number.

Right now, I’m using

(...*?)(([0-9]))

and it ends up with this file path:
E:\Games\Projects\SA-MP\ScavengeSurvive\gamemodes…/scripts/SSS/Char/Animations.pwn**(**
That trailing bracket at the end is the last issue to resolve, would be awesome if someone would help me with the regex :smile:

0 Likes

#6
(...*?)(([0-9]))

Means:

1:(Match any character; then match any character; then match an indefinite amount of characters UNTIL the next pattern matches) 2:( 3:(match 0-9) )
And translates to "match at least 2 (because of …) characters and then everything until you find the first number.
Note: “N:()” are the capturing groups.

What you are searching for is:

(.*?)\(([0-9]+)\)
0 Likes

#7

Thanks, guys!

0 Likes

#8

Just to follow up, here’s the code I that worked successfully to allow the output results to be clickable for the updated CScope plugin. Note that I also had to update the output generated in the output view to show the full path to the file. While I might have been able to set a working directory for the relative paths I felt the output would be more consistent to mimic the standard Find Results output. So output like:

[code]In folder C:\workspace\schwanky_app
Found 2 matches for C symbol: doSchwankyStuff

C:\workspace\schwanky_app\schwanky_api.h:
863 [scope: ] int doSchwankyStuff(int stuff);

C:\workspace\schwanky_app\schwanky_api.c:
619 [scope: doSchwankyStuff] int doSchwankyStuff(int stuff)[/code]

can be processed in the results command like this:

[code]class CscopeDisplayResultsCommand(sublime_plugin.TextCommand):
def run(self, edit, symbol, output):
cscope_view = self.view.window().new_file()
cscope_view.set_scratch(True)
cscope_view.settings().set(“result_file_regex”,r’(^([a-zA-Z]:)?(\/][a-zA-Z0-9._-]+)+(\/])?)’)
cscope_view.settings().set(“result_line_regex”,r’^\s]*([0-9]+) \S+’)
cscope_view.set_name("Cscope - " + symbol)

    cscope_view.insert(edit, 0, output)

    if get_setting("display_outline") == True:
        symbol_regions = cscope_view.find_all(symbol, sublime.LITERAL)
        cscope_view.add_regions('cscopesublime-outlines', symbol_regions[1:], "text.find-in-files", "", sublime.DRAW_OUTLINED)

    cscope_view.set_syntax_file(CSCOPE_SYNTAX_FILE)[/code]

I think a build system might likely have been able to implement the functionality of this plugin, but since I was already walking down the road of updating the existing plugin I implemented as such. Thank you for the help, guys!

0 Likes

#9

Your first regexp is overkill. r"(.*):$" would work just fine. And except for the missing get_setting definition (which is probably part of the plugin you’re editing) it looks fine.

But does F4 (for the next “error”) also work on standard views? I thought that was only possible with output panels.

0 Likes