wz1000 / HieDb

Generates a references DB from .hie files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting x-references in bytespan format

gustavoavena opened this issue · comments

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!

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.

Thanks for the quick reply @wz1000!

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

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.

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! 🙂