diff --git a/salve/server_functions/highlight/misc.py b/salve/server_functions/highlight/misc.py index 1e455ab..af8a74f 100644 --- a/salve/server_functions/highlight/misc.py +++ b/salve/server_functions/highlight/misc.py @@ -37,6 +37,7 @@ def normal_text_range( def get_new_token_type(token: str) -> str | None: """Turns pygments token types into a generic predefined Token""" for old_token, new_token in default_tokens.items(): - if old_token.startswith(token): + if token.startswith(old_token): return new_token + return None diff --git a/salve/server_functions/links_and_hidden_chars.py b/salve/server_functions/links_and_hidden_chars.py index e1f609a..055652d 100644 --- a/salve/server_functions/links_and_hidden_chars.py +++ b/salve/server_functions/links_and_hidden_chars.py @@ -12,6 +12,7 @@ def get_urls(whole_text: str, text_range: tuple[int, int]) -> list[Token]: while True: if start_pos[0] > text_range[1]: break + line: str = lines[start_pos[0] - text_range[0]][start_pos[1] :] match_start: Match[str] | None = url_regex.search(line) if match_start is None: diff --git a/tests/test_ipc.py b/tests/test_ipc.py index 6902a98..3ce939b 100644 --- a/tests/test_ipc.py +++ b/tests/test_ipc.py @@ -88,23 +88,36 @@ def test_IPC(): "cancelled": False, "command": "highlight", "result": [ + ((1, 0), 4, "Keyword"), + ((1, 5), 4, "Identifier"), + ((1, 10), 6, "Keyword"), ((1, 17), 1, "Identifier"), + ((1, 20), 12, "Comment"), ((3, 0), 3, "Identifier"), ((3, 3), 1, "Punctuation"), + ((3, 5), 4, "Identifier"), ((3, 10), 1, "Operator"), + ((3, 12), 3, "Identifier"), ((4, 0), 1, "Punctuation"), ((4, 1), 3, "Identifier"), ((4, 5), 2, "Operator"), ((4, 8), 4, "Identifier"), ((4, 12), 1, "Punctuation"), + ((4, 15), 12, "Comment"), + ((6, 0), 5, "Identifier"), ((6, 5), 2, "Punctuation"), ((9, 0), 5, "Keyword"), + ((9, 6), 3, "Identifier"), ((9, 9), 1, "Punctuation"), ((9, 10), 3, "Identifier"), ((9, 13), 2, "Punctuation"), - ((11, 4), 4, "Identifier"), + ((10, 4), 3, "String"), + ((11, 4), 4, "String"), + ((12, 4), 3, "String"), ((14, 4), 3, "Keyword"), + ((14, 8), 8, "Identifier"), ((14, 16), 1, "Punctuation"), + ((14, 17), 4, "Identifier"), ((14, 21), 2, "Punctuation"), ((15, 8), 4, "Keyword"), ((18, 0), 3, "Identifier"), diff --git a/tests/testing_file1.py b/tests/testing_file1.py index d333f69..86a9c2b 100644 --- a/tests/testing_file1.py +++ b/tests/testing_file1.py @@ -1,7 +1,7 @@ from this import s # noqa: F401 Bar: type = int -(xyz := test) +(xyz := test) # noqa: F821 print()