Skip to content

Commit

Permalink
Add specail support for gorazor
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuvist committed Jul 5, 2014
1 parent bf864dd commit fd0b979
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
62 changes: 60 additions & 2 deletions gscomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,19 @@ def on_query_completions(self, view, prefix, locations):
'fn': view.file_name() or '',
}
show_snippets = gs.setting('autocomplete_snippets', True) is True
fn = view.file_name() or '<stdin>'

if not pkgname:
if not fn.endswith(".gohtml") and not pkgname:
return (resolve_snippets(ctx), AC_OPTS) if show_snippets else ([], AC_OPTS)

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

fn = view.file_name() or '<stdin>'
if fn.endswith(".gohtml"):
src, offset = self.get_gohtml_src(default_pkgname, src, pos)

if not src:
return ([], AC_OPTS)

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

def get_extra_gohtml_src(self, src, i, pos):
extra_src = u""
try:
i = src.index("@{", i)
except ValueError:
return extra_src

counter = 0
while i < pos:
j = src.index("\n", i)
if j >= pos:
break

if not src[i] == "<":
i += 1
line = src[i:j+1].strip()
if not line.startswith("<") and line != "{":
extra_src += line + "\n"
if line.endswith("{"):
counter += 1
if line.startswith("}"):
counter -= 1

if line == "}" and counter == 0:
try:
i = src.index("@{", j)
except ValueError:
return extra_src
else:
i = j + 1

return extra_src


def get_gohtml_src(self, default_pkgname, src, pos):
if src == None or not src.startswith("@{"):
return None, 0

i = src.rindex("\n", 0, pos)
line = src[i:pos].strip()
if line.startswith("@"):
line = u"\n" + line[1:]
else:
line = u"\n" + line

i = src.index("}")
extra_src = self.get_extra_gohtml_src(src, i, pos)
go_source = "package " + default_pkgname + "\n" + src[2:i]
i = go_source.index(")") + 1

go_source = go_source[0:i] + "\nfunc main(){\n raw := func(string)string{}\n" + go_source[i:] + extra_src + line + "\n}"
offset = len(go_source) - 2

return go_source, offset

def find_end_pt(self, view, pat, start, end, flags=sublime.LITERAL):
r = view.find(pat, start, flags)
return r.end() if r and r.end() < end else -1
Expand Down
5 changes: 5 additions & 0 deletions gslint.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ def watch():

view = gs.active_valid_go_view()

if view is not None and view.file_name():
fn = view.file_name()
if fn.endswith(".gohtml"):
return

if view is not None and (view.file_name() and gs.setting('comp_lint_enabled') is True):
fn = view.file_name()
fr = ref(fn)
Expand Down

0 comments on commit fd0b979

Please sign in to comment.