@@ -444,6 +444,50 @@ def workspace_diagnostic(
444444 )
445445 return types .WorkspaceDiagnosticReport (items = [])
446446
447+ @self .server .feature (types .TEXT_DOCUMENT_COMPLETION )
448+ def completion (
449+ ls : LanguageServer , params : types .CompletionParams
450+ ) -> t .Optional [types .CompletionList ]:
451+ """Handle completion requests from the client."""
452+ try :
453+ uri = URI (params .text_document .uri )
454+ context = self ._context_get_or_load (uri )
455+
456+ # Get completions using the existing completions module
457+ completion_response = get_sql_completions (context , uri )
458+
459+ # Convert to LSP completion items
460+ completion_items = []
461+
462+ # Add model completions
463+ for model in completion_response .models :
464+ completion_items .append (
465+ types .CompletionItem (
466+ label = model ,
467+ kind = types .CompletionItemKind .Reference ,
468+ detail = "SQLMesh Model" ,
469+ )
470+ )
471+
472+ # Add keyword completions
473+ for keyword in completion_response .keywords :
474+ completion_items .append (
475+ types .CompletionItem (
476+ label = keyword ,
477+ kind = types .CompletionItemKind .Keyword ,
478+ detail = "SQL Keyword" ,
479+ )
480+ )
481+
482+ return types .CompletionList (
483+ is_incomplete = False ,
484+ items = completion_items ,
485+ )
486+
487+ except Exception as e :
488+ ls .show_message (f"Error getting completions: { e } " , types .MessageType .Error )
489+ return None
490+
447491 def _get_diagnostics_for_uri (self , uri : URI ) -> t .Tuple [t .List [types .Diagnostic ], int ]:
448492 """Get diagnostics for a specific URI, returning (diagnostics, result_id)."""
449493 # Check if we have cached diagnostics
0 commit comments