Skip to content

Commit bd7fcfd

Browse files
author
kokobd
committed
fix comment for findSelectionRangesByPositions
1 parent 48a4709 commit bd7fcfd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

plugins/hls-selection-range-plugin/src/Ide/Plugin/SelectionRange.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,21 @@ spansToSelectionRange (span:spans) = Just $
119119
SelectionRange {_range = realSrcSpanToRange span, _parent = spansToSelectionRange spans}
120120

121121
{-|
122-
Filters the selection ranges containing at least one of the given positions, without taking each selection range's
123-
parent into account.
122+
For each position, find the selection range that contains it, without taking each selection range's
123+
parent into account. These selection ranges are un-divisible, representing the leaf nodes in original AST, so they
124+
won't overlap.
124125
-}
125126
findSelectionRangesByPositions :: [SelectionRange] -- ^ all possible selection ranges
126127
-> [Position] -- ^ requested positions
127128
-> [SelectionRange]
128129
findSelectionRangesByPositions selectionRanges = fmap findByPosition
130+
{-
131+
Performance Tips:
132+
Doing a linear search from the first selection range for each position is not optimal.
133+
If it becomes too slow for a large file and many positions, you may optimize the implementation.
134+
At least we don't need to search from the very beginning for each position, if the are sorted firstly.
135+
Or maybe we could apply some techniques like binary search?
136+
-}
129137
where
130138
findByPosition :: Position -> SelectionRange
131139
findByPosition p = fromMaybe SelectionRange{_range = Range p p, _parent = Nothing} $

0 commit comments

Comments
 (0)