-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from GaloisInc/sc/position-range-shadow
CN server: enhance abstractions for `Position`s and `Range`s
- Loading branch information
Showing
5 changed files
with
79 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
open! Base | ||
|
||
type t = Lsp.Types.Position.t | ||
|
||
let create ~(line : int) ~(character : int) = Lsp.Types.Position.create ~line ~character | ||
let eq (p1 : t) (p2 : t) : bool = p1.line = p2.line && p1.character = p2.character | ||
|
||
let lt (p1 : t) (p2 : t) : bool = | ||
p1.line < p2.line || (p1.line = p2.line && p1.character < p2.character) | ||
;; | ||
|
||
let le (p1 : t) (p2 : t) : bool = lt p1 p2 || eq p1 p2 | ||
|
||
let gt (p1 : t) (p2 : t) : bool = | ||
p1.line > p2.line || (p1.line = p2.line && p1.character > p2.character) | ||
;; | ||
|
||
let ge (p1 : t) (p2 : t) : bool = gt p1 p2 || eq p1 p2 | ||
let compare (p1 : t) (p2 : t) : int = if lt p1 p2 then -1 else if gt p1 p2 then 1 else 0 | ||
let to_string (p : t) : string = Printf.sprintf "%i:%i" p.line p.character |
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,12 @@ | ||
open! Base | ||
|
||
type t = Lsp.Types.Position.t | ||
|
||
val create : line:int -> character:int -> t | ||
val compare : t -> t -> int | ||
val lt : t -> t -> bool | ||
val le : t -> t -> bool | ||
val eq : t -> t -> bool | ||
val ge : t -> t -> bool | ||
val gt : t -> t -> bool | ||
val to_string : t -> string |
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,26 @@ | ||
open! Base | ||
|
||
type t = Lsp.Types.Range.t | ||
|
||
let create ~(start : Position.t) ~(end_ : Position.t) : t = | ||
Lsp.Types.Range.create ~start ~end_ | ||
;; | ||
|
||
let to_string (range : t) : string = | ||
Printf.sprintf "%s-%s" (Position.to_string range.start) (Position.to_string range.end_) | ||
;; | ||
|
||
let ( |--| ) ((l1, c1) : int * int) ((l2, c2) : int * int) : t = | ||
create | ||
~start:(Position.create ~line:l1 ~character:c1) | ||
~end_:(Position.create ~line:l2 ~character:c2) | ||
;; | ||
|
||
let of_cerb_loc (loc : Cerb_location.t) : t option = | ||
match Cerb_location.to_cartesian loc with | ||
| None -> None | ||
| Some ((l1, c1), (l2, c2)) -> | ||
let start = Position.create ~line:l1 ~character:c1 in | ||
let end_ = Position.create ~line:l2 ~character:c2 in | ||
Some (create ~start ~end_) | ||
;; |
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,11 @@ | ||
open! Base | ||
|
||
type t = Lsp.Types.Range.t | ||
|
||
val create : start:Position.t -> end_:Position.t -> t | ||
val to_string : t -> string | ||
|
||
(** Convenience notation: [(begin_line, begin_char) |--| (end_line, end_char)] *) | ||
val ( |--| ) : int * int -> int * int -> t | ||
|
||
val of_cerb_loc : Cerb_location.t -> t option |