|
32 | 32 | FIND_MATHICS_WORD_RE = re.compile( |
33 | 33 | fr"({NAMED_CHARACTER_START})|(?:.*[\[\(])?({SYMBOLS}$)" |
34 | 34 | ) |
35 | | -FIND_MATHICS_WORD_RE = re.compile(r"((?:\[)?[^\s]+)") |
| 35 | +FIND_MATHICS_WORD_RE = re.compile(r"((?:\[)?[^\s\[\(\{]+)") |
| 36 | +CHARGROUP_START = frozenset(["(", "[", "{", ","]) |
36 | 37 |
|
37 | 38 |
|
38 | 39 | class TokenKind(Enum): |
@@ -145,11 +146,13 @@ def get_word_before_cursor_with_kind(self, document: Document) -> WordToken: |
145 | 146 |
|
146 | 147 | word_before_cursor = text_before_cursor[len(text_before_cursor) + start :] |
147 | 148 | text_before_word = text_before_cursor[: len(word_before_cursor)] |
148 | | - if text_before_word.endswith(r"\["): |
| 149 | + if word_before_cursor.startswith(r"\["): |
149 | 150 | 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: |
153 | 156 | word_before_cursor = word_before_cursor[1:] |
154 | 157 |
|
155 | 158 | if word_before_cursor.isnumeric(): |
|
0 commit comments