fix(cpp): survive clangd crashes and degenerate ranges during parse#200
Merged
Merged
Conversation
Make large-workspace C++ parsing resilient to clangd faults instead of
aborting the whole run on a single failure:
- lsp/client.go: auto-restart the LSP server (C++ only) when the jsonrpc2
connection dies (clangd segfaults on pathological template typeHierarchy).
Generation-counter guarding lets many goroutines observe the same dead
conn but only one respawns; cached docs are marked not-opened so DidOpen
re-notifies the fresh server. Call/Notify detect conn-closed and trigger it.
- collect.go/export.go: runSafe() recovers per-symbol panics ("崩了就跳过")
so one bad symbol is skipped, not fatal; wrap Collect/Export loops.
- lsp_methods.go/utils.go: guard degenerate (inverted/out-of-bounds) clangd
ranges in Locate/GetDistance/RelativePostionWithLines to avoid slice panics.
- collect.go: collectCppBasesViaAST resolves dependent template bases
(class Foo : public Tmpl<X,Y>) from textDocument/ast, which typeHierarchy
cannot expose; cppSymbolAST adds a per-symbol AST path for .cpp out-of-line
definitions. typeHierarchy crashes are counted/logged, not disabled.
- cpp/lib.go: enable clangd --background-index for a persisted cross-TU index
that survives restarts and speeds the per-symbol query storm.
Duslia
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What type of PR is this?
fix
Check the PR title.
(Optional) Translate the PR title into Chinese.
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
Make large-workspace C++ parsing resilient to clangd faults instead of aborting the whole run on a single failure:
zh(optional):
(Optional) Which issue(s) this PR fixes:
(optional) The PR that updates user documentation: