Get linenumber of match

The cli tool seems to return an offset and length parameter, but this can be quite annoying to work with on large documents, is there anyway to get a start/end line number and start/end column number?

1 Like

I found 2 issues related to this:

The 2nd one was opened by me. I had forgotten about the first issue.
They are really duplicates.

According to comments in the 1st issue, both Vim and Emacs are annoyed by having Unicode offsets (which is not documented properly by the way in the LT API).
A Unicode offset is rather ambiguous, e.g. with composing characters.
In fact even LT is confused as its command line does not highlight errors properly with composing Unicode characters in:

I had asked about how to do that in Vim in the vimdev mailing list and whether a new Vim function was needed. But the author of Vim was not keen. See his reply:

I now see that had a workaround in comments:

let l:byte_index = byteidx(system("cat " . expand(myfile)), offset)
let l:line = byte2line(l:byte_index)
let l:col = l:byte_index - line2byte(l:line)

I have not tried it yet. I will try to fix my Vim plugin during my Christmas holidays using such a workaround. However, it’s rather ugly and might also be slow for large documents.

IMO, providing the line numbers seems like a basic requirement to help tools integrate LanguageTool. Not having it anymore in the new JSON API is an unfortunate regression.
And the old XML API is now deprecated.