Skip to content

Commit 82d488b

Browse files
committed
Add kind icons to BibTex completions
1 parent 91996c0 commit 82d488b

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

latextools/biblatex_crossref_completions.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ def validator(s):
5151

5252
contents = view.substr(sublime.Region(0, view.size()))
5353
for entry_type, key in re.findall(
54-
r"(@(?!preamble|comment|string)[a-zA-Z]+)\s*\{\s*([^,]+)\b",
55-
contents,
56-
re.IGNORECASE,
54+
r"(@(?!preamble|comment|string)[a-zA-Z]+)\s*\{\s*([^,]+)\b", contents, re.IGNORECASE
5755
):
5856
if validator(entry_type):
5957
keys.append(key)
@@ -113,14 +111,22 @@ def _get_replacement(matcher, key):
113111

114112
def get_completions_if_matches(regex, line, get_key_list_func, view):
115113
matcher = regex.match(line)
116-
if matcher:
117-
return (
118-
[(key, _get_replacement(matcher, key)) for key in sorted(set(get_key_list_func(view)))],
119-
sublime.INHIBIT_WORD_COMPLETIONS,
120-
)
121-
else:
114+
if not matcher:
122115
return []
123116

117+
KIND_INFO = [sublime.KindId.NAVIGATION, "r", "Reference"]
118+
119+
completions = [
120+
sublime.CompletionItem(
121+
trigger=name,
122+
completion=_get_replacement(matcher, name),
123+
kind=KIND_INFO
124+
)
125+
for name in get_key_list_func(view)
126+
]
127+
128+
return sublime.CompletionList(completions, sublime.INHIBIT_WORD_COMPLETIONS)
129+
124130

125131
class BiblatexCrossrefCompletions(sublime_plugin.EventListener):
126132
def on_query_completions(self, view, prefix, locations):

latextools/biblatex_name_completions.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
VALUE_REGEX = r"[\s~]*(?P<ENTRIES>(?:dna[\s~]+.+)+)?[\s~]*(?P<OPEN>\{)?(?P<EQUALS>\s*=\s*)?"
2121

2222
ON_NAME_FIELD_REGEX = re.compile(
23-
VALUE_REGEX + r"(?:" + r"|".join((s[::-1] for s in NAME_FIELDS)) + r")\b",
24-
re.IGNORECASE,
23+
VALUE_REGEX + r"(?:" + r"|".join((s[::-1] for s in NAME_FIELDS)) + r")\b", re.IGNORECASE
2524
)
2625

2726

@@ -42,7 +41,7 @@ def _get_replacement(matcher, key):
4241

4342
return "{0}{1}{2}".format(
4443
"" if equals else "= " if match.startswith(" ") else " = ",
45-
("" if matcher.group("OPEN") else "{" if not equals or match.startswith(" ") else " {"),
44+
"" if matcher.group("OPEN") else "{" if not equals or match.startswith(" ") else " {",
4645
key,
4746
)
4847

@@ -107,7 +106,7 @@ def get_names(contents):
107106
break
108107
in_entry = False
109108

110-
return sorted(set(names))
109+
return set(names)
111110

112111

113112
class BiblatexNameCompletions(sublime_plugin.EventListener):
@@ -122,10 +121,19 @@ def on_query_completions(self, view, prefix, locations):
122121
current_line = current_line[len(prefix) :]
123122

124123
matcher = ON_NAME_FIELD_REGEX.match(current_line)
125-
if matcher:
126-
return (
127-
[(name, _get_replacement(matcher, name)) for name in get_names_from_view(view)],
128-
sublime.INHIBIT_WORD_COMPLETIONS,
124+
if not matcher:
125+
return []
126+
127+
KIND_INFO = [sublime.KindId.VARIABLE, "n", "Name"]
128+
129+
completions = [
130+
sublime.CompletionItem(
131+
trigger=name,
132+
completion=_get_replacement(matcher, name),
133+
kind=KIND_INFO,
134+
details=" ",
129135
)
136+
for name in get_names_from_view(view)
137+
]
130138

131-
return []
139+
return sublime.CompletionList(completions, sublime.INHIBIT_WORD_COMPLETIONS)

0 commit comments

Comments
 (0)