Skip to content

Commit 0494ac2

Browse files
committed
Add minimalistic sublime text 3 plugin.
1 parent 659c0a4 commit 0494ac2

9 files changed

+928
-0
lines changed

subl3/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Sublime Text 3 plugin
2+
3+
If you want full Go experience in sublime, use [GoSublime](https://github.com/DisposaBoy/GoSublime).
4+
5+
This plugin is written by me (nsf) as a result of frustration with GoSublime. I wanted something simpler and plugin has to use system version of the gocode. As you may know, GoSublime uses a fork of gocode, which is integrated into its own daemon called MarGo (as far as I know).
6+
7+
I don't have any big plans on this plugin. The reason why I moved to sublime in the first place is, again, frustration, but with Atom (too slow). We'll see how it goes. I think I might add gofmt on save also and perhaps it's worth adding proper support for snippets, because there is no nice way to show function arguments in sublime.
8+
9+
Oh yes, this plugin uses GoSublime syntax files for Go. Well, they use a fork of gocode, I'll use the fork of their syntax files, fair deal.

subl3/gocode.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sublime, sublime_plugin, subprocess
2+
3+
class Gocode(sublime_plugin.EventListener):
4+
def on_query_completions(self, view, prefix, locations):
5+
loc = locations[0]
6+
if not view.match_selector(loc, "source.go"):
7+
return None
8+
9+
src = view.substr(sublime.Region(0, view.size()))
10+
filename = view.file_name()
11+
cloc = "c{0}".format(loc)
12+
gocode = subprocess.Popen(["gocode", "-f=csv", "autocomplete", filename, cloc],
13+
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
14+
out = gocode.communicate(src.encode())[0].decode()
15+
16+
result = []
17+
for line in filter(bool, out.split("\n")):
18+
arg = line.split(",,")
19+
result.append([arg[1] + "\t" + arg[0], arg[1]])
20+
21+
return (result, sublime.INHIBIT_WORD_COMPLETIONS)

subl3/syntax/GoSublime-Go.tmLanguage

Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>comment</key>
6+
<string>Based on work from github.com/frou/GoFeather and github.com/DisposaBoy/GoSublime</string>
7+
<key>fileTypes</key>
8+
<array>
9+
<string>go</string>
10+
</array>
11+
<key>firstLineMatch</key>
12+
<string>-[*]-( Mode:)? Go -[*]-</string>
13+
<key>keyEquivalent</key>
14+
<string>^~G</string>
15+
<key>name</key>
16+
<string>GoSublime: Go</string>
17+
<key>patterns</key>
18+
<array>
19+
<dict>
20+
<key>begin</key>
21+
<string>/\*</string>
22+
<key>end</key>
23+
<string>\*/</string>
24+
<key>name</key>
25+
<string>comment.block.go</string>
26+
</dict>
27+
<dict>
28+
<key>begin</key>
29+
<string>//</string>
30+
<key>end</key>
31+
<string>\z</string>
32+
<key>name</key>
33+
<string>comment.line.double-slash.go</string>
34+
</dict>
35+
<dict>
36+
<key>begin</key>
37+
<string>"</string>
38+
<key>beginCaptures</key>
39+
<dict>
40+
<key>0</key>
41+
<dict>
42+
<key>name</key>
43+
<string>punctuation.definition.string.begin.go</string>
44+
</dict>
45+
</dict>
46+
<key>end</key>
47+
<string>"</string>
48+
<key>endCaptures</key>
49+
<dict>
50+
<key>0</key>
51+
<dict>
52+
<key>name</key>
53+
<string>punctuation.definition.string.end.go</string>
54+
</dict>
55+
</dict>
56+
<key>name</key>
57+
<string>string.quoted.double.go</string>
58+
<key>patterns</key>
59+
<array>
60+
<dict>
61+
<key>include</key>
62+
<string>#string_placeholder</string>
63+
</dict>
64+
<dict>
65+
<key>include</key>
66+
<string>#string_escaped_char</string>
67+
</dict>
68+
</array>
69+
</dict>
70+
<dict>
71+
<key>begin</key>
72+
<string>`</string>
73+
<key>beginCaptures</key>
74+
<dict>
75+
<key>0</key>
76+
<dict>
77+
<key>name</key>
78+
<string>punctuation.definition.string.begin.go</string>
79+
</dict>
80+
</dict>
81+
<key>end</key>
82+
<string>`</string>
83+
<key>endCaptures</key>
84+
<dict>
85+
<key>0</key>
86+
<dict>
87+
<key>name</key>
88+
<string>punctuation.definition.string.end.go</string>
89+
</dict>
90+
</dict>
91+
<key>name</key>
92+
<string>string.quoted.raw.go</string>
93+
<key>patterns</key>
94+
<array>
95+
<dict>
96+
<key>include</key>
97+
<string>#string_placeholder</string>
98+
</dict>
99+
<dict>
100+
<key>include</key>
101+
<string>source.gotemplate</string>
102+
</dict>
103+
</array>
104+
</dict>
105+
<dict>
106+
<key>match</key>
107+
<string>\b(true|false|nil|iota)\b</string>
108+
<key>name</key>
109+
<string>constant.language.go</string>
110+
</dict>
111+
<dict>
112+
<key>match</key>
113+
<string>\b((\d+\.(\d+)?([eE][+-]?\d+)?|\d+[eE][+-]?\d+|\.\d+([eE][+-]?\d+)?)i?)\b</string>
114+
<key>name</key>
115+
<string>constant.numeric.floating-point.go</string>
116+
</dict>
117+
<dict>
118+
<key>match</key>
119+
<string>\b(\d+i|0[xX][0-9A-Fa-f]+|0[0-7]*|[1-9][0-9]*)\b</string>
120+
<key>name</key>
121+
<string>constant.numeric.integer.go</string>
122+
</dict>
123+
<dict>
124+
<key>match</key>
125+
<string>'(?:[^'\\]|\\(?:\\|[abfnrtv']|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3}))'</string>
126+
<key>name</key>
127+
<string>constant.other.rune.go</string>
128+
</dict>
129+
<dict>
130+
<key>match</key>
131+
<string>\b(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64)?|uintptr)\b</string>
132+
<key>name</key>
133+
<string>storage.type.go</string>
134+
</dict>
135+
<dict>
136+
<key>comment</key>
137+
<string>A subset of keyword.other.go for flow control keywords.</string>
138+
<key>match</key>
139+
<string>\b(break|case|continue|default|defer|else|for|go|goto|if|range|return|select|switch)\b</string>
140+
<key>name</key>
141+
<string>keyword.control.go</string>
142+
</dict>
143+
<dict>
144+
<key>match</key>
145+
<string>\b(break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go|goto|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b</string>
146+
<key>name</key>
147+
<string>keyword.other.go</string>
148+
</dict>
149+
<dict>
150+
<key>captures</key>
151+
<dict>
152+
<key>0</key>
153+
<dict>
154+
<key>name</key>
155+
<string>variable.other.go</string>
156+
</dict>
157+
<key>1</key>
158+
<dict>
159+
<key>name</key>
160+
<string>keyword.operator.initialize.go</string>
161+
</dict>
162+
</dict>
163+
<key>comment</key>
164+
<string>This matches the 'x := 0' style of variable declaration.</string>
165+
<key>match</key>
166+
<string>(?:[[:alpha:]_][[:alnum:]_]*)(?:,\s+[[:alpha:]_][[:alnum:]_]*)*\s*(:=)</string>
167+
<key>name</key>
168+
<string>meta.initialization.short.go</string>
169+
</dict>
170+
<dict>
171+
<key>match</key>
172+
<string>(?&lt;=(\Afunc|...\))\s)\b(\w+)\b(?=\()</string>
173+
<key>name</key>
174+
<string>entity.name.function.go</string>
175+
</dict>
176+
<dict>
177+
<key>match</key>
178+
<string>(?&lt;=(\sfunc|....\))\s)\b(\w+)\b(?=\()</string>
179+
<key>name</key>
180+
<string>entity.name.function.go</string>
181+
</dict>
182+
<dict>
183+
<key>match</key>
184+
<string>(?&lt;=\Atype\s)\b(\w+)\b</string>
185+
<key>name</key>
186+
<string>entity.name.type.go</string>
187+
</dict>
188+
<dict>
189+
<key>match</key>
190+
<string>(?&lt;=\stype\s)\b(\w+)\b</string>
191+
<key>name</key>
192+
<string>entity.name.type.go</string>
193+
</dict>
194+
<dict>
195+
<key>match</key>
196+
<string>\b(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)\b</string>
197+
<key>name</key>
198+
<string>support.function.builtin.go</string>
199+
</dict>
200+
<dict>
201+
<key>match</key>
202+
<string>\b(\w+)\b(?=\()</string>
203+
<key>name</key>
204+
<string>support.function.go</string>
205+
</dict>
206+
<dict>
207+
<key>match</key>
208+
<string>(&lt;-)</string>
209+
<key>name</key>
210+
<string>keyword.operator.channel.go</string>
211+
</dict>
212+
<dict>
213+
<key>match</key>
214+
<string>(==|!=|&lt;|&lt;=|&gt;|&gt;=)</string>
215+
<key>name</key>
216+
<string>keyword.operator.comparison.go</string>
217+
</dict>
218+
<dict>
219+
<key>match</key>
220+
<string>(&amp;&amp;|[|]{2}|!)</string>
221+
<key>name</key>
222+
<string>keyword.operator.logical.go</string>
223+
</dict>
224+
<dict>
225+
<key>match</key>
226+
<string>([+]{2})</string>
227+
<key>name</key>
228+
<string>keyword.operator.increment.go</string>
229+
</dict>
230+
<dict>
231+
<key>match</key>
232+
<string>(--)</string>
233+
<key>name</key>
234+
<string>keyword.decrement.go</string>
235+
</dict>
236+
<dict>
237+
<key>match</key>
238+
<string>(=|(?:[+]|-|[|]|^|[*]|/|%|&lt;&lt;|&gt;&gt;|&amp;|&amp;^)=)</string>
239+
<key>name</key>
240+
<string>keyword.operator.assignment.go</string>
241+
</dict>
242+
<dict>
243+
<key>match</key>
244+
<string>([+]|-|[*]|/|%|&amp;|[|]|^|&amp;^|&lt;&lt;|&gt;&gt;)</string>
245+
<key>name</key>
246+
<string>keyword.operator.arithmetic.go</string>
247+
</dict>
248+
<dict>
249+
<key>match</key>
250+
<string>(;)</string>
251+
<key>name</key>
252+
<string>keyword.operator.semi-colon.go</string>
253+
</dict>
254+
<dict>
255+
<key>match</key>
256+
<string>(,)</string>
257+
<key>name</key>
258+
<string>punctuation.definition.comma.go</string>
259+
</dict>
260+
<dict>
261+
<key>match</key>
262+
<string>([.])</string>
263+
<key>name</key>
264+
<string>punctuation.definition.dot.go</string>
265+
</dict>
266+
<dict>
267+
<key>match</key>
268+
<string>(:)</string>
269+
<key>name</key>
270+
<string>punctuation.definition.colon.go</string>
271+
</dict>
272+
<dict>
273+
<key>match</key>
274+
<string>(\[|\]|{|}|\(|\))</string>
275+
<key>name</key>
276+
<string>punctuation.definition.bracket.go</string>
277+
</dict>
278+
</array>
279+
<key>repository</key>
280+
<dict>
281+
<key>string_escaped_char</key>
282+
<dict>
283+
<key>patterns</key>
284+
<array>
285+
<dict>
286+
<key>match</key>
287+
<string>\\(\\|[abfnrtv'"]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3})</string>
288+
<key>name</key>
289+
<string>constant.character.escape.go</string>
290+
</dict>
291+
<dict>
292+
<key>match</key>
293+
<string>\\.</string>
294+
<key>name</key>
295+
<string>invalid.illegal.unknown-escape.go</string>
296+
</dict>
297+
</array>
298+
</dict>
299+
<key>string_placeholder</key>
300+
<dict>
301+
<key>patterns</key>
302+
<array>
303+
<dict>
304+
<key>match</key>
305+
<string>(?x)%
306+
(\d+\$)? # field (argument #)
307+
[#0\- +']* # flags
308+
[,;:_]? # separator character (AltiVec)
309+
((-?\d+)|\*(-?\d+\$)?)? # minimum field width
310+
(\.((-?\d+)|\*(-?\d+\$)?)?)? # precision
311+
[diouxXDOUeEfFgGaAcCsSqpnvtTbyYhHmMzZ%] # conversion type
312+
</string>
313+
<key>name</key>
314+
<string>constant.other.placeholder.go</string>
315+
</dict>
316+
</array>
317+
</dict>
318+
</dict>
319+
<key>scopeName</key>
320+
<string>source.go</string>
321+
<key>uuid</key>
322+
<string>1caaa75c-b61d-11e2-ba93-138feb5db969</string>
323+
</dict>
324+
</plist>

0 commit comments

Comments
 (0)