Skip to content

chore: patching diagnostics kcl lsp error (symptom, not root cause) #7977

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nadr0
Copy link
Contributor

@nadr0 nadr0 commented Aug 4, 2025

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

chunk-JEVQZFNC.js?v=99604e51:780 Uncaught (in promise) RangeError: Position 112 is out of range for changeset of length 0
    at _ChangeSet.mapPos (chunk-JEVQZFNC.js?v=99604e51:780:13)
    at findSharedChunks (chunk-JEVQZFNC.js?v=99604e51:3076:49)
    at _RangeSet.compare (chunk-JEVQZFNC.js?v=99604e51:2871:24)
    at findChangedDeco (chunk-HHQTB6RG.js?v=99604e51:3349:12)
    at DocView.update (chunk-HHQTB6RG.js?v=99604e51:2828:20)
    at _EditorView.update (chunk-HHQTB6RG.js?v=99604e51:7203:30)
    at _EditorView.dispatchTransactions (chunk-HHQTB6RG.js?v=99604e51:7114:145)
    at _EditorView.dispatch (chunk-HHQTB6RG.js?v=99604e51:7136:10)
    at EditorManager.setDiagnostics (manager.ts:259:22)
    at KclManager.setDiagnosticsForCurrentErrors (KclSingleton.ts:237:36)
image

Implementation

When a user does CRTL+A and deletes all the code it needs to executeCode on the empty string. The setDiagnostics 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 because safeParse 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 and backspace 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.

@nadr0 nadr0 requested a review from a team as a code owner August 4, 2025 20:21
Copy link

vercel bot commented Aug 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 4, 2025 8:27pm

@nadr0 nadr0 changed the title chore: patching diagnostics kcl lsp error chore: patching diagnostics kcl lsp error (symptom, not root cause) Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant