2020VALUE_REGEX = r"[\s~]*(?P<ENTRIES>(?:dna[\s~]+.+)+)?[\s~]*(?P<OPEN>\{)?(?P<EQUALS>\s*=\s*)?"
2121
2222ON_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
113112class 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