Skip to content

Pygls crashes with Vim LSP plugin #541

@itsmeknt

Description

@itsmeknt

Hello! I am testing the my Pygls server on various plugins. It seems to work find for Emacs and Helix, but when I tried it with Vim it crashes.

For Pygls, I am using the branch tagged v2.0.0a3
For Vim, I am using this library for LSP plugin: https://github.com/yegappan/lsp?tab=readme-ov-file

My .vimrc file looks like this:

packadd lsp

call LspAddServer([#{
        \    name: 'toxidious',
        \    filetype: ['python', 'toxchat'],
	\    path: 'nc',
	\    args: ['localhost', '8282']
	\  }])

(my language server is called toxidious and runs on a local TCP port 8282.)

I initiated a ls.worksplace_apply_edit_async() request to the editor, which crashes with the following error message:

Unable to deserialize message                                                                                                                                                                                                                                                                                                                                              
Traceback (most recent call last):                                                                                                                                                                                                                                                                                                                                         
  File "/home/kevin/workspace/toxidious/venv/lib/python3.13/site-packages/pygls/protocol/json_rpc.py", line 434, in structure_message                                                                                                                                                                                                                                      
    self._result_types.pop(data["id"]) or JsonRPCResponseMessage                                                                                                                                                                                                                                                                                                           
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^                                                                                                                                                                                                                                                                                                                                     
KeyError: 15036         

For convenience, the link to the code is here

Poking around the code in the debugger, I notice that:
self._result_types = {'434205ff-56f1-4ca1-9b16-662bf9e1e233': <class 'lsprotocol.types.ApplyWorkspaceEditResponse'>}

But Vim responded with this message:

{                                                                                                                                                                                                                                                                                                                                                                          
  "id": 434205,                                                                                                                                                                                                                                                                                                                                                            
  "jsonrpc": "2.0",                                                                                                                                                                                                                                                                                                                                                        
  "result": {                                                                                                                                                                                                                                                                                                                                                              
    "applied": true                                                                                                                                                                                                                                                                                                                                                        
  }                                                                                                                                                                                                                                                                                                                                                                        
}     

It seems like Vim parses the ID incorrectly, keeping only the first 6 digits and removing the first non-digit character it sees. Additionally, the ID data type is an integer, not a string.

It seems like Vim only expects integer IDs.

When I changed the ID to use integer IDs here and typecasted the data["id"] to str(data["id"]) here, Vim correctly applies the workspace edit. However, pygls complains that it doesn't recognize the response id, so this probably broke something else.

I'd like to have my language server support Vim with any of their plug ins. Is there anything Pygls can do to fix this, or is this simply a Vim LSP plugin implementation error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions