kubeshop / vscode-monokle

An extension for Visual Studio Code to validate your Kubernetes configuration
https://marketplace.visualstudio.com/items?itemName=kubeshop.monokle
MIT License
6 stars 0 forks source link

Highlights for validation errors are a bit off after editing a file #1

Closed f1ames closed 1 year ago

f1ames commented 1 year ago

Some highlights seems to be a bit off (see screenshot below). Tested with https://github.com/kubeshop/monokle-demo.

Might be an issue with @monokle/validation.

image

f1ames commented 1 year ago

Hmmm, looks like it might be OS specific issue 🤔

For me (Windows, WSL) it looks the same as in the cloud (which seems correct):

image image

@WitoDelnat did you do any actions in between or it was off from the very beginning? Maybe you can share your SARIF result file so I can see if offsets are correct (meaning if it's on @monokle/validation side or SARIF ext side).

f1ames commented 1 year ago

This happens when file is edited - on edit highlight stays in place, not being moved with old content when something is added/removed.

When running Validate command manually, it will be corrected. However, when automatic validation runs on file save it will stay as is. I suspect this is due to a difference how we interact with SARIF API in those two cases.

f1ames commented 1 year ago

It seems the issue is in @monokle/validation library, where start/end line are calculated incorrectly. I'm working on isolating this particular case to find the root cause why it happens.

f1ames commented 1 year ago

Fixed in https://github.com/kubeshop/vscode-monokle/commit/9342085b9d468a9c05ed01c4463f7b0f2e2baac1.

It turned out, that this issue is caused by @monokle/validator parser cache. The parser caches resources content by resource.id where id is generated based on only few resource properties. Depending on what was modified in the file the cache may not be cleared.

I still think the cache is quite useful, making validation really efficient (especially with multiple resources), so I implemented mechanism to only clear cache of a particular resource when it is modified.