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

Rename does not work properly with ppx_string #1176

Open
ddickstein opened this issue Sep 5, 2023 · 2 comments
Open

Rename does not work properly with ppx_string #1176

ddickstein opened this issue Sep 5, 2023 · 2 comments
Labels

Comments

@ddickstein
Copy link
Collaborator

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
            }
          }
        } }
    }
  }
}
@rgrinberg
Copy link
Member

Just to confirm, rename doesn't work properly with ppx_string in ocamllsp, but it does work in merlin. Is that correct?

@ddickstein
Copy link
Collaborator Author

ddickstein commented Sep 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants