@@ -368,43 +368,45 @@ def function_call(ls: LanguageServer, params: t.Any) -> t.Dict[str, t.Any]:
368368
369369 self .server .feature (name )(create_function_call (method ))
370370
371- @self .server .command (EXTERNAL_MODEL_UPDATE_COLUMNS )
372- def command_external_models_update_columns (ls : LanguageServer , raw : t .Any ) -> None :
373- try :
374- if not isinstance (raw , list ):
375- raise ValueError ("Invalid command parameters" )
376- if len (raw ) != 1 :
377- raise ValueError ("Command expects exactly one parameter" )
378- model_name = raw [0 ]
379- if not isinstance (model_name , str ):
380- raise ValueError ("Command parameter must be a string" )
381-
382- context = self ._context_get_or_load ()
383- if not isinstance (context , LSPContext ):
384- raise ValueError ("Context is not loaded or invalid" )
385- model = context .context .get_model (model_name )
386- if model is None :
387- raise ValueError (f"External model '{ model_name } ' not found" )
388- if model ._path is None :
389- raise ValueError (f"External model '{ model_name } ' does not have a file path" )
390- uri = URI .from_path (model ._path )
391- updated = context .update_external_model_columns (
392- ls = ls ,
393- uri = uri ,
394- model_name = model_name ,
395- )
396- if updated :
397- ls .show_message (
398- f"Updated columns for '{ model_name } '" ,
399- types .MessageType .Info ,
400- )
401- else :
402- ls .show_message (
403- f"Columns for '{ model_name } ' are already up to date" ,
371+ # Check if command is already registered to prevent duplicate registration errors
372+ if EXTERNAL_MODEL_UPDATE_COLUMNS not in getattr (self .server , '_commands' , {}):
373+ @self .server .command (EXTERNAL_MODEL_UPDATE_COLUMNS )
374+ def command_external_models_update_columns (ls : LanguageServer , raw : t .Any ) -> None :
375+ try :
376+ if not isinstance (raw , list ):
377+ raise ValueError ("Invalid command parameters" )
378+ if len (raw ) != 1 :
379+ raise ValueError ("Command expects exactly one parameter" )
380+ model_name = raw [0 ]
381+ if not isinstance (model_name , str ):
382+ raise ValueError ("Command parameter must be a string" )
383+
384+ context = self ._context_get_or_load ()
385+ if not isinstance (context , LSPContext ):
386+ raise ValueError ("Context is not loaded or invalid" )
387+ model = context .context .get_model (model_name )
388+ if model is None :
389+ raise ValueError (f"External model '{ model_name } ' not found" )
390+ if model ._path is None :
391+ raise ValueError (f"External model '{ model_name } ' does not have a file path" )
392+ uri = URI .from_path (model ._path )
393+ updated = context .update_external_model_columns (
394+ ls = ls ,
395+ uri = uri ,
396+ model_name = model_name ,
404397 )
405- except Exception as e :
406- ls .show_message (f"Error executing command: { e } " , types .MessageType .Error )
407- return None
398+ if updated :
399+ ls .show_message (
400+ f"Updated columns for '{ model_name } '" ,
401+ types .MessageType .Info ,
402+ )
403+ else :
404+ ls .show_message (
405+ f"Columns for '{ model_name } ' are already up to date" ,
406+ )
407+ except Exception as e :
408+ ls .show_message (f"Error executing command: { e } " , types .MessageType .Error )
409+ return None
408410
409411 @self .server .feature (types .INITIALIZE )
410412 def initialize (ls : LanguageServer , params : types .InitializeParams ) -> None :
0 commit comments