sqlmesh 0.194.2.dev11__py3-none-any.whl → 0.195.1.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sqlmesh/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.194.2.dev11'
21
- __version_tuple__ = version_tuple = (0, 194, 2, 'dev11')
20
+ __version__ = version = '0.195.1.dev1'
21
+ __version_tuple__ = version_tuple = (0, 195, 1, 'dev1')
sqlmesh/lsp/main.py CHANGED
@@ -52,6 +52,7 @@ from sqlmesh.lsp.reference import (
52
52
  get_references,
53
53
  get_all_references,
54
54
  )
55
+ from sqlmesh.lsp.rename import prepare_rename, rename_symbol, get_document_highlights
55
56
  from sqlmesh.lsp.uri import URI
56
57
  from web.server.api.endpoints.lineage import column_lineage, model_lineage
57
58
  from web.server.api.endpoints.models import get_models
@@ -435,6 +436,59 @@ class SQLMeshLanguageServer:
435
436
  ls.show_message(f"Error getting locations: {e}", types.MessageType.Error)
436
437
  return None
437
438
 
439
+ @self.server.feature(types.TEXT_DOCUMENT_PREPARE_RENAME)
440
+ def prepare_rename_handler(
441
+ ls: LanguageServer, params: types.PrepareRenameParams
442
+ ) -> t.Optional[types.PrepareRenameResult]:
443
+ """Prepare for rename operation by checking if the symbol can be renamed."""
444
+ try:
445
+ uri = URI(params.text_document.uri)
446
+ self._ensure_context_for_document(uri)
447
+ if self.lsp_context is None:
448
+ raise RuntimeError(f"No context found for document: {uri}")
449
+
450
+ result = prepare_rename(self.lsp_context, uri, params.position)
451
+ return result
452
+ except Exception as e:
453
+ ls.log_trace(f"Error preparing rename: {e}")
454
+ return None
455
+
456
+ @self.server.feature(types.TEXT_DOCUMENT_RENAME)
457
+ def rename_handler(
458
+ ls: LanguageServer, params: types.RenameParams
459
+ ) -> t.Optional[types.WorkspaceEdit]:
460
+ """Perform rename operation on the symbol at the given position."""
461
+ try:
462
+ uri = URI(params.text_document.uri)
463
+ self._ensure_context_for_document(uri)
464
+ if self.lsp_context is None:
465
+ raise RuntimeError(f"No context found for document: {uri}")
466
+
467
+ workspace_edit = rename_symbol(
468
+ self.lsp_context, uri, params.position, params.new_name
469
+ )
470
+ return workspace_edit
471
+ except Exception as e:
472
+ ls.show_message(f"Error performing rename: {e}", types.MessageType.Error)
473
+ return None
474
+
475
+ @self.server.feature(types.TEXT_DOCUMENT_DOCUMENT_HIGHLIGHT)
476
+ def document_highlight_handler(
477
+ ls: LanguageServer, params: types.DocumentHighlightParams
478
+ ) -> t.Optional[t.List[types.DocumentHighlight]]:
479
+ """Highlight all occurrences of the symbol at the given position."""
480
+ try:
481
+ uri = URI(params.text_document.uri)
482
+ self._ensure_context_for_document(uri)
483
+ if self.lsp_context is None:
484
+ raise RuntimeError(f"No context found for document: {uri}")
485
+
486
+ highlights = get_document_highlights(self.lsp_context, uri, params.position)
487
+ return highlights
488
+ except Exception as e:
489
+ ls.log_trace(f"Error getting document highlights: {e}")
490
+ return None
491
+
438
492
  @self.server.feature(types.TEXT_DOCUMENT_DIAGNOSTIC)
439
493
  def diagnostic(
440
494
  ls: LanguageServer, params: types.DocumentDiagnosticParams
sqlmesh/lsp/rename.py ADDED
@@ -0,0 +1,137 @@
1
+ import typing as t
2
+ from lsprotocol.types import (
3
+ Position,
4
+ TextEdit,
5
+ WorkspaceEdit,
6
+ PrepareRenameResult_Type1,
7
+ DocumentHighlight,
8
+ DocumentHighlightKind,
9
+ )
10
+
11
+ from sqlmesh.lsp.context import LSPContext
12
+ from sqlmesh.lsp.reference import (
13
+ _position_within_range,
14
+ get_cte_references,
15
+ LSPCteReference,
16
+ )
17
+ from sqlmesh.lsp.uri import URI
18
+
19
+
20
+ def prepare_rename(
21
+ lsp_context: LSPContext, document_uri: URI, position: Position
22
+ ) -> t.Optional[PrepareRenameResult_Type1]:
23
+ """
24
+ Prepare for rename operation by checking if the symbol at the position can be renamed.
25
+
26
+ Args:
27
+ lsp_context: The LSP context
28
+ document_uri: The URI of the document
29
+ position: The position in the document
30
+
31
+ Returns:
32
+ PrepareRenameResult if the symbol can be renamed, None otherwise
33
+ """
34
+ # Check if there's a CTE at this position
35
+ cte_references = get_cte_references(lsp_context, document_uri, position)
36
+ if cte_references:
37
+ # Find the target CTE definition to get its range
38
+ target_range = None
39
+ for ref in cte_references:
40
+ # Check if cursor is on a CTE usage
41
+ if _position_within_range(position, ref.range):
42
+ target_range = ref.target_range
43
+ break
44
+ # Check if cursor is on the CTE definition
45
+ elif _position_within_range(position, ref.target_range):
46
+ target_range = ref.target_range
47
+ break
48
+ if target_range:
49
+ return PrepareRenameResult_Type1(range=target_range, placeholder="cte_name")
50
+
51
+ # For now, only CTEs are supported
52
+ return None
53
+
54
+
55
+ def rename_symbol(
56
+ lsp_context: LSPContext, document_uri: URI, position: Position, new_name: str
57
+ ) -> t.Optional[WorkspaceEdit]:
58
+ """
59
+ Perform rename operation on the symbol at the given position.
60
+
61
+ Args:
62
+ lsp_context: The LSP context
63
+ document_uri: The URI of the document
64
+ position: The position in the document
65
+ new_name: The new name for the symbol
66
+
67
+ Returns:
68
+ WorkspaceEdit with the changes, or None if no symbol to rename
69
+ """
70
+ # Check if there's a CTE at this position
71
+ cte_references = get_cte_references(lsp_context, document_uri, position)
72
+ if cte_references:
73
+ return _rename_cte(cte_references, new_name)
74
+
75
+ # For now, only CTEs are supported
76
+ return None
77
+
78
+
79
+ def _rename_cte(cte_references: t.List[LSPCteReference], new_name: str) -> WorkspaceEdit:
80
+ """
81
+ Create a WorkspaceEdit for renaming a CTE.
82
+
83
+ Args:
84
+ cte_references: List of CTE references (definition and usages)
85
+ new_name: The new name for the CTE
86
+
87
+ Returns:
88
+ WorkspaceEdit with the text edits for renaming the CTE
89
+ """
90
+ changes: t.Dict[str, t.List[TextEdit]] = {}
91
+
92
+ for ref in cte_references:
93
+ uri = ref.uri
94
+ if uri not in changes:
95
+ changes[uri] = []
96
+
97
+ # Create a text edit for this reference
98
+ text_edit = TextEdit(range=ref.range, new_text=new_name)
99
+ changes[uri].append(text_edit)
100
+
101
+ return WorkspaceEdit(changes=changes)
102
+
103
+
104
+ def get_document_highlights(
105
+ lsp_context: LSPContext, document_uri: URI, position: Position
106
+ ) -> t.Optional[t.List[DocumentHighlight]]:
107
+ """
108
+ Get document highlights for all occurrences of the symbol at the given position.
109
+
110
+ This function finds all occurrences of a symbol (CTE) within the current document
111
+ and returns them as DocumentHighlight objects for "Change All Occurrences" feature.
112
+
113
+ Args:
114
+ lsp_context: The LSP context
115
+ document_uri: The URI of the document
116
+ position: The position in the document to find highlights for
117
+
118
+ Returns:
119
+ List of DocumentHighlight objects or None if no symbol found
120
+ """
121
+ # Check if there's a CTE at this position
122
+ cte_references = get_cte_references(lsp_context, document_uri, position)
123
+ if cte_references:
124
+ highlights = []
125
+ for ref in cte_references:
126
+ # Determine the highlight kind based on whether it's a definition or usage
127
+ kind = (
128
+ DocumentHighlightKind.Write
129
+ if ref.range == ref.target_range
130
+ else DocumentHighlightKind.Read
131
+ )
132
+
133
+ highlights.append(DocumentHighlight(range=ref.range, kind=kind))
134
+ return highlights
135
+
136
+ # For now, only CTEs are supported
137
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlmesh
3
- Version: 0.194.2.dev11
3
+ Version: 0.195.1.dev1
4
4
  Summary: Next-generation data transformation framework
5
5
  Author-email: "TobikoData Inc." <engineering@tobikodata.com>
6
6
  License: Apache License
@@ -1,5 +1,5 @@
1
1
  sqlmesh/__init__.py,sha256=QjwaamJIdW7voXoS880yAx7tHm-Im4_mqGA-XJgafos,7631
2
- sqlmesh/_version.py,sha256=MNQTsCYy-w7J4BscaAPLUKS1LdzZ-X95OrTOYfZBTr8,530
2
+ sqlmesh/_version.py,sha256=KKraTIapru6kL78lgWzBs83rYHvwFHv7dGSun2AsNMA,528
3
3
  sqlmesh/magics.py,sha256=d7udR_sieKWzp_YXNFPA2O173xDCqk6u9CIKB7Skb2c,41206
4
4
  sqlmesh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  sqlmesh/cicd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -172,8 +172,9 @@ sqlmesh/lsp/custom.py,sha256=IJ70li8d5RbOFDrjHfsI2UNOiOp-WB22lrgpdJ7lVSg,2942
172
172
  sqlmesh/lsp/description.py,sha256=PjguwyVw5YeYSgT0JMhkf5U1Jry-sDPLvQ2caIR9JPQ,856
173
173
  sqlmesh/lsp/helpers.py,sha256=EFc1u3-b7kSv5-tNwmKUDxId72RCLDBnN2lLTgRSzzQ,1020
174
174
  sqlmesh/lsp/hints.py,sha256=j-blccBUil94yRoDjWfkSM0HqMmsKD6hP2TaWdWWVk4,3734
175
- sqlmesh/lsp/main.py,sha256=EanNAS5ArBRc2oYsS3jhL46pfzXLn78xwSW-9R4RQ3o,33731
175
+ sqlmesh/lsp/main.py,sha256=8Lr9Yufq4JpfacVmQpyu2XOoWaswxJur8Kmsn15DpuA,36295
176
176
  sqlmesh/lsp/reference.py,sha256=NyfpK12TouDuy5-G7KOhvifkJItMfrakKwnMoU6SiVk,32088
177
+ sqlmesh/lsp/rename.py,sha256=399v1vyVRHHxvbCHVcuS4Pl8K2N-Z60JdZ6e1znOI4s,4397
177
178
  sqlmesh/lsp/uri.py,sha256=mvSLbZGmMTHPpliThOtVWiFcHnfJzp1w39q9l-xD2SI,802
178
179
  sqlmesh/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
179
180
  sqlmesh/migrations/v0001_init.py,sha256=h8FwMYJj9_O8yGpk12guaSaGwX5A3we2GiKeHrXi15o,2048
@@ -282,7 +283,7 @@ sqlmesh/utils/pydantic.py,sha256=I898jAFqa3qU6lG2uPpRebVFncOUo8ZrLWM_R3K3DHU,116
282
283
  sqlmesh/utils/rich.py,sha256=BpB47G0-JcU41LkGkeGKroexj4NOV5fox4-GOIXPgIc,3545
283
284
  sqlmesh/utils/windows.py,sha256=r7Yin4WEwbvH7sKA3hOJtRsclmscNuBeCklCfVPvtQs,611
284
285
  sqlmesh/utils/yaml.py,sha256=np-WVcwmwsKghCgAj1OBBMsK1SXSRn4wR-H37cGiFr8,2282
285
- sqlmesh-0.194.2.dev11.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
286
+ sqlmesh-0.195.1.dev1.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
286
287
  web/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
287
288
  web/client/dist/index.html,sha256=w71qWSLmp-xwmVJO8m41k8Rtni3iZlF0hmhiTr-NeCI,5472
288
289
  web/client/dist/assets/Audits-sYYNn2gO.js,sha256=zSAKkif2kU0JuPH05xjNYITNPmsbDlvLKUc2-orr8AY,1041
@@ -400,8 +401,8 @@ web/server/api/endpoints/models.py,sha256=ud-lRwriyI_OYg9tZchrBgeiXELiRTLNEodraf
400
401
  web/server/api/endpoints/modules.py,sha256=8hqqgonGay_mJmpCw0IdbjsPhWlQH2VLdKAqha-myac,468
401
402
  web/server/api/endpoints/plan.py,sha256=OYuQ_4dgbhG9ibTcX1a8mvYgH3ANxw9Fhbb4wg6QWqc,9222
402
403
  web/server/api/endpoints/table_diff.py,sha256=SCy3-pr5x6bEEiOaZGCDbiHQhpgxwmnz3Acqa2Ie6jI,2090
403
- sqlmesh-0.194.2.dev11.dist-info/METADATA,sha256=oq74Uag6ssiJ86MvYiKIxlOyrCeQLWxuEJI98oMSQ54,26691
404
- sqlmesh-0.194.2.dev11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
405
- sqlmesh-0.194.2.dev11.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
406
- sqlmesh-0.194.2.dev11.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
407
- sqlmesh-0.194.2.dev11.dist-info/RECORD,,
404
+ sqlmesh-0.195.1.dev1.dist-info/METADATA,sha256=RrH8OpiPoLmMtc0v556MegQfFOwgiaRyfUKRxOxXWzI,26690
405
+ sqlmesh-0.195.1.dev1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
406
+ sqlmesh-0.195.1.dev1.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
407
+ sqlmesh-0.195.1.dev1.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
408
+ sqlmesh-0.195.1.dev1.dist-info/RECORD,,