@@ -524,9 +524,16 @@ def __init__(self, lang_server: SyncLanguageServer, agent: Union["SerenaAgent",
524524 :param agent: the agent to use (only needed for marking files as modified). You can pass None if you don't
525525 need an agent to be avare of file modifications performed by the symbol manager.
526526 """
527- self .lang_server = lang_server
527+ self ._lang_server = lang_server
528528 self .agent = agent
529529
530+ def set_language_server (self , lang_server : SyncLanguageServer ) -> None :
531+ """
532+ Set the language server to use for symbol retrieval and editing operations.
533+ This is useful if you want to change the language server after initializing the SymbolManager.
534+ """
535+ self ._lang_server = lang_server
536+
530537 def find_by_name (
531538 self ,
532539 name_path : str ,
@@ -542,7 +549,7 @@ def find_by_name(
542549 to symbols within a specific file or directory.
543550 """
544551 symbols : list [Symbol ] = []
545- symbol_roots = self .lang_server .request_full_symbol_tree (within_relative_path = within_relative_path , include_body = include_body )
552+ symbol_roots = self ._lang_server .request_full_symbol_tree (within_relative_path = within_relative_path , include_body = include_body )
546553 for root in symbol_roots :
547554 symbols .extend (
548555 Symbol (root ).find (
@@ -552,14 +559,14 @@ def find_by_name(
552559 return symbols
553560
554561 def get_document_symbols (self , relative_path : str ) -> list [Symbol ]:
555- symbol_dicts , roots = self .lang_server .request_document_symbols (relative_path , include_body = False )
562+ symbol_dicts , roots = self ._lang_server .request_document_symbols (relative_path , include_body = False )
556563 symbols = [Symbol (s ) for s in symbol_dicts ]
557564 return symbols
558565
559566 def find_by_location (self , location : SymbolLocation ) -> Symbol | None :
560567 if location .relative_path is None :
561568 return None
562- symbol_dicts , roots = self .lang_server .request_document_symbols (location .relative_path , include_body = False )
569+ symbol_dicts , roots = self ._lang_server .request_document_symbols (location .relative_path , include_body = False )
563570 for symbol_dict in symbol_dicts :
564571 symbol = Symbol (symbol_dict )
565572 if symbol .location == location :
@@ -628,7 +635,7 @@ def find_referencing_symbols_by_location(
628635 assert symbol_location .relative_path is not None
629636 assert symbol_location .line is not None
630637 assert symbol_location .column is not None
631- references = self .lang_server .request_referencing_symbols (
638+ references = self ._lang_server .request_referencing_symbols (
632639 relative_file_path = symbol_location .relative_path ,
633640 line = symbol_location .line ,
634641 column = symbol_location .column ,
@@ -648,9 +655,9 @@ def find_referencing_symbols_by_location(
648655
649656 @contextmanager
650657 def _edited_file (self , relative_path : str ) -> Iterator [None ]:
651- with self .lang_server .open_file (relative_path ) as file_buffer :
658+ with self ._lang_server .open_file (relative_path ) as file_buffer :
652659 yield
653- root_path = self .lang_server .language_server .repository_root_path
660+ root_path = self ._lang_server .language_server .repository_root_path
654661 abs_path = os .path .join (root_path , relative_path )
655662 with open (abs_path , "w" , encoding = "utf-8" ) as f :
656663 f .write (file_buffer .contents )
@@ -671,7 +678,7 @@ def _edited_symbol_location(self, location: SymbolLocation) -> Iterator[Symbol]:
671678
672679 def _get_code_file_content (self , relative_path : str ) -> str :
673680 """Get the content of a file using the language server."""
674- return self .lang_server .language_server .retrieve_full_file_content (relative_path )
681+ return self ._lang_server .language_server .retrieve_full_file_content (relative_path )
675682
676683 def replace_body (self , name_path : str , relative_file_path : str , body : str , * , use_same_indentation : bool = True ) -> None :
677684 """
@@ -720,8 +727,8 @@ def replace_body_at_location(self, location: SymbolLocation, body: str, *, use_s
720727 # make sure body always ends with at least one newline
721728 if not body .endswith ("\n " ):
722729 body += "\n "
723- self .lang_server .delete_text_between_positions (location .relative_path , start_pos , end_pos )
724- self .lang_server .insert_text_at_position (location .relative_path , start_line , start_col , body )
730+ self ._lang_server .delete_text_between_positions (location .relative_path , start_pos , end_pos )
731+ self ._lang_server .insert_text_at_position (location .relative_path , start_line , start_col , body )
725732
726733 def insert_after_symbol (
727734 self ,
@@ -804,7 +811,7 @@ def insert_after_symbol_at_location(
804811 col = 0
805812
806813 with self ._edited_symbol_location (location ):
807- self .lang_server .insert_text_at_position (location .relative_path , line = line , column = col , text_to_be_inserted = body )
814+ self ._lang_server .insert_text_at_position (location .relative_path , line = line , column = col , text_to_be_inserted = body )
808815
809816 def insert_before_symbol (
810817 self ,
@@ -857,7 +864,7 @@ def insert_before_symbol_at_location(
857864 body += "\n "
858865 assert location .relative_path is not None
859866
860- self .lang_server .insert_text_at_position (location .relative_path , line = line , column = col , text_to_be_inserted = body )
867+ self ._lang_server .insert_text_at_position (location .relative_path , line = line , column = col , text_to_be_inserted = body )
861868
862869 def insert_at_line (self , relative_path : str , line : int , content : str ) -> None :
863870 """
@@ -867,7 +874,7 @@ def insert_at_line(self, relative_path: str, line: int, content: str) -> None:
867874 :param content: the content to insert
868875 """
869876 with self ._edited_file (relative_path ):
870- self .lang_server .insert_text_at_position (relative_path , line , 0 , content )
877+ self ._lang_server .insert_text_at_position (relative_path , line , 0 , content )
871878
872879 def delete_lines (self , relative_path : str , start_line : int , end_line : int ) -> None :
873880 """
@@ -882,7 +889,7 @@ def delete_lines(self, relative_path: str, start_line: int, end_line: int) -> No
882889 with self ._edited_file (relative_path ):
883890 start_pos = Position (line = start_line , character = start_col )
884891 end_pos = Position (line = end_line_for_delete , character = end_col )
885- self .lang_server .delete_text_between_positions (relative_path , start_pos , end_pos )
892+ self ._lang_server .delete_text_between_positions (relative_path , start_pos , end_pos )
886893
887894 def delete_symbol_at_location (self , location : SymbolLocation ) -> None :
888895 """
@@ -892,7 +899,7 @@ def delete_symbol_at_location(self, location: SymbolLocation) -> None:
892899 assert location .relative_path is not None
893900 assert symbol .body_start_position is not None
894901 assert symbol .body_end_position is not None
895- self .lang_server .delete_text_between_positions (location .relative_path , symbol .body_start_position , symbol .body_end_position )
902+ self ._lang_server .delete_text_between_positions (location .relative_path , symbol .body_start_position , symbol .body_end_position )
896903
897904 def delete_symbol (self , name_path : str , relative_file_path : str ) -> None :
898905 """
0 commit comments