Skip to content

Client Handlers

lsp_utils.GenericClientHandler

GenericClientHandler(*args: Any, **kwargs: Any)

Bases: ClientHandler

A generic implementation of an LSP plugin handler.

package_name class-attribute instance-attribute

package_name: str = ''

The name of the released package. Also used for the name of the LSP client and for reading package settings.

This name is required and must match the basename of the corresponding *.sublime-settings file. It's also used as a directory name for package storage when implementing a server resource interface. Recommended to use __package__ value for this one. If you need to override handler name in the UI, override get_displayed_name() also.

setup classmethod

setup() -> None

Register the plugin with LSP.

Call this from the plugin_loaded function of your package.

Raises:

Type Description
Exception

If package_name is not set.

cleanup classmethod

cleanup() -> None

Unregister the plugin from LSP.

Call this from the plugin_unloaded function of your package. Also removes the directory returned from package_storage() if the package is being removed by Package Control.

get_displayed_name classmethod

get_displayed_name() -> str

Return the name that will be shown in the ST UI (for example in the status field).

Defaults to the value of package_name.

storage_path classmethod

storage_path() -> str

Storage path.

Use this as your base directory to install server files. Its path is '$DATA/Package Storage'.

package_storage classmethod

package_storage() -> str

Storage path for this package.

Its path is '$DATA/Package Storage/[Package_Name]'.

get_command classmethod

get_command() -> list[str]

Return a list of arguments to use to start the server.

The default implementation returns combined result of binary_path() and get_binary_arguments().

binary_path classmethod

binary_path() -> str

Filesystem path to the server executable.

The default implementation returns binary_path property of the server instance (returned from get_server()), if available.

get_binary_arguments classmethod

get_binary_arguments() -> list[str]

Return a list of extra arguments to append to the command when starting the server.

See get_command().

read_settings classmethod

read_settings() -> tuple[Settings, str]

Load the settings of the package from the *.sublime-settings file named after package_name.

Saves the settings back to the file if on_settings_read() returns True.

Returns:

Type Description
tuple[Settings, str]

The settings object and the resource path of the settings file.

get_additional_variables classmethod

get_additional_variables() -> dict[str, str]

Override to add more variables here to be expanded when reading settings.

Default implementation adds a ${server_path} variable that holds filesystem path to the server binary (only when manages_server is True).

Remember to call the super class and merge the results if overriding.

get_additional_paths classmethod

get_additional_paths() -> list[str]

Override to prepend additional paths to the default PATH environment variable.

Remember to call the super class and merge the results if overriding.

manages_server classmethod

manages_server() -> bool

Whether this handler manages a server.

If the response is True then the get_server() should also be implemented.

get_server classmethod

get_server() -> ServerResourceInterface | None

Instance of the server managed by this plugin.

Only used when manages_server() returns True.

on_settings_read classmethod

on_settings_read(settings: Settings) -> bool

On package settings are read.

Receives a sublime.Settings object.

It's recommended to use on_settings_changed() instead if you don't need to persistent your changes to the disk.

Returns:

Type Description
bool

True to save modifications back into the settings file.

is_allowed_to_start classmethod

is_allowed_to_start(window: Window, initiating_view: View, workspace_folders: list[WorkspaceFolder], configuration: ClientConfig) -> str | None

Determine if the session is allowed to start.

Returns:

Type Description
str | None

A string describing the reason why we should not start a language server session, or None if we should go ahead and start a session.

on_ready

on_ready(api: ApiWrapperInterface) -> None

When the instance is ready.

Parameters:

Name Type Description Default
api ApiWrapperInterface

The API instance for interacting with the server.

required

on_settings_changed

on_settings_changed(settings: DottedDict) -> None

Override to alter settings that are returned to the server.

Triggered for workspace/didChangeConfiguration notification and workspace/configuration requests.

Parameters:

Name Type Description Default
settings DottedDict

The settings that the server should receive.

required

lsp_utils.ClientHandler

ClientHandler(*args: Any, **kwargs: Any)

Bases: AbstractPlugin, ClientHandlerInterface, ABC

The base class for creating an LSP plugin.