@@ -46,14 +46,35 @@ module Error = {
4646}
4747
4848module HoverHint = {
49- type position = {
50- line : int ,
51- col : int ,
49+ module Position = {
50+ type t = {
51+ line : int ,
52+ col : int ,
53+ }
54+ let compareLineCol = (pos1 , pos2 ) => {
55+ if pos1 .line < pos2 .line {
56+ Ordering .less
57+ } else if pos1 .line > pos2 .line {
58+ Ordering .greater
59+ } // same line, compare column
60+ else if pos1 .col < pos2 .col {
61+ Ordering .less
62+ } else if pos1 .col > pos2 .col {
63+ Ordering .greater
64+ } else {
65+ Ordering .equal
66+ }
67+ }
68+ // let \"<" = (pos1, pos2) => compareLineCol(pos1, pos2) === Ordering.less
69+ let \"<=" = (pos1 , pos2 ) => compareLineCol (pos1 , pos2 ) !== Ordering .greater
70+ // let \">" = (pos1, pos2) => compareLineCol(pos1, pos2) === Ordering.greater
71+ let \">=" = (pos1 , pos2 ) => compareLineCol (pos1 , pos2 ) !== Ordering .less
72+ // let \"==" = (pos1, pos2) => compareLineCol(pos1, pos2) === Ordering.equal
5273 }
5374
5475 type t = {
55- start : position ,
56- end : position ,
76+ start : Position . t ,
77+ end : Position . t ,
5778 hint : string ,
5879 }
5980}
@@ -613,8 +634,21 @@ let createHoverHintExtension = (hoverHints: array<HoverHint.t>) => {
613634 let doc = view -> CM6 .EditorView .state -> CM6 .EditorState .doc
614635 let {number : line , from } = doc -> CM6 .Text .lineAt (pos )
615636 let col = pos - from
616- let found = hoverHints -> Array .find (({start , end }) => {
617- line >= start .line && line <= end .line && col >= start .col && col <= end .col
637+ let mousePos = {HoverHint .Position .line , col }
638+
639+ let found = Array .reduce (hoverHints , None , (prev , currentHint ) => {
640+ open ! HoverHint .Position
641+ let currentHintIncludesMousePos = currentHint .start <= mousePos && currentHint .end >= mousePos
642+ switch prev {
643+ | None if currentHintIncludesMousePos => Some (currentHint )
644+ | Some (prevHint )
645+ if currentHintIncludesMousePos &&
646+ (currentHint .start >= prevHint .start &&
647+ currentHint .end <= prevHint .end ) =>
648+ Some (currentHint )
649+ | None
650+ | Some (_ ) => prev
651+ }
618652 })
619653 switch found {
620654 | Some ({hint , start , end }) =>
0 commit comments