File tree Expand file tree Collapse file tree 4 files changed +24
-0
lines changed Expand file tree Collapse file tree 4 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ let of_string s =
39
39
; line = 0
40
40
}
41
41
42
+ let offset t = t.abs_pos + t.rel_pos
43
+
42
44
let length =
43
45
let f acc sub = acc + Substring. length sub in
44
46
fun { abs_pos = _ ; current; left; right; rel_pos = _ ; line = _ } ->
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ val drop_until : t -> t -> t
30
30
val apply_change :
31
31
t -> Types.Range .t -> [ `UTF16 | `UTF8 ] -> replacement :string -> t
32
32
33
+ val offset : t -> int
34
+
33
35
module Private : sig
34
36
type zipper : = t
35
37
Original file line number Diff line number Diff line change @@ -104,3 +104,11 @@ let apply_text_document_edits t (edits : TextEdit.t list) =
104
104
let text = apply_changes t.zipper t.position_encoding edits in
105
105
let zipper = String_zipper. of_string text in
106
106
{ t with text = Some text; zipper }
107
+
108
+ module Expert = struct
109
+ let goto t pos =
110
+ let zipper = String_zipper. goto_position t.zipper pos `UTF8 in
111
+ { t with zipper }
112
+
113
+ let offset t = String_zipper. offset t.zipper
114
+ end
Original file line number Diff line number Diff line change @@ -30,3 +30,15 @@ val set_version : t -> version:int -> t
30
30
when multiple inserts are done in the same position. All the offsets are
31
31
interpreted relative to the original document. *)
32
32
val apply_text_document_edits : t -> TextEdit .t list -> t
33
+
34
+ module Expert : sig
35
+ (* * These functions allow one to work with the underlying zipper. This gives
36
+ the opportunity for better performance on chained edits. *)
37
+
38
+ (* * [goto t pos] move the zipper of [t] to [pos]. [pos] must be in utf8 *)
39
+ val goto : t -> Position .t -> t
40
+
41
+ (* * [offset t] return the global offset in the string where the zipper is
42
+ currently focused *)
43
+ val offset : t -> int
44
+ end
You can’t perform that action at this time.
0 commit comments