Closed
Description
Refs: #19300
Complexity: 2
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
- python version 3.7 or greater.
Steps
- Create a virtual environment:
python -m venv .venv
- Activate your virtual environment.
- Install
lsprotocol
:python -m pip install lsprotocol
- import
types
andconverters
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.