Skip to content

Commit 861f906

Browse files
committed
Better word-boundary detection..
in NamedCharacters and Symbols Also include grouping start symbols "(", "{", "[" in detection.
1 parent 4eaec08 commit 861f906

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

mathicsscript/completion.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
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\[\(\{]+)")
36+
CHARGROUP_START = frozenset(["(", "[", "{", ","])
3637

3738

3839
class TokenKind(Enum):
@@ -145,11 +146,13 @@ def get_word_before_cursor_with_kind(self, document: Document) -> WordToken:
145146

146147
word_before_cursor = text_before_cursor[len(text_before_cursor) + start :]
147148
text_before_word = text_before_cursor[: len(word_before_cursor)]
148-
if text_before_word.endswith(r"\["):
149+
if word_before_cursor.startswith(r"\["):
149150
return WordToken(word_before_cursor[2:], TokenKind.NamedCharacter)
150-
elif word_before_cursor.startswith(r"\["):
151-
return WordToken(word_before_cursor[2:], TokenKind.NamedCharacter)
152-
if word_before_cursor.startswith(r"["):
151+
elif text_before_word.endswith(r"\["):
152+
return WordToken(word_before_cursor, TokenKind.NamedCharacter)
153+
elif text_before_word[-1:] in CHARGROUP_START:
154+
word_before_cursor = word_before_cursor
155+
elif word_before_cursor[1:] in CHARGROUP_START:
153156
word_before_cursor = word_before_cursor[1:]
154157

155158
if word_before_cursor.isnumeric():

0 commit comments

Comments
 (0)