natebosch / vim-lsc

A vim plugin for communicating with a language server
BSD 3-Clause "New" or "Revised" License
693 stars 82 forks source link

Error exiting vim when coding in Python using pyls #127

Open softinio opened 5 years ago

softinio commented 5 years ago

I get this:

[lsc:Error] Command exited unexpectedly: pyls

Configuration issue or a bug do you think? Thanks!

natebosch commented 5 years ago

This happens if the server exits before we called the exit command - maybe it's exiting when we call shutdown and not waiting for the followup exit request...

Can you try logging communication and see what the requests around shutdown look like? https://github.com/natebosch/vim-lsc/wiki/Server-Debugging-Tips

softinio commented 5 years ago

@natebosch thanks for getting back to me so quickly. Did what you suggested here is the output of the logs:

in.log

Content-Length: 575

{"method": "initialize", "jsonrpc": "2.0", "id": 1, "params": {"rootUri": "file:///Users/srahmanian/source/lambda_rahmanian.xyz", "capabilities": {"workspace": {"applyEdit": true}, "textDocument": {"completion": {"snippetSupport": false}, "synchronization": {"willSaveWaitUntil": false, "willSave": false, "didSave": false}, "codeAction": {"codeActionLiteralSupport": {"codeActionKind": {"valueSet": ["quickfix", "refactor", "source"]}}}, "signatureHelp": {"dynamicRegistration": false}, "definition": {"dynamicRegistration": false}}}, "processId": 5276, "trace": "verbose"}}Content-Length: 826

{"method": "textDocument/didOpen", "jsonrpc": "2.0", "params": {"textDocument": {"uri": "file:///Users/srahmanian/source/lambda_rahmanian.xyz/handler.py", "version": 1, "languageId": "python", "text": "from __future__ import print_function\n\nfrom urllib.parse import unquote_plus\n\nfrom pymagecli.utils import get_file_and_resize\n\n\ndef lambda_handler(event, context):\n    \"\"\"\n    AWS Lambda handler to resize uploaded images to 600px\n    \"\"\"\n    print(\"Incoming event: {}\".format(event))\n    for object in event.get('Records'):\n        key = unquote_plus(object['s3']['object']['key'])\n        bucket_name = unquote_plus(object['s3']['bucket']['name'])\n        print(\"Pymage: Resizing {} in bucket: {}\".format(key, bucket_name))\n        get_file_and_resize(bucket_name=bucket_name, file_name=key)\n"}}}Content-Length: 216

{"method": "textDocument/documentHighlight", "jsonrpc": "2.0", "id": 2, "params": {"textDocument": {"uri": "file:///Users/srahmanian/source/lambda_rahmanian.xyz/handler.py"}, "position": {"character": 0, "line": 0}}}Content-Length: 57

{"method": "initialized", "jsonrpc": "2.0", "params": {}}Content-Length: 311

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"range": {"end": {"character": 0, "line": 17}, "start": {"character": 0, "line": 17}}, "text": "", "rangeLength": 0}], "textDocument": {"uri": "file:///Users/srahmanian/source/lambda_rahmanian.xyz/handler.py", "version": 2}}}Content-Length: 157

{"method": "textDocument/didClose", "jsonrpc": "2.0", "params": {"textDocument": {"uri": "file:///Users/srahmanian/source/lambda_rahmanian.xyz/handler.py"}}}Content-Length: 49

{"method": "shutdown", "jsonrpc": "2.0", "id": 3}

out.log

Content-Length: 605
Content-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, "signatureHelpProvider": {"triggerCharacters": ["(", ","]}, "textDocumentSync": 2, "experimental": {}}}}Content-Length: 43
Content-Type: application/vscode-jsonrpc; charset=utf8

{"jsonrpc": "2.0", "id": 2, "result": null}Content-Length: 168
Content-Type: application/vscode-jsonrpc; charset=utf8

{"jsonrpc": "2.0", "method": "textDocument/publishDiagnostics", "params": {"uri": "file:///Users/srahmanian/source/lambda_rahmanian.xyz/handler.py", "diagnostics": []}}Content-Length: 43
Content-Type: application/vscode-jsonrpc; charset=utf8

{"jsonrpc": "2.0", "id": 3, "result": null}

Anything else you want me to try or anything I can help me let me know. Thanks!

softinio commented 5 years ago

In case helpful, I use neovim with these plugins:

https://github.com/softinio/dotfiles/blob/master/vim/plugins.vim

and this vimrc:

https://github.com/softinio/dotfiles/blob/master/vim/vimrc

softinio commented 5 years ago

my guess is pyls only supports the exit command and not shutdown

https://github.com/palantir/python-language-server/blob/ab3e5eaef848a0cc752110f85ed95187f5cffcc4/pyls/python_ls.py#L88

@natebosch Should pyls be supporting shutdown ? Is there a standard for it as part of the protocol?

Thanks

natebosch commented 5 years ago

Yes, shutdown should be supported by the server, and it looks like in this case it might be: https://github.com/palantir/python-language-server/blob/98977b6f3e502231ce1a6aea80fc505a1c923bbd/pyls/python_ls.py#L105

We are also getting a non-error result from that request which is an indication that it's working.

I made some changes in this area few months ago - https://github.com/natebosch/vim-lsc/commit/4f7b89c8a0920cc926f35bf64f831b50e8fb572d

Are you synced past that commit?

natebosch commented 5 years ago

The log doesn't include the exit request which makes me think that perhaps the server process is ending before the exit is sent - that would explain this behavior.

It's also possible (though I wouldn't expect it) that the call to ch_sendraw is not returning before the process exits and the on_exit handler is called.

I opened https://github.com/natebosch/vim-lsc/pull/134 to see if that might be what is happening - can you try that branch?

If that fixes it I'm happy to merge it. If it doesn't we'll need to explore other options:

softinio commented 5 years ago

Just saw your replies thanks for looking into this. WIll try that branch and let you know

softinio commented 5 years ago

Just tried your allow-fast-exit branch and got the same usual error. Thanks.

natebosch commented 5 years ago

@softinio - I think it's probably worth filing an issue against the server since it seems like it may be exiting on shutdown and not waiting fro the exit request...

softinio commented 5 years ago

@natebosch I think it might be related to this existing problem reported on the server:

https://github.com/palantir/python-language-server/issues/434