-
Notifications
You must be signed in to change notification settings - Fork 148
/
showreference.lua
56 lines (49 loc) · 1.94 KB
/
showreference.lua
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
local id = ID("showreference.showreferencemenu")
local ident = "([a-zA-Z_][a-zA-Z_0-9%.%:]*)"
return {
name = "Show reference",
description = "Adds 'show reference' option to the editor menu.",
author = "Paul Kulchenko",
version = 0.3,
dependencies = "1.30",
onMenuEditor = function(self, menu, editor, event)
local point = editor:ScreenToClient(event:GetPosition())
local pos = editor:PositionFromPointClose(point.x, point.y)
if not pos then return end
local line = editor:LineFromPosition(pos)
local linetx = editor:GetLine(line)
local localpos = pos-editor:PositionFromLine(line)
local selected = editor:GetSelectionStart() ~= editor:GetSelectionEnd()
and pos >= editor:GetSelectionStart() and pos <= editor:GetSelectionEnd()
local start = linetx:sub(1,localpos):find(ident.."$")
local right = linetx:sub(localpos+1,#linetx):match("^([a-zA-Z_0-9]*)%s*['\"{%(]?")
local ref = selected
and editor:GetTextRange(editor:GetSelectionStart(), editor:GetSelectionEnd())
or (start and linetx:sub(start,localpos)..right or nil)
local target = self:GetConfig().target
local transform = self:GetConfig().transform
if ref and target then
menu:Append(id, ("Show Reference: %s"):format(ref))
if transform then ref = select(2, pcall(transform, ref)) end
menu:Connect(id, wx.wxEVT_COMMAND_MENU_SELECTED,
function() wx.wxLaunchDefaultBrowser(target:format(ref), 0) end)
end
end
}
--[[ configuration example:
showreference = {
target = 'http://love2d.org/wiki/%s',
}
or
showreference = {
target = 'http://docs.coronalabs.com/api/%s.html',
transform = function(s)
local tip = GetTipInfo(ide:GetEditor(), s)
if tip then s = tip:match("%)%s*(%S+)") or s end
s = (type(G[s]) == "function" and "global." or "")..s
s = s..(s:find("[%.%:]") and "" or ".index")
s = s:find("^_") and "type."..s:sub(2) or "library."..s
return(s:gsub("[%.%:]","/"))
end,
}
--]]