-
Notifications
You must be signed in to change notification settings - Fork 50
/
Function Tooltip.tmCommand
138 lines (120 loc) · 4.09 KB
/
Function Tooltip.tmCommand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?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>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby -wKU
SUPPORT = ENV['TM_SUPPORT_PATH']
DIALOG = SUPPORT + '/bin/tm_dialog'
require SUPPORT + '/lib/escape'
require SUPPORT + '/lib/osx/plist'
require ENV['TM_BUNDLE_SUPPORT'] + '/lib/php.rb'
require ENV['TM_SUPPORT_PATH'] + '/lib/ui'
require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes'
# ENV['TM_BUNDLE_SUPPORT'] = '/Library/Application Support/TextMate/Bundles/PHP.tmbundle/Support/'
# ENV['TM_CURRENT_LINE'] = 'dummy(array_merge(array("array", "number", "one"), array("array2")))'
# ENV['TM_LINE_INDEX'] = '53'
#
# ENV['TM_CURRENT_LINE'] = "date('Y-m-d', time() + ONE_MONTH)"
# ENV['TM_LINE_INDEX'] = '23'
lang = ENV['LANG'] ? ENV['LANG'][0..2] : 'en'
$fnFilename = ENV['TM_BUNDLE_SUPPORT'] + '/function-docs/' + lang + '.txt'
if !File.exist?($fnFilename)
$fnFilename = ENV['TM_BUNDLE_SUPPORT'] + '/function-docs/en.txt'
end
class String
def nbsp
gsub(' ', '&nbsp;')
end
end
def show_function_and_exit(function, line = nil)
return unless function =~ /^[A-Za-z_][A-Za-z0-9_]*$/
functions = `grep -i '^#{function}%' "#{$fnFilename}"`.split("\n")
if functions.size == 1
function, prototype, description = functions.pop.split('%')
function = PHPFunction.new(prototype)
params = function.params.map do |param|
html = ''
html << '<span class="type">' + param[:type] + '</span> '.nbsp unless param[:type].to_s.empty?
html << param[:name]
unless param[:default].to_s.empty?
html << ' = '.nbsp + param[:default]
end
html = '<i>[' + html + ']</i>' if param[:optional]
html
end
if line
arg = 0
depth = 0
line.reverse.each_byte do |char|
if char == ?, and depth == 0
arg += 1
elsif char == ?(
depth -= 1 if depth > 0
elsif char == ?)
depth += 1
end
end
if arg < params.size
params[arg] = '<b>' + params[arg] + '</b>'
elsif not params.empty?
params[-1] = '<b>' + params[-1] + '</b>'
end
end
prototype = '<span class="type">' + function.type + '</span> <span>'.nbsp + function.name + '</span>(' + params.join(', '.nbsp) + ')'
tip = <<-HTML
<style type="text/css" media="screen">
p {
margin: 0;
}
p.prototype span {
color: #00008B;
}
p.prototype i {
color: #666;
}
p.description {
font-size: smaller;
}
p.prototype span.type {
color: #006400;
}
</style>
<p class="prototype">#{prototype}</p>
<p class="description">#{description}</p>
HTML
TextMate::UI.tool_tip tip, :format => :html
exit
end
end
function = nil
show_function_and_exit(function = ENV['TM_CURRENT_WORD'].to_s)
prefix = ENV['TM_CURRENT_LINE'][0..ENV['TM_LINE_INDEX'].to_i].reverse
# Keep moving back a function call until we get a match and exit
while prefix =~ /\(\s*(\w+)/
show_function_and_exit(function = $1.reverse, ENV['TM_CURRENT_LINE'][($' + $&).length..ENV['TM_LINE_INDEX'].to_i - 1])
prefix = prefix[$&.length..-1]
end
show_function_and_exit(function = $1) if ENV['TM_CURRENT_LINE'][0..ENV['TM_LINE_INDEX'].to_i] =~ /(\w+)\($/
TextMate.exit_show_tool_tip "Function not found: " + function.to_s
</string>
<key>fallbackInput</key>
<string>line</string>
<key>input</key>
<string>none</string>
<key>inputFormat</key>
<string>xml</string>
<key>keyEquivalent</key>
<string>~</string>
<key>name</key>
<string>Documentation for Function Call (tool tip)</string>
<key>output</key>
<string>showAsTooltip</string>
<key>scope</key>
<string>source.php</string>
<key>uuid</key>
<string>19A164B7-4A3C-421B-9866-85FB9077A983</string>
</dict>
</plist>