-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[info] Hook completion call, fix still some issues with range.
- Loading branch information
Showing
6 changed files
with
147 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(************************************************************************) | ||
(* Coq Language Server Protocol *) | ||
(* Copyright 2019 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *) | ||
(* Copyright 2022 Inria -- Dual License LGPL 2.1 / GPL3+ *) | ||
(* Written by: Emilio J. Gallego Arias *) | ||
(************************************************************************) | ||
(* Status: Experimental *) | ||
(************************************************************************) | ||
|
||
type t = | ||
{ range : Lang.Range.t | ||
; contents : String.t | ||
} | ||
|
||
let make ~contents ~range = { range; contents } | ||
|
||
let delim c = | ||
match c with | ||
| '\n' | ' ' -> true | ||
| _ -> false | ||
|
||
let rec find_backwards_delim offset lower text = | ||
if offset = lower then offset | ||
else if delim text.[offset - 1] then offset | ||
else find_backwards_delim (offset - 1) lower text | ||
|
||
let rec id_at_point acc offset upper text = | ||
if delim text.[offset] || offset + 1 = upper then acc | ||
else id_at_point (text.[offset] :: acc) (offset + 1) upper text | ||
|
||
let id_at_point offset upper text = | ||
let id = id_at_point [] offset upper text |> List.rev in | ||
let len = List.length id in | ||
String.init len (List.nth id) | ||
|
||
let debug_find cat msg = | ||
if Debug.find then Io.Log.trace ("Span.find: " ^ cat) msg | ||
|
||
let find ~offset ~(range : Lang.Range.t) text = | ||
let lower = range.start.offset in | ||
let upper = range.end_.offset in | ||
debug_find "lower / upper" (string_of_int lower ^ "/" ^ string_of_int upper); | ||
debug_find "text length" (string_of_int (String.length text)); | ||
let rtext = String.sub text lower (upper - lower) in | ||
debug_find "ranged" rtext; | ||
debug_find "char at off" (String.make 1 text.[offset]); | ||
debug_find "initial offset" (string_of_int offset); | ||
let offset = find_backwards_delim offset lower text in | ||
debug_find "span.find, base offset" (string_of_int offset); | ||
id_at_point offset upper text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(************************************************************************) | ||
(* Coq Language Server Protocol *) | ||
(* Copyright 2019 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *) | ||
(* Copyright 2022 Inria -- Dual License LGPL 2.1 / GPL3+ *) | ||
(* Written by: Emilio J. Gallego Arias *) | ||
(************************************************************************) | ||
(* Status: Experimental *) | ||
(************************************************************************) | ||
|
||
type t = | ||
{ range : Lang.Range.t | ||
; contents : String.t | ||
} | ||
|
||
val make : contents:String.t -> range:Lang.Range.t -> t | ||
|
||
(** [find ~offset ~range text] finds an identifier at offset, offset is | ||
absolutely positioned *) | ||
val find : offset:int -> range:Lang.Range.t -> string -> string | ||
|
||
(** TODO: | ||
- We want some kind of tokenization for the span, two kinds of | ||
spans, with AST, and without | ||
(** Focused text span on a range / XXX same structure than caching *) | ||
type context = | ||
| Parsed of { span : t; node : Doc.node } | ||
(** [span] corresponding to [node] *) | ||
| Text of { span : t; prev : Doc.node } | ||
(** Independent [span], [prev] node for help *) | ||
*) |