ocaml-lsp
ocaml-lsp copied to clipboard
Rename does not work properly with ppx_string
I have a file that ends with the following:
let f x =
[%string
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
%{x}"]
;;
This is the zero-indexed line-range 241-245. Renaming x to y produces:
let f y =
[%string
y]
;;
The debug log of the messages is:
[DEBUG][2023-09-05 17:34:12] .../lua/vim/lsp.lua:1392 "LSP[ocaml-lsp]" "client.request" 1 "textDocument/prepareRename"
{
position = {
character = 6,
line = 241
},
textDocument = {
uri = "file:///path/to/file.ml"
}
}
[DEBUG][2023-09-05 17:34:12] .../vim/lsp/rpc.lua:284 "rpc.send"
{
id = 6,
jsonrpc = "2.0",
method = "textDocument/prepareRename",
params = {
position = {
character = 6,
line = 241
},
textDocument = {
uri = "file:///path/to/file.ml"
}
}
}
[DEBUG][2023-09-05 17:34:12] .../vim/lsp/rpc.lua:387 "rpc.receive"
{
id = 6,
jsonrpc = "2.0",
result = {
["end"] = {
character = 7,
line = 241
},
start = {
character = 6,
line = 241
}
}
}
[DEBUG][2023-09-05 17:34:12] .../lua/vim/lsp.lua:1392 "LSP[ocaml-lsp]" "client.request" 1 "textDocument/rename"
{
newName = "y",
position = {
character = 6,
line = 241
},
textDocument = {
uri = "file:///path/to/file.ml"
}
}
[DEBUG][2023-09-05 17:34:12] .../vim/lsp/rpc.lua:284 "rpc.send"
{
id = 7,
jsonrpc = "2.0",
method = "textDocument/rename",
params = {
newName = "y",
position = {
character = 6,
line = 241
},
textDocument = {
uri = "file:///path/to/file.ml"
}
}
}
[DEBUG][2023-09-05 17:34:12] .../vim/lsp/rpc.lua:387 "rpc.receive"
{
id = 7,
jsonrpc = "2.0",
result = {
changes = {
["file:///path/to/file.ml"] = { {
newText = "y",
range = {
["end"] = {
character = 7,
line = 241
},
start = {
character = 6,
line = 241
}
}
}, {
newText = "y",
range = {
["end"] = {
character = 10,
line = 244
},
start = {
character = 4,
line = 243
}
}
} }
}
}
}
Just to confirm, rename doesn't work properly with ppx_string in ocamllsp, but it does work in merlin. Is that correct?
Ah interesting this is definitely a Merlin bug (inspecting the debug output reveals this) but the :MerlinRename command in Vim does not actually perform the bad rename. The debug log says:
# 0.11 occurrences - Occurrences paths
[
{
"start": { "line": 242, "col": 6 },
"end": { "line": 242, "col": 7 },
"under_cursor": true,
"path": "x"
}
]
# 0.11 New_merlin - run(result)
{
"class": "return",
"value": [
{ "start": { "line": 242, "col": 6 }, "end": { "line": 242, "col": 7 } },
{ "start": { "line": 244, "col": 4 }, "end": { "line": 245, "col": 10 } }
],
...
}
but :MerlinRename y actually does:
let f y =
[%string
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
%{x}"]
;;
which is not ideal, but not bad behavior. But ocaml-lsp is more faithfully applying the Merlin edits than the Merlin vim plugin. I'll file a bug on Merlin.