Skip to content

Commit

Permalink
[hover] Fix get_id_at_point in the presence of Unicode chars
Browse files Browse the repository at this point in the history
This was affecting hover and jump to definition.

Thanks to Pierre Courtieu for the example and report.

Closes #594
  • Loading branch information
ejgallego committed Nov 7, 2023
1 parent 53e12d3 commit 2fa608a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
mistake (@ejgallego, #588)
- hover plugins can now access the full document, this is convenient
for many use cases (@ejgallego, #591)
- fix hover position computation on the presence of Utf characters
(@ejgallego, #597, thanks to Pierre Courtieu for the report and
example, closes #594)

# coq-lsp 0.1.8: Trick-or-treat
-------------------------------
Expand Down
7 changes: 6 additions & 1 deletion controller/rq_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(* Written by: Emilio J. Gallego Arias *)
(************************************************************************)

(* XXX: this doesn't work for Unicode either... *)
(* Common with completion... refactor and make proper *)
let is_id_char x =
('a' <= x && x <= 'z')
Expand Down Expand Up @@ -43,5 +44,9 @@ let get_id_at_point ~contents ~point =
let { Fleche.Contents.lines; _ } = contents in
if line <= Array.length lines then
let line = Array.get lines line in
if character <= String.length line then find_id line character else None
(* XXX UTF this will fail on unicode chars that differ among UTF-8/16 (cc
#531) *)
match Coq.Utf8.index_of_char ~line ~char:character with
| None -> None
| Some character -> find_id line character
else None
7 changes: 7 additions & 0 deletions examples/unicode2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(* Thanks to Pierre Courtieu for the example and report *)
Require Import Utf8.

(* Check hover works properly for `Nopick` *)
Variant pick_spec (T : Type) (P : T -> Prop) : option T -> Type :=
| Pick : forall x : T, P x -> pick_spec T P (Some x)
| Nopick : (∀ x : T, ¬ (P x)) → pick_spec T P None.

0 comments on commit 2fa608a

Please sign in to comment.