sqlmesh 0.189.3.dev14__py3-none-any.whl → 0.189.3.dev16__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/lsp/completions.py +18 -2
- sqlmesh/lsp/context.py +7 -12
- sqlmesh/lsp/custom.py +1 -0
- sqlmesh/lsp/helpers.py +27 -0
- sqlmesh/lsp/main.py +38 -11
- sqlmesh/lsp/reference.py +164 -50
- {sqlmesh-0.189.3.dev14.dist-info → sqlmesh-0.189.3.dev16.dist-info}/METADATA +1 -1
- {sqlmesh-0.189.3.dev14.dist-info → sqlmesh-0.189.3.dev16.dist-info}/RECORD +13 -12
- {sqlmesh-0.189.3.dev14.dist-info → sqlmesh-0.189.3.dev16.dist-info}/WHEEL +0 -0
- {sqlmesh-0.189.3.dev14.dist-info → sqlmesh-0.189.3.dev16.dist-info}/entry_points.txt +0 -0
- {sqlmesh-0.189.3.dev14.dist-info → sqlmesh-0.189.3.dev16.dist-info}/licenses/LICENSE +0 -0
- {sqlmesh-0.189.3.dev14.dist-info → sqlmesh-0.189.3.dev16.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.189.3.
|
|
21
|
-
__version_tuple__ = version_tuple = (0, 189, 3, '
|
|
20
|
+
__version__ = version = '0.189.3.dev16'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 189, 3, 'dev16')
|
sqlmesh/lsp/completions.py
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
from functools import lru_cache
|
|
2
2
|
from sqlglot import Dialect, Tokenizer
|
|
3
3
|
from sqlmesh.lsp.custom import AllModelsResponse
|
|
4
|
+
from sqlmesh import macro
|
|
4
5
|
import typing as t
|
|
5
6
|
from sqlmesh.lsp.context import AuditTarget, LSPContext, ModelTarget
|
|
6
7
|
from sqlmesh.lsp.uri import URI
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
def get_sql_completions(
|
|
10
|
-
context: t.Optional[LSPContext]
|
|
11
|
+
context: t.Optional[LSPContext] = None,
|
|
12
|
+
file_uri: t.Optional[URI] = None,
|
|
13
|
+
content: t.Optional[str] = None,
|
|
11
14
|
) -> AllModelsResponse:
|
|
12
15
|
"""
|
|
13
16
|
Return a list of completions for a given file.
|
|
@@ -26,6 +29,7 @@ def get_sql_completions(
|
|
|
26
29
|
return AllModelsResponse(
|
|
27
30
|
models=list(get_models(context, file_uri)),
|
|
28
31
|
keywords=all_keywords,
|
|
32
|
+
macros=list(get_macros(context, file_uri)),
|
|
29
33
|
)
|
|
30
34
|
|
|
31
35
|
|
|
@@ -56,6 +60,17 @@ def get_models(context: t.Optional[LSPContext], file_uri: t.Optional[URI]) -> t.
|
|
|
56
60
|
return all_models
|
|
57
61
|
|
|
58
62
|
|
|
63
|
+
def get_macros(context: t.Optional[LSPContext], file_uri: t.Optional[URI]) -> t.Set[str]:
|
|
64
|
+
"""Return a set of all macros with the ``@`` prefix."""
|
|
65
|
+
names = set(macro.get_registry())
|
|
66
|
+
try:
|
|
67
|
+
if context is not None:
|
|
68
|
+
names.update(context.context._macros)
|
|
69
|
+
except Exception:
|
|
70
|
+
pass
|
|
71
|
+
return names
|
|
72
|
+
|
|
73
|
+
|
|
59
74
|
def get_keywords(context: t.Optional[LSPContext], file_uri: t.Optional[URI]) -> t.Set[str]:
|
|
60
75
|
"""
|
|
61
76
|
Return a list of sql keywords for a given file.
|
|
@@ -138,6 +153,7 @@ def get_dialect(context: t.Optional[LSPContext], file_uri: t.Optional[URI]) -> t
|
|
|
138
153
|
def extract_keywords_from_content(content: str, dialect: t.Optional[str] = None) -> t.Set[str]:
|
|
139
154
|
"""
|
|
140
155
|
Extract identifiers from SQL content using the tokenizer.
|
|
156
|
+
|
|
141
157
|
Only extracts identifiers (variable names, table names, column names, etc.)
|
|
142
158
|
that are not SQL keywords.
|
|
143
159
|
"""
|
|
@@ -155,7 +171,7 @@ def extract_keywords_from_content(content: str, dialect: t.Optional[str] = None)
|
|
|
155
171
|
keywords.add(token.text)
|
|
156
172
|
|
|
157
173
|
except Exception:
|
|
158
|
-
# If tokenization fails, return empty set
|
|
174
|
+
# If tokenization fails, return an empty set
|
|
159
175
|
pass
|
|
160
176
|
|
|
161
177
|
return keywords
|
sqlmesh/lsp/context.py
CHANGED
|
@@ -176,18 +176,13 @@ class LSPContext:
|
|
|
176
176
|
if audit._path is not None
|
|
177
177
|
]
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
@staticmethod
|
|
180
|
+
def get_completions(
|
|
181
|
+
self: t.Optional["LSPContext"] = None,
|
|
182
|
+
uri: t.Optional[URI] = None,
|
|
183
|
+
file_content: t.Optional[str] = None,
|
|
181
184
|
) -> AllModelsResponse:
|
|
182
|
-
"""Get
|
|
183
|
-
|
|
184
|
-
Args:
|
|
185
|
-
uri: The URI of the file to get autocomplete suggestions for.
|
|
186
|
-
content: The content of the file (optional).
|
|
187
|
-
|
|
188
|
-
Returns:
|
|
189
|
-
AllModelsResponse containing models and keywords.
|
|
190
|
-
"""
|
|
185
|
+
"""Get completion suggestions for a file"""
|
|
191
186
|
from sqlmesh.lsp.completions import get_sql_completions
|
|
192
187
|
|
|
193
|
-
return get_sql_completions(self, uri,
|
|
188
|
+
return get_sql_completions(self, uri, file_content)
|
sqlmesh/lsp/custom.py
CHANGED
sqlmesh/lsp/helpers.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from lsprotocol.types import Range, Position
|
|
2
|
+
|
|
3
|
+
from sqlmesh.core.linter.helpers import (
|
|
4
|
+
Range as SQLMeshRange,
|
|
5
|
+
Position as SQLMeshPosition,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def to_lsp_range(
|
|
10
|
+
range: SQLMeshRange,
|
|
11
|
+
) -> Range:
|
|
12
|
+
"""
|
|
13
|
+
Converts a SQLMesh Range to an LSP Range.
|
|
14
|
+
"""
|
|
15
|
+
return Range(
|
|
16
|
+
start=Position(line=range.start.line, character=range.start.character),
|
|
17
|
+
end=Position(line=range.end.line, character=range.end.character),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def to_lsp_position(
|
|
22
|
+
position: SQLMeshPosition,
|
|
23
|
+
) -> Position:
|
|
24
|
+
"""
|
|
25
|
+
Converts a SQLMesh Position to an LSP Position.
|
|
26
|
+
"""
|
|
27
|
+
return Position(line=position.line, character=position.character)
|
sqlmesh/lsp/main.py
CHANGED
|
@@ -44,7 +44,12 @@ from sqlmesh.lsp.custom import (
|
|
|
44
44
|
CustomMethod,
|
|
45
45
|
)
|
|
46
46
|
from sqlmesh.lsp.hints import get_hints
|
|
47
|
-
from sqlmesh.lsp.reference import
|
|
47
|
+
from sqlmesh.lsp.reference import (
|
|
48
|
+
LSPCteReference,
|
|
49
|
+
LSPModelReference,
|
|
50
|
+
get_references,
|
|
51
|
+
get_all_references,
|
|
52
|
+
)
|
|
48
53
|
from sqlmesh.lsp.uri import URI
|
|
49
54
|
from web.server.api.endpoints.lineage import column_lineage, model_lineage
|
|
50
55
|
from web.server.api.endpoints.models import get_models
|
|
@@ -140,7 +145,7 @@ class SQLMeshLanguageServer:
|
|
|
140
145
|
|
|
141
146
|
try:
|
|
142
147
|
context = self._context_get_or_load(uri)
|
|
143
|
-
return
|
|
148
|
+
return LSPContext.get_completions(context, uri, content)
|
|
144
149
|
except Exception as e:
|
|
145
150
|
from sqlmesh.lsp.completions import get_sql_completions
|
|
146
151
|
|
|
@@ -368,7 +373,7 @@ class SQLMeshLanguageServer:
|
|
|
368
373
|
if not references:
|
|
369
374
|
return None
|
|
370
375
|
reference = references[0]
|
|
371
|
-
if not reference.markdown_description:
|
|
376
|
+
if isinstance(reference, LSPCteReference) or not reference.markdown_description:
|
|
372
377
|
return None
|
|
373
378
|
return types.Hover(
|
|
374
379
|
contents=types.MarkupContent(
|
|
@@ -418,8 +423,8 @@ class SQLMeshLanguageServer:
|
|
|
418
423
|
references = get_references(self.lsp_context, uri, params.position)
|
|
419
424
|
location_links = []
|
|
420
425
|
for reference in references:
|
|
421
|
-
# Use target_range if available (
|
|
422
|
-
if reference
|
|
426
|
+
# Use target_range if available (CTEs, Macros), otherwise default to start of file
|
|
427
|
+
if not isinstance(reference, LSPModelReference):
|
|
423
428
|
target_range = reference.target_range
|
|
424
429
|
target_selection_range = reference.target_range
|
|
425
430
|
else:
|
|
@@ -449,7 +454,7 @@ class SQLMeshLanguageServer:
|
|
|
449
454
|
def find_references(
|
|
450
455
|
ls: LanguageServer, params: types.ReferenceParams
|
|
451
456
|
) -> t.Optional[t.List[types.Location]]:
|
|
452
|
-
"""Find all references of a symbol (
|
|
457
|
+
"""Find all references of a symbol (supporting CTEs, models for now)"""
|
|
453
458
|
try:
|
|
454
459
|
uri = URI(params.text_document.uri)
|
|
455
460
|
self._ensure_context_for_document(uri)
|
|
@@ -457,10 +462,10 @@ class SQLMeshLanguageServer:
|
|
|
457
462
|
if self.lsp_context is None:
|
|
458
463
|
raise RuntimeError(f"No context found for document: {document.path}")
|
|
459
464
|
|
|
460
|
-
|
|
465
|
+
all_references = get_all_references(self.lsp_context, uri, params.position)
|
|
461
466
|
|
|
462
467
|
# Convert references to Location objects
|
|
463
|
-
locations = [types.Location(uri=ref.uri, range=ref.range) for ref in
|
|
468
|
+
locations = [types.Location(uri=ref.uri, range=ref.range) for ref in all_references]
|
|
464
469
|
|
|
465
470
|
return locations if locations else None
|
|
466
471
|
except Exception as e:
|
|
@@ -560,7 +565,10 @@ class SQLMeshLanguageServer:
|
|
|
560
565
|
)
|
|
561
566
|
return types.WorkspaceDiagnosticReport(items=[])
|
|
562
567
|
|
|
563
|
-
@self.server.feature(
|
|
568
|
+
@self.server.feature(
|
|
569
|
+
types.TEXT_DOCUMENT_COMPLETION,
|
|
570
|
+
types.CompletionOptions(trigger_characters=["@"]), # advertise "@" for macros
|
|
571
|
+
)
|
|
564
572
|
def completion(
|
|
565
573
|
ls: LanguageServer, params: types.CompletionParams
|
|
566
574
|
) -> t.Optional[types.CompletionList]:
|
|
@@ -578,7 +586,7 @@ class SQLMeshLanguageServer:
|
|
|
578
586
|
pass
|
|
579
587
|
|
|
580
588
|
# Get completions using the existing completions module
|
|
581
|
-
completion_response =
|
|
589
|
+
completion_response = LSPContext.get_completions(context, uri, content)
|
|
582
590
|
|
|
583
591
|
completion_items = []
|
|
584
592
|
# Add model completions
|
|
@@ -590,7 +598,26 @@ class SQLMeshLanguageServer:
|
|
|
590
598
|
detail="SQLMesh Model",
|
|
591
599
|
)
|
|
592
600
|
)
|
|
593
|
-
# Add
|
|
601
|
+
# Add macro completions
|
|
602
|
+
triggered_by_at = (
|
|
603
|
+
params.context is not None
|
|
604
|
+
and getattr(params.context, "trigger_character", None) == "@"
|
|
605
|
+
)
|
|
606
|
+
|
|
607
|
+
for macro_name in completion_response.macros:
|
|
608
|
+
insert_text = macro_name if triggered_by_at else f"@{macro_name}"
|
|
609
|
+
|
|
610
|
+
completion_items.append(
|
|
611
|
+
types.CompletionItem(
|
|
612
|
+
label=f"@{macro_name}",
|
|
613
|
+
insert_text=insert_text,
|
|
614
|
+
insert_text_format=types.InsertTextFormat.PlainText,
|
|
615
|
+
filter_text=macro_name,
|
|
616
|
+
kind=types.CompletionItemKind.Function,
|
|
617
|
+
detail="SQLMesh Macro",
|
|
618
|
+
)
|
|
619
|
+
)
|
|
620
|
+
|
|
594
621
|
for keyword in completion_response.keywords:
|
|
595
622
|
completion_items.append(
|
|
596
623
|
types.CompletionItem(
|
sqlmesh/lsp/reference.py
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
from lsprotocol.types import Range, Position
|
|
2
2
|
import typing as t
|
|
3
3
|
from pathlib import Path
|
|
4
|
+
from pydantic import Field
|
|
4
5
|
|
|
5
6
|
from sqlmesh.core.audit import StandaloneAudit
|
|
6
7
|
from sqlmesh.core.dialect import normalize_model_name
|
|
7
8
|
from sqlmesh.core.linter.helpers import (
|
|
8
9
|
TokenPositionDetails,
|
|
9
|
-
Range as SQLMeshRange,
|
|
10
|
-
Position as SQLMeshPosition,
|
|
11
10
|
)
|
|
12
11
|
from sqlmesh.core.model.definition import SqlModel
|
|
13
12
|
from sqlmesh.lsp.context import LSPContext, ModelTarget, AuditTarget
|
|
14
13
|
from sqlglot import exp
|
|
15
14
|
from sqlmesh.lsp.description import generate_markdown_description
|
|
16
15
|
from sqlglot.optimizer.scope import build_scope
|
|
16
|
+
|
|
17
|
+
from sqlmesh.lsp.helpers import to_lsp_range, to_lsp_position
|
|
17
18
|
from sqlmesh.lsp.uri import URI
|
|
18
19
|
from sqlmesh.utils.pydantic import PydanticModel
|
|
19
20
|
from sqlglot.optimizer.normalize_identifiers import normalize_identifiers
|
|
@@ -23,21 +24,37 @@ from sqlmesh import macro
|
|
|
23
24
|
import inspect
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
class
|
|
27
|
-
"""
|
|
28
|
-
A reference to a model or CTE.
|
|
27
|
+
class LSPModelReference(PydanticModel):
|
|
28
|
+
"""A LSP reference to a model."""
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
type: t.Literal["model"] = "model"
|
|
31
|
+
uri: str
|
|
32
|
+
range: Range
|
|
33
|
+
markdown_description: t.Optional[str] = None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class LSPCteReference(PydanticModel):
|
|
37
|
+
"""A LSP reference to a CTE."""
|
|
36
38
|
|
|
39
|
+
type: t.Literal["cte"] = "cte"
|
|
40
|
+
uri: str
|
|
37
41
|
range: Range
|
|
42
|
+
target_range: Range
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class LSPMacroReference(PydanticModel):
|
|
46
|
+
"""A LSP reference to a macro."""
|
|
47
|
+
|
|
48
|
+
type: t.Literal["macro"] = "macro"
|
|
38
49
|
uri: str
|
|
50
|
+
range: Range
|
|
51
|
+
target_range: Range
|
|
39
52
|
markdown_description: t.Optional[str] = None
|
|
40
|
-
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
Reference = t.Annotated[
|
|
56
|
+
t.Union[LSPModelReference, LSPCteReference, LSPMacroReference], Field(discriminator="type")
|
|
57
|
+
]
|
|
41
58
|
|
|
42
59
|
|
|
43
60
|
def by_position(position: Position) -> t.Callable[[Reference], bool]:
|
|
@@ -136,7 +153,7 @@ def get_model_definitions_for_a_path(
|
|
|
136
153
|
return []
|
|
137
154
|
|
|
138
155
|
# Find all possible references
|
|
139
|
-
references = []
|
|
156
|
+
references: t.List[Reference] = []
|
|
140
157
|
|
|
141
158
|
with open(file_path, "r", encoding="utf-8") as file:
|
|
142
159
|
read_file = file.readlines()
|
|
@@ -173,7 +190,7 @@ def get_model_definitions_for_a_path(
|
|
|
173
190
|
table_range = to_lsp_range(table_range_sqlmesh)
|
|
174
191
|
|
|
175
192
|
references.append(
|
|
176
|
-
|
|
193
|
+
LSPCteReference(
|
|
177
194
|
uri=document_uri.value, # Same file
|
|
178
195
|
range=table_range,
|
|
179
196
|
target_range=target_range,
|
|
@@ -227,7 +244,7 @@ def get_model_definitions_for_a_path(
|
|
|
227
244
|
description = generate_markdown_description(referenced_model)
|
|
228
245
|
|
|
229
246
|
references.append(
|
|
230
|
-
|
|
247
|
+
LSPModelReference(
|
|
231
248
|
uri=referenced_model_uri.value,
|
|
232
249
|
range=Range(
|
|
233
250
|
start=to_lsp_position(start_pos_sqlmesh),
|
|
@@ -286,7 +303,7 @@ def get_macro_definitions_for_a_path(
|
|
|
286
303
|
return []
|
|
287
304
|
|
|
288
305
|
references = []
|
|
289
|
-
|
|
306
|
+
_, config_path = lsp_context.context.config_for_path(
|
|
290
307
|
file_path,
|
|
291
308
|
)
|
|
292
309
|
|
|
@@ -372,7 +389,7 @@ def get_macro_reference(
|
|
|
372
389
|
# Create a reference to the macro definition
|
|
373
390
|
macro_uri = URI.from_path(path)
|
|
374
391
|
|
|
375
|
-
return
|
|
392
|
+
return LSPMacroReference(
|
|
376
393
|
uri=macro_uri.value,
|
|
377
394
|
range=to_lsp_range(macro_range),
|
|
378
395
|
target_range=Range(
|
|
@@ -405,7 +422,7 @@ def get_built_in_macro_reference(macro_name: str, macro_range: Range) -> t.Optio
|
|
|
405
422
|
# Calculate the end line number by counting the number of source lines
|
|
406
423
|
end_line_number = line_number + len(source_lines) - 1
|
|
407
424
|
|
|
408
|
-
return
|
|
425
|
+
return LSPMacroReference(
|
|
409
426
|
uri=URI.from_path(Path(filename)).value,
|
|
410
427
|
range=macro_range,
|
|
411
428
|
target_range=Range(
|
|
@@ -416,9 +433,99 @@ def get_built_in_macro_reference(macro_name: str, macro_range: Range) -> t.Optio
|
|
|
416
433
|
)
|
|
417
434
|
|
|
418
435
|
|
|
436
|
+
def get_model_find_all_references(
|
|
437
|
+
lint_context: LSPContext, document_uri: URI, position: Position
|
|
438
|
+
) -> t.List[LSPModelReference]:
|
|
439
|
+
"""
|
|
440
|
+
Get all references to a model across the entire project.
|
|
441
|
+
|
|
442
|
+
This function finds all usages of a model in other files by searching through
|
|
443
|
+
all models in the project and checking their dependencies.
|
|
444
|
+
|
|
445
|
+
Args:
|
|
446
|
+
lint_context: The LSP context
|
|
447
|
+
document_uri: The URI of the document
|
|
448
|
+
position: The position to check for model references
|
|
449
|
+
|
|
450
|
+
Returns:
|
|
451
|
+
A list of references to the model across all files
|
|
452
|
+
"""
|
|
453
|
+
# First, get the references in the current file to determine what model we're looking for
|
|
454
|
+
current_file_references = [
|
|
455
|
+
ref
|
|
456
|
+
for ref in get_model_definitions_for_a_path(lint_context, document_uri)
|
|
457
|
+
if isinstance(ref, LSPModelReference)
|
|
458
|
+
]
|
|
459
|
+
|
|
460
|
+
# Find the model reference at the cursor position
|
|
461
|
+
target_model_uri: t.Optional[str] = None
|
|
462
|
+
for ref in current_file_references:
|
|
463
|
+
if _position_within_range(position, ref.range):
|
|
464
|
+
# This is a model reference, get the target model URI
|
|
465
|
+
target_model_uri = ref.uri
|
|
466
|
+
break
|
|
467
|
+
|
|
468
|
+
if target_model_uri is None:
|
|
469
|
+
return []
|
|
470
|
+
|
|
471
|
+
# Start with the model definition
|
|
472
|
+
all_references: t.List[LSPModelReference] = [
|
|
473
|
+
LSPModelReference(
|
|
474
|
+
uri=ref.uri,
|
|
475
|
+
range=Range(
|
|
476
|
+
start=Position(line=0, character=0),
|
|
477
|
+
end=Position(line=0, character=0),
|
|
478
|
+
),
|
|
479
|
+
markdown_description=ref.markdown_description,
|
|
480
|
+
)
|
|
481
|
+
]
|
|
482
|
+
|
|
483
|
+
# Then add the original reference
|
|
484
|
+
for ref in current_file_references:
|
|
485
|
+
if ref.uri == target_model_uri and isinstance(ref, LSPModelReference):
|
|
486
|
+
all_references.append(
|
|
487
|
+
LSPModelReference(
|
|
488
|
+
uri=document_uri.value,
|
|
489
|
+
range=ref.range,
|
|
490
|
+
markdown_description=ref.markdown_description,
|
|
491
|
+
)
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
# Search through the models in the project
|
|
495
|
+
for path, target in lint_context.map.items():
|
|
496
|
+
if not isinstance(target, (ModelTarget, AuditTarget)):
|
|
497
|
+
continue
|
|
498
|
+
|
|
499
|
+
file_uri = URI.from_path(path)
|
|
500
|
+
|
|
501
|
+
# Skip current file, already processed
|
|
502
|
+
if file_uri.value == document_uri.value:
|
|
503
|
+
continue
|
|
504
|
+
|
|
505
|
+
# Get model references for this file
|
|
506
|
+
file_references = [
|
|
507
|
+
ref
|
|
508
|
+
for ref in get_model_definitions_for_a_path(lint_context, file_uri)
|
|
509
|
+
if isinstance(ref, LSPModelReference)
|
|
510
|
+
]
|
|
511
|
+
|
|
512
|
+
# Add references that point to the target model file
|
|
513
|
+
for ref in file_references:
|
|
514
|
+
if ref.uri == target_model_uri and isinstance(ref, LSPModelReference):
|
|
515
|
+
all_references.append(
|
|
516
|
+
LSPModelReference(
|
|
517
|
+
uri=file_uri.value,
|
|
518
|
+
range=ref.range,
|
|
519
|
+
markdown_description=ref.markdown_description,
|
|
520
|
+
)
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
return all_references
|
|
524
|
+
|
|
525
|
+
|
|
419
526
|
def get_cte_references(
|
|
420
527
|
lint_context: LSPContext, document_uri: URI, position: Position
|
|
421
|
-
) -> t.List[
|
|
528
|
+
) -> t.List[LSPCteReference]:
|
|
422
529
|
"""
|
|
423
530
|
Get all references to a CTE at a specific position in a document.
|
|
424
531
|
|
|
@@ -432,12 +539,12 @@ def get_cte_references(
|
|
|
432
539
|
Returns:
|
|
433
540
|
A list of references to the CTE (including its definition and all usages)
|
|
434
541
|
"""
|
|
435
|
-
references = get_model_definitions_for_a_path(lint_context, document_uri)
|
|
436
542
|
|
|
437
|
-
# Filter
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
543
|
+
# Filter to get the CTE references
|
|
544
|
+
cte_references: t.List[LSPCteReference] = [
|
|
545
|
+
ref
|
|
546
|
+
for ref in get_model_definitions_for_a_path(lint_context, document_uri)
|
|
547
|
+
if isinstance(ref, LSPCteReference)
|
|
441
548
|
]
|
|
442
549
|
|
|
443
550
|
if not cte_references:
|
|
@@ -450,7 +557,7 @@ def get_cte_references(
|
|
|
450
557
|
target_cte_definition_range = ref.target_range
|
|
451
558
|
break
|
|
452
559
|
# Check if cursor is on the CTE definition
|
|
453
|
-
elif
|
|
560
|
+
elif _position_within_range(position, ref.target_range):
|
|
454
561
|
target_cte_definition_range = ref.target_range
|
|
455
562
|
break
|
|
456
563
|
|
|
@@ -459,10 +566,10 @@ def get_cte_references(
|
|
|
459
566
|
|
|
460
567
|
# Add the CTE definition
|
|
461
568
|
matching_references = [
|
|
462
|
-
|
|
569
|
+
LSPCteReference(
|
|
463
570
|
uri=document_uri.value,
|
|
464
571
|
range=target_cte_definition_range,
|
|
465
|
-
|
|
572
|
+
target_range=target_cte_definition_range,
|
|
466
573
|
)
|
|
467
574
|
]
|
|
468
575
|
|
|
@@ -470,16 +577,44 @@ def get_cte_references(
|
|
|
470
577
|
for ref in cte_references:
|
|
471
578
|
if ref.target_range == target_cte_definition_range:
|
|
472
579
|
matching_references.append(
|
|
473
|
-
|
|
580
|
+
LSPCteReference(
|
|
474
581
|
uri=document_uri.value,
|
|
475
582
|
range=ref.range,
|
|
476
|
-
|
|
583
|
+
target_range=ref.target_range,
|
|
477
584
|
)
|
|
478
585
|
)
|
|
479
586
|
|
|
480
587
|
return matching_references
|
|
481
588
|
|
|
482
589
|
|
|
590
|
+
def get_all_references(
|
|
591
|
+
lint_context: LSPContext, document_uri: URI, position: Position
|
|
592
|
+
) -> t.Sequence[Reference]:
|
|
593
|
+
"""
|
|
594
|
+
Get all references of a symbol at a specific position in a document.
|
|
595
|
+
|
|
596
|
+
This function determines the type of reference (CTE, model for now) at the cursor
|
|
597
|
+
position and returns all references to that symbol across the project.
|
|
598
|
+
|
|
599
|
+
Args:
|
|
600
|
+
lint_context: The LSP context
|
|
601
|
+
document_uri: The URI of the document
|
|
602
|
+
position: The position to check for references
|
|
603
|
+
|
|
604
|
+
Returns:
|
|
605
|
+
A list of references to the symbol at the given position
|
|
606
|
+
"""
|
|
607
|
+
# First try CTE references (within same file)
|
|
608
|
+
if cte_references := get_cte_references(lint_context, document_uri, position):
|
|
609
|
+
return cte_references
|
|
610
|
+
|
|
611
|
+
# Then try model references (across files)
|
|
612
|
+
if model_references := get_model_find_all_references(lint_context, document_uri, position):
|
|
613
|
+
return model_references
|
|
614
|
+
|
|
615
|
+
return []
|
|
616
|
+
|
|
617
|
+
|
|
483
618
|
def _position_within_range(position: Position, range: Range) -> bool:
|
|
484
619
|
"""Check if a position is within a given range."""
|
|
485
620
|
return (
|
|
@@ -489,24 +624,3 @@ def _position_within_range(position: Position, range: Range) -> bool:
|
|
|
489
624
|
range.end.line > position.line
|
|
490
625
|
or (range.end.line == position.line and range.end.character >= position.character)
|
|
491
626
|
)
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
def to_lsp_range(
|
|
495
|
-
range: SQLMeshRange,
|
|
496
|
-
) -> Range:
|
|
497
|
-
"""
|
|
498
|
-
Converts a SQLMesh Range to an LSP Range.
|
|
499
|
-
"""
|
|
500
|
-
return Range(
|
|
501
|
-
start=Position(line=range.start.line, character=range.start.character),
|
|
502
|
-
end=Position(line=range.end.line, character=range.end.character),
|
|
503
|
-
)
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
def to_lsp_position(
|
|
507
|
-
position: SQLMeshPosition,
|
|
508
|
-
) -> Position:
|
|
509
|
-
"""
|
|
510
|
-
Converts a SQLMesh Position to an LSP Position.
|
|
511
|
-
"""
|
|
512
|
-
return Position(line=position.line, character=position.character)
|
|
@@ -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=KfgTUJjeG5ywaHgAjhP6EdeZuF4EZOqNtxrzAhc-txM,530
|
|
3
3
|
sqlmesh/magics.py,sha256=gjzoxREb1XT8Yho_PQMlMqhhkLq_sEfBM8S3PTgxvWE,40337
|
|
4
4
|
sqlmesh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
sqlmesh/cicd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -159,13 +159,14 @@ sqlmesh/integrations/github/cicd/command.py,sha256=rNWb-aMOA9R23YumD5vPwR0PgPGGj
|
|
|
159
159
|
sqlmesh/integrations/github/cicd/config.py,sha256=tRhMZaLf1p6AWXvi67n85Q-lptJNGt1Wk_Jr61ytpiM,2104
|
|
160
160
|
sqlmesh/integrations/github/cicd/controller.py,sha256=IgUWK9orYSMiElO3GaL6Ja-osFgA7je3RDcLChWUi5s,43769
|
|
161
161
|
sqlmesh/lsp/api.py,sha256=LJdECSaEZoPbu_Xl4KscVG-WLt7_g4dY-zKGO68dH14,2162
|
|
162
|
-
sqlmesh/lsp/completions.py,sha256=
|
|
163
|
-
sqlmesh/lsp/context.py,sha256=
|
|
164
|
-
sqlmesh/lsp/custom.py,sha256=
|
|
162
|
+
sqlmesh/lsp/completions.py,sha256=dsGE8f6RWNjOPvs80QdTvv1YaKo1bbTJ5ZzQmnNcpbA,6184
|
|
163
|
+
sqlmesh/lsp/context.py,sha256=QGbNL0sifxzVJ7T1U5oWcJ5FXrOrLrVKt1jtH1qM_50,6099
|
|
164
|
+
sqlmesh/lsp/custom.py,sha256=40ekRrcsJ-lsF4-uPs4mo8CFegTWK_zKzi4am_NO9oo,2196
|
|
165
165
|
sqlmesh/lsp/description.py,sha256=4QIGC9ix8IzmWF6DVUNhY4m1Crk3sNQA6hZ1RbyqU78,827
|
|
166
|
+
sqlmesh/lsp/helpers.py,sha256=igzUgeYAO3LUZFr3qN4l9hzztOy66lRubX93KtCMduY,654
|
|
166
167
|
sqlmesh/lsp/hints.py,sha256=j-blccBUil94yRoDjWfkSM0HqMmsKD6hP2TaWdWWVk4,3734
|
|
167
|
-
sqlmesh/lsp/main.py,sha256=
|
|
168
|
-
sqlmesh/lsp/reference.py,sha256=
|
|
168
|
+
sqlmesh/lsp/main.py,sha256=QpwMayubrXIgapAWuiGtkW_RTrcvvo_8qA8-IpGVG0I,36375
|
|
169
|
+
sqlmesh/lsp/reference.py,sha256=hHkSdnlcdoMO5nAhrpY1Ui-hRJ_SqX_5YqRGV192nPQ,21525
|
|
169
170
|
sqlmesh/lsp/uri.py,sha256=mvSLbZGmMTHPpliThOtVWiFcHnfJzp1w39q9l-xD2SI,802
|
|
170
171
|
sqlmesh/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
171
172
|
sqlmesh/migrations/v0001_init.py,sha256=h8FwMYJj9_O8yGpk12guaSaGwX5A3we2GiKeHrXi15o,2048
|
|
@@ -274,7 +275,7 @@ sqlmesh/utils/pydantic.py,sha256=I898jAFqa3qU6lG2uPpRebVFncOUo8ZrLWM_R3K3DHU,116
|
|
|
274
275
|
sqlmesh/utils/rich.py,sha256=xNZyPCqEc4TAlJlsEthg-5eYUWpaizz0QjBzO7a1Yv4,1509
|
|
275
276
|
sqlmesh/utils/windows.py,sha256=r7Yin4WEwbvH7sKA3hOJtRsclmscNuBeCklCfVPvtQs,611
|
|
276
277
|
sqlmesh/utils/yaml.py,sha256=np-WVcwmwsKghCgAj1OBBMsK1SXSRn4wR-H37cGiFr8,2282
|
|
277
|
-
sqlmesh-0.189.3.
|
|
278
|
+
sqlmesh-0.189.3.dev16.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
|
|
278
279
|
web/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
279
280
|
web/client/dist/index.html,sha256=OVPMTMsqC8zy0qnBcMb7PpVcqTHdIJoCmJLYh7gC1Xs,5472
|
|
280
281
|
web/client/dist/assets/Audits-Bvr7M5Cg.js,sha256=GrigkyEVYbM5zy0PAjOXdqmVV0kL-STP5gFQmx35vhw,1041
|
|
@@ -392,8 +393,8 @@ web/server/api/endpoints/models.py,sha256=ud-lRwriyI_OYg9tZchrBgeiXELiRTLNEodraf
|
|
|
392
393
|
web/server/api/endpoints/modules.py,sha256=8hqqgonGay_mJmpCw0IdbjsPhWlQH2VLdKAqha-myac,468
|
|
393
394
|
web/server/api/endpoints/plan.py,sha256=OYuQ_4dgbhG9ibTcX1a8mvYgH3ANxw9Fhbb4wg6QWqc,9222
|
|
394
395
|
web/server/api/endpoints/table_diff.py,sha256=SCy3-pr5x6bEEiOaZGCDbiHQhpgxwmnz3Acqa2Ie6jI,2090
|
|
395
|
-
sqlmesh-0.189.3.
|
|
396
|
-
sqlmesh-0.189.3.
|
|
397
|
-
sqlmesh-0.189.3.
|
|
398
|
-
sqlmesh-0.189.3.
|
|
399
|
-
sqlmesh-0.189.3.
|
|
396
|
+
sqlmesh-0.189.3.dev16.dist-info/METADATA,sha256=v0_guwqYg2fdwDYdVgmVV6SBmXvvr-AWIJ_LuVA8mQY,26541
|
|
397
|
+
sqlmesh-0.189.3.dev16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
398
|
+
sqlmesh-0.189.3.dev16.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
|
|
399
|
+
sqlmesh-0.189.3.dev16.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
|
|
400
|
+
sqlmesh-0.189.3.dev16.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|