Skip to content

Commit daa803e

Browse files
committed
added support for non-standard packages using gopkgdoc.appspot.com
fixed a bug for package alias handling when alias len > 1
1 parent f49e33a commit daa803e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

GoToDoc.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def get_imports(src):
2929
''''build a list of imported packages from src, each tuple is (pkg_alias, pkg_path)
3030
[('', 'compress/bzip2'), ('E', 'errors'), ('.', 'archive/tar'), ('_', 'database/sql/driver')]
3131
'''
32-
single_import_pattern = ''' import \s+ (\w|\.){0,1} \s* "(.*?)" '''
32+
single_import_pattern = ''' import \s+ (\w+|\.){0,1} \s* "(.*?)" '''
3333
single_imports = re.findall(single_import_pattern, src, re.M | re.X | re.S)
3434

3535
multi_import_pattern0 = '''import \s* \( (.*?) \)'''
3636
multi_imports0 = re.findall(multi_import_pattern0, src, re.M | re.X | re.S)
3737

38-
multi_import_pattern = ''' (\w|\.){0,1} \s* "(.*?)" '''
38+
multi_import_pattern = ''' (\w+|\.){0,1} \s* "(.*?)" '''
3939
multi_imports = re.findall(multi_import_pattern, ''.join(multi_imports0), re.M | re.X | re.S)
4040

4141
return single_imports + multi_imports
@@ -51,8 +51,8 @@ def get_full_pkg(imports, pkg):
5151
return ''
5252

5353

54-
def get_pkg_doc_path(view, sel):
55-
'''Find the full import path for the selected obj in src'''
54+
def get_pkg_doc_url(view, sel):
55+
'''return pkg doc url for the selected obj in src'''
5656
region = sublime.Region(0, view.size())
5757
src = view.substr(region)
5858
imports = get_imports(src)
@@ -70,10 +70,12 @@ def get_pkg_doc_path(view, sel):
7070
fpkg = get_full_pkg(imports, pkg)
7171
#print 'pkg:', pkg, 'typ:', typ, 'fpkg:', fpkg
7272

73-
if typ:
74-
return fpkg + '/#' + typ
73+
#check if it's non-std package like "launchpad.net/mgo"
74+
if re.match('.*?\..*?/.*', fpkg):
75+
return 'http://gopkgdoc.appspot.com/pkg/' + fpkg + '#' + typ
7576
else:
76-
return fpkg
77+
return 'http://golang.org/pkg/' + fpkg + '/#' + typ
78+
7779

7880

7981

@@ -93,7 +95,7 @@ def run(self, edit):
9395
elif sel_txt in GO_BUILTINS:
9496
doc_url = 'http://golang.org/pkg/builtin/#' + sel_txt
9597
else:
96-
doc_url = 'http://golang.org/pkg/' + get_pkg_doc_path(self.view, sel)
98+
doc_url = get_pkg_doc_url(self.view, sel)
9799

98100
webbrowser.open_new_tab(doc_url)
99101

0 commit comments

Comments
 (0)