Skip to content

Commit db208ff

Browse files
fix: use local pywire in CI
1 parent 75c187f commit db208ff

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

noxfile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import os
12
import nox
23

34
nox.options.sessions = ["tests"]
45

56
@nox.session(python=["3.11", "3.12", "3.13", "3.14"], venv_backend="uv")
67
def tests(session):
8+
# Install the local pywire package first so we don't fetch an old version from PyPI
9+
if os.path.exists("../pywire"):
10+
session.install("-e", "../pywire")
711
session.install(".[dev]")
812
session.run("pytest", *session.posargs)

src/pywire_language_server/transpiler.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def transpile(self) -> Tuple[str, SourceMap]:
7171
if parsed.directives:
7272
for d in parsed.directives:
7373
if isinstance(d, PathDirective):
74-
start_line = d.line - 1
74+
start_line = max(0, d.line - 1)
7575
end_line = start_line
7676
if not d.is_simple_string:
7777
for i in range(start_line, len(self.lines)):
@@ -88,7 +88,10 @@ def transpile(self) -> Tuple[str, SourceMap]:
8888
self.generated_code.append(f"__path = {routes_repr}\n")
8989
self.generated_line_idx += 1
9090
elif isinstance(d, LayoutDirective):
91-
self.directive_ranges["layout"] = (d.line - 1, d.line - 1)
91+
self.directive_ranges["layout"] = (
92+
max(0, d.line - 1),
93+
max(0, d.line - 1),
94+
)
9295
else:
9396
# Fallback for directives if parser missed them
9497
self._scan_directives_legacy()
@@ -182,7 +185,7 @@ def _traverse_node(self, node: TemplateNode):
182185
# skip control blocks like {$if ...}
183186
continue
184187

185-
line = node.line - 1
188+
line = max(0, node.line - 1)
186189
col = node.column
187190
prefix = "_ = "
188191
self.generated_code.append(prefix)
@@ -194,7 +197,7 @@ def _traverse_node(self, node: TemplateNode):
194197
self.generated_line_idx += 1
195198

196199
def _emit_interpolation_from_node(self, node: InterpolationNode):
197-
line = node.line - 1
200+
line = max(0, node.line - 1)
198201
col = node.column
199202
expr = node.expression
200203
prefix = "_ = "
@@ -281,7 +284,7 @@ def _find_attr_location(
281284
return start_line, start_col, start_col + 1
282285

283286
def _emit_control_flow(self, attr):
284-
line = attr.line - 1
287+
line = max(0, attr.line - 1)
285288
col = attr.column
286289
prefix = ""
287290
expr = ""
@@ -340,7 +343,7 @@ def _emit_control_flow(self, attr):
340343
self.generated_line_idx += 1
341344

342345
def _emit_event_handler(self, attr: EventAttribute):
343-
line = attr.line - 1
346+
line = max(0, attr.line - 1)
344347
col = attr.column
345348
# ... event_cls logic ...
346349
event_cls = "EventData"
@@ -387,7 +390,7 @@ def _emit_event_handler(self, attr: EventAttribute):
387390
self.generated_line_idx += 1
388391

389392
def _emit_reactive_attr(self, attr: ReactiveAttribute):
390-
line = attr.line - 1
393+
line = max(0, attr.line - 1)
391394
col = attr.column
392395
prefix = "_ = "
393396
self.generated_code.append(prefix)
@@ -404,7 +407,7 @@ def _emit_reactive_attr(self, attr: ReactiveAttribute):
404407
self.generated_line_idx += 1
405408

406409
def _emit_spread_attr(self, attr: SpreadAttribute):
407-
line = attr.line - 1
410+
line = max(0, attr.line - 1)
408411
col = attr.column
409412
prefix = "_ = **"
410413
self.generated_code.append(prefix)

tests/test_ty_integration.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,15 @@ async def test_definition_reference_fallback(mock_ls, mock_ty_client):
315315
text_document=TextDocumentIdentifier(uri=uri),
316316
position=pos
317317
)
318+
319+
# Force mock return value for this test
320+
server_module.virtual_manager.get_shadow_uri.return_value = "file:///shadow.py"
321+
318322
result = await server_module.definition(mock_ls, def_params)
319323

320324
# Verify send_request was called (meaning fallback found a mapped position)
321325
call_args = mock_ty_client.send_request.call_args
322-
assert call_args is not None
326+
assert call_args is not None, f"Ty send_request was not called. doc.source_map.mappings: {[(m.original_line, m.original_col, m.length) for m in doc.source_map.mappings]}"
323327
method, _ = call_args[0]
324328
assert method == "textDocument/definition"
325329
assert result is not None

0 commit comments

Comments
 (0)