notskm / vscode-clang-tidy

MIT License
49 stars 25 forks source link

Russian symbols break warning position. #13

Closed IgorKhramtsov closed 3 years ago

IgorKhramtsov commented 4 years ago

The warning position is shifted on russian characters count come before. The same appears not only if russian symbols in comments, but if they in quotes too.

Expecting: image Actual: image

notskm commented 4 years ago

I'm not sure if this is a problem I can solve.

Clang-Tidy reports a byte offset for the start and end locations of a diagnostic.

The VSCode API provides TextDocument.positionAt(offset: number): vscode.Position This converts a character offset to a vscode.Position. vscode.Position allows me to tell VSCode where in the file to render the diagnostic.

As far as I know, there is no alternative to TextDocument.positionAt() that takes a byte offset. If we're dealing with ASCII, this is fine. But it fails as soon as you start using multi-byte characters.

There is an issue for this in the VSCode repo, but it has been closed as "out of scope". https://github.com/Microsoft/vscode/issues/5735

IgorKhramtsov commented 4 years ago

Sad, but ok. Thanks.

mjblog commented 4 years ago

I'm not sure if this is a problem I can solve.

Maybe we could get line number from the raw text? I have encountered the same problem. And I used the attached patch to get the right line number. I'm not sure it's a correct solution, but at least I can find the right place to fix now... @notskm @Crataegus27

quick_and_dirty_fix.patch.txt

notskm commented 4 years ago

@mjblog This looks like it just highlights the entire line where an error occurs. I'd much rather highlight the specific parts of a line where the error is.

mjblog commented 4 years ago

@notskm Yes, I just fetch lineno from the error message as a quick workaround. But, of course we can also fetch the start position from the error message.
Although the start and end positions still suffer from the multi-byte problem, we provide a correct lineno anyway. It's a pareto improvement, I suppose. As you said ,if VSCODE do not provide interfaces to handle multi-byte characters, there will be no perfect solution.