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

[hover] Fix get_id_at_point in the presence of Unicode chars #597

Merged
merged 1 commit into from
Nov 7, 2023
Merged
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
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.