2424from sqlmesh .lsp .context import (
2525 LSPContext ,
2626 ModelTarget ,
27- render_model as render_model_context ,
2827)
2928from sqlmesh .lsp .custom import (
3029 ALL_MODELS_FEATURE ,
@@ -58,10 +57,6 @@ def __init__(
5857 self .context_class = context_class
5958 self .lsp_context : t .Optional [LSPContext ] = None
6059
61- # Cache stores tuples of (diagnostics, diagnostic_version)
62- self .lint_cache : t .Dict [URI , t .Tuple [t .List [AnnotatedRuleViolation ], int ]] = {}
63- self ._diagnostic_version_counter : int = 0
64-
6560 self .client_supports_pull_diagnostics = False
6661 # Register LSP features (e.g., formatting, hover, etc.)
6762 self ._register_features ()
@@ -120,7 +115,7 @@ def all_models(ls: LanguageServer, params: AllModelsRequest) -> AllModelsRespons
120115 def render_model (ls : LanguageServer , params : RenderModelRequest ) -> RenderModelResponse :
121116 uri = URI (params .textDocumentUri )
122117 context = self ._context_get_or_load (uri )
123- return RenderModelResponse (models = list ( render_model_context ( context , uri ) ))
118+ return RenderModelResponse (models = context . render_model ( uri ))
124119
125120 @self .server .feature (API_FEATURE )
126121 def api (ls : LanguageServer , request : ApiRequest ) -> t .Dict [str , t .Any ]:
@@ -173,17 +168,11 @@ def did_open(ls: LanguageServer, params: types.DidOpenTextDocumentParams) -> Non
173168 if models is None or not isinstance (models , ModelTarget ):
174169 return
175170
176- if self .lint_cache .get (uri ) is None :
177- diagnostics = context .context .lint_models (
178- models .names ,
179- raise_on_error = False ,
180- )
181- self ._diagnostic_version_counter += 1
182- self .lint_cache [uri ] = (diagnostics , self ._diagnostic_version_counter )
171+ # Get diagnostics from context (which handles caching)
172+ diagnostics = context .lint_model (uri )
183173
184174 # Only publish diagnostics if client doesn't support pull diagnostics
185175 if not self .client_supports_pull_diagnostics :
186- diagnostics , _ = self .lint_cache [uri ]
187176 ls .publish_diagnostics (
188177 params .text_document .uri ,
189178 SQLMeshLanguageServer ._diagnostics_to_lsp_diagnostics (diagnostics ),
@@ -197,13 +186,8 @@ def did_change(ls: LanguageServer, params: types.DidChangeTextDocumentParams) ->
197186 if models is None or not isinstance (models , ModelTarget ):
198187 return
199188
200- # Always update the cache
201- diagnostics = context .context .lint_models (
202- models .names ,
203- raise_on_error = False ,
204- )
205- self ._diagnostic_version_counter += 1
206- self .lint_cache [uri ] = (diagnostics , self ._diagnostic_version_counter )
189+ # Get diagnostics from context (which handles caching)
190+ diagnostics = context .lint_model (uri )
207191
208192 # Only publish diagnostics if client doesn't support pull diagnostics
209193 if not self .client_supports_pull_diagnostics :
@@ -220,13 +204,8 @@ def did_save(ls: LanguageServer, params: types.DidSaveTextDocumentParams) -> Non
220204 if models is None or not isinstance (models , ModelTarget ):
221205 return
222206
223- # Always update the cache
224- diagnostics = context .context .lint_models (
225- models .names ,
226- raise_on_error = False ,
227- )
228- self ._diagnostic_version_counter += 1
229- self .lint_cache [uri ] = (diagnostics , self ._diagnostic_version_counter )
207+ # Get diagnostics from context (which handles caching)
208+ diagnostics = context .lint_model (uri )
230209
231210 # Only publish diagnostics if client doesn't support pull diagnostics
232211 if not self .client_supports_pull_diagnostics :
@@ -445,31 +424,16 @@ def workspace_diagnostic(
445424 return types .WorkspaceDiagnosticReport (items = [])
446425
447426 def _get_diagnostics_for_uri (self , uri : URI ) -> t .Tuple [t .List [types .Diagnostic ], int ]:
448- """Get diagnostics for a specific URI, returning (diagnostics, result_id)."""
449- # Check if we have cached diagnostics
450- if uri in self .lint_cache :
451- diagnostics , result_id = self .lint_cache [uri ]
452- return SQLMeshLanguageServer ._diagnostics_to_lsp_diagnostics (diagnostics ), result_id
427+ """Get diagnostics for a specific URI, returning (diagnostics, result_id).
453428
454- # Try to get diagnostics by loading context and linting
429+ Since we no longer track version numbers, we always return 0 as the result_id.
430+ This means pull diagnostics will always fetch fresh results.
431+ """
455432 try :
456433 context = self ._context_get_or_load (uri )
457- models = context .map [uri .to_path ()]
458- if models is None or not isinstance (models , ModelTarget ):
459- return [], 0
460-
461- # Lint the models and cache the results
462- diagnostics = context .context .lint_models (
463- models .names ,
464- raise_on_error = False ,
465- )
466- self ._diagnostic_version_counter += 1
467- self .lint_cache [uri ] = (diagnostics , self ._diagnostic_version_counter )
468- return SQLMeshLanguageServer ._diagnostics_to_lsp_diagnostics (
469- diagnostics
470- ), self ._diagnostic_version_counter
434+ diagnostics = context .lint_model (uri )
435+ return SQLMeshLanguageServer ._diagnostics_to_lsp_diagnostics (diagnostics ), 0
471436 except Exception :
472- # If we can't get diagnostics, return empty list with no result ID
473437 return [], 0
474438
475439 def _context_get_or_load (self , document_uri : URI ) -> LSPContext :
@@ -523,7 +487,7 @@ def _ensure_context_for_document(
523487 created_context = self .context_class (paths = [path ])
524488 self .lsp_context = LSPContext (created_context )
525489 loaded = True
526- # Re-check context for document now that it's loaded
490+ # Re-check context for the document now that it's loaded
527491 return self ._ensure_context_for_document (document_uri )
528492 except Exception as e :
529493 self .server .show_message (
0 commit comments