Skip to content

Feat(lsp): Add rename functionality for CTEs in vscode#4718

Merged
benfdking merged 4 commits intomainfrom
themis/renamelsp
Jun 23, 2025
Merged

Feat(lsp): Add rename functionality for CTEs in vscode#4718
benfdking merged 4 commits intomainfrom
themis/renamelsp

Conversation

@themisvaltinos
Copy link
Copy Markdown
Collaborator

@themisvaltinos themisvaltinos commented Jun 11, 2025

This update adds CTE renaming (F2) to the SQLMesh LSP server, letting users rename CTEs and their references with proper scope handling. Still to do:

@benfdking
Copy link
Copy Markdown
Contributor

benfdking commented Jun 12, 2025

WITH A AS (
  SELECT 1 AS B
)

SELECT A.B AS C FROM A WHERE A.B > 2

SELECT A.* FROM A WHERE A.B > 2

^ Do the two As in A.B get renamed.

@themisvaltinos
Copy link
Copy Markdown
Collaborator Author

^ Do the two As in A.B get renamed.

thanks after #4763 now yes they do as they're picked up as references. added tests for it and end to end for rename functionality in general

@benfdking benfdking requested a review from Copilot June 23, 2025 09:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds rename support for Common Table Expressions (CTEs) in the SQLMesh LSP server and VSCode extension, including UI interactions, preview, and document highlights.

  • Implements prepare_rename, rename_symbol, and get_document_highlights in sqlmesh/lsp/rename.py and wires up LSP handlers in sqlmesh/lsp/main.py.
  • Expands end-to-end Playwright tests in vscode/extension/tests/rename_cte.spec.ts to cover rename, cancel, and preview flows.
  • Adds Python LSP unit tests (tests/lsp/test_rename_cte.py and tests/lsp/test_document_highlight.py) to verify rename and highlight behavior.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sqlmesh/lsp/rename.py Implements core CTE rename and highlight logic
sqlmesh/lsp/main.py Registers LSP handlers for prepareRename, rename, and highlight
vscode/extension/tests/rename_cte.spec.ts Adds UI tests for rename, cancel, preview, and references
tests/lsp/test_rename_cte.py Unit tests for prepareRename and renameSymbol flows
tests/lsp/test_document_highlight.py Unit tests for document highlight on CTE symbols
Comments suppressed due to low confidence (2)

sqlmesh/lsp/rename.py:49

  • Hardcoding the placeholder to 'cte_name' may confuse users; consider using the actual CTE identifier (e.g., extract the text under the target_range) so the rename UI shows the current name.
            return PrepareRenameResult_Type1(range=target_range, placeholder="cte_name")

vscode/extension/tests/rename_cte.spec.ts:61

  • [nitpick] This test only verifies the definition rename; you may want to also assert that usage occurrences (e.g. in the FROM clause) were updated to 'new_marketing' for full coverage.
    await expect(window.locator('text=WITH new_marketing AS')).toBeVisible()

Comment thread sqlmesh/lsp/rename.py
Comment thread sqlmesh/lsp/main.py
Comment thread vscode/extension/tests/rename_cte.spec.ts Outdated
@benfdking benfdking merged commit 00d30f7 into main Jun 23, 2025
25 checks passed
@benfdking benfdking deleted the themis/renamelsp branch June 23, 2025 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants