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

LSP :: Error from the Language Server: KeyError: 28 (Invalid Parameters) #96

Closed
JulienPalard opened this issue Mar 19, 2021 · 6 comments · Fixed by #99
Closed

LSP :: Error from the Language Server: KeyError: 28 (Invalid Parameters) #96

JulienPalard opened this issue Mar 19, 2021 · 6 comments · Fixed by #99

Comments

@JulienPalard
Copy link

I'm trying jedi-language-server for the first time, sorry I'm I don't give all relevant infos...

Using emacs 27.1 on Debian, with lsp-jedi 20200812.1826, and jedi-language-server version 0.28.3.

In a file containing:

import random

random.gauss

If I point to the dot I get:

LSP :: Error from the Language Server: KeyError: 28 (Invalid Parameters)

in the minibuffer.

If you need more information, don't hesitate to ask (telling me how to gather them). I tried good old strace on jedi-language-server looking for tracebacks or KeyError but found nothing.

@pappasam
Copy link
Owner

pappasam commented Mar 19, 2021

Thanks for opening this issue! Questions for you:

  1. What LSP action are you trying to perform? Completion, Hover, Code Action, etc?
  2. Would you be able to update your example file in the following way:
import random

random.|gauss

Where | represents your cursor location at the time you perform your LSP action?

@JulienPalard
Copy link
Author

Thanks for opening this issue! Questions for you:

1. What LSP action are you trying to perform? Completion, Hover, Code Action, etc?

I don't know how to perform the hover action yet, so I can't say if it is it or not... I was doing nothing, just waiting.

2. Would you be able to update your example file in the following way:

Yes and no, my emacs point is not a thin cursor, it's ... an emacs point: it spans over the whole dot between random and gauss but for me it means:

import random

random|.gauss

Ohhh I tried another way, instead of stracing jedi-language-server, I straced emacs, to ensure I'll get all spawned subprocesses, just in case, and BOOM I have it:

334266 <... read resumed>"Content-Length: 1314\r\nContent-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n{\"jsonrpc\": \"2.0\", \"id\": \"14\", \"error\": {\"code\": -32602, \"message\": \"KeyError: 28\", \"data\": \"{'traceback': ['  File \\\"/home/mdk/.local/lib/python3.9/site-packages/pygls/protocol.py\\\", line 343, in _handle_request\\\\n    self._execute_request(msg_id, handler, params)\\\\n', '  File \\\"/home/mdk/.local/lib/python3.9/site-packages/pygls/protocol.py\\\", line 272, in _execute_request\\\\n    method_name, method_type, msg_id, handler(params))\\\\n', '  File \\\"/home/mdk/.local/lib/python3.9/site-packages/jedi_language_server/server.py\\\", line 509, in code_action\\\\n    extract_function_changes = text_edit_utils.lsp_document_changes(\\\\n', '  File \\\"/home/mdk/.local/lib/python3.9/site-packages/jedi_language_server/text_edit_utils.py\\\", line 33, in lsp_document_changes\\\\n    return [\\\\n', '  File \\\"/home/mdk/.local/lib/python3.9/site-packages/jedi_language_server/text_edit_utils.py\\\", line 64, in lsp_text_document_edits\\\\n  "..., 4096) = 1395 
334269 write(2, "Executing <Task pending name='Task-1' coro=<aio_readline() running at /home/mdk/.local/lib/python3.9/site-packages/pygls/server.py:50> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib/python3.9/asyncio/futures.py:384, <TaskWakeupMethWrapper object at 0x7fd8ff3881d0>()] created at /usr/lib/python3.9/asyncio/base_events.py:424> cb=[_run_until_complete_cb() at /usr/lib/python3.9/asyncio/base_events.py:184] created at /usr/lib/python3.9/asyncio/base_events.py:621> took 0.881 seconds\n", 520) = 520                                                                                  
334269 epoll_wait(3, [{EPOLLIN, {u32=4, u64=4}}], 1, 0) = 1                                                                                                    
334269 stat("/usr/lib/python3.9/asyncio/base_events.py", {st_mode=S_IFREG|0644, st_size=73809, ...}) = 0                                                       
334266 write(4, "\33[47;1H\33[?25l\33[1m\33[38;5;180m\33[48;5;237mLSP\33[m\33[39;49m\33[38;5;188m\33[48;5;237m :: Error from the Language Server: KeyError: 28 (Invalid Parameters) \33[39;49m\33[4;7H\33[?12l\33[?25h\33[?12;25h", 180 <unfinished ...>      

Here it is as a Python traceback:

Traceback (most recent call last):
  File "/home/mdk/.local/lib/python3.9/site-packages/pygls/protocol.py", line 343, in _handle_request
    self._execute_request(msg_id, handler, params)
  File "/home/mdk/.local/lib/python3.9/site-packages/pygls/protocol.py", line 272, in _execute_request
    method_name, method_type, msg_id, handler(params))
  File "/home/mdk/.local/lib/python3.9/site-packages/jedi_language_server/server.py", line 509, in code_action
    extract_function_changes = text_edit_utils.lsp_document_changes(
  File "/home/mdk/.local/lib/python3.9/site-packages/jedi_language_server/text_edit_utils.py", line 33, in lsp_document_changes
    return [
  File "/home/mdk/.local/lib/python3.9/site-packages/jedi_language_server/text_edit_utils.py", line 64, in lsp_text_document_edits
    text_edits = lsp_text_edits(changed_file)
  File "/home/mdk/.local/lib/python3.9/site-packages/jedi_language_server/text_edit_utils.py", line 90, in lsp_text_edits
    start = opcode_position_lookup_old[opcode.old_start]
  File "/home/mdk/.local/lib/python3.9/site-packages/jedi_language_server/text_edit_utils.py", line 152, in __getitem__
    raise KeyError(item)
KeyError: 28

From text_edit_utils.py:90, when the exception occurs, the opcode_position_lookup_old contains:

{range(0, 14): LinePosition(range_start=0, range_end=14, line=0, code='import random\n'), range(14, 15): LinePosition(range_start=14, range_end=15, line=1, code='\n'), range(15, 28): LinePosition(range_start=15, range_end=28, line=2, code='random.gauss\n')}

pappasam added a commit that referenced this issue Mar 20, 2021
@pappasam
Copy link
Owner

pappasam commented Mar 20, 2021

@JulienPalard amazing info, thanks so much for digging into this and clearly laying out the problem! Please try out #99 and let me know if it resolves your issue. I've added a test case for your specific example and it now passes.

@pappasam
Copy link
Owner

If you're looking for tips on testing this out locally: #95 (comment)

@pappasam
Copy link
Owner

Based on my tests, I believe this has been closed in the latest release. @JulienPalard Please confirm, and then I'll close

@pappasam pappasam reopened this Mar 20, 2021
@JulienPalard
Copy link
Author

Yes, it works for me, thanks!

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

Successfully merging a pull request may close this issue.

2 participants