4646 FormatProjectResponse ,
4747 CustomMethod ,
4848)
49+ from sqlmesh .lsp .errors import ContextFailedError , contextErrorToDiagnostic
4950from sqlmesh .lsp .hints import get_hints
5051from sqlmesh .lsp .reference import (
5152 LSPCteReference ,
5657)
5758from sqlmesh .lsp .rename import prepare_rename , rename_symbol , get_document_highlights
5859from sqlmesh .lsp .uri import URI
59- from sqlmesh .utils .errors import ConfigError
60+ from sqlmesh .utils .errors import ConfigError , ModelBlockFieldValidationMissingFieldsError , ModeBlockExtraFields
6061from web .server .api .endpoints .lineage import column_lineage , model_lineage
6162from web .server .api .endpoints .models import get_models
6263from typing import Union
@@ -77,9 +78,6 @@ class ContextLoaded:
7778 lsp_context : LSPContext
7879
7980
80- type ContextFailedError = str | ConfigError
81-
82-
8381@dataclass
8482class ContextFailed :
8583 """State when context failed to load with an error message."""
@@ -324,7 +322,9 @@ def initialize(ls: LanguageServer, params: types.InitializeParams) -> None:
324322 ls .show_message ("Client supports pull diagnostics" , types .MessageType .Info )
325323 else :
326324 self .client_supports_pull_diagnostics = False
327- ls .show_message ("Client does not support pull diagnostics" , types .MessageType .Info )
325+ ls .show_message (
326+ "Client does not support pull diagnostics" , types .MessageType .Info
327+ )
328328 else :
329329 self .client_supports_pull_diagnostics = False
330330 ls .show_message ("Client capabilities not available" , types .MessageType .Info )
@@ -357,7 +357,7 @@ def did_open(ls: LanguageServer, params: types.DidOpenTextDocumentParams) -> Non
357357 uri = URI (params .text_document .uri )
358358 try :
359359 context = self ._context_get_or_load (ls , uri )
360-
360+
361361 # Only publish diagnostics if client doesn't support pull diagnostics
362362 if not self .client_supports_pull_diagnostics :
363363 diagnostics = context .lint_model (uri )
@@ -894,30 +894,9 @@ def _create_lsp_context(
894894 return self .context_state .lsp_context
895895 except Exception as e :
896896 # Only show the error message once
897- if not self .has_raised_loading_error :
898- location_info = f" at { e .location } " if isinstance (e , ConfigError ) and e .location else ""
899- self .server .show_message (
900- f"Error creating context error type { type (e )} : { e } { location_info } " ,
901- types .MessageType .Error ,
902- )
903- self .has_raised_loading_error = True
904- error_message = e if isinstance (e , ConfigError ) else str (e )
905- if isinstance (e , ConfigError ) and e .location is not None :
906- uri = URI .from_path (e .location )
907- ls .show_message (f"Publishing diagnostic to URI: { uri .value } " , types .MessageType .Info )
908- ls .publish_diagnostics (
909- uri .value ,
910- [
911- types .Diagnostic (
912- range = types .Range (
913- start = types .Position (line = 0 , character = 0 ),
914- end = types .Position (line = 0 , character = 0 ),
915- ),
916- message = str (error_message ),
917- severity = types .DiagnosticSeverity .Error ,
918- )
919- ],
920- )
897+ (uri , diagnostic ), error = contextErrorToDiagnostic (e )
898+ if diagnostic :
899+ ls .publish_diagnostics (uri , [diagnostic ])
921900
922901 # Store the error in context state such that later requests can
923902 # show the actual error. Try to preserve any partially loaded context
@@ -927,7 +906,7 @@ def _create_lsp_context(
927906 context = self .context_state .lsp_context .context
928907 elif isinstance (self .context_state , ContextFailed ) and self .context_state .context :
929908 context = self .context_state .context
930- self .context_state = ContextFailed (error_message = error_message , context = context )
909+ self .context_state = ContextFailed (error_message = error , context = context )
931910 return None
932911
933912 @staticmethod
0 commit comments