Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
139 lines (120 sloc) 4.1 KB
<?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 ruby18 -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(' ', '&amp;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 &lt;&lt; '&lt;span class="type"&gt;' + param[:type] + '&lt;/span&gt; '.nbsp unless param[:type].to_s.empty?
html &lt;&lt; param[:name]
unless param[:default].to_s.empty?
html &lt;&lt; ' = '.nbsp + param[:default]
end
html = '&lt;i&gt;[' + html + ']&lt;/i&gt;' 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 &gt; 0
elsif char == ?)
depth += 1
end
end
if arg &lt; params.size
params[arg] = '&lt;b&gt;' + params[arg] + '&lt;/b&gt;'
elsif not params.empty?
params[-1] = '&lt;b&gt;' + params[-1] + '&lt;/b&gt;'
end
end
prototype = '&lt;span class="type"&gt;' + function.type + '&lt;/span&gt; &lt;span&gt;'.nbsp + function.name + '&lt;/span&gt;(' + params.join(', '.nbsp) + ')'
tip = &lt;&lt;-HTML
&lt;style type="text/css" media="screen"&gt;
p {
margin: 0;
}
p.prototype span {
color: #00008B;
}
p.prototype i {
color: #666;
}
p.description {
font-size: smaller;
}
p.prototype span.type {
color: #006400;
}
&lt;/style&gt;
&lt;p class="prototype"&gt;#{prototype}&lt;/p&gt;
&lt;p class="description"&gt;#{description}&lt;/p&gt;
HTML
TextMate::UI.tool_tip tip, :format =&gt; :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'][($' + $&amp;).length..ENV['TM_LINE_INDEX'].to_i - 1])
prefix = prefix[$&amp;.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>