Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Why does any non-initialize operation always fail for me?#448

Unanswered
winstonpurnomo asked this question inQ&A
Discussion options

Hi all, trying to use python-language-server LSP implementation for something. I am programatically sending JSONRPC messages from Python to pyls using the options pyls --tcp --host localhost --port 8080, and here are the messages am I sending:

{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"processId": None, "rootUri": "file:///Users/username/Folder", "capabilities": {"workspace": {"applyEdit": false, "workspaceEdit": {"documentChanges": false}}}}}

It responds with

{"jsonrpc":"2.0","id":1,"result":{"capabilities":{"codeActionProvider":true,"codeLensProvider":{"resolveProvider":false},"completionProvider":{"resolveProvider":false,"triggerCharacters":["."]},"documentFormattingProvider":true,"documentHighlightProvider":true,"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"definitionProvider":true,"executeCommandProvider":{"commands":[]},"hoverProvider":true,"referencesProvider":true,"renameProvider":true,"foldingRangeProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",",","="]},"textDocumentSync":{"change":2,"save":{"includeText":true},"openClose":true},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}},"experimental":{}}}}

Then I try to get document symbols with this:

{"jsonrpc": "2.0", "method": "textDocument/documentSymbol", "params": {"textDocument": {"uri": "file:///Users/username/Folder/main.py"}}, "id": 2}

This always gives back an error with this traceback:

2023-09-28 23:19:26,315 UTC - ERROR - pyls_jsonrpc.endpoint - Failed to handle request 3Traceback (most recent call last):  File "/Users/username/.pyenv/versions/3.10.13/envs/assembly/lib/python3.10/site-packages/pyls_jsonrpc/endpoint.py", line 113, in consume    self._handle_request(message['id'], message['method'], message.get('params'))  File "/Users/username/.pyenv/versions/3.10.13/envs/assembly/lib/python3.10/site-packages/pyls_jsonrpc/endpoint.py", line 182, in _handle_request    handler_result = handler(params)  File "/Users/username/.pyenv/versions/3.10.13/envs/assembly/lib/python3.10/site-packages/pyls_jsonrpc/dispatchers.py", line 23, in handler    return method(**(params or {}))  File "/Users/username/.pyenv/versions/3.10.13/envs/assembly/lib/python3.10/site-packages/pyls/python_ls.py", line 322, in m_text_document__completion    return self.completions(textDocument['uri'], position)  File "/Users/username/.pyenv/versions/3.10.13/envs/assembly/lib/python3.10/site-packages/pyls/python_ls.py", line 240, in completions    completions = self._hook('pyls_completions', doc_uri, position=position)  File "/Users/username/.pyenv/versions/3.10.13/envs/assembly/lib/python3.10/site-packages/pyls/python_ls.py", line 154, in _hook    doc = workspace.get_document(doc_uri) if doc_uri else NoneAttributeError: 'NoneType' object has no attribute 'get_document'

Ideas why this is happening?

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

Are you sending adidOpen request first to register the file you're trying to get symbols for?

You must be logged in to vote
2 replies
@winstonpurnomo
Comment options

Thanks for your response. I have tried to send this following message, and it fails with a different error?

>>>Content-Length: 238{"jsonrpc": "2.0", "method": "initialize", "params": {"processId": null, "rootUri": "file:///Users/username/Folder", "capabilities": {"workspace": {"applyEdit": true, "workspaceEdit": {"documentChanges": true}}}}, "id": 1}<<<Content-Length: 730Content-Type: application/vscode-jsonrpc; charset=utf8{"jsonrpc":"2.0","id":1,"result":{"capabilities":{"codeActionProvider":true,"codeLensProvider":{"resolveProvider":false},"completionProvider":{"resolveProvider":false,"triggerCharacters":["."]},"documentFormattingProvider":true,"documentHighlightProvider":true,"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"definitionProvider":true,"executeCommandProvider":{"commands":[]},"hoverProvider":true,"referencesProvider":true,"renameProvider":true,"foldingRangeProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",",","="]},"textDocumentSync":{"change":2,"save":{"includeText":true},"openClose":true},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}},"experimental":{}}}}>>>Content-Length: 230{"jsonrpc": "2.0", "method": "textDocument/didOpen", "params": {"textDocument": {"uri": "file:///Users/username/Folder/main.py", "languageId": "py", "version": 1, "text": "def main():\n\treturn x"}}, "id": 2}<<<Content-Length: 1060Content-Type: application/vscode-jsonrpc; charset=utf8{"jsonrpc":"2.0","id":2,"error":{"code":-32602,"message":"AttributeError: 'NoneType' object has no attribute 'put_document'","data":{"traceback":["  File \"\/Users\/username\/.pyenv\/versions\/3.10.13\/envs\/env\/lib\/python3.10\/site-packages\/pyls_jsonrpc\/endpoint.py\", line 113, in consume\n    self._handle_request(message['id'], message['method'], message.get('params'))\n","  File \"\/Users\/username\/.pyenv\/versions\/3.10.13\/envs\/env\/lib\/python3.10\/site-packages\/pyls_jsonrpc\/endpoint.py\", line 182, in _handle_request\n    handler_result = handler(params)\n","  File \"\/Users\/username\/.pyenv\/versions\/3.10.13\/envs\/env\/lib\/python3.10\/site-packages\/pyls_jsonrpc\/dispatchers.py\", line 23, in handler\n    return method(**(params or {}))\n","  File \"\/Users\/username\/.pyenv\/versions\/3.10.13\/envs\/env\/lib\/python3.10\/site-packages\/pyls\/python_ls.py\", line 298, in m_text_document__did_ope
@ccordoba12
Comment options

Sorry, I forgot to mention that you also need to send adidChangeConfiguration request after you receive theinitialize response from the server.

I'm sorry to say it but this shows that you don't understand how a client is supposed to communicate with the server. So, please take a close look to the LSP docs in order to do that.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@winstonpurnomo@ccordoba12

[8]ページ先頭

©2009-2025 Movatter.jp