Skip to content
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

LSP2LSIF #73

Open
2 of 7 tasks
abitrolly opened this issue Apr 30, 2021 · 3 comments
Open
2 of 7 tasks

LSP2LSIF #73

abitrolly opened this issue Apr 30, 2021 · 3 comments

Comments

@abitrolly
Copy link
Member

abitrolly commented Apr 30, 2021

  • I need to troubleshoot failing tests for my Ruby project in GitLab.

  • Write LSIF indexer that uses existing LSP server

    • Start some LSP server for Ruby
      podman run -it -p 127.0.0.1:9084:7658 -e LOG_LEVEL=DEBUG docker.io/yakshaveinc/solargraph
      
      The server on port 9084 silently exits after the first wrong request. Maybe it needs some debug params.
      • Send initialize request. LSP uses JSON-RPC protocol with Content-length headers and without HTTP methods.
        • Add lsp:// Transport Plugin to httpie (requests Transport Adapter) for easier debugging from command line
      • Feed it *.rb files using textDocument/didOpen(textDocumentItem)[https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentItem]
        • Request what server knows about those files
          • Write out LSIF
            • Add LSIF to GitLab and test that it works
@abitrolly
Copy link
Member Author

Debugging with httpie fails, because it sends HTTP headers and expects HTTP headers. It should be patched (or extended with TransportPlugin to just send Content-Length and expect Content-Length in return.

The plugin in turn is requests Transport Adapter.

(expand) http -v 127.0.0.1:9084 method=initialize id=1 --debug --traceback --stream
$ http -v 127.0.0.1:9084 method=initialize id=1 --debug --traceback --stream
HTTPie 2.3.0
Requests 2.25.1
Pygments 2.7.4
Python 3.9.4 (default, Apr  6 2021, 00:00:00) 
[GCC 11.0.1 20210324 (Red Hat 11.0.1-0)]
/usr/bin/python3
Linux 5.11.15-300.fc34.x86_64

<Environment {'colors': 256,
 'config': {'default_options': []},
 'config_dir': PosixPath('/home/anatoli/.config/httpie'),
 'devnull': <property object at 0x7fba3c170e50>,
 'is_windows': False,
 'log_error': <function Environment.log_error at 0x7fba3c175d30>,
 'program_name': 'http',
 'stderr': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>,
 'stderr_isatty': True,
 'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
 'stdin_encoding': 'utf-8',
 'stdin_isatty': True,
 'stdout': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>,
 'stdout_encoding': 'utf-8',
 'stdout_isatty': True}>

>>> requests.request(**{'auth': None,
 'data': '{"method": "initialize", "id": "1"}',
 'headers': {'User-Agent': b'HTTPie/2.3.0', 'Accept': b'application/json, */*;q=0.5', 'Content-Type': b'application/json'},
 'method': 'post',
 'params': <generator object MultiValueOrderedDict.items at 0x7fba3baf00b0>,
 'url': 'http://127.0.0.1:9084'})

POST / HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 35
Content-Type: application/json
Host: 127.0.0.1:9084
User-Agent: HTTPie/2.3.0

{
    "id": "1",
    "method": "initialize"
}



http: error: ConnectionError: ('Connection aborted.', BadStatusLine('Content-Length: 528\r\n')) while doing a POST request to URL: http://127.0.0.1:9084/

/spent 10h

@abitrolly
Copy link
Member Author

abitrolly commented May 2, 2021

requests only needs to implement one method - send() - https://docs.python-requests.org/en/latest/_modules/requests/adapters/

The requests API is tied to Session, but it is not possible to add own methods to it without monkeypatching. So users will need to use standard .get() (or .post()) calls with JSON-RPC method names added to passed JSON.

import requests
from requests_lsp import LSPAdapter

session = requests.Session()
session.mount("lsp://", LSPAdapter())

response = session.get("lsp://127.0.0.1:9084", json={"id":"1", "method": "initialize"})
print(response.json())

Adapter should save connection between calls, provide Content-Length header and JSON-RPC ids if they are not set.

abitrolly added a commit to abitrolly/requests-lsp that referenced this issue May 3, 2021
This turned out to be a raw socket implementation, which doesn't
really shares much with `requests-curl`, except for initial layout.

I didn't implement any syntax sugar, such as "id" increments etc.,
because it will make sent JSON dependent on this specific library.
Maybe in future, but for now covers my use case of using LSP server
to provide LSIF syntax info for my files.

yakshaveinc/tasks#73
@abitrolly
Copy link
Member Author

Working proof of concept for requests adapter is done - https://github.com/abitrolly/requests-lsp

/spent 20h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant