Skip to content

Commit c167676

Browse files
benfdkingclaude
andcommitted
fix(vscode): use context manager for file opening in tests
Used 'with' statement to properly close file handle after reading. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 268d423 commit c167676

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

sqlmesh/lsp/main.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
from sqlmesh.lsp.completions import get_sql_completions
1515
from sqlmesh.lsp.context import LSPContext, ModelTarget
1616
from sqlmesh.lsp.custom import ALL_MODELS_FEATURE, AllModelsRequest, AllModelsResponse
17-
from sqlmesh.lsp.reference import get_model_definitions_for_a_path, filter_references_by_position
17+
from sqlmesh.lsp.reference import (
18+
get_model_definitions_for_a_path,
19+
filter_references_by_position,
20+
)
1821

1922

2023
class SQLMeshLanguageServer:
@@ -186,18 +189,10 @@ def goto_definition(
186189
if self.lsp_context is None:
187190
raise RuntimeError(f"No context found for document: {document.path}")
188191

189-
# Get all possible references
190192
references = get_model_definitions_for_a_path(
191193
self.lsp_context, params.text_document.uri
192194
)
193-
if not references:
194-
return []
195-
196-
# Filter references by cursor position
197195
filtered_references = filter_references_by_position(references, params.position)
198-
if not filtered_references:
199-
return []
200-
201196
return [
202197
types.LocationLink(
203198
target_uri=reference.uri,

tests/lsp/test_reference.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def test_filter_references_by_position() -> None:
130130

131131
# Get file contents to locate positions for testing
132132
path = waiter_revenue_by_day_uri.removeprefix("file://")
133-
read_file = open(path, "r").readlines()
133+
with open(path, "r") as file:
134+
read_file = file.readlines()
134135

135136
# Test positions for each reference
136137
for i, reference in enumerate(all_references):

0 commit comments

Comments
 (0)