Skip to content

Commit fd0b979

Browse files
committed
Add specail support for gorazor
1 parent bf864dd commit fd0b979

2 files changed

Lines changed: 65 additions & 2 deletions

File tree

gscomplete.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,19 @@ def on_query_completions(self, view, prefix, locations):
125125
'fn': view.file_name() or '',
126126
}
127127
show_snippets = gs.setting('autocomplete_snippets', True) is True
128+
fn = view.file_name() or '<stdin>'
128129

129-
if not pkgname:
130+
if not fn.endswith(".gohtml") and not pkgname:
130131
return (resolve_snippets(ctx), AC_OPTS) if show_snippets else ([], AC_OPTS)
131132

132133
# gocode is case-sesitive so push the location back to the 'dot' so it gives
133134
# gives us everything then st2 can pick the matches for us
134135
offset = pos - len(prefix)
135136
src = view.substr(sublime.Region(0, view.size()))
136137

137-
fn = view.file_name() or '<stdin>'
138+
if fn.endswith(".gohtml"):
139+
src, offset = self.get_gohtml_src(default_pkgname, src, pos)
140+
138141
if not src:
139142
return ([], AC_OPTS)
140143

@@ -151,6 +154,61 @@ def on_query_completions(self, view, prefix, locations):
151154
cl.extend(resolve_snippets(ctx))
152155
return (cl, AC_OPTS)
153156

157+
def get_extra_gohtml_src(self, src, i, pos):
158+
extra_src = u""
159+
try:
160+
i = src.index("@{", i)
161+
except ValueError:
162+
return extra_src
163+
164+
counter = 0
165+
while i < pos:
166+
j = src.index("\n", i)
167+
if j >= pos:
168+
break
169+
170+
if not src[i] == "<":
171+
i += 1
172+
line = src[i:j+1].strip()
173+
if not line.startswith("<") and line != "{":
174+
extra_src += line + "\n"
175+
if line.endswith("{"):
176+
counter += 1
177+
if line.startswith("}"):
178+
counter -= 1
179+
180+
if line == "}" and counter == 0:
181+
try:
182+
i = src.index("@{", j)
183+
except ValueError:
184+
return extra_src
185+
else:
186+
i = j + 1
187+
188+
return extra_src
189+
190+
191+
def get_gohtml_src(self, default_pkgname, src, pos):
192+
if src == None or not src.startswith("@{"):
193+
return None, 0
194+
195+
i = src.rindex("\n", 0, pos)
196+
line = src[i:pos].strip()
197+
if line.startswith("@"):
198+
line = u"\n" + line[1:]
199+
else:
200+
line = u"\n" + line
201+
202+
i = src.index("}")
203+
extra_src = self.get_extra_gohtml_src(src, i, pos)
204+
go_source = "package " + default_pkgname + "\n" + src[2:i]
205+
i = go_source.index(")") + 1
206+
207+
go_source = go_source[0:i] + "\nfunc main(){\n raw := func(string)string{}\n" + go_source[i:] + extra_src + line + "\n}"
208+
offset = len(go_source) - 2
209+
210+
return go_source, offset
211+
154212
def find_end_pt(self, view, pat, start, end, flags=sublime.LITERAL):
155213
r = view.find(pat, start, flags)
156214
return r.end() if r and r.end() < end else -1

gslint.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ def watch():
136136

137137
view = gs.active_valid_go_view()
138138

139+
if view is not None and view.file_name():
140+
fn = view.file_name()
141+
if fn.endswith(".gohtml"):
142+
return
143+
139144
if view is not None and (view.file_name() and gs.setting('comp_lint_enabled') is True):
140145
fn = view.file_name()
141146
fr = ref(fn)

0 commit comments

Comments
 (0)