-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnimrod.py
63 lines (47 loc) · 1.99 KB
/
nimrod.py
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
import sublime, sublime_plugin
import os, subprocess
import re
##Resources
# http://sublimetext.info/docs/en/extensibility/plugins.html
# http://www.sublimetext.com/docs/2/api_reference.html#sublime.View
# http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/
# http://www.sublimetext.com/docs/plugin-examples
class LookupCommand(sublime_plugin.TextCommand):
def idetool(self, cmd, filename, line, col, extra = ""):
args = "nimrod --verbosity:0 idetools " \
+ cmd + " --track:" \
+ filename + "," + str(line) + "," + str(col) \
+ " " + filename + extra
result = ""
for result in os.popen(args): pass
return result
def lookup(self, filename, line, col):
result = self.idetool("--def", filename, line, col)
#Parse the result
value = self.parse(result)
if value is not None:
self.open_definition(value[2], value[3], value[4])
def parse(self, result):
p = re.compile('^(?P<cmd>\S+)\s(?P<ast>\S+)\s(?P<symbol>\S+)\s(?P<type>[^\t]+)\s(?P<path>[^\t]+)\s(?P<line>\d+)\s(?P<col>\d+)\s(?P<description>\".+\")?')
m = p.match(result)
if m is not None:
print(m)
cmd = m.group("cmd")
if cmd == "def":
return (m.group("symbol"), m.group("type"),
m.group("path"), m.group("line"),
m.group("col"), m.group("description"))
return None
def open_definition(self, filename, line, col):
print(filename, line, col)
win = self.view.window()
arg = filename + ":" + str(line) + ":" + str(col)
win.open_file(arg, sublime.ENCODED_POSITION | sublime.TRANSIENT)
def run(self, edit):
filename = self.view.file_name()
sels = self.view.sel()
for sel in sels:
pos = self.view.rowcol(sel.begin())
line = pos[0]+1
col = pos[1]
self.lookup(filename, line, col)