1212from sqlmesh .core .context import Context
1313from sqlmesh .core .linter .definition import AnnotatedRuleViolation
1414from sqlmesh .lsp .context import LSPContext
15+ from sqlmesh .lsp .custom import ALL_MODELS_FEATURE , AllModelsRequest , AllModelsResponse
1516from sqlmesh .lsp .reference import get_model_definitions_for_a_path
1617
1718
@@ -38,6 +39,12 @@ def __init__(
3839 def _register_features (self ) -> None :
3940 """Register LSP features on the internal LanguageServer instance."""
4041
42+ @self .server .feature (ALL_MODELS_FEATURE )
43+ def all_models (ls : LanguageServer , params : AllModelsRequest ) -> AllModelsResponse :
44+ context = self ._context_get_or_load (params .textDocument .uri )
45+ models = context .context .models
46+ return AllModelsResponse (models = [model .name for model in models .values ()])
47+
4148 @self .server .feature (types .TEXT_DOCUMENT_DID_OPEN )
4249 def did_open (ls : LanguageServer , params : types .DidOpenTextDocumentParams ) -> None :
4350 context = self ._context_get_or_load (params .text_document .uri )
@@ -130,43 +137,6 @@ def formatting(
130137 ls .show_message (f"Error formatting SQL: { e } " , types .MessageType .Error )
131138 return []
132139
133- @self .server .feature (types .TEXT_DOCUMENT_DEFINITION )
134- def goto_definition (
135- ls : LanguageServer , params : types .DefinitionParams
136- ) -> t .List [types .LocationLink ]:
137- """Jump to an object's definition."""
138- try :
139- self ._ensure_context_for_document (params .text_document .uri )
140- document = ls .workspace .get_document (params .text_document .uri )
141- if self .lsp_context is None :
142- raise RuntimeError (f"No context found for document: { document .path } " )
143-
144- references = get_model_definitions_for_a_path (
145- self .lsp_context , params .text_document .uri
146- )
147- if len (references ) == 0 :
148- return []
149-
150- return [
151- types .LocationLink (
152- target_uri = reference .uri ,
153- target_selection_range = types .Range (
154- start = types .Position (line = 0 , character = 0 ),
155- end = types .Position (line = 0 , character = 0 ),
156- ),
157- target_range = types .Range (
158- start = types .Position (line = 0 , character = 0 ),
159- end = types .Position (line = 0 , character = 0 ),
160- ),
161- origin_selection_range = reference .range ,
162- )
163- for reference in references
164- ]
165-
166- except Exception as e :
167- ls .show_message (f"Error formatting SQL: { e } " , types .MessageType .Error )
168- return []
169-
170140 @self .server .feature (types .TEXT_DOCUMENT_DEFINITION )
171141 def goto_definition (
172142 ls : LanguageServer , params : types .DefinitionParams
0 commit comments