pub struct VscodeServerManager { /* private fields */ }
Expand description
Manages the lifecycle of a VSCode server instance.
This struct is the primary entry point for interacting with the server. It handles downloading (if not embedded and not already present), starting, stopping, and querying the state of the VSCode server.
Instances are typically created using VscodeServerManager::new()
or VscodeServerManager::with_config()
.
The server process is cleaned up when the VscodeServerManager
instance is dropped.
Implementations§
Source§impl VscodeServerManager
impl VscodeServerManager
Sourcepub async fn new() -> Result<Self, ServerError>
pub async fn new() -> Result<Self, ServerError>
Creates a new VscodeServerManager
with default configuration.
This is an asynchronous operation as it may involve initial setup.
§Errors
Currently, this constructor does not return errors but is async
for future compatibility
and consistency with with_config
.
Sourcepub async fn with_config(config: ServerConfig) -> Result<Self, ServerError>
pub async fn with_config(config: ServerConfig) -> Result<Self, ServerError>
Sourcepub async fn ensure_server(&mut self) -> Result<(), ServerError>
pub async fn ensure_server(&mut self) -> Result<(), ServerError>
Ensures that the VSCode server is available, downloading it if necessary.
This method performs the following steps:
- If the
embed
feature is enabled, it first tries to extract an embedded server. - If no embedded server is found or the feature is disabled, it attempts to detect the latest compatible VSCode server version.
- It checks if this version is already present in the configured
server_dir
. - If not present, it downloads and extracts the server.
This method must be called before start()
if the server’s presence is not guaranteed.
It is an asynchronous operation due to potential network I/O.
§Errors
Returns ServerError
if:
- Version detection fails (
ServerError::VersionDetectionFailed
). - Downloading fails (
ServerError::Network
,ServerError::DownloadFailed
). - Extraction fails (
ServerError::ExtractionFailed
,ServerError::Io
). - The platform is unsupported (
ServerError::UnsupportedPlatform
).
Sourcepub async fn start(&self) -> Result<(), ServerError>
pub async fn start(&self) -> Result<(), ServerError>
Starts the VSCode server process.
Before calling start
, ensure_server
should typically be called to make sure
the server binaries are available.
The server will be started with the configuration provided during the manager’s creation.
This is an asynchronous operation.
§Errors
Returns ServerError
if:
- The server is already running (
ServerError::AlreadyRunning
). - The server path has not been determined (e.g.,
ensure_server
was not called) (ServerError::ServerNotFound
). - The server executable cannot be found at the expected path (
ServerError::ServerNotFound
). - The server process fails to start (
ServerError::StartFailed
,ServerError::Io
).
Sourcepub async fn stop(&self) -> Result<(), ServerError>
pub async fn stop(&self) -> Result<(), ServerError>
Stops the VSCode server process if it is running.
This is an asynchronous operation.
§Errors
Returns ServerError::NotRunning
if the server was not running.
May return ServerError::Io
if there’s an issue killing the process, though this is rare.
Sourcepub async fn is_running(&self) -> bool
pub async fn is_running(&self) -> bool
Checks if the VSCode server process is currently running.
This method checks the status of the underlying process. It is an asynchronous operation as it involves locking the process state.
Sourcepub fn url(&self) -> String
pub fn url(&self) -> String
Returns the URL (host and port) where the server is expected to be listening.
This is constructed from the host
and port
in the ServerConfig
.
It does not guarantee that the server is actually listening on this URL, only that
this is its configured address.
Sourcepub fn info(&self) -> Option<&ServerInfo>
pub fn info(&self) -> Option<&ServerInfo>
Returns a reference to the ServerInfo
if the server version has been determined
(e.g., after ensure_server
has been called).
Returns None
if server information is not yet available.
Sourcepub fn config(&self) -> &ServerConfig
pub fn config(&self) -> &ServerConfig
Returns a reference to the current ServerConfig
.