Skip to main content

Zero-dependency Python library for Language Server Protocol types

Project description

LSP Types

PyPI version Python Tests License: MIT

Publish the excellent work of Sublime LSP as a PyPI package.

image

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 uv 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.12.1.tar.gz (66.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.12.1-py3-none-any.whl (68.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lsp_types-0.12.1.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

Hashes for lsp_types-0.12.1.tar.gz
Algorithm Hash digest
SHA256 a34e2780f88752d672726e0f574bf5dbb76d5888dff8ce547cf88e9ded926b29
MD5 2d3fcf3fc33376ccbb079b9b390d8ea5
BLAKE2b-256 c3c488df9ef956d989872a9cde3c867ead6510740bde5e8fc7d9f916af3d6950

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lsp_types-0.12.1-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

Hashes for lsp_types-0.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ef633fe2d870b93bbeac09fed6fe2ca4f585e9bd87cdbf63d0cf883eacd8ac5
MD5 76b0baf427254a8d1ff23a0d5c9e10c0
BLAKE2b-256 90be277fb3d5c9f8a6cb54a66af2f327bc7954dffc248a54c98481de120278fc

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