feat: Add --fix and --export-fixes support #27
+3,262
−206
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.
This change introduces an automatic fixing capability to
clangd-tidy, allowing it to apply clang-tidy's suggested fixes, including complex cross-file refactorings like renames. Cross-file fixes are something not supported by clang-tidy, only by clangd via LSP.This is implemented via two new flags:
--fix: Directly applies fixes to the source files.--export-fixes <file>: Exports the fixes to a YAML file in the format used byclang-apply-replacements.To support this complex, stateful interaction with
clangd, the tool's architecture has been significantly refactored.Event-Driven Architecture
The newly introduced complex LSP interactions are expressed using
Flows. Their focus is to make it somewhat easier to reason about the asynchronous operations and state management involved in interacting withclangd. To support this, a new event-driven architecture has been introduced using anEventBus.This new architecture brings several benefits:
clangdcrashes, retrying incomplete operations without losing state.Fix Application Logic
To support cross-file fixes, which are not available through inline code actions, the tool now performs a more sophisticated dance with the LSP server:
clangd's background indexing to complete to ensure it has a complete view of the project.clangd.applyRename).workspace/applyEditrequests from the server, which may contain edits for multiple files.Other Changes
cattrsto>= 25.1.0to support newly introducedUniontypes.cattrsversion. Python 3.9 is already EOL.loggingfor warnings instead of printing directly to stderr.Performance
This has been evaluated on a non-trivial C++ codebase (~50 files). Using just the
--diagnosticsmode, the performance impact is around 1% overhead compared to the previous version.