File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
plugins/hls-selection-range-plugin/src/Ide/Plugin Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -119,13 +119,21 @@ spansToSelectionRange (span:spans) = Just $
119
119
SelectionRange {_range = realSrcSpanToRange span , _parent = spansToSelectionRange spans}
120
120
121
121
{-|
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.
124
125
-}
125
126
findSelectionRangesByPositions :: [SelectionRange ] -- ^ all possible selection ranges
126
127
-> [Position ] -- ^ requested positions
127
128
-> [SelectionRange ]
128
129
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
+ -}
129
137
where
130
138
findByPosition :: Position -> SelectionRange
131
139
findByPosition p = fromMaybe SelectionRange {_range = Range p p, _parent = Nothing } $
You can’t perform that action at this time.
0 commit comments