Open avario-cpu opened 2 weeks ago
Heyy, the task of investigating the issue with the vim.lsp.buf.code_action() call not properly handling code ranges for method extraction using pylsp with the rope plugin. The problem seems to be related to the range parameters not covering the complete statements, leading to syntax errors during refactoring.
Example code:-
async def run_main_task(slot: int, shop_watcher: ShopWatcher): mute_ssim_prints.set()
# Create a new task for scanning and notification
main_task = asyncio.create_task(shop_watcher.scan_for_shop_and_notify())
# Extracted statement
await secondary_windows_spawned.wait() # Extracted to a new method
await twm.manage_secondary_windows(slot, SECONDARY_WINDOWS) # line 34
mute_ssim_prints.clear()
await main_task
return None
My issue is about trying to refactor using pylsp with the rope plugin, through a
code_action
I'm trying to extract
await secondary_windows_spawned.wait()
from:Here is range the lsp is using (from logs):
range = { ["end"] = { character = 43, line = 32 }, start = { character = 1, line = 32 } }, similar = false } }
The attempt to execute a method extraction code action over this range results in a
Extracted piece should contain complete statements
error.But, what I was seemingly able to observe as the actual parsed statements in logs are:
await twm.manage_secondary_w
(the beginning of line 34)(ed.wait()
(the end of line 33 with some added indentation and a curious(
replacing what would be the normally be the bridging character when concatenating wtih the previous result.)Despite the range table cleary indicating a span over a single line, it looks like there are two partial lines sent to rope.
[Neovim lsp docs](https://neovim.io/doc/user/lsp.html#vim.lsp.buf.code_action()) mention {row,col} being passed as "tuples" ? but there are no tuples in lua ? Am I missing something there ? There seems to be a curious reversal in the appearing order of the
start
andend
key inside therange
table when received by the lsp, but sincestart
andend
are, from my understanding, keys, this shouldn't matter ?!my call basically is:
The observation of those statments being parsed with the
vim.the lsp.buf.code_action()
call is what I've assumed from my looking in logs, but I'm not sure. If you wish to find those values, search the below logs for "string>"full relevant logs:
if you prefer the logs wrapped:
Click to expand
[DEBUG][2024-08-24 16:11:58] ...m/lsp/client.lua:678 "LSP[pylsp]" "client.request" 3 "workspace/executeCommand" { arguments = { { document_uri = "file:///C:/Users/ville/MyMegaScript/src/apps/shop_watcher/shop_watcher_main.py", global_ = false, range = { ["end"] = { character = 43, line = 32 }, start = { character = 1, line = 32 } }, similar = false } }, command = "pylsp_rope.refactor.extract.method"}