@@ -83,6 +83,10 @@ def get_references(
8383 macro_references = get_macro_definitions_for_a_path (lint_context , document_uri )
8484 references .extend (macro_references )
8585
86+ # Get single variable references
87+ variable_references = get_macro_variables_definitions (lint_context , document_uri )
88+ references .extend (variable_references )
89+
8690 filtered_references = list (filter (by_position (position ), references ))
8791 return filtered_references
8892
@@ -478,3 +482,41 @@ def get_built_in_macro_reference(macro_name: str, macro_range: Range) -> t.Optio
478482 ),
479483 markdown_description = func .__doc__ if func .__doc__ else None ,
480484 )
485+
486+
487+ def get_macro_variables_definitions (
488+ lsp_context : LSPContext , document_uri : URI
489+ ) -> t .List [Reference ]:
490+ """
491+ Get references to all macro variables.
492+
493+ This function returns a list of references to all macro variables defined in the SQLMesh
494+ environment. It is used for autocompletion and hover information in the LSP.
495+ """
496+ references : t .List [Reference ] = []
497+ path = document_uri .to_path ()
498+
499+ file_info = lsp_context .map [path ]
500+ # Process based on whether it's a model or standalone audit
501+ if isinstance (file_info , ModelTarget ):
502+ # It's a model
503+ target : t .Optional [t .Union [Model , StandaloneAudit ]] = lsp_context .context .get_model (
504+ model_or_snapshot = file_info .names [0 ], raise_if_missing = False
505+ )
506+ if target is None or not isinstance (target , SqlModel ):
507+ return []
508+ query = target .query
509+ file_path = target ._path
510+ elif isinstance (file_info , AuditTarget ):
511+ # It's a standalone audit
512+ target = lsp_context .context .standalone_audits .get (file_info .name )
513+ if target is None :
514+ return []
515+ query = target .query
516+ file_path = target ._path
517+ else :
518+ return []
519+
520+
521+
522+ return references
0 commit comments