Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#247] Add .clangd configuration file syntax checker #249
[#247] Add .clangd configuration file syntax checker #249
Changes from 4 commits
64f8d69
c714fe7
8792280
b64d55a
4493b67
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is an incorrect assumption in this if - that is that buffer is the whole file contents. This is probably true for small files, but not so for bigger files. getPointer() is the index in the buffer, and getIndex() is the index in the file (but in code points, not bytes or characters)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implies that we should/could not rely on the buffer delivered with the exception? If so, I've to re-read the file in the MarkedYAMLException catch clause to determine the document/file length:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That code snippet is the number of bytes in the file :-( number of bytes, chars and code points can all be different.
Turning the code point index back into char pr byte index is a non-trivial operation. I would say it probably isn't worth it.
What is the problem that using the length of the file is trying to solve? Is it an out of bound exception on the charEnd by just adding 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
![image](https://private-user-images.githubusercontent.com/123444711/303142409-08f1dc61-da3c-4110-b40e-762208720600.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk5ODA3MjAsIm5iZiI6MTczOTk4MDQyMCwicGF0aCI6Ii8xMjM0NDQ3MTEvMzAzMTQyNDA5LTA4ZjFkYzYxLWRhM2MtNDExMC1iNDBlLTc2MjIwODcyMDYwMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxOVQxNTUzNDBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05MzhlYjI2ODcyMTQyZWQ5NWYxY2VkNTI5YWNkNjYwZWE3NWFhN2RkNDgzNWQ0ZTg1MjI2NzA5MjhhMmI0Mzg4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.yiWMAkt5aVagX-iOTKU7r_OKtII6lG3a3fpODiSWttM)
problemMark.getIndex() == buffer.length()
then the marker index points to the non visible \r or \n character and the marker cannot be displayed:The maker is only visible on the file in the project explorer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, as above, when there is no \r\n, index + 1 > buffer.length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a small error here, index is in codePoints, but charStart is measured in characters. So you can get some slightly offset files. Consider this file that uses tab incorrectly:
renders the error as expected:
But if you use a character requiring surrogate pairs such as
😂
you get an off by one error. If there are lots of such characters before the error in the file it can be quite far off.In this case since the error is a single character wide, you can end up having no red underline at all because the range is less than a displayed character:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems hard to solve. As you mentioned above, all we have is the number of bytes:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - it is a small (but interesting) problem. I am not convinced you need to solve it, but just be aware of it.
You can choose to not solve it, and leave it as a known problem that it will get the charStart/End correct only if bytes == chars == code points. I don't know how often this will be a real world problem.
Same thing for the above end of file.
I think it is ok to have this deficiency because the error marker will be present on the file and error message will be correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS If you do want to solve the problem, you can read the number of code points in the file and then you will have exact indexes. To do this you need to do BOM handling (see
org.yaml.snakeyaml.reader.UnicodeReader
) and convert char to code point (seeorg.yaml.snakeyaml.reader.StreamReader.update()
ororg.yaml.snakeyaml.error.Mark.toCodePoints(char[])
for code you may be able to call)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll see if I can solve this later. I can open a separate issue for that.
It is indeed a problem on larger files. I've to re-read the file into a buffer stream to get the end of the buffer. The buffer in the MarkedYAMLException was limited to ~800 bytes:
![image](https://private-user-images.githubusercontent.com/123444711/303148475-9bd51007-1f30-4bf0-bd51-2f42dbde6533.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk5ODA3MjAsIm5iZiI6MTczOTk4MDQyMCwicGF0aCI6Ii8xMjM0NDQ3MTEvMzAzMTQ4NDc1LTliZDUxMDA3LTFmMzAtNGJmMC1iZDUxLTJmNDJkYmRlNjUzMy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxOVQxNTUzNDBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05ZjE0ZTNmNjVlYWU5OGQ4Zjk3ZjIyZjUzNmU5OTU0N2QwOTJhOTRjNzFmYTZlYjVkNzkzNDY2NWE4ODZjOTdkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.HB_Eq0QxpM-xpNOPgt1XNARwV_xkXn4a0K0jX2EFLWE)
IMO the missing error marker at the end of the file is more relevant, because I think it is more a real world problem to forget the final } than using non UTF-8 characters in a txt file. So I would like to add the re-read of the file to the catch clause at mentioned here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.