Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix token range end error #4

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/spinasm_lsp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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),
),
),
},
Expand All @@ -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),
),
),
},
Expand All @@ -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),
),
),
},
Expand All @@ -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),
),
),
},
Expand Down Expand Up @@ -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",
),
],
Expand All @@ -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",
),
],
Expand All @@ -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",
),
],
Expand Down
18 changes: 10 additions & 8 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)
)
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pytest_lsp import ClientServerConfig, LanguageClient

from .conftest import (
ASSIGNMENTS,
DEFINITIONS,
HOVERS,
PATCH_DIR,
PREPARE_RENAMES,
Expand Down Expand Up @@ -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
Expand Down
Loading