Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

## Fixes

- Use consistent document snapshots and versions when converting rename
occurrences into workspace edits. (#2062, @rgrinberg)
- Keep construct-completion text edits on the request line when Merlin recovery
returns a multiline location. (#2034, @rgrinberg)
- Advertise Dune promotion code actions using their returned `quickfix` kind.
Expand Down
20 changes: 12 additions & 8 deletions ocaml-lsp-server/src/rename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ let prepare

let rename (state : State.t) { RenameParams.textDocument = { uri }; position; newName; _ }
=
let doc = Document_store.get state.store uri in
let documents =
Document_store.fold
state.store
~init:(Map.empty (module Uri))
~f:(fun document documents ->
Map.set documents ~key:(Document.uri document) ~data:document)
in
let doc = Map.find_exn documents uri in
match Document.kind doc with
| `Other -> Fiber.return (WorkspaceEdit.create ())
| `Merlin merlin ->
Expand Down Expand Up @@ -106,10 +113,9 @@ let rename (state : State.t) { RenameParams.textDocument = { uri }; position; ne
let edits =
Map.mapi locs ~f:(fun ~key:doc_uri ~data:locs ->
let source =
match Document_store.get_opt state.store doc_uri with
| Some doc when DocumentUri.equal doc_uri (Document.uri doc) ->
Document.source doc
| Some _ | None ->
match Map.find documents doc_uri with
| Some doc -> Document.source doc
| None ->
let source_path = Uri.to_path doc_uri in
In_channel.with_open_text source_path In_channel.input_all |> Msource.make
in
Expand Down Expand Up @@ -152,9 +158,7 @@ let rename (state : State.t) { RenameParams.textDocument = { uri }; position; ne
let documentChanges =
Map.to_alist edits
|> List.map ~f:(fun (uri, edits) ->
let version =
Document_store.get_opt state.store uri |> Option.map ~f:Document.version
in
let version = Map.find documents uri |> Option.map ~f:Document.version in
let textDocument =
OptionalVersionedTextDocumentIdentifier.create ~uri ?version ()
in
Expand Down
Loading