Jetbrains Autocomplete Crash Prevention #5825
Open
+110
−79
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 was a primarily AI-generated PR. Had Claude analyze #5819 and it came up with this analysis and solution:
AI analysis
After analyzing the code, I can identify several potential issues that could be causing crashes and conflicts with other JetBrains extensions:
Race Conditions in Lookup Management: The AutocompleteLookupListener uses an AtomicBoolean for tracking lookup state, but there's a potential race condition in the state management. The isLookupEmpty() function might return incorrect values if called between state changes.
Inlay Rendering Conflicts: The ContinueInlayRenderer doesn't check for existing inlays from other extensions before rendering, which could cause visual conflicts or crash when multiple extensions try to render inlays at the same position.
Interference with IDE's Native Completion: The AutocompleteService attempts to handle both native IDE completions and Continue's completions simultaneously, which can lead to conflicts. The shouldSkipRender check might not be sufficient to prevent all edge cases.
Resource Cleanup Issues: In AutocompleteService, the cleanup of inlays isn't always guaranteed in all code paths, especially during error conditions. This could lead to memory leaks or visual artifacts.
Thread Safety Concerns: The code mixes UI thread operations with background processing without proper synchronization in some places.
These changes address the main issues by:
Adding proper thread synchronization with a dedicated lock object
Improving state management for lookup tracking
Adding checks for conflicting inlays from other extensions
Ensuring cleanup happens in a thread-safe manner
Adding error handling and cleanup in failure cases
Using WriteAction.runAndWait instead of WriteAction.run to ensure proper sequencing
Additionally, you should consider adding these settings to give users more control:
Add a setting to control the delay before showing completions to avoid conflicts with IDE completions
Add a setting to control whether Continue completions should show while IDE completions are active
Add a setting to control the maximum number of concurrent inlays allowed
These changes should significantly reduce crashes and conflicts with other JetBrains extensions while maintaining the core functionality of the Continue autocomplete feature.
The main cause of the crashes appears to be race conditions and improper handling of concurrent modifications to the editor's inlay model when multiple extensions are active. The solution focuses on proper synchronization and conflict prevention rather than trying to force compatibility in all cases.
Summary by cubic
Improved JetBrains autocomplete stability by fixing race conditions, adding thread safety, and preventing conflicts with other extensions.