Jump into XCode to log emitting line #30

Open
holtwick opened this Issue Jan 13, 2011 · 19 comments

Comments

Projects
None yet
7 participants
Contributor

holtwick commented Jan 13, 2011

May I remember the 'jump to code' feature ;) It was part of this ticket. https://github.com/fpillet/NSLogger/issues/closed#issue/10

I think it should be a straight forward implementation using some Apple Script magic. Maybe someone who knows Apple Script better than me could prepare the code to be used in NSLogger?

Would be great if I could have double click on a log entry to jump to the code. Maybe worth a settings option to let the user choose if he prefers jump to code or logging details?

Owner

fpillet commented Jan 13, 2011

I don't forget about you ... I just didn't have the time to do it yet -- need to intercept mouve clicks in the cell and over the filename/function line and call the xed command line to open the file. Will do soon :-)

As to differentiating simple and double clicks, that's relatively easy - there is a flag for that in events.

Contributor

holtwick commented Jan 13, 2011

Sorry, I didn't want to urge you :)

Maybe it could be added as a button to the details window as a first step.

But I don't need the detail window at all, therefore it would be also ok for me to get into the code on double click directly ;)

Contributor

holtwick commented Jan 13, 2011

Argh... by accident I closed this ticket. I think only you can reopen it again. Sorry.

Contributor

holtwick commented Oct 31, 2011

Congratulations to 1.0 release. I would really love to see this feature in NSLogger though. I made some investigation and you can use the following XCode command line tool to jump to a file and line:

xed --line 100 ~/work/xyz/MainWindowController.m

It should be very straight forward to implement this feature e.g. using NSTask to call this. It seems that XCode is entelligent enough to open the correct Workspace or Project.

Owner

fpillet commented Oct 31, 2011

I pushed an experimental implementation to the 'development' branch. Alt-doubleclick to open the file in Xcode. Unfortunately, xed doesn't seem to direct Xcode to select the proper line (there's an OSA error, try it in console with the same arguments to see it).

If you want to help refine the implementation, look at -logCellDoubleClicked: in LoggerWindowController.m. Ultimately, what I want is an arrow that shows up when you hover a log entry that has a valid filename attached to it. Lacking the time to implement this, though.

Contributor

holtwick commented Oct 31, 2011

Indeed. I have no idea how to solve it. I posted a question to StackOverflow where hopefully some genius may help us out with a solution. http://stackoverflow.com/questions/7957016/jump-to-file-and-line-from-outside-xcode-4-2

Thanks for implementing the stuff so far.

Bug reported to Apple as rdar://10626303 - See a copy of it at http://openradar.appspot.com/radar?id=1480404

If you want to you could replace xed with the following shell/applescript combo:

#!/bin/bash

if [ "$1" = "-l" ] || [ "$1" = "--line" ] ; then
        line=$2
        file=$3
else
        line=1
        file=$1
fi

osascript &>/dev/null <<EOF
tell application "Xcode"
        open "$file"
        activate
        tell application "System Events"
                tell process "Xcode"
                        keystroke "l" using command down
                        repeat until window "Jump" exists
                        end repeat
                        click text field 1 of window "Jump"
                        set value of text field 1 of window "Jump" to "$line"
                        keystroke return
                end tell
        end tell
end tell
EOF

Warning:

  • no error checking,
  • crude commandline parsing
  • not the full functionality of the original xed
  • "Jump in 'filename.m'" in the "Navigate" Menu in Xcode must have command+L as shortcut
  • Universal Access has to be turned on for this to work
Contributor

holtwick commented Mar 30, 2012

Awesome! The open line did not work for me and since I'm not very good at AppleScript I made a little workaround ;)

#!/bin/bash

if [ "$1" = "-l" ] || [ "$1" = "--line" ] ; then
        line=$2
        file=$3
else
        line=1
        file=$1
fi

xed "$file"

osascript &>/dev/null <<EOF
tell application "Xcode"        
        activate
        tell application "System Events"
                tell process "Xcode"
                        keystroke "l" using command down
                        repeat until window "Jump" exists
                        end repeat
                        click text field 1 of window "Jump"
                        set value of text field 1 of window "Jump" to "$line"
                        keystroke return
                end tell
        end tell
end tell
EOF
Owner

fpillet commented Mar 30, 2012

Fantastic! Thanks guys - BTW I'm now using AppCode most of the time instead of Xcode, which starts sucking balls. Need to find a way to do this for AppCode too :-)

Thanks for the awesome script, will get this integrated in NSLogger ASAP.

if you omit the "open" thing, it jumps to the line in the current open file in Xcode so that would not be wise to do.

Perhaps that's some file name quoting issue, if i hit the problem too i'll update.

Current Code in this gist: https://gist.github.com/2250729

Contributor

holtwick commented Mar 30, 2012

Indeed, your script works perfectly. The problem was that I did not use an absolute file path. Sorry, my fault. This will be a killer feature for NSLogger :)

Contributor

holtwick commented Apr 8, 2012

I added the feature from the development branch again. So far it seems to work fine. On ALT + Double Click it jumps into Xcode. It just does not show the cursor or hilite the line somehow, but this may just be little tweaks in the Apple Script. Hope you like it: holtwick/NSLogger@22e2150

Contributor

pbernery commented May 1, 2012

That's a really nice future. Great job guys.

I noticed two bugs though:

  • I have several osascript processes running on my machine after using the feature
  • Double-clicking does not always do what expected: sometimes the "Jump" stays open, sometimes I have line of code deleted, sometimes it does not jump to the line. I guess this is a "synchronization" problem.

I had a rapid look into it but did not find any solution for now.

snarfed commented Apr 4, 2013

thanks, guys! this is great, much appreciated.

one note, in case it helps anyone else: i have a global key binding for Command-L, so the keystroke "l" using command down AppleScript didn't work for me. I replaced it with click menu item index 36 of menu "Navigate" of menu bar item "Navigate" of menu bar 1. Works in Xcode 4.6. It'll need to be updated if/when the Navigate menu changes, or replaced with something that iterates through the menu items and checks for the "Jump in " substring, but it works for me for now.

Contributor

PaulCapestany commented Apr 10, 2013

I optimized this script to make it get to the line in the source file much faster. It could probably use some fallback logic in case for some reason you don't already have the project open (though.. that's what mainly seemed to slow everything down...)

Code is here → Made "⌥ + double click" Open Quickly

snarfed commented Apr 10, 2013

awesome, thanks!

Contributor

PaulCapestany commented Apr 10, 2013

I also realized that some of the weird behavior people may have been noticing with this is most likely caused by having to press ⌥ when double clicking: if you don't let go of the ⌥ key pretty darn fast, then it can interfere with the AppleScript keystroke commands, resulting in Xcode not doing what you want it to do.

Code that I think addresses this issue: #102

Contributor

PaulCapestany commented Jul 5, 2013

For whoever may be interested, I came up with what I think are some more improvements: #114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment