Skip to content

Commit 4d8e9ec

Browse files
committed
feat!: allow the linter to return fixes that affect other files
- This change builds the building block to the linter to return violations whose fixes affect other files. - This is in preparation for the change where nomissingexternalmodels can add a fix that will add the model to the external models
1 parent 9238534 commit 4d8e9ec

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
@@ -269,9 +269,13 @@ def get_code_actions(
269269
# Create code actions for each fix
270270
for fix in found_violation.fixes:
271271
# Convert our Fix to LSP TextEdits
272-
text_edits = []
272+
changes: t.Dict[str, t.List[types.TextEdit]] = {}
273273
for edit in fix.edits:
274-
text_edits.append(
274+
uri_key = URI.from_path(edit.path).value
275+
if uri_key not in changes:
276+
changes[uri_key] = []
277+
# Create a TextEdit for the LSP
278+
changes[uri_key].append(
275279
types.TextEdit(
276280
range=types.Range(
277281
start=types.Position(
@@ -292,7 +296,7 @@ def get_code_actions(
292296
title=fix.title,
293297
kind=types.CodeActionKind.QuickFix,
294298
diagnostics=[diagnostic],
295-
edit=types.WorkspaceEdit(changes={params.text_document.uri: text_edits}),
299+
edit=types.WorkspaceEdit(changes=changes),
296300
)
297301
code_actions.append(code_action)
298302

0 commit comments

Comments
 (0)