ADFA-3739: collect and report Kotlin syntax errors#1191
Conversation
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
fixes duplicate class errors for org.antrl.v4.* classes Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
It is now included in the embeddable JAR (named UnsafeAndroid) with proper relocations. Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
…ject re-sync Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Handles document events to manage instances of in-memory KtFile that can be used by various Kt LSP components (like diagnostics provider, code completions) to re-use already parsed KtFile instances Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
This ensures that extension functions whose receiver type is not available in the current scope are not suggested for scope completions Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
The StandaloneProjectFactory takes care of setting up a special MockProject instance which allows us to use Intellij's MessageBus to notify the analysis API about file changes. Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
…odules Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Libraries are already indexed by JvmLibraryIndexingService Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
This indexed is *always* refreshed after every successful build Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
📝 WalkthroughRelease Notes - ADFA-3739: Kotlin Syntax Error Collection and ReportingFeatures
Changes
Risks & Considerations
WalkthroughThe PR refactors Kotlin LSP components: snippet management shifts from eager parsing to lazy retrieval through a shared registry, while diagnostic collection expands to include PSI error elements alongside Kotlin analysis diagnostics. Changes
Sequence Diagram(s)sequenceDiagram
participant KSR as KotlinSnippetRepository
participant SR as SnippetRegistry
participant Client as LSP Client
Note over KSR,SR: Old Flow (Eager Loading)
Client->>KSR: init()
KSR->>SR: SnippetParser.parse("kt", scopes)
SR-->>KSR: Populate snippets map
Client->>KSR: getSnippets()
KSR-->>Client: Return cached snippets
Note over KSR,SR: New Flow (Lazy Loading)
Client->>KSR: init()
KSR->>SR: initBuiltIn("kt", scopes)
SR-->>KSR: OK
Client->>KSR: snippets getter
KSR->>SR: getSnippets("kt", scope) per scope
SR-->>KSR: Retrieve snippet map
KSR-->>Client: Return computed snippets
sequenceDiagram
participant KDP as KotlinDiagnosticProvider
participant PSI as PSI File
participant KA as Kotlin Analysis
participant DI as DiagnosticItem
Note over KDP,DI: Enhanced Diagnostic Collection
KDP->>PSI: Collect PsiErrorElement instances
PSI-->>KDP: Return error elements
KDP->>DI: Create ERROR DiagnosticItem per element
DI-->>KDP: Return diagnostic items
KDP->>KA: collectDiagnostics(EXTENDED_AND_COMMON_CHECKERS)
KA-->>KDP: Return KaDiagnostic results
KDP->>DI: toDiagnosticItem() via helper
DI-->>KDP: Return diagnostic items
KDP-->>KDP: Aggregate both sources
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/completion/KotlinSnippetRepository.kt (2)
3-5:SnippetParserimport appears unused after this change.
init()now delegates toSnippetRegistry.initBuiltIn, andSnippetParseris no longer referenced in this file. Worth dropping the import if your linter/IDE doesn't already flag it.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/completion/KotlinSnippetRepository.kt` around lines 3 - 5, The file KotlinSnippetRepository.kt still imports SnippetParser but the init() implementation now delegates to SnippetRegistry.initBuiltIn and no longer references SnippetParser; remove the unused import statement for SnippetParser to clean up the code and satisfy the linter, leaving the imports for ISnippet and SnippetRegistry intact and ensuring KotlinSnippetRepository.init() continues to call SnippetRegistry.initBuiltIn.
8-11: Getter rebuilds the full map on every access.Every read of
snippetsnow iterates allKotlinSnippetScope.entries, invokesSnippetRegistry.getSnippets(...)per scope (each taking a read lock and merging built-in + user + plugin snippets — seeSnippetRegistry.kt:51-64), and allocates a freshMap. PerKotlinCompletions.kt:430-456, this property is read twice on every completion request — once forGLOBALand again for the context-specific scope — so you do N scope lookups and build a full N-entry map just to read two entries.Cheap win: skip the intermediate map and look scopes up on demand.
♻️ Proposed refactor
- val snippets: Map<KotlinSnippetScope, List<ISnippet>> - get() = KotlinSnippetScope.entries.associateWith { scope -> - SnippetRegistry.getSnippets("kt", scope.filename) - } + fun snippetsFor(scope: KotlinSnippetScope): List<ISnippet> = + SnippetRegistry.getSnippets("kt", scope.filename)Then update the two call sites in
KotlinCompletions.collectSnippetCompletionsto useKotlinSnippetRepository.snippetsFor(scope)instead ofKotlinSnippetRepository.snippets[scope].🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/completion/KotlinSnippetRepository.kt` around lines 8 - 11, The current KotlinSnippetRepository.snippets getter rebuilds the entire map on every access; replace it with a lightweight lookup method (e.g., KotlinSnippetRepository.snippetsFor(scope: KotlinSnippetScope)) that returns SnippetRegistry.getSnippets("kt", scope.filename) for the given scope on demand (avoiding allocating the full Map and repeated reads), and update call sites in KotlinCompletions.collectSnippetCompletions to call snippetsFor(scope) instead of accessing snippets[scope]; keep KotlinSnippetScope and SnippetRegistry.getSnippets(...) usage intact and remove or deprecate the old full-map getter.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/completion/KotlinSnippetRepository.kt`:
- Around line 3-5: The file KotlinSnippetRepository.kt still imports
SnippetParser but the init() implementation now delegates to
SnippetRegistry.initBuiltIn and no longer references SnippetParser; remove the
unused import statement for SnippetParser to clean up the code and satisfy the
linter, leaving the imports for ISnippet and SnippetRegistry intact and ensuring
KotlinSnippetRepository.init() continues to call SnippetRegistry.initBuiltIn.
- Around line 8-11: The current KotlinSnippetRepository.snippets getter rebuilds
the entire map on every access; replace it with a lightweight lookup method
(e.g., KotlinSnippetRepository.snippetsFor(scope: KotlinSnippetScope)) that
returns SnippetRegistry.getSnippets("kt", scope.filename) for the given scope on
demand (avoiding allocating the full Map and repeated reads), and update call
sites in KotlinCompletions.collectSnippetCompletions to call snippetsFor(scope)
instead of accessing snippets[scope]; keep KotlinSnippetScope and
SnippetRegistry.getSnippets(...) usage intact and remove or deprecate the old
full-map getter.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0678c908-d70e-4e57-990c-0aa1f6ad3f29
📒 Files selected for processing (2)
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/completion/KotlinSnippetRepository.ktlsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/diagnostic/KotlinDiagnosticProvider.kt
See ADFA-3739 for more details.