Client Handlers¶
lsp_utils.GenericClientHandler
¶
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
¶
Register the plugin with LSP.
Call this from the plugin_loaded function of your package.
Raises:
| Type | Description |
|---|---|
Exception
|
If |
cleanup
classmethod
¶
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
¶
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
¶
Return a list of extra arguments to append to the command when starting the server.
See get_command().
read_settings
classmethod
¶
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
¶
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
¶
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
|
|
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 |
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
¶
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 |