Skip to main content

Zero-dependency Python library for Language Server Protocol types

Project description

LSP Types

PyPI version Python License: MIT

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:

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 PyrightSession.create(initial_code=code)
    diagnostics = await pyright_session.get_diagnostics()

    assert diagnostics["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["diagnostics"] == []

Development

  • Requires Python 3.11+.
  • Requires poetry for 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lsp_types-0.7.1.tar.gz (60.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lsp_types-0.7.1-py3-none-any.whl (61.9 kB view details)

Uploaded Python 3

File details

Details for the file lsp_types-0.7.1.tar.gz.

File metadata

  • Download URL: lsp_types-0.7.1.tar.gz
  • Upload date:
  • Size: 60.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.2.0

File hashes

Hashes for lsp_types-0.7.1.tar.gz
Algorithm Hash digest
SHA256 4ecfd4d6fa4e259a75de56f0f0479b8fb0a8dd97f35b64d0cc40b7efe0508dbf
MD5 efaec93d848d3242b3582ec530b66467
BLAKE2b-256 b152875f3182e43f59650700f1245ba032f8adfdcb8087bfe0d86c934854495d

See more details on using hashes here.

File details

Details for the file lsp_types-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: lsp_types-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 61.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.2.0

File hashes

Hashes for lsp_types-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e24849a9c269c76f0073e647b4aebe38925a952553f8fc7648b7bcc6772c9cd
MD5 fd974c02eacb3e7584cbfd124cbece3e
BLAKE2b-256 8a542d2b6017aa9f91c9f136498049f0e4c194da3bc4711bcd133babfff1e0d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page