lsprotocol is a Python library that provides generated type definitions for the Language Server Protocol (LSP). It allows developers to build language servers and clients by providing a robust and easy-to-use type generation system, staying up-to-date with the latest LSP specification. The library follows a yearly major release cadence.
pip install lsprotocolVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create LSP type objects, and how to use the built-in converters to serialize (unstructure) and deserialize (structure) these objects to and from Python dictionaries, typically for JSON communication.
Review your code for `lsprotocol.types` imports and object instantiations. Refer to the `pygls` migration guides (v1.0 and v2.0) for examples of renamed types, as `pygls` also adopted `lsprotocol`'s types.
Inspect release notes and `pygls` v2.0 migration guides for renamed types and adjust your code accordingly. This specifically affects users leveraging the newer LSP specification features.
If an LSP server you're interacting with rejects `null` values for optional fields, you may need to manually filter out `None` values from the unstructured dictionary before serialization to JSON.
Always check the `lsprotocol` release notes to understand which LSP specification version it targets. Ensure your client or server implementation is compatible with that specific LSP spec version to avoid unexpected behavior or missing capabilities.
Install the `lsprotocol` library using pip: `python -m pip install lsprotocol`
Ensure `lsprotocol` is installed in the Python environment used by your type checker. If using an IDE, verify that the correct Python interpreter and environment are selected and that the type checker's configuration includes the relevant site-packages.
Ensure both `lsprotocol` and its `attrs` dependency are up-to-date and compatible. It's often best to install them in a fresh virtual environment. If this occurs within a VS Code extension, look for an `importStrategy` setting (e.g., `"black-formatter.importStrategy": "useBundled"`) to ensure the extension uses its internal, compatible dependencies.
Update `lsprotocol` to the latest version, as such issues are often addressed in new releases. If the problem persists, consider simplifying the data structures being processed or, as a last resort, temporarily increasing Python's recursion limit (e.g., `sys.setrecursionlimit(2000)`).