wz1000 / HieDb

Generates a references DB from .hie files
BSD 3-Clause "New" or "Revised" License
64 stars 24 forks source link

Getting x-references in bytespan format #33

Closed gustavoavena closed 3 years ago

gustavoavena commented 3 years ago

Hey! I'm trying to use x-reference information from hiedbs, but I'm running into some trouble because I need them to be in Bytespan format (i.e. start and length), instead of Ranges (i.e. startLine, startCol, endLine, endCol).

I've built something that can get the information by reading the source file, getting the length of the lines and mapping ranges to bytespans using that information, but that's very slow...

Is there's a better way to do this with the existing API?

Thanks!

wz1000 commented 3 years ago

I don't think this is possible with the current API. GHC only maintains (line,col) information for sourcespans, but not positions in the buffer.

However, it should be fairly quick to compute a mapping from line numbers to byte offsets for each file. I would be surprised if this added too much overhead.

gustavoavena commented 3 years ago

Thanks for the quick reply @wz1000!

Hmm... I'm using HieDb.Dump.sourceCode to read the file. Could that be adding an overhead?

wz1000 commented 3 years ago

I suppose there could be some overhead from decoding the text and splitting it up into lines, but shouldn't be too bad. However, you don't want to pay for reading the entire hie file on every query. Ideally you could precompute all the line offsets for the files you care about, and then just do lookups to answer queries instead of consulting the hie files.

gustavoavena commented 3 years ago

Yep, you're right. Turns out I missed a silly bug in my code, which was the main reason for the slowness... Sorry for bringing this up unnecessarily and thank you so much for the quick responses @wz1000! 🙂