-
-
Notifications
You must be signed in to change notification settings - Fork 30
ADFA-4584 | Extract AI features into plugins and expand the plugin API #1489
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
jatezzz
wants to merge
9
commits into
stage
Choose a base branch
from
refactor/ADFA-4584-ai-hackathon-plugin
base: stage
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2132485
refactor(app): extract AI/agent features into standalone plugins
jatezzz 72b73a4
feat(plugin-api): expand IDE service layer with backward compatibility
jatezzz 9c7dd37
feat(editor): add inline code-suggestion pipeline for plugins
jatezzz 2bf361c
feat(plugins): dynamic toolbar icons, mic permission, and API dump
jatezzz 0b6d95f
fix(plugin-manager): stop crash restoring plugin fragments after proc…
jatezzz 9c9e771
refactor: address Coderabbit's comments
jatezzz 51af13e
Merge branch 'stage' into refactor/ADFA-4584-ai-hackathon-plugin
jatezzz d04e644
feat(plugin-api): add SharedServices cross-plugin service registry
jatezzz 2cc6c28
Merge remote-tracking branch 'origin/refactor/ADFA-4584-ai-hackathon-…
jatezzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
139 changes: 139 additions & 0 deletions
139
editor/src/main/java/com/itsaky/androidide/editor/ui/GhostTextRenderer.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /* | ||
| * This file is part of AndroidIDE. | ||
| * | ||
| * AndroidIDE is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * AndroidIDE is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.itsaky.androidide.editor.ui | ||
|
|
||
| import android.graphics.Canvas | ||
| import android.graphics.Paint | ||
| import io.github.rosemoe.sora.widget.CodeEditor | ||
| import io.github.rosemoe.sora.widget.EditorRenderer | ||
|
|
||
| /** | ||
| * An [EditorRenderer] that draws an inline "ghost text" suggestion (dimmed grey text) at a fixed | ||
| * anchor position, after the editor's normal content. Multi-line suggestions are previewed in full, | ||
| * one row per line, so what is drawn matches what [IDEEditor] commits on accept. This backs the host | ||
| * side of the inline-suggestion plugin pipeline (`IdeEditorService.showInlineSuggestion`). | ||
| * | ||
| * Extends [TracingEditorRenderer] so it inherits the block-line data-race guards (ADFA-2468) while | ||
| * layering ghost text on top of the normal draw pass — the editor only supports a single renderer, | ||
| * so the two behaviours have to share one class. | ||
| * | ||
| * State is mutated from the main thread (via [IDEEditor]); [draw] reads it defensively and must | ||
| * never throw — a bad suggestion or transient layout state can never take the editor's draw pass | ||
| * down with it. | ||
| */ | ||
| class GhostTextRenderer(private val editor: CodeEditor) : TracingEditorRenderer(editor = editor) { | ||
|
jatezzz marked this conversation as resolved.
|
||
|
|
||
| @Volatile | ||
| private var suggestion: String? = null | ||
|
|
||
| @Volatile | ||
| private var anchorLine: Int = -1 | ||
|
|
||
| @Volatile | ||
| private var anchorColumn: Int = -1 | ||
|
|
||
| /** Id of the plugin that owns the current suggestion, so dismissals can be scoped to it. */ | ||
| @Volatile | ||
| private var ownerPluginId: String? = null | ||
|
|
||
| private val ghostPaint = Paint(Paint.ANTI_ALIAS_FLAG) | ||
|
|
||
| val hasSuggestion: Boolean | ||
| get() = suggestion != null | ||
|
|
||
| /** | ||
| * Sets the pending suggestion anchored at the given 0-indexed [line]/[column], owned by | ||
| * [pluginId]. A newer suggestion replaces any existing one (last writer wins) and takes ownership. | ||
| */ | ||
| fun setSuggestion(text: String, line: Int, column: Int, pluginId: String) { | ||
| suggestion = text.takeIf { it.isNotEmpty() } | ||
| anchorLine = line | ||
| anchorColumn = column | ||
| ownerPluginId = pluginId | ||
| } | ||
|
|
||
| /** Clears any pending suggestion and returns the text that was showing (or null). */ | ||
| fun takeSuggestion(): String? { | ||
| val current = suggestion | ||
| clearSuggestion() | ||
| return current | ||
| } | ||
|
|
||
| /** | ||
| * Clears the suggestion only if it is owned by [pluginId], so one plugin can't dismiss another's | ||
| * ghost text. Returns true if a suggestion was actually cleared. | ||
| */ | ||
| fun clearSuggestionFor(pluginId: String): Boolean { | ||
| if (suggestion == null || ownerPluginId != pluginId) return false | ||
| clearSuggestion() | ||
| return true | ||
| } | ||
|
|
||
| fun clearSuggestion() { | ||
| suggestion = null | ||
| anchorLine = -1 | ||
| anchorColumn = -1 | ||
| ownerPluginId = null | ||
| } | ||
|
|
||
| override fun draw(canvas: Canvas) { | ||
| super.draw(canvas) | ||
|
|
||
| val text = suggestion ?: return | ||
| val line = anchorLine | ||
| val column = anchorColumn | ||
| try { | ||
| val content = editor.text | ||
| if (line < 0 || line >= content.lineCount) return | ||
| if (column < 0 || column > content.getColumnCount(line)) return | ||
|
|
||
| val basePaint = editor.textPaint | ||
| ghostPaint.textSize = basePaint.textSize | ||
| ghostPaint.typeface = basePaint.typeface | ||
| // Mid-grey at ~50% alpha reads as "ghost" on both light and dark themes. | ||
| ghostPaint.color = GHOST_COLOR | ||
|
|
||
| // First line continues from the anchor column; continuation lines start at the content's | ||
| // left edge (column 0 of the anchor line). offsetX applies the current horizontal scroll. | ||
| val firstX = editor.getCharOffsetX(line, column) + editor.offsetX | ||
| val leftX = editor.getCharOffsetX(line, 0) + editor.offsetX | ||
| // getRowBaseline is the exact baseline sora draws its own text at (content space). Rows past | ||
| // the last existing line have no baseline of their own, so extrapolate by row height. | ||
| val anchorBaseline = editor.getRowBaseline(line).toFloat() | ||
| val rowHeight = editor.rowHeight | ||
|
|
||
| // Continuation lines overlay the rows below the anchor (the preview does not push content | ||
| // down); drawing every line guarantees the preview matches the committed text exactly. | ||
| text.split('\n').forEachIndexed { i, lineText -> | ||
| val targetLine = line + i | ||
| val baseline = if (targetLine < content.lineCount) { | ||
| editor.getRowBaseline(targetLine).toFloat() | ||
| } else { | ||
| anchorBaseline + i * rowHeight | ||
| } | ||
| canvas.drawText(lineText, if (i == 0) firstX else leftX, baseline, ghostPaint) | ||
| } | ||
| } catch (_: Throwable) { | ||
| // Never let suggestion rendering crash the editor. | ||
| } | ||
| } | ||
|
|
||
| private companion object { | ||
| private const val GHOST_COLOR = 0x80888888.toInt() | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.