Bodigrim / text-rope

A wrapper around Text for fast line/column navigation and logarithmic concatenation
https://hackage.haskell.org/package/text-rope
BSD 3-Clause "New" or "Revised" License
36 stars 4 forks source link

Add a function to extract specific line from TextLines? #5

Open jhrcek opened 4 months ago

jhrcek commented 4 months ago

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 and getLine :: Word -> TextLines -> Maybe Text

With the current api I can do it like this

What do you think about adding few high-level helpers like this to the library?

Bodigrim commented 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.

jhrcek commented 4 months ago

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
Bodigrim commented 2 months ago

@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.

jhrcek commented 2 months ago

Thanks, will look into it in the next few days.