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

Fix: lsp_bridge.py raises a KeyError when a code action is triggered in tramp. #1113

Merged

Conversation

i-aki-y
Copy link
Contributor

@i-aki-y i-aki-y commented Nov 18, 2024

Problem

When I triggered a code action in a file over the tramp, the lsp_bridge.py output the following error, and the code action did not work.

--- [19:54:05.515935] Recv textDocument/codeAction response (26129) from 'ruff' for project sandbox
Error when processing response 26129
Traceback (most recent call last):
  File "... /lsp-bridge/core/handler/__init__.py", line 38, in handle_response
    self.process_response(response)
  File "... /lsp-bridge/core/handler/code_action.py", line 37, in process_response
    changes = item["edit"]["changes"]
KeyError: 'changes'

Fix

The item["edit"] is assumed to be a WorkspaceEdit instance and it looks to have one of (changes or documentChanges ).
See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspaceEdit

Since the current version only supports the changes case, I added an implementation to support documentChanges to fix the problem.

Note

Although I have implemented cases for all documentChanges types (TextDocumentEdit, CreateFile, DeleteFile, RenameFile), I was only able to confirm the case of TextDocumentEdit that is returned in code_action.py and rename.py. I could not test the other types, CreateFile, DeleteFile, and RenameFile, because I am not sure in what use cases lsp would return these operations.

I would appreciate it if you could confirm this.

@manateelazycat manateelazycat merged commit 72a19f4 into manateelazycat:master Nov 18, 2024
1 check passed
@manateelazycat
Copy link
Owner

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 this pull request may close these issues.

2 participants