lsp-types


Namelsp-types JSON
Version 0.7.0 PyPI version JSON
download
home_pagehttps://github.com/mazyod/lsp-python-types
SummaryZero-dependency Python library for Language Server Protocol types
upload_time2025-02-12 08:13:53
maintainerNone
docs_urlNone
authorMazyad Alabduljaleel
requires_python<4.0,>=3.11
licenseMIT
keywords lsp language-server-protocol ide development-tools editor-tools
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LSP Types

[![PyPI version](https://badge.fury.io/py/lsp-types.svg)](https://badge.fury.io/py/lsp-types)
[![Python](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

_Publish the excellent work of [Sublime LSP](https://github.com/sublimelsp/lsp-python-types) 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

```sh
pip install lsp-types
```

## Usage

Using the LSP types:

```python
import lsp_types

# Use the types
```

Using an LSP process through stdio:

```python
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

```python
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:
```sh
make generate-latest-types
```

Download the latest json schema:
```sh
make download-schemas
```

Generate the types:
```sh
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mazyod/lsp-python-types",
    "name": "lsp-types",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": "lsp, language-server-protocol, ide, development-tools, editor-tools",
    "author": "Mazyad Alabduljaleel",
    "author_email": "mazjaleel@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2b/8b/2a3484246f32fa80abdc63e6c3ff31b4033c3ba49d5c64daa54f035856c9/lsp_types-0.7.0.tar.gz",
    "platform": null,
    "description": "# LSP Types\n\n[![PyPI version](https://badge.fury.io/py/lsp-types.svg)](https://badge.fury.io/py/lsp-types)\n[![Python](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n_Publish the excellent work of [Sublime LSP](https://github.com/sublimelsp/lsp-python-types) as a PyPI package._\n\n__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.\n\nIt is a goal to maintain zero-dependency status for as long as possible.\n\n## Installation\n\n```sh\npip install lsp-types\n```\n\n## Usage\n\nUsing the LSP types:\n\n```python\nimport lsp_types\n\n# Use the types\n```\n\nUsing an LSP process through stdio:\n\n```python\nfrom lsp_types.process import LSPProcess, ProcessLaunchInfo\n\nprocess_info = ProcessLaunchInfo(cmd=[\n    \"pyright-langserver\", \"--stdio\"\n])\n\nasync with LSPProcess(process_info) as process:\n    # Initialize the process\n    ...\n\n    # Grab a typed listener\n    diagnostics_listener = process.notify.on_publish_diagnostics(timeout=1.0)\n\n    # Send a notification (`await` is optional. It ensures messages have been drained)\n    await process.notify.did_open_text_document(...)\n\n    # Wait for diagnostics to come in\n    diagnostics = await diagnostics_listener\n```\n\n## LSPs\n\nThe following LSPs are available out of the box:\n\n### Pyright\n\n```python\nasync def test_pyright_session():\n    code = \"\"\"\\\ndef greet(name: str) -> str:\n    return 123\n\"\"\"\n\n    pyright_session = await PyrightSession.create(initial_code=code)\n    diagnostics = await pyright_session.get_diagnostics()\n\n    assert diagnostics[\"diagnostics\"] != []\n\n    code = \"\"\"\\\ndef greet(name: str) -> str:\n    return f\"Hello, {name}\"\n\"\"\"\n\n    assert await pyright_session.update_code(code) == 2\n\n    diagnostics = await pyright_session.get_diagnostics()\n    assert diagnostics[\"diagnostics\"] == []\n```\n\n## Development\n\n- Requires Python 3.11+.\n- Requires `poetry` for dev dependencies.\n\nGenerate latest types in one go:\n```sh\nmake generate-latest-types\n```\n\nDownload the latest json schema:\n```sh\nmake download-schemas\n```\n\nGenerate the types:\n```sh\nmake generate-schemas\n```\n\nCopy the `lsp_types/types.py` file to your project.\n\nNOTE: Do not import types that begin with `__`. These types are internal types and are not meant to be used.\n\n### TODOs\n\n- Automate package releases on Github.\n- Support server request handlers.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Zero-dependency Python library for Language Server Protocol types",
    "version": "0.7.0",
    "project_urls": {
        "Documentation": "https://github.com/mazyod/lsp-python-types#readme",
        "Homepage": "https://github.com/mazyod/lsp-python-types",
        "Repository": "https://github.com/mazyod/lsp-python-types"
    },
    "split_keywords": [
        "lsp",
        " language-server-protocol",
        " ide",
        " development-tools",
        " editor-tools"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f1c5857633fd78603342d300aa66442ab46c73d9cf86ff5fed3dc8025df5d14b",
                "md5": "f44b83fa1343b6f859db245aca15d6ea",
                "sha256": "3bb9b35b43fc137e3a9ef24ff4a13931edb0142d22222d663cf8fd44bd5fe8fe"
            },
            "downloads": -1,
            "filename": "lsp_types-0.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f44b83fa1343b6f859db245aca15d6ea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 61847,
            "upload_time": "2025-02-12T08:13:50",
            "upload_time_iso_8601": "2025-02-12T08:13:50.837798Z",
            "url": "https://files.pythonhosted.org/packages/f1/c5/857633fd78603342d300aa66442ab46c73d9cf86ff5fed3dc8025df5d14b/lsp_types-0.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b8b2a3484246f32fa80abdc63e6c3ff31b4033c3ba49d5c64daa54f035856c9",
                "md5": "a8b57fcd66e2e778a7f3ad2effbc5d29",
                "sha256": "5aab4965d6914d5ea2b57f21dec5c252a46b1b96e897ccc191b66cf5f9042782"
            },
            "downloads": -1,
            "filename": "lsp_types-0.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a8b57fcd66e2e778a7f3ad2effbc5d29",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 60132,
            "upload_time": "2025-02-12T08:13:53",
            "upload_time_iso_8601": "2025-02-12T08:13:53.551921Z",
            "url": "https://files.pythonhosted.org/packages/2b/8b/2a3484246f32fa80abdc63e6c3ff31b4033c3ba49d5c64daa54f035856c9/lsp_types-0.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-12 08:13:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mazyod",
    "github_project": "lsp-python-types",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "lsp-types"
}
        
Elapsed time: 0.78381s