Skip to content

Commit 5ccd57e

Browse files
authored
feat!: allow the linter to return fixes that affect other files (#5057)
1 parent e32fa9e commit 5ccd57e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

sqlmesh/core/linter/rule.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import abc
44
from dataclasses import dataclass
5+
from pathlib import Path
56

67
from sqlmesh.core.model import Model
78

@@ -43,6 +44,7 @@ class Range:
4344
class TextEdit:
4445
"""A text edit to apply to a file."""
4546

47+
path: Path
4648
range: Range
4749
new_text: str
4850

sqlmesh/core/linter/rules/builtin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ def _create_fixes(
5353
columns = model.columns_to_types
5454
if not columns:
5555
return None
56+
path = model._path
57+
if path is None:
58+
return None
5659
new_text = ", ".join(columns.keys())
5760
return [
5861
Fix(
5962
title="Replace SELECT * with explicit column list",
6063
edits=[
6164
TextEdit(
65+
path=path,
6266
range=violation_range,
6367
new_text=new_text,
6468
)

sqlmesh/lsp/context.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,13 @@ def get_code_actions(
274274
# Create code actions for each fix
275275
for fix in found_violation.fixes:
276276
# Convert our Fix to LSP TextEdits
277-
text_edits = []
277+
changes: t.Dict[str, t.List[types.TextEdit]] = {}
278278
for edit in fix.edits:
279-
text_edits.append(
279+
uri_key = URI.from_path(edit.path).value
280+
if uri_key not in changes:
281+
changes[uri_key] = []
282+
# Create a TextEdit for the LSP
283+
changes[uri_key].append(
280284
types.TextEdit(
281285
range=types.Range(
282286
start=types.Position(
@@ -297,7 +301,7 @@ def get_code_actions(
297301
title=fix.title,
298302
kind=types.CodeActionKind.QuickFix,
299303
diagnostics=[diagnostic],
300-
edit=types.WorkspaceEdit(changes={params.text_document.uri: text_edits}),
304+
edit=types.WorkspaceEdit(changes=changes),
301305
)
302306
code_actions.append(code_action)
303307

0 commit comments

Comments
 (0)