3232 FIND_MATHICS_WORD_RE = re .compile (
3333 fr"({ NAMED_CHARACTER_START } )|(?:.*[\[\(])?({ SYMBOLS } $)"
3434 )
35- FIND_MATHICS_WORD_RE = re .compile (r"((?:\[)?[^\s\[\(\{ ]+)" )
35+ FIND_MATHICS_WORD_RE = re .compile (r"((?:\[)?[^\s]+)" )
3636
3737
3838class TokenKind (Enum ):
@@ -56,7 +56,7 @@ class MathicsCompleter(WordCompleter):
5656 def __init__ (self , definitions ):
5757 self .definitions = definitions
5858 self .completer = WordCompleter ([])
59- self .named_characters = [ name + "]" for name in named_characters .keys ()]
59+ self .named_characters = sorted ( named_characters .keys ())
6060
6161 # From WordCompleter, adjusted with default values
6262 self .ignore_case = True
@@ -144,7 +144,10 @@ def get_word_before_cursor_with_kind(self, document: Document) -> WordToken:
144144 )
145145
146146 word_before_cursor = text_before_cursor [len (text_before_cursor ) + start :]
147- if word_before_cursor .startswith (r"\[" ):
147+ text_before_word = text_before_cursor [: len (word_before_cursor )]
148+ if text_before_word .endswith (r"\[" ):
149+ return WordToken (word_before_cursor [2 :], TokenKind .NamedCharacter )
150+ elif word_before_cursor .startswith (r"\[" ):
148151 return WordToken (word_before_cursor [2 :], TokenKind .NamedCharacter )
149152 if word_before_cursor .startswith (r"[" ):
150153 word_before_cursor = word_before_cursor [1 :]
0 commit comments