|
5 | 5 | <key>beforeRunningCommand</key>
|
6 | 6 | <string>nop</string>
|
7 | 7 | <key>command</key>
|
8 |
| - <string>#!/usr/bin/env ruby |
| 8 | + <string>#!/usr/bin/env ruby18 |
9 | 9 |
|
10 |
| -require "#{ENV['TM_BUNDLE_SUPPORT']}/gomate" |
11 |
| -Go::godef</string> |
| 10 | +require ENV['TM_SUPPORT_PATH'] + '/lib/textmate' |
| 11 | +require ENV['TM_SUPPORT_PATH'] + '/lib/tm/process' |
| 12 | +require ENV['TM_SUPPORT_PATH'] + '/lib/tm/save_current_document' |
| 13 | +
|
| 14 | +# TextMate's special TM_GODEF or expect 'godef' on PATH |
| 15 | +godef_cmd = ENV['TM_GODEF'] || 'godef' |
| 16 | +
|
| 17 | +TextMate.save_if_untitled('go') |
| 18 | +
|
| 19 | +# load current document from stdin |
| 20 | +document = [] |
| 21 | +while line = $stdin.gets |
| 22 | + document.push(line) |
| 23 | +end |
| 24 | +
|
| 25 | +# byte offset of cursor position from the beginning of file |
| 26 | +cursor = document[ 0, ENV['TM_LINE_NUMBER'].to_i - 1].join().length + ENV['TM_LINE_INDEX'].to_i |
| 27 | +
|
| 28 | +args = [] |
| 29 | +args.push(godef_cmd) |
| 30 | +args.push('-f') |
| 31 | +args.push(ENV['TM_FILEPATH']) |
| 32 | +args.push('-o') |
| 33 | +args.push("#{cursor}") |
| 34 | +
|
| 35 | +# /usr/local/Cellar/go/1.7.1/libexec/src/database/sql/sql.go:960:15 |
| 36 | +out, err = TextMate::Process.run(*args) |
| 37 | +
|
| 38 | +if err.nil? || err == '' |
| 39 | + file_details = out.split(':') |
| 40 | + TextMate.go_to(:file => file_details[0], |
| 41 | + :line => file_details[1], |
| 42 | + :column => file_details[2].to_i) |
| 43 | +elsif err.casecmp "godef: no identifier found"; |
| 44 | + require "#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb" |
| 45 | + package = TextMate::UI.request_string :title => "Open Package", :default => '', :prompt => "Which package do you wish to open?" |
| 46 | + #TODO: Find and open package |
| 47 | +else |
| 48 | + TextMate.exit_show_tool_tip(err) |
| 49 | +end</string> |
12 | 50 | <key>input</key>
|
13 | 51 | <string>selection</string>
|
14 | 52 | <key>inputFormat</key>
|
15 | 53 | <string>text</string>
|
16 | 54 | <key>keyEquivalent</key>
|
17 |
| - <string>@g</string> |
| 55 | + <string>@D</string> |
18 | 56 | <key>name</key>
|
19 | 57 | <string>Go to Definition</string>
|
20 | 58 | <key>outputCaret</key>
|
|
0 commit comments