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

Stale occurrences #1488

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:

# Remove this pin once a compatible version of Merlin has been released
- name: Pin dev Merlin
run: opam --cli=2.1 pin --with-version=5.4-503 https://github.com/liam923/merlin.git#rename-holes
run: opam --cli=2.1 pin --with-version=5.4-503 https://github.com/ocaml/merlin.git#main

- name: Build and install dependencies
run: opam install .
Expand Down
19 changes: 12 additions & 7 deletions ocaml-lsp-server/src/ocaml_lsp_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ let references
match Document.kind doc with
| `Other -> Fiber.return None
| `Merlin doc ->
let* locs, synced =
let* occurrences, synced =
Document.Merlin.dispatch_exn
~name:"occurrences"
doc
Expand All @@ -445,7 +445,8 @@ let references
| _ -> Fiber.return ()
in
Some
(List.map locs ~f:(fun loc ->
(List.map occurrences ~f:(fun (occurrence : Query_protocol.occurrence) ->
let loc = occurrence.loc in
let range = Range.of_loc loc in
let uri =
match loc.loc_start.pos_fname with
Expand All @@ -470,14 +471,15 @@ let highlight
match Document.kind doc with
| `Other -> Fiber.return None
| `Merlin m ->
let+ locs, _synced =
let+ occurrences, _synced =
Document.Merlin.dispatch_exn
~name:"occurrences"
m
(Occurrences (`Ident_at (Position.logical position), `Buffer))
in
let lsp_locs =
List.filter_map locs ~f:(fun loc ->
List.filter_map occurrences ~f:(fun (occurrence : Query_protocol.occurrence) ->
let loc = occurrence.loc in
let range = Range.of_loc loc in
(* filter out multi-line ranges, since those are very noisy and happen
a lot with certain PPXs *)
Expand Down Expand Up @@ -660,16 +662,19 @@ let on_request
match Document.kind doc with
| `Other -> Fiber.return None
| `Merlin doc ->
let+ locs, _synced =
let+ occurrences, _synced =
Document.Merlin.dispatch_exn
~name:"occurrences"
doc
(Occurrences (`Ident_at (Position.logical position), `Buffer))
in
let loc =
List.find_opt locs ~f:(fun loc ->
List.find_map occurrences ~f:(fun (occurrence : Query_protocol.occurrence) ->
let loc = occurrence.loc in
let range = Range.of_loc loc in
Position.compare_inclusion position range = `Inside)
match Position.compare_inclusion position range with
| `Inside -> Some loc
| `Outside _ -> None)
in
Option.map loc ~f:Range.of_loc)
()
Expand Down
10 changes: 9 additions & 1 deletion ocaml-lsp-server/src/rename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ let rename (state : State.t) { RenameParams.textDocument = { uri }; position; ne
let command =
Query_protocol.Occurrences (`Ident_at (Position.logical position), `Renaming)
in
let+ locs, _desync = Document.Merlin.dispatch_exn ~name:"rename" merlin command in
let+ occurrences, _desync =
Document.Merlin.dispatch_exn ~name:"rename" merlin command
in
let locs =
List.filter_map occurrences ~f:(fun (occurrence : Query_protocol.occurrence) ->
match occurrence.is_stale with
| true -> None
| false -> Some occurrence.loc)
in
let version = Document.version doc in
let uri = Document.uri doc in
let edits =
Expand Down