MCPcopy Create free account
hub / github.com/FSoft-AI4Code/HyperAgent / SyncLanguageServer

Class SyncLanguageServer

src/hyperagent/multilspy/language_server.py:642–813  ·  view source on GitHub ↗

The SyncLanguageServer class provides a language agnostic interface to the Language Server Protocol. It is used to communicate with Language Servers of different programming languages.

Source from the content-addressed store, hash-verified

640
641@ensure_all_methods_implemented(LanguageServer)
642class SyncLanguageServer:
643 """
644 The SyncLanguageServer class provides a language agnostic interface to the Language Server Protocol.
645 It is used to communicate with Language Servers of different programming languages.
646 """
647
648 def __init__(self, language_server: LanguageServer) -> None:
649 self.language_server = language_server
650 self.loop = None
651 self.loop_thread = None
652
653 @classmethod
654 def create(
655 cls, config: MultilspyConfig, logger: MultilspyLogger, repository_root_path: str
656 ) -> "SyncLanguageServer":
657 """
658 Creates a language specific LanguageServer instance based on the given configuration, and appropriate settings for the programming language.
659
660 If language is Java, then ensure that jdk-17.0.6 or higher is installed, `java` is in PATH, and JAVA_HOME is set to the installation directory.
661
662 :param repository_root_path: The root path of the repository.
663 :param config: The Multilspy configuration.
664 :param logger: The logger to use.
665
666 :return SyncLanguageServer: A language specific LanguageServer instance.
667 """
668 return SyncLanguageServer(LanguageServer.create(config, logger, repository_root_path))
669
670 @contextmanager
671 def open_file(self, relative_file_path: str) -> Iterator[None]:
672 """
673 Open a file in the Language Server. This is required before making any requests to the Language Server.
674
675 :param relative_file_path: The relative path of the file to open.
676 """
677 with self.language_server.open_file(relative_file_path):
678 yield
679
680 def insert_text_at_position(
681 self, relative_file_path: str, line: int, column: int, text_to_be_inserted: str
682 ) -> multilspy_types.Position:
683 """
684 Insert text at the given line and column in the given file and return
685 the updated cursor position after inserting the text.
686
687 :param relative_file_path: The relative path of the file to open.
688 :param line: The line number at which text should be inserted.
689 :param column: The column number at which text should be inserted.
690 :param text_to_be_inserted: The text to insert.
691 """
692 return self.language_server.insert_text_at_position(relative_file_path, line, column, text_to_be_inserted)
693
694 def delete_text_between_positions(
695 self,
696 relative_file_path: str,
697 start: multilspy_types.Position,
698 end: multilspy_types.Position,
699 ) -> str:

Callers 1

createMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected