Struct VscodeServerManager

Source
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

Source

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.

Source

pub async fn with_config(config: ServerConfig) -> Result<Self, ServerError>

Creates a new VscodeServerManager with the specified configuration.

This is an asynchronous operation.

§Arguments
  • config - A ServerConfig struct with custom settings for the server.
§Errors

Currently, this constructor does not return errors but is async for future compatibility.

Source

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:

  1. If the embed feature is enabled, it first tries to extract an embedded server.
  2. If no embedded server is found or the feature is disabled, it attempts to detect the latest compatible VSCode server version.
  3. It checks if this version is already present in the configured server_dir.
  4. 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).
Source

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).
Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn config(&self) -> &ServerConfig

Returns a reference to the current ServerConfig.

Trait Implementations§

Source§

impl Drop for VscodeServerManager

Ensures the server process is stopped when the VscodeServerManager goes out of scope.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,