Zero-dependency Python library for Language Server Protocol types
Project description
LSP Types
Publish the excellent work of Sublime LSP as a PyPI package.
LSP Types is a Python package that aims to provide a fully typed interface to Language Server Protocol (LSP) interactions. It can be used to simply utilize the types, or to interact with an LSP server over stdio.
It is a goal to maintain zero-dependency status for as long as possible.
Installation
pip install lsp-types
Usage
Using the LSP types:
import lsp_types
# Use the types
Using an LSP process through stdio:
[!TIP] Recommend using basedpyright for extended features.
from lsp_types.process import LSPProcess, ProcessLaunchInfo
process_info = ProcessLaunchInfo(cmd=[
"pyright-langserver", "--stdio"
])
async with LSPProcess(process_info) as process:
# Initialize the process
...
# Grab a typed listener
diagnostics_listener = process.notify.on_publish_diagnostics(timeout=1.0)
# Send a notification (`await` is optional. It ensures messages have been drained)
await process.notify.did_open_text_document(...)
# Wait for diagnostics to come in
diagnostics = await diagnostics_listener
LSPs
The following LSPs are available out of the box:
Pyright
async def test_pyright_session():
code = """\
def greet(name: str) -> str:
return 123
"""
pyright_session = await Session.create(PyrightBackend(), initial_code=code)
diagnostics = await pyright_session.get_diagnostics()
assert diagnostics != []
code = """\
def greet(name: str) -> str:
return f"Hello, {name}"
"""
assert await pyright_session.update_code(code) == 2
diagnostics = await pyright_session.get_diagnostics()
assert diagnostics == []
Development
- Requires Python 3.12+.
- Requires
uvfor dev dependencies.
Generate latest types in one go:
make generate-latest-types
Download the latest json schema:
make download-schemas
Generate the types:
make generate-schemas
Copy the lsp_types/types.py file to your project.
NOTE: Do not import types that begin with __. These types are internal types and are not meant to be used.
TODOs
- Automate package releases on Github.
- Support server request handlers.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lsp_types-0.12.2.tar.gz.
File metadata
- Download URL: lsp_types-0.12.2.tar.gz
- Upload date:
- Size: 66.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2439341e83bb56fa536c1f54db6ac7c66d9ab854cfe8496cd01f32d39586eb71
|
|
| MD5 |
3259873040749eff04e48b051b0b94fc
|
|
| BLAKE2b-256 |
886947827ce95f8ee4b459613f05693a20753b3359a4c68c9e9fb0e9295d9665
|
File details
Details for the file lsp_types-0.12.2-py3-none-any.whl.
File metadata
- Download URL: lsp_types-0.12.2-py3-none-any.whl
- Upload date:
- Size: 68.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fc1f2e299ed35b9f00ce5531c9e2325dbd6ca122815d8a7e9b5614f8e92ce69
|
|
| MD5 |
7844b2ef9bc5a0ca967aea33fe6370df
|
|
| BLAKE2b-256 |
775f9278beabfb1b0fd60d091672fa774e32496d962c3252fd4d3a12c89b8019
|