sqlmesh 0.204.1.dev5__py3-none-any.whl → 0.204.1.dev7__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 +2 -2
- sqlmesh/core/linter/helpers.py +1 -1
- sqlmesh/lsp/main.py +16 -13
- sqlmesh/lsp/reference.py +45 -52
- sqlmesh/lsp/rename.py +14 -8
- {sqlmesh-0.204.1.dev5.dist-info → sqlmesh-0.204.1.dev7.dist-info}/METADATA +1 -1
- {sqlmesh-0.204.1.dev5.dist-info → sqlmesh-0.204.1.dev7.dist-info}/RECORD +11 -11
- {sqlmesh-0.204.1.dev5.dist-info → sqlmesh-0.204.1.dev7.dist-info}/WHEEL +0 -0
- {sqlmesh-0.204.1.dev5.dist-info → sqlmesh-0.204.1.dev7.dist-info}/entry_points.txt +0 -0
- {sqlmesh-0.204.1.dev5.dist-info → sqlmesh-0.204.1.dev7.dist-info}/licenses/LICENSE +0 -0
- {sqlmesh-0.204.1.dev5.dist-info → sqlmesh-0.204.1.dev7.dist-info}/top_level.txt +0 -0
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.204.1.
|
|
21
|
-
__version_tuple__ = version_tuple = (0, 204, 1, '
|
|
20
|
+
__version__ = version = '0.204.1.dev7'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 204, 1, 'dev7')
|
sqlmesh/core/linter/helpers.py
CHANGED
sqlmesh/lsp/main.py
CHANGED
|
@@ -48,6 +48,7 @@ from sqlmesh.lsp.custom import (
|
|
|
48
48
|
CustomMethod,
|
|
49
49
|
)
|
|
50
50
|
from sqlmesh.lsp.errors import ContextFailedError, context_error_to_diagnostic
|
|
51
|
+
from sqlmesh.lsp.helpers import to_lsp_range, to_sqlmesh_position
|
|
51
52
|
from sqlmesh.lsp.hints import get_hints
|
|
52
53
|
from sqlmesh.lsp.reference import (
|
|
53
54
|
LSPCteReference,
|
|
@@ -418,7 +419,7 @@ class SQLMeshLanguageServer:
|
|
|
418
419
|
context = self._context_get_or_load(uri)
|
|
419
420
|
document = ls.workspace.get_text_document(params.text_document.uri)
|
|
420
421
|
|
|
421
|
-
references = get_references(context, uri, params.position)
|
|
422
|
+
references = get_references(context, uri, to_sqlmesh_position(params.position))
|
|
422
423
|
if not references:
|
|
423
424
|
return None
|
|
424
425
|
reference = references[0]
|
|
@@ -429,7 +430,7 @@ class SQLMeshLanguageServer:
|
|
|
429
430
|
kind=types.MarkupKind.Markdown,
|
|
430
431
|
value=reference.markdown_description,
|
|
431
432
|
),
|
|
432
|
-
range=reference.range,
|
|
433
|
+
range=to_lsp_range(reference.range),
|
|
433
434
|
)
|
|
434
435
|
|
|
435
436
|
except Exception as e:
|
|
@@ -464,7 +465,7 @@ class SQLMeshLanguageServer:
|
|
|
464
465
|
uri = URI(params.text_document.uri)
|
|
465
466
|
context = self._context_get_or_load(uri)
|
|
466
467
|
|
|
467
|
-
references = get_references(context, uri, params.position)
|
|
468
|
+
references = get_references(context, uri, to_sqlmesh_position(params.position))
|
|
468
469
|
location_links = []
|
|
469
470
|
for reference in references:
|
|
470
471
|
# Use target_range if available (CTEs, Macros, and external models in YAML)
|
|
@@ -489,20 +490,20 @@ class SQLMeshLanguageServer:
|
|
|
489
490
|
end=types.Position(line=0, character=0),
|
|
490
491
|
)
|
|
491
492
|
if reference.target_range is not None:
|
|
492
|
-
target_range = reference.target_range
|
|
493
|
-
target_selection_range = reference.target_range
|
|
493
|
+
target_range = to_lsp_range(reference.target_range)
|
|
494
|
+
target_selection_range = to_lsp_range(reference.target_range)
|
|
494
495
|
else:
|
|
495
496
|
# CTEs and Macros always have target_range
|
|
496
|
-
target_range = reference.target_range
|
|
497
|
-
target_selection_range = reference.target_range
|
|
497
|
+
target_range = to_lsp_range(reference.target_range)
|
|
498
|
+
target_selection_range = to_lsp_range(reference.target_range)
|
|
498
499
|
|
|
499
|
-
if reference.
|
|
500
|
+
if reference.path is not None:
|
|
500
501
|
location_links.append(
|
|
501
502
|
types.LocationLink(
|
|
502
|
-
target_uri=reference.
|
|
503
|
+
target_uri=URI.from_path(reference.path).value,
|
|
503
504
|
target_selection_range=target_selection_range,
|
|
504
505
|
target_range=target_range,
|
|
505
|
-
origin_selection_range=reference.range,
|
|
506
|
+
origin_selection_range=to_lsp_range(reference.range),
|
|
506
507
|
)
|
|
507
508
|
)
|
|
508
509
|
return location_links
|
|
@@ -519,13 +520,15 @@ class SQLMeshLanguageServer:
|
|
|
519
520
|
uri = URI(params.text_document.uri)
|
|
520
521
|
context = self._context_get_or_load(uri)
|
|
521
522
|
|
|
522
|
-
all_references = get_all_references(
|
|
523
|
+
all_references = get_all_references(
|
|
524
|
+
context, uri, to_sqlmesh_position(params.position)
|
|
525
|
+
)
|
|
523
526
|
|
|
524
527
|
# Convert references to Location objects
|
|
525
528
|
locations = [
|
|
526
|
-
types.Location(uri=ref.
|
|
529
|
+
types.Location(uri=URI.from_path(ref.path).value, range=to_lsp_range(ref.range))
|
|
527
530
|
for ref in all_references
|
|
528
|
-
if ref.
|
|
531
|
+
if ref.path is not None
|
|
529
532
|
]
|
|
530
533
|
|
|
531
534
|
return locations if locations else None
|
sqlmesh/lsp/reference.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
from lsprotocol.types import Range, Position
|
|
2
1
|
import typing as t
|
|
3
2
|
from pathlib import Path
|
|
4
3
|
from pydantic import Field
|
|
@@ -8,13 +7,13 @@ from sqlmesh.core.dialect import normalize_model_name
|
|
|
8
7
|
from sqlmesh.core.linter.helpers import (
|
|
9
8
|
TokenPositionDetails,
|
|
10
9
|
)
|
|
10
|
+
from sqlmesh.core.linter.rule import Range, Position
|
|
11
11
|
from sqlmesh.core.model.definition import SqlModel, ExternalModel
|
|
12
12
|
from sqlmesh.lsp.context import LSPContext, ModelTarget, AuditTarget
|
|
13
13
|
from sqlglot import exp
|
|
14
14
|
from sqlmesh.lsp.description import generate_markdown_description
|
|
15
15
|
from sqlglot.optimizer.scope import build_scope
|
|
16
16
|
|
|
17
|
-
from sqlmesh.lsp.helpers import to_lsp_range, to_lsp_position
|
|
18
17
|
from sqlmesh.lsp.uri import URI
|
|
19
18
|
from sqlmesh.utils.pydantic import PydanticModel
|
|
20
19
|
from sqlglot.optimizer.normalize_identifiers import normalize_identifiers
|
|
@@ -29,7 +28,7 @@ class LSPModelReference(PydanticModel):
|
|
|
29
28
|
"""A LSP reference to a model, excluding external models."""
|
|
30
29
|
|
|
31
30
|
type: t.Literal["model"] = "model"
|
|
32
|
-
|
|
31
|
+
path: Path
|
|
33
32
|
range: Range
|
|
34
33
|
markdown_description: t.Optional[str] = None
|
|
35
34
|
|
|
@@ -40,9 +39,9 @@ class LSPExternalModelReference(PydanticModel):
|
|
|
40
39
|
type: t.Literal["external_model"] = "external_model"
|
|
41
40
|
range: Range
|
|
42
41
|
target_range: t.Optional[Range] = None
|
|
43
|
-
|
|
44
|
-
"""The
|
|
45
|
-
external models can be unregistered and so
|
|
42
|
+
path: t.Optional[Path] = None
|
|
43
|
+
"""The path of the external model, typically a YAML file, it is optional because
|
|
44
|
+
external models can be unregistered and so the path is not available."""
|
|
46
45
|
|
|
47
46
|
markdown_description: t.Optional[str] = None
|
|
48
47
|
|
|
@@ -51,7 +50,7 @@ class LSPCteReference(PydanticModel):
|
|
|
51
50
|
"""A LSP reference to a CTE."""
|
|
52
51
|
|
|
53
52
|
type: t.Literal["cte"] = "cte"
|
|
54
|
-
|
|
53
|
+
path: Path
|
|
55
54
|
range: Range
|
|
56
55
|
target_range: Range
|
|
57
56
|
|
|
@@ -60,7 +59,7 @@ class LSPMacroReference(PydanticModel):
|
|
|
60
59
|
"""A LSP reference to a macro."""
|
|
61
60
|
|
|
62
61
|
type: t.Literal["macro"] = "macro"
|
|
63
|
-
|
|
62
|
+
path: Path
|
|
64
63
|
range: Range
|
|
65
64
|
target_range: Range
|
|
66
65
|
markdown_description: t.Optional[str] = None
|
|
@@ -203,15 +202,11 @@ def get_model_definitions_for_a_path(
|
|
|
203
202
|
table.this.meta
|
|
204
203
|
).to_range(read_file)
|
|
205
204
|
|
|
206
|
-
# Convert SQLMesh Range to LSP Range
|
|
207
|
-
target_range = to_lsp_range(target_range_sqlmesh)
|
|
208
|
-
table_range = to_lsp_range(table_range_sqlmesh)
|
|
209
|
-
|
|
210
205
|
references.append(
|
|
211
206
|
LSPCteReference(
|
|
212
|
-
|
|
213
|
-
range=
|
|
214
|
-
target_range=
|
|
207
|
+
path=document_uri.to_path(), # Same file
|
|
208
|
+
range=table_range_sqlmesh,
|
|
209
|
+
target_range=target_range_sqlmesh,
|
|
215
210
|
)
|
|
216
211
|
)
|
|
217
212
|
|
|
@@ -219,10 +214,10 @@ def get_model_definitions_for_a_path(
|
|
|
219
214
|
scope=scope,
|
|
220
215
|
reference_name=table.name,
|
|
221
216
|
read_file=read_file,
|
|
222
|
-
|
|
217
|
+
referenced_model_path=document_uri.to_path(),
|
|
223
218
|
description="",
|
|
224
219
|
reference_type="cte",
|
|
225
|
-
cte_target_range=
|
|
220
|
+
cte_target_range=target_range_sqlmesh,
|
|
226
221
|
)
|
|
227
222
|
references.extend(column_references)
|
|
228
223
|
continue
|
|
@@ -257,8 +252,8 @@ def get_model_definitions_for_a_path(
|
|
|
257
252
|
references.append(
|
|
258
253
|
LSPExternalModelReference(
|
|
259
254
|
range=Range(
|
|
260
|
-
start=
|
|
261
|
-
end=
|
|
255
|
+
start=start_pos_sqlmesh,
|
|
256
|
+
end=end_pos_sqlmesh,
|
|
262
257
|
),
|
|
263
258
|
markdown_description="Unregistered external model",
|
|
264
259
|
)
|
|
@@ -270,7 +265,6 @@ def get_model_definitions_for_a_path(
|
|
|
270
265
|
# Check whether the path exists
|
|
271
266
|
if not referenced_model_path.is_file():
|
|
272
267
|
continue
|
|
273
|
-
referenced_model_uri = URI.from_path(referenced_model_path)
|
|
274
268
|
|
|
275
269
|
# Extract metadata for positioning
|
|
276
270
|
table_meta = TokenPositionDetails.from_meta(table.this.meta)
|
|
@@ -299,10 +293,10 @@ def get_model_definitions_for_a_path(
|
|
|
299
293
|
)
|
|
300
294
|
references.append(
|
|
301
295
|
LSPExternalModelReference(
|
|
302
|
-
|
|
296
|
+
path=referenced_model_path,
|
|
303
297
|
range=Range(
|
|
304
|
-
start=
|
|
305
|
-
end=
|
|
298
|
+
start=start_pos_sqlmesh,
|
|
299
|
+
end=end_pos_sqlmesh,
|
|
306
300
|
),
|
|
307
301
|
markdown_description=description,
|
|
308
302
|
target_range=yaml_target_range,
|
|
@@ -313,7 +307,7 @@ def get_model_definitions_for_a_path(
|
|
|
313
307
|
scope=scope,
|
|
314
308
|
reference_name=normalized_reference_name,
|
|
315
309
|
read_file=read_file,
|
|
316
|
-
|
|
310
|
+
referenced_model_path=referenced_model_path,
|
|
317
311
|
description=description,
|
|
318
312
|
yaml_target_range=yaml_target_range,
|
|
319
313
|
reference_type="external_model",
|
|
@@ -324,10 +318,10 @@ def get_model_definitions_for_a_path(
|
|
|
324
318
|
else:
|
|
325
319
|
references.append(
|
|
326
320
|
LSPModelReference(
|
|
327
|
-
|
|
321
|
+
path=referenced_model_path,
|
|
328
322
|
range=Range(
|
|
329
|
-
start=
|
|
330
|
-
end=
|
|
323
|
+
start=start_pos_sqlmesh,
|
|
324
|
+
end=end_pos_sqlmesh,
|
|
331
325
|
),
|
|
332
326
|
markdown_description=description,
|
|
333
327
|
)
|
|
@@ -337,7 +331,7 @@ def get_model_definitions_for_a_path(
|
|
|
337
331
|
scope=scope,
|
|
338
332
|
reference_name=normalized_reference_name,
|
|
339
333
|
read_file=read_file,
|
|
340
|
-
|
|
334
|
+
referenced_model_path=referenced_model_path,
|
|
341
335
|
description=description,
|
|
342
336
|
reference_type="model",
|
|
343
337
|
default_catalog=lint_context.context.default_catalog,
|
|
@@ -433,7 +427,7 @@ def get_macro_reference(
|
|
|
433
427
|
macro_range = TokenPositionDetails.from_meta(node.meta).to_range(read_file)
|
|
434
428
|
|
|
435
429
|
# Check if it's a built-in method
|
|
436
|
-
if builtin := get_built_in_macro_reference(macro_name,
|
|
430
|
+
if builtin := get_built_in_macro_reference(macro_name, macro_range):
|
|
437
431
|
return builtin
|
|
438
432
|
else:
|
|
439
433
|
# Skip if we can't get the position
|
|
@@ -481,11 +475,10 @@ def get_macro_reference(
|
|
|
481
475
|
return None
|
|
482
476
|
|
|
483
477
|
# Create a reference to the macro definition
|
|
484
|
-
macro_uri = URI.from_path(path)
|
|
485
478
|
|
|
486
479
|
return LSPMacroReference(
|
|
487
|
-
|
|
488
|
-
range=
|
|
480
|
+
path=path,
|
|
481
|
+
range=macro_range,
|
|
489
482
|
target_range=Range(
|
|
490
483
|
start=Position(line=start_line - 1, character=0),
|
|
491
484
|
end=Position(line=end_line - 1, character=get_length_of_end_line),
|
|
@@ -517,7 +510,7 @@ def get_built_in_macro_reference(macro_name: str, macro_range: Range) -> t.Optio
|
|
|
517
510
|
end_line_number = line_number + len(source_lines) - 1
|
|
518
511
|
|
|
519
512
|
return LSPMacroReference(
|
|
520
|
-
|
|
513
|
+
path=Path(filename),
|
|
521
514
|
range=macro_range,
|
|
522
515
|
target_range=Range(
|
|
523
516
|
start=Position(line=line_number - 1, character=0),
|
|
@@ -559,12 +552,12 @@ def get_model_find_all_references(
|
|
|
559
552
|
|
|
560
553
|
assert isinstance(model_at_position, LSPModelReference) # for mypy
|
|
561
554
|
|
|
562
|
-
|
|
555
|
+
target_model_path = model_at_position.path
|
|
563
556
|
|
|
564
557
|
# Start with the model definition
|
|
565
558
|
all_references: t.List[LSPModelReference] = [
|
|
566
559
|
LSPModelReference(
|
|
567
|
-
|
|
560
|
+
path=model_at_position.path,
|
|
568
561
|
range=Range(
|
|
569
562
|
start=Position(line=0, character=0),
|
|
570
563
|
end=Position(line=0, character=0),
|
|
@@ -575,7 +568,7 @@ def get_model_find_all_references(
|
|
|
575
568
|
|
|
576
569
|
# Then add references from the current file
|
|
577
570
|
current_file_refs = filter(
|
|
578
|
-
lambda ref: isinstance(ref, LSPModelReference) and ref.
|
|
571
|
+
lambda ref: isinstance(ref, LSPModelReference) and ref.path == target_model_path,
|
|
579
572
|
get_model_definitions_for_a_path(lint_context, document_uri),
|
|
580
573
|
)
|
|
581
574
|
|
|
@@ -584,7 +577,7 @@ def get_model_find_all_references(
|
|
|
584
577
|
|
|
585
578
|
all_references.append(
|
|
586
579
|
LSPModelReference(
|
|
587
|
-
|
|
580
|
+
path=document_uri.to_path(),
|
|
588
581
|
range=ref.range,
|
|
589
582
|
markdown_description=ref.markdown_description,
|
|
590
583
|
)
|
|
@@ -600,7 +593,7 @@ def get_model_find_all_references(
|
|
|
600
593
|
|
|
601
594
|
# Get model references that point to the target model
|
|
602
595
|
matching_refs = filter(
|
|
603
|
-
lambda ref: isinstance(ref, LSPModelReference) and ref.
|
|
596
|
+
lambda ref: isinstance(ref, LSPModelReference) and ref.path == target_model_path,
|
|
604
597
|
get_model_definitions_for_a_path(lint_context, file_uri),
|
|
605
598
|
)
|
|
606
599
|
|
|
@@ -609,7 +602,7 @@ def get_model_find_all_references(
|
|
|
609
602
|
|
|
610
603
|
all_references.append(
|
|
611
604
|
LSPModelReference(
|
|
612
|
-
|
|
605
|
+
path=path,
|
|
613
606
|
range=ref.range,
|
|
614
607
|
markdown_description=ref.markdown_description,
|
|
615
608
|
)
|
|
@@ -662,7 +655,7 @@ def get_cte_references(
|
|
|
662
655
|
# Add the CTE definition
|
|
663
656
|
matching_references = [
|
|
664
657
|
LSPCteReference(
|
|
665
|
-
|
|
658
|
+
path=document_uri.to_path(),
|
|
666
659
|
range=target_cte_definition_range,
|
|
667
660
|
target_range=target_cte_definition_range,
|
|
668
661
|
)
|
|
@@ -673,7 +666,7 @@ def get_cte_references(
|
|
|
673
666
|
if ref.target_range == target_cte_definition_range:
|
|
674
667
|
matching_references.append(
|
|
675
668
|
LSPCteReference(
|
|
676
|
-
|
|
669
|
+
path=document_uri.to_path(),
|
|
677
670
|
range=ref.range,
|
|
678
671
|
target_range=ref.target_range,
|
|
679
672
|
)
|
|
@@ -713,13 +706,13 @@ def get_macro_find_all_references(
|
|
|
713
706
|
|
|
714
707
|
assert isinstance(macro_at_position, LSPMacroReference) # for mypy
|
|
715
708
|
|
|
716
|
-
|
|
709
|
+
target_macro_path = macro_at_position.path
|
|
717
710
|
target_macro_target_range = macro_at_position.target_range
|
|
718
711
|
|
|
719
712
|
# Start with the macro definition
|
|
720
713
|
all_references: t.List[LSPMacroReference] = [
|
|
721
714
|
LSPMacroReference(
|
|
722
|
-
|
|
715
|
+
path=target_macro_path,
|
|
723
716
|
range=target_macro_target_range,
|
|
724
717
|
target_range=target_macro_target_range,
|
|
725
718
|
markdown_description=None,
|
|
@@ -733,7 +726,7 @@ def get_macro_find_all_references(
|
|
|
733
726
|
# Get macro references that point to the same macro definition
|
|
734
727
|
matching_refs = filter(
|
|
735
728
|
lambda ref: isinstance(ref, LSPMacroReference)
|
|
736
|
-
and ref.
|
|
729
|
+
and ref.path == target_macro_path
|
|
737
730
|
and ref.target_range == target_macro_target_range,
|
|
738
731
|
get_macro_definitions_for_a_path(lsp_context, file_uri),
|
|
739
732
|
)
|
|
@@ -742,7 +735,7 @@ def get_macro_find_all_references(
|
|
|
742
735
|
assert isinstance(ref, LSPMacroReference) # for mypy
|
|
743
736
|
all_references.append(
|
|
744
737
|
LSPMacroReference(
|
|
745
|
-
|
|
738
|
+
path=path,
|
|
746
739
|
range=ref.range,
|
|
747
740
|
target_range=ref.target_range,
|
|
748
741
|
markdown_description=ref.markdown_description,
|
|
@@ -813,8 +806,8 @@ def _get_column_table_range(column: exp.Column, read_file: t.List[str]) -> Range
|
|
|
813
806
|
end_range = TokenPositionDetails.from_meta(table_parts[-1].meta).to_range(read_file)
|
|
814
807
|
|
|
815
808
|
return Range(
|
|
816
|
-
start=
|
|
817
|
-
end=
|
|
809
|
+
start=start_range.start,
|
|
810
|
+
end=end_range.end,
|
|
818
811
|
)
|
|
819
812
|
|
|
820
813
|
|
|
@@ -822,7 +815,7 @@ def _process_column_references(
|
|
|
822
815
|
scope: t.Any,
|
|
823
816
|
reference_name: str,
|
|
824
817
|
read_file: t.List[str],
|
|
825
|
-
|
|
818
|
+
referenced_model_path: Path,
|
|
826
819
|
description: t.Optional[str] = None,
|
|
827
820
|
yaml_target_range: t.Optional[Range] = None,
|
|
828
821
|
reference_type: t.Literal["model", "external_model", "cte"] = "model",
|
|
@@ -837,7 +830,7 @@ def _process_column_references(
|
|
|
837
830
|
scope: The SQL scope to search for columns
|
|
838
831
|
reference_name: The full reference name (may include database/catalog)
|
|
839
832
|
read_file: The file content as list of lines
|
|
840
|
-
|
|
833
|
+
referenced_model_path: Path of the referenced model
|
|
841
834
|
description: Markdown description for the reference
|
|
842
835
|
yaml_target_range: Target range for external models (YAML files)
|
|
843
836
|
reference_type: Type of reference - "model", "external_model", or "cte"
|
|
@@ -857,7 +850,7 @@ def _process_column_references(
|
|
|
857
850
|
table_range = _get_column_table_range(column, read_file)
|
|
858
851
|
references.append(
|
|
859
852
|
LSPCteReference(
|
|
860
|
-
|
|
853
|
+
path=referenced_model_path,
|
|
861
854
|
range=table_range,
|
|
862
855
|
target_range=cte_target_range,
|
|
863
856
|
)
|
|
@@ -875,7 +868,7 @@ def _process_column_references(
|
|
|
875
868
|
if reference_type == "external_model":
|
|
876
869
|
references.append(
|
|
877
870
|
LSPExternalModelReference(
|
|
878
|
-
|
|
871
|
+
path=referenced_model_path,
|
|
879
872
|
range=table_range,
|
|
880
873
|
markdown_description=description,
|
|
881
874
|
target_range=yaml_target_range,
|
|
@@ -884,7 +877,7 @@ def _process_column_references(
|
|
|
884
877
|
else:
|
|
885
878
|
references.append(
|
|
886
879
|
LSPModelReference(
|
|
887
|
-
|
|
880
|
+
path=referenced_model_path,
|
|
888
881
|
range=table_range,
|
|
889
882
|
markdown_description=description,
|
|
890
883
|
)
|
sqlmesh/lsp/rename.py
CHANGED
|
@@ -9,6 +9,7 @@ from lsprotocol.types import (
|
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
from sqlmesh.lsp.context import LSPContext
|
|
12
|
+
from sqlmesh.lsp.helpers import to_sqlmesh_position, to_lsp_range
|
|
12
13
|
from sqlmesh.lsp.reference import (
|
|
13
14
|
_position_within_range,
|
|
14
15
|
get_cte_references,
|
|
@@ -18,7 +19,7 @@ from sqlmesh.lsp.uri import URI
|
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
def prepare_rename(
|
|
21
|
-
lsp_context: LSPContext, document_uri: URI,
|
|
22
|
+
lsp_context: LSPContext, document_uri: URI, lsp_position: Position
|
|
22
23
|
) -> t.Optional[PrepareRenameResult_Type1]:
|
|
23
24
|
"""
|
|
24
25
|
Prepare for rename operation by checking if the symbol at the position can be renamed.
|
|
@@ -32,6 +33,7 @@ def prepare_rename(
|
|
|
32
33
|
PrepareRenameResult if the symbol can be renamed, None otherwise
|
|
33
34
|
"""
|
|
34
35
|
# Check if there's a CTE at this position
|
|
36
|
+
position = to_sqlmesh_position(lsp_position)
|
|
35
37
|
cte_references = get_cte_references(lsp_context, document_uri, position)
|
|
36
38
|
if cte_references:
|
|
37
39
|
# Find the target CTE definition to get its range
|
|
@@ -46,14 +48,16 @@ def prepare_rename(
|
|
|
46
48
|
target_range = ref.target_range
|
|
47
49
|
break
|
|
48
50
|
if target_range:
|
|
49
|
-
return PrepareRenameResult_Type1(
|
|
51
|
+
return PrepareRenameResult_Type1(
|
|
52
|
+
range=to_lsp_range(target_range), placeholder="cte_name"
|
|
53
|
+
)
|
|
50
54
|
|
|
51
55
|
# For now, only CTEs are supported
|
|
52
56
|
return None
|
|
53
57
|
|
|
54
58
|
|
|
55
59
|
def rename_symbol(
|
|
56
|
-
lsp_context: LSPContext, document_uri: URI,
|
|
60
|
+
lsp_context: LSPContext, document_uri: URI, lsp_position: Position, new_name: str
|
|
57
61
|
) -> t.Optional[WorkspaceEdit]:
|
|
58
62
|
"""
|
|
59
63
|
Perform rename operation on the symbol at the given position.
|
|
@@ -68,7 +72,9 @@ def rename_symbol(
|
|
|
68
72
|
WorkspaceEdit with the changes, or None if no symbol to rename
|
|
69
73
|
"""
|
|
70
74
|
# Check if there's a CTE at this position
|
|
71
|
-
cte_references = get_cte_references(
|
|
75
|
+
cte_references = get_cte_references(
|
|
76
|
+
lsp_context, document_uri, to_sqlmesh_position(lsp_position)
|
|
77
|
+
)
|
|
72
78
|
if cte_references:
|
|
73
79
|
return _rename_cte(cte_references, new_name)
|
|
74
80
|
|
|
@@ -90,12 +96,12 @@ def _rename_cte(cte_references: t.List[LSPCteReference], new_name: str) -> Works
|
|
|
90
96
|
changes: t.Dict[str, t.List[TextEdit]] = {}
|
|
91
97
|
|
|
92
98
|
for ref in cte_references:
|
|
93
|
-
uri = ref.
|
|
99
|
+
uri = URI.from_path(ref.path).value
|
|
94
100
|
if uri not in changes:
|
|
95
101
|
changes[uri] = []
|
|
96
102
|
|
|
97
103
|
# Create a text edit for this reference
|
|
98
|
-
text_edit = TextEdit(range=ref.range, new_text=new_name)
|
|
104
|
+
text_edit = TextEdit(range=to_lsp_range(ref.range), new_text=new_name)
|
|
99
105
|
changes[uri].append(text_edit)
|
|
100
106
|
|
|
101
107
|
return WorkspaceEdit(changes=changes)
|
|
@@ -119,7 +125,7 @@ def get_document_highlights(
|
|
|
119
125
|
List of DocumentHighlight objects or None if no symbol found
|
|
120
126
|
"""
|
|
121
127
|
# Check if there's a CTE at this position
|
|
122
|
-
cte_references = get_cte_references(lsp_context, document_uri, position)
|
|
128
|
+
cte_references = get_cte_references(lsp_context, document_uri, to_sqlmesh_position(position))
|
|
123
129
|
if cte_references:
|
|
124
130
|
highlights = []
|
|
125
131
|
for ref in cte_references:
|
|
@@ -130,7 +136,7 @@ def get_document_highlights(
|
|
|
130
136
|
else DocumentHighlightKind.Read
|
|
131
137
|
)
|
|
132
138
|
|
|
133
|
-
highlights.append(DocumentHighlight(range=ref.range, kind=kind))
|
|
139
|
+
highlights.append(DocumentHighlight(range=to_lsp_range(ref.range), kind=kind))
|
|
134
140
|
return highlights
|
|
135
141
|
|
|
136
142
|
# For now, only CTEs are supported
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
sqlmesh/__init__.py,sha256=QjwaamJIdW7voXoS880yAx7tHm-Im4_mqGA-XJgafos,7631
|
|
2
|
-
sqlmesh/_version.py,sha256=
|
|
2
|
+
sqlmesh/_version.py,sha256=pxy9S-rsevnRrrGriKqOmzCljxxUvSfVO0XH8mHUKvw,528
|
|
3
3
|
sqlmesh/magics.py,sha256=bEzYqXHcM0P3CjyUZ1O9arlmXAdLAhoglKbQ29fD9AE,41842
|
|
4
4
|
sqlmesh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
sqlmesh/cicd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -77,7 +77,7 @@ sqlmesh/core/engine_adapter/spark.py,sha256=sYkVOPS0X43UPbI0z7Hh_EpKlI36qkOcr4NN
|
|
|
77
77
|
sqlmesh/core/engine_adapter/trino.py,sha256=Tws3GxqnC6BmXFohqru1TDxsgPH-21qV6Oky7FaaLpE,15908
|
|
78
78
|
sqlmesh/core/linter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
79
79
|
sqlmesh/core/linter/definition.py,sha256=JDJTkhByUw4Tr3nF-BOHKFAx_eASQqEqzX6AUVQUz8I,5659
|
|
80
|
-
sqlmesh/core/linter/helpers.py,sha256=
|
|
80
|
+
sqlmesh/core/linter/helpers.py,sha256=Fc_rh5earww0V8oKSEPVnUEY0bnpEmK88O4FLV3W-QE,5022
|
|
81
81
|
sqlmesh/core/linter/rule.py,sha256=cyGoAz9HuhBYRfbgow_MZhzmDvQE7NK1gzzKsAN0cwY,3694
|
|
82
82
|
sqlmesh/core/linter/rules/__init__.py,sha256=gevzfb67vFqckTCoVAe_TBGf6hQ-YtE1_YuGuXyh1L0,77
|
|
83
83
|
sqlmesh/core/linter/rules/builtin.py,sha256=UNelGDGuzE-gPc6DsFw9h0BUbzmwx-Xyrx8wZh61Qq8,5163
|
|
@@ -171,9 +171,9 @@ sqlmesh/lsp/description.py,sha256=PjguwyVw5YeYSgT0JMhkf5U1Jry-sDPLvQ2caIR9JPQ,85
|
|
|
171
171
|
sqlmesh/lsp/errors.py,sha256=3NMim_5J00Eypz7t8b7XbkBfy8gIsRkeq-VcjD4COtc,1489
|
|
172
172
|
sqlmesh/lsp/helpers.py,sha256=EFc1u3-b7kSv5-tNwmKUDxId72RCLDBnN2lLTgRSzzQ,1020
|
|
173
173
|
sqlmesh/lsp/hints.py,sha256=j-blccBUil94yRoDjWfkSM0HqMmsKD6hP2TaWdWWVk4,3734
|
|
174
|
-
sqlmesh/lsp/main.py,sha256=
|
|
175
|
-
sqlmesh/lsp/reference.py,sha256=
|
|
176
|
-
sqlmesh/lsp/rename.py,sha256=
|
|
174
|
+
sqlmesh/lsp/main.py,sha256=UsnEsrX8wOmhgK_MVWOzZcQVcEkEQLFihloAZ-taBQY,40275
|
|
175
|
+
sqlmesh/lsp/reference.py,sha256=ucyvi52bmmmD5XGC_On0JDvQefwPrgX41KNuamjyOPQ,32624
|
|
176
|
+
sqlmesh/lsp/rename.py,sha256=DPnxrYXT5gSECbX3q9lzWYl-5xnQMw-jlMOkiKgxjxg,4674
|
|
177
177
|
sqlmesh/lsp/uri.py,sha256=mvSLbZGmMTHPpliThOtVWiFcHnfJzp1w39q9l-xD2SI,802
|
|
178
178
|
sqlmesh/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
179
179
|
sqlmesh/migrations/v0001_init.py,sha256=h8FwMYJj9_O8yGpk12guaSaGwX5A3we2GiKeHrXi15o,2048
|
|
@@ -285,7 +285,7 @@ sqlmesh/utils/pydantic.py,sha256=o_NsXbIpDqNpUA1Uc5xF0ZzoXQYYB0DfHwdRxBwXPNk,120
|
|
|
285
285
|
sqlmesh/utils/rich.py,sha256=cwQ5nJ6sgz64xHtoh6_ec7ReV5YpsOGhMtUJnwoRfEI,3549
|
|
286
286
|
sqlmesh/utils/windows.py,sha256=r7Yin4WEwbvH7sKA3hOJtRsclmscNuBeCklCfVPvtQs,611
|
|
287
287
|
sqlmesh/utils/yaml.py,sha256=hvo5lmybYLcIx4p6CQwufS8X4MbwS60lEBnCmYJCXmU,2336
|
|
288
|
-
sqlmesh-0.204.1.
|
|
288
|
+
sqlmesh-0.204.1.dev7.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
|
|
289
289
|
web/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
290
290
|
web/client/dist/index.html,sha256=SXykdSRNgrT1k6I2dPZPEfpxPjIsi8-yVFijt-naSA4,5472
|
|
291
291
|
web/client/dist/assets/Audits-Jm353fhk.js,sha256=ry6b5IKT3hLAfD5C3T2BqxulfauEV0n0YZ2vsP4eQ_U,1041
|
|
@@ -403,8 +403,8 @@ web/server/api/endpoints/models.py,sha256=kwj0s7uve3iZSMfmjkoPVMFMeY1sD0peTeyrWf
|
|
|
403
403
|
web/server/api/endpoints/modules.py,sha256=8hqqgonGay_mJmpCw0IdbjsPhWlQH2VLdKAqha-myac,468
|
|
404
404
|
web/server/api/endpoints/plan.py,sha256=bbbY50W_2MsZSTxOHWMKz0tbIm75nsRSlPy8GI2fg9Q,9306
|
|
405
405
|
web/server/api/endpoints/table_diff.py,sha256=SCy3-pr5x6bEEiOaZGCDbiHQhpgxwmnz3Acqa2Ie6jI,2090
|
|
406
|
-
sqlmesh-0.204.1.
|
|
407
|
-
sqlmesh-0.204.1.
|
|
408
|
-
sqlmesh-0.204.1.
|
|
409
|
-
sqlmesh-0.204.1.
|
|
410
|
-
sqlmesh-0.204.1.
|
|
406
|
+
sqlmesh-0.204.1.dev7.dist-info/METADATA,sha256=6nMUi99giGG3LR8p_OrIP7p6vR0_vC328NpsnDjGFWI,26678
|
|
407
|
+
sqlmesh-0.204.1.dev7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
408
|
+
sqlmesh-0.204.1.dev7.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
|
|
409
|
+
sqlmesh-0.204.1.dev7.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
|
|
410
|
+
sqlmesh-0.204.1.dev7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|