Skip to content

Test: serialization and deserialization using lsprotocol  #19544

Closed
@karthiknadig

Description

@karthiknadig

Refs: #19300

Complexity: 2

Create Issue


lsprotocol is Python implementation of LSP types generated from published LSP model. In this test scenario you will install lsprotocol and try serializing and deserializing few types. The lsprotocol types in python were generated from https://github.com/microsoft/vscode-languageserver-node/blob/main/protocol/metaModel.json

Requirements

  1. python version 3.7 or greater.

Steps

  1. Create a virtual environment: python -m venv .venv
  2. Activate your virtual environment.
  3. Install lsprotocol: python -m pip install lsprotocol
  4. import types and converters and try to structure (deserialize) and unstructure (serialize) code. See example below.

Pick some request, notification, or structure and try the following. In this example I use Diagnostic structure.

import json

from lsprotocol import converters, types

converter = converters.get_converter()

# test de-serialization
data = {
    "range": {
        "start": {"line": 0, "character": 0},
        "end": {"line": 0, "character": 0},
    },
    "message": "Missing module docstring",
    "severity": 3,
    "code": "C0114:missing-module-docstring",
    "source": "my_lint",
}
obj = converter.structure(data, types.Diagnostic)
print(type(obj)) # should print <class 'lsprotocol.types.Diagnostic'>

# test serialization
data = converter.unstructure(obj, types.Diagnostic)
print(json.dumps(data, indent=4)) # should look similar to `data` above. 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions