@@ -29,13 +29,13 @@ def get_imports(src):
29
29
''''build a list of imported packages from src, each tuple is (pkg_alias, pkg_path)
30
30
[('', 'compress/bzip2'), ('E', 'errors'), ('.', 'archive/tar'), ('_', 'database/sql/driver')]
31
31
'''
32
- single_import_pattern = ''' import \s+ (\w|\.){0,1} \s* "(.*?)" '''
32
+ single_import_pattern = ''' import \s+ (\w+ |\.){0,1} \s* "(.*?)" '''
33
33
single_imports = re .findall (single_import_pattern , src , re .M | re .X | re .S )
34
34
35
35
multi_import_pattern0 = '''import \s* \( (.*?) \)'''
36
36
multi_imports0 = re .findall (multi_import_pattern0 , src , re .M | re .X | re .S )
37
37
38
- multi_import_pattern = ''' (\w|\.){0,1} \s* "(.*?)" '''
38
+ multi_import_pattern = ''' (\w+ |\.){0,1} \s* "(.*?)" '''
39
39
multi_imports = re .findall (multi_import_pattern , '' .join (multi_imports0 ), re .M | re .X | re .S )
40
40
41
41
return single_imports + multi_imports
@@ -51,8 +51,8 @@ def get_full_pkg(imports, pkg):
51
51
return ''
52
52
53
53
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'''
56
56
region = sublime .Region (0 , view .size ())
57
57
src = view .substr (region )
58
58
imports = get_imports (src )
@@ -70,10 +70,12 @@ def get_pkg_doc_path(view, sel):
70
70
fpkg = get_full_pkg (imports , pkg )
71
71
#print 'pkg:', pkg, 'typ:', typ, 'fpkg:', fpkg
72
72
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
75
76
else :
76
- return fpkg
77
+ return 'http://golang.org/pkg/' + fpkg + '/#' + typ
78
+
77
79
78
80
79
81
@@ -93,7 +95,7 @@ def run(self, edit):
93
95
elif sel_txt in GO_BUILTINS :
94
96
doc_url = 'http://golang.org/pkg/builtin/#' + sel_txt
95
97
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 )
97
99
98
100
webbrowser .open_new_tab (doc_url )
99
101
0 commit comments