Skip to content
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: 2 additions & 0 deletions sqlmesh/core/linter/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import abc
from dataclasses import dataclass
from pathlib import Path

from sqlmesh.core.model import Model

Expand Down Expand Up @@ -43,6 +44,7 @@ class Range:
class TextEdit:
"""A text edit to apply to a file."""

path: Path
range: Range
new_text: str

Expand Down
4 changes: 4 additions & 0 deletions sqlmesh/core/linter/rules/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ def _create_fixes(
columns = model.columns_to_types
if not columns:
return None
path = model._path
if path is None:
return None
new_text = ", ".join(columns.keys())
return [
Fix(
title="Replace SELECT * with explicit column list",
edits=[
TextEdit(
path=path,
range=violation_range,
new_text=new_text,
)
Expand Down
10 changes: 7 additions & 3 deletions sqlmesh/lsp/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,13 @@ def get_code_actions(
# Create code actions for each fix
for fix in found_violation.fixes:
# Convert our Fix to LSP TextEdits
text_edits = []
changes: t.Dict[str, t.List[types.TextEdit]] = {}
for edit in fix.edits:
text_edits.append(
uri_key = URI.from_path(edit.path).value
if uri_key not in changes:
changes[uri_key] = []
# Create a TextEdit for the LSP
changes[uri_key].append(
types.TextEdit(
range=types.Range(
start=types.Position(
Expand All @@ -292,7 +296,7 @@ def get_code_actions(
title=fix.title,
kind=types.CodeActionKind.QuickFix,
diagnostics=[diagnostic],
edit=types.WorkspaceEdit(changes={params.text_document.uri: text_edits}),
edit=types.WorkspaceEdit(changes=changes),
)
code_actions.append(code_action)

Expand Down
Loading