Skip to content

Commit d5ebbee

Browse files
committed
Add kind icons to LaTeX directive completions
1 parent 3b1d60e commit d5ebbee

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

latextools/latex_directive_completions.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,25 @@ class LatexDirectiveCompletion(sublime_plugin.EventListener):
211211
@async_completions
212212
def on_query_completions(self, view, prefix, locations):
213213
if len(locations) > 1:
214-
return
215-
point = locations[0]
216-
if not view.match_selector(point, "text.tex.latex comment.line.percentage"):
217-
return
214+
return []
215+
216+
pt = locations[0]
217+
if not view.match_selector(pt, "text.tex.latex comment.line.percentage"):
218+
return []
218219

219-
line_str = view.substr(sublime.Region(view.line(point).a, point))
220+
line_reg = view.line(pt)
221+
line_reg.b = pt
222+
line_str = view.substr(line_reg)
220223
if prefix:
221224
line_str = line_str[: -len(prefix)]
222225

223226
# circumvent completion if it cannot be possible
224227
if "!" not in line_str:
225-
return
228+
return []
226229

227-
comp = None
230+
completions = []
228231

229-
tex_directives = [
232+
directives = [
230233
"root",
231234
"spellcheck",
232235
"program",
@@ -235,12 +238,22 @@ def on_query_completions(self, view, prefix, locations):
235238
"jobname",
236239
"options",
237240
]
241+
242+
kind = [sublime.KindId.KEYWORD, "d", "Directive"]
243+
238244
if _EXCLAMATION_MARK_RE.match(line_str):
239-
row, _ = view.rowcol(point)
245+
row, _ = view.rowcol(pt)
240246
# do this completion only in the first 20 lines
241247
if row < 20:
242-
comp = [("TEX {0}\tTEX directive".format(s), "TEX " + s) for s in tex_directives]
248+
completions = [
249+
sublime.CompletionItem(trigger="TEX " + directive, kind=kind, details=" ")
250+
for directive in directives
251+
]
252+
243253
elif _TEX_PREFIX_RE.match(line_str):
244-
comp = [(s + "\tTEX directive", s) for s in tex_directives]
245-
# other completions are handled via fill all helper
246-
return comp
254+
completions = [
255+
sublime.CompletionItem(trigger=directive, kind=kind, details=" ")
256+
for directive in directives
257+
]
258+
259+
return completions

0 commit comments

Comments
 (0)