Skip to content

Python

lsp_utils.UvVenvManager

UvVenvManager(plugin_storage_path: Path, pyproject_directory_resource_path: ResourcePath, server_binary_name: str)

Handles installation and update of dependencies specified in pyproject.toml.

Initialize UvVenvManager.

Parameters:

Name Type Description Default
plugin_storage_path Path

The path to the plugin's storage (cls.plugin_storage_path).

required
pyproject_directory_resource_path ResourcePath

The resource path to the directory that contains the pyproject.toml file. Must have a Packages/<package_name>/ prefix followed by the path to the directory containing pyproject.toml within the package.

required
server_binary_name str

The name of the binary used to start the server within the venv's scripts/bin directory.

required

venv_path property

venv_path: Path

The path to the venv.

Depends on the contents of pyproject.toml and uv.lock and on the version of uv so changes when those are updated.

venv_bin_path property

venv_bin_path: Path

The path to the directory with the binaries of the venv (Scripts on Windows, bin elsewhere).

on_pre_start_async classmethod

on_pre_start_async(context: OnPreStartContext, plugin_storage_path: Path, pyproject_directory_resource_path: ResourcePath, server_binary_name: str) -> None

Initialize UvVenvManager for an LspPlugin.

Automatically adds support for a root server_path package setting that defaults to "auto", meaning that the package-managed server instance will be used. It can be overridden to use a custom server binary.

Also extends the PATH to include the venv directory if the managed server instance is used.

Parameters:

Name Type Description Default
context OnPreStartContext

The plugin context.

required
plugin_storage_path Path

The path to the plugin's storage (cls.plugin_storage_path).

required
pyproject_directory_resource_path ResourcePath

The ResourcePath to the directory that contains the pyproject.toml file. Must have a Packages/<package_name>/ prefix followed by the path to the directory containing pyproject.toml within the package.

required
server_binary_name str

The name of the binary used to start the server within the venv's scripts/bin directory.

required

install_async

install_async() -> None

Create the venv with the dependencies from pyproject.toml and uv.lock unless it already exists.

Blocks while installing so must be called on the async thread.

lsp_utils.UvRunner

UvRunner()

Runs uv commands through either system-local or self-managed instance of UV.

Installs self-managed version of uv in Package Storage if system-local version is not available. Make sure to initialize an instance on the async thread since it can perform long blocking operations when downloading uv.

run_command

run_command(*args: str, cwd: str) -> None

Run uv with the given arguments in the cwd directory. Raises on failure.