Skip to content

Test: serialization and deserialization using lsprotocol #19544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
karthiknadig opened this issue Jul 25, 2022 · 5 comments
Closed
2 tasks done

Test: serialization and deserialization using lsprotocol #19544

karthiknadig opened this issue Jul 25, 2022 · 5 comments

Comments

@karthiknadig
Copy link
Member

karthiknadig commented Jul 25, 2022

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. 
@karthiknadig karthiknadig added this to the July 2022 milestone Jul 25, 2022
@ghost ghost assigned mjbvz and luabud Jul 26, 2022
@mjbvz
Copy link

mjbvz commented Jul 26, 2022

The code example works fine but I'm blocked on testing this more fully because I can't get python debugging working. I've selected the venv but f5 complains that it can't find lsprotocol. Running in the terminal works fine

@karthiknadig
Copy link
Member Author

@mjbvz Does the extension show that you have the right environment selected?

@mjbvz
Copy link

mjbvz commented Jul 26, 2022

Yes I believe it does

Screen Shot 2022-07-26 at 12 53 08 PM

@karthiknadig
Copy link
Member Author

@karrtikr Looks like in Matt's case python was aliased to global python. So, when he did python -m pip install lsprotocol it installed to the global environment. But our tooling uses absolute path to environment, so they all failed to detect.

@mjbvz
Copy link

mjbvz commented Jul 26, 2022

Thanks @karthiknadig for the help! We were able to figure out python was aliased to the global python version, bypassing the venv version

I tested a few types and they all seemed to work. Was a little confused how to use enums at first before realizing I could use types.SymbolKind.MODULE.value (or just inline the constant for it)

@mjbvz mjbvz removed their assignment Jul 26, 2022
@luabud luabud removed their assignment Jul 27, 2022
@luabud luabud closed this as completed Jul 27, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants