diff --git a/src/spinasm_lsp/parser.py b/src/spinasm_lsp/parser.py index 8b52874..8723f66 100644 --- a/src/spinasm_lsp/parser.py +++ b/src/spinasm_lsp/parser.py @@ -63,7 +63,7 @@ def __init__( ): if end is None: width = len(symbol["stxt"]) - end = lsp.Position(line=start.line, character=start.character + width - 1) + end = lsp.Position(line=start.line, character=start.character + width) self.symbol: Symbol = symbol self.range: lsp.Range = lsp.Range(start=start, end=end) diff --git a/tests/conftest.py b/tests/conftest.py index d9743a2..a867aaa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -45,7 +45,7 @@ class RenameDict(TypedDict): # Example assignments from the "Basic.spn" patch, for testing definition locations -ASSIGNMENTS: list[AssignmentDict] = [ +DEFINITIONS: list[AssignmentDict] = [ { # Variable "symbol": "apout", @@ -54,7 +54,7 @@ class RenameDict(TypedDict): uri=f"file:///{PATCH_DIR / 'Basic.spn'}", range=lsp.Range( start=lsp.Position(line=23, character=4), - end=lsp.Position(line=23, character=8), + end=lsp.Position(line=23, character=9), ), ), }, @@ -66,7 +66,7 @@ class RenameDict(TypedDict): uri=f"file:///{PATCH_DIR / 'Basic.spn'}", range=lsp.Range( start=lsp.Position(line=16, character=4), - end=lsp.Position(line=16, character=8), + end=lsp.Position(line=16, character=9), ), ), }, @@ -79,7 +79,7 @@ class RenameDict(TypedDict): uri=f"file:///{PATCH_DIR / 'Basic.spn'}", range=lsp.Range( start=lsp.Position(line=16, character=4), - end=lsp.Position(line=16, character=8), + end=lsp.Position(line=16, character=9), ), ), }, @@ -91,7 +91,7 @@ class RenameDict(TypedDict): uri=f"file:///{PATCH_DIR / 'Basic.spn'}", range=lsp.Range( start=lsp.Position(line=41, character=0), - end=lsp.Position(line=41, character=5), + end=lsp.Position(line=41, character=6), ), ), }, @@ -181,16 +181,16 @@ class RenameDict(TypedDict): "position": lsp.Position(line=8, character=4), "changes": [ lsp.TextEdit( - range=lsp.Range(start=lsp.Position(8, 4), end=lsp.Position(8, 6)), + range=lsp.Range(start=lsp.Position(8, 4), end=lsp.Position(8, 7)), new_text="FOO", ), # This symbol is `ap1#``, and should be matched when renaming `ap1` lsp.TextEdit( - range=lsp.Range(start=lsp.Position(51, 4), end=lsp.Position(51, 6)), + range=lsp.Range(start=lsp.Position(51, 4), end=lsp.Position(51, 7)), new_text="FOO", ), lsp.TextEdit( - range=lsp.Range(start=lsp.Position(52, 5), end=lsp.Position(52, 7)), + range=lsp.Range(start=lsp.Position(52, 5), end=lsp.Position(52, 8)), new_text="FOO", ), ], @@ -201,11 +201,11 @@ class RenameDict(TypedDict): "position": lsp.Position(line=41, character=0), "changes": [ lsp.TextEdit( - range=lsp.Range(start=lsp.Position(37, 8), end=lsp.Position(37, 13)), + range=lsp.Range(start=lsp.Position(37, 8), end=lsp.Position(37, 14)), new_text="END", ), lsp.TextEdit( - range=lsp.Range(start=lsp.Position(41, 0), end=lsp.Position(41, 5)), + range=lsp.Range(start=lsp.Position(41, 0), end=lsp.Position(41, 6)), new_text="END", ), ], @@ -217,15 +217,15 @@ class RenameDict(TypedDict): "changes": [ # Renaming `lap1a#` should also rename `lap1a` lsp.TextEdit( - range=lsp.Range(start=lsp.Position(12, 4), end=lsp.Position(12, 8)), + range=lsp.Range(start=lsp.Position(12, 4), end=lsp.Position(12, 9)), new_text="FOO", ), lsp.TextEdit( - range=lsp.Range(start=lsp.Position(61, 4), end=lsp.Position(61, 8)), + range=lsp.Range(start=lsp.Position(61, 4), end=lsp.Position(61, 9)), new_text="FOO", ), lsp.TextEdit( - range=lsp.Range(start=lsp.Position(62, 5), end=lsp.Position(62, 9)), + range=lsp.Range(start=lsp.Position(62, 5), end=lsp.Position(62, 10)), new_text="FOO", ), ], diff --git a/tests/test_parser.py b/tests/test_parser.py index 8d05d08..6f4394a 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -43,19 +43,21 @@ def test_get_token_from_registry(sentence_token_registry): """Test that tokens are correctly retrieved by position from a registry.""" sentence, reg = sentence_token_registry - # Manually build a mapping of column indexes to expected token words + # Manually build a mapping of column indexes to expected token words. Note that + # each word includes the whitespace immediately after it, which is consistent with + # other LSPs, and that all other whitespace is None. token_positions = {i: None for i in range(len(sentence))} - for i in range(0, 4): + for i in range(0, 5): token_positions[i] = "This" - for i in range(7, 9): + for i in range(7, 10): token_positions[i] = "is" - for i in range(10, 11): + for i in range(10, 12): token_positions[i] = "a" - for i in range(12, 16): + for i in range(12, 17): token_positions[i] = "line" - for i in range(20, 24): + for i in range(20, 25): token_positions[i] = "with" - for i in range(25, 31): + for i in range(25, 32): token_positions[i] = "words." for i, word in token_positions.items(): @@ -106,5 +108,5 @@ def test_concatenate_cho_rdal_tokens(): } assert cho_rdal.range == lsp.Range( - start=lsp.Position(line=0, character=0), end=lsp.Position(line=0, character=13) + start=lsp.Position(line=0, character=0), end=lsp.Position(line=0, character=14) ) diff --git a/tests/test_server.py b/tests/test_server.py index e799fde..6b55a5e 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -4,7 +4,7 @@ from pytest_lsp import ClientServerConfig, LanguageClient from .conftest import ( - ASSIGNMENTS, + DEFINITIONS, HOVERS, PATCH_DIR, PREPARE_RENAMES, @@ -32,7 +32,7 @@ async def client(request, lsp_client: LanguageClient): @pytest.mark.asyncio() -@pytest.mark.parametrize("assignment", ASSIGNMENTS, ids=lambda x: x["symbol"]) +@pytest.mark.parametrize("assignment", DEFINITIONS, ids=lambda x: x["symbol"]) async def test_definition(assignment: dict, client: LanguageClient): """Test that the definition location of different assignments is correct.""" uri = assignment["defined"].uri