Open jhrcek opened 4 months ago
I'd prefer
getLine :: Word -> Rope -> Text
getRange :: Position -> Position -> Rope -> Text
and same for TextLines
instead of Rope
, but let's wait for #4 to land first.
Great, I'm not in a hurry to implement it. Just a question about your proposed types: Wouldn't it make more sense to wrap the return types in Maybe? You know, to distinguish between cases where given Word / Position x Position are "out of bounds"?
getLine 0 "hello" == Just "hello"
getLine 1 "hello" == Nothing
@jhrcek #4 has landed, so feel free to take a stab at this issue.
I'd prefer to keep new functions consistent with existing split*
functions, which do not return Maybe
.
Thanks, will look into it in the next few days.
I'm currently looking at implementing some functionality in haskell language server which uses this library.
I would like to implement something like
getTextAtRange :: LSP.Range -> Rope -> Maybe Text
andgetLine :: Word -> TextLines -> Maybe Text
With the current api I can do it like this
Rope.lines r
and then index to the resulting list (I assume this is inefficient - linear time in number of lines?)Rope.splitAtLine
twice (example of this in hls: https://github.com/haskell/haskell-language-server/blob/50923e5c790e9c55c2b9b1bfcc8e78f7169f8ea3/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs#L907-L908) - this seems like more efficient way to achieve that, but not very convenient.What do you think about adding few high-level helpers like this to the library?