Skip to content

Commit 4eaec08

Browse files
committed
Handle completion of named characters better
1 parent 9dbbcbd commit 4eaec08

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

mathicsscript/completion.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
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

3838
class 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:]

mathicsscript/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# This file is suitable for sourcing inside POSIX shell as
44
# well as importing into Python. That's why there is no
55
# space around "=" below.
6-
__version__="3.1.0" # noqa
6+
__version__="3.1.1.dev0" # noqa

0 commit comments

Comments
 (0)