chore: patching diagnostics kcl lsp error (symptom, not root cause) #7977
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.
related #7256
Issue
When you
CRTL+A
and delete the entire KCL Editor for your file the system can keep the engine scene because the execute code will not finish.Debugging but cannot find exact root cause
Implementation
When a user does
CRTL+A
and deletes all the code it needs toexecuteCode
on the empty string. ThesetDiagnostics
is keeping an old diagnostics around which will try to be applied to the empty code which will crash during runtime and then won't actually execute the code becausesafeParse
fails before executing the code.e.g. The code and diagnostics are desynced for some reason. I am not able to figure out why they are desynced.
I check if the current code is the empty string and if the any diagnostics are present. There is no way that this is possible. I rewrite them to the
[]
to prevent the code from bricking.I still
console.error
if this happens.Anyone have other suggestions? I was able to reproduce this issue a few times with
CRTL+A
andbackspace
but it isn't easy. I know for a fact if you hard code some bad diagnostics into this workflow manually it will break so it is a workflow that is problematic. I just don't know where the root cause is to have these two things desync.Symptom, not root cause
I know this is a patch to prevent the code from bricking. Is it worth merging this? Maybe someone else has insights into this?
I know if the code is empty we should never have any diagnostics unless the diagnostic says "You have no code!" but I don't think that would ever happen. This feels like a corrective step at a later time in the workflow instead of preventing it at the root cause level. Note this workflow will only happen if the code is literally
''
the empty string.If someone CTRL+A and and writes a new block of code in its place, it could brick for this same reason but since the original bug was around CRTL+A and delete I tried to solve that symptom workflow.