Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/PLUGIN_API_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ need a source change, a recompile, or both · `tooling` = API-stability
milestone. **[verified]** = read from the checked-in ABI dump. **[reconstructed]**
= diffed from `plugin-api/src` history (predates the dump; symbol-accurate).

### 26.48 — unreleased
- **added — Show the IDE's own documentation from a plugin** _(ADFA-7134)_
`IdeTooltipService.showTooltip(anchorView, category, tag)` now reads the IDE's documentation
when `category` is `ide`, `java`, `kotlin` or `xml`, for example
`showTooltip(view, "java", "android.widget.TextView")`. Before, every category was replaced
with the plugin's own, so those calls found nothing. Any other category still reads the
plugin's own entries, so a plugin that passes its own category under another spelling is
unaffected. Floor `plugin.min_ide_version` at `26.48` to rely on it.

### 26.43 — unreleased
- **breaking — JavaScript highlighting and the IDE's grammar names are the IDE's** _(ADFA-7084)_
The IDE now highlights `js`, `mjs`, `cjs` and `jsx` itself. A `LanguageDefinition` can still
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@ import android.view.View
* Service that allows plugins to show tooltips using the IDE's tooltip system.
*/
interface IdeTooltipService {
/**
* Show a tooltip from the IDE's own documentation or from this plugin's.
*
* A [category] of `ide`, `java`, `kotlin` or `xml` reads the IDE's documentation, for example
* `showTooltip(view, "java", "android.widget.TextView")`. Any other value reads this plugin's
* entries, as [showTooltip] without a category does.
*
* @param anchorView The view to anchor the tooltip to
* @param category The tooltip category
* @param tag The tooltip tag
*/
fun showTooltip(
anchorView: View,
category: String,
tag: String,
)

/**
* Show a tooltip for the given category and tag.
*
* @param anchorView The view to anchor the tooltip to
* @param category The tooltip category
* @param tag The tooltip tag
*/
fun showTooltip(anchorView: View, category: String, tag: String)

/**
* Show a tooltip for the default IDE category.
*
* @param anchorView The view to anchor the tooltip to
* @param tag The tooltip tag
*/
fun showTooltip(anchorView: View, tag: String)

/**
* Check if a tooltip exists for the given category and tag.
*
* @param category The tooltip category
* @param tag The tooltip tag
* @return True if the tooltip exists
*/
}
/**
* Show a tooltip from this plugin's own documentation entries.
*
* @param anchorView The view to anchor the tooltip to
* @param tag The tooltip tag
*/
fun showTooltip(
anchorView: View,
tag: String,
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package com.itsaky.androidide.plugins.manager

import com.itsaky.androidide.idetooltips.TooltipCategory

const val PLUGIN_CATEGORY_PREFIX: String = "plugin_"

private val IDE_TOOLTIP_CATEGORIES =
setOf(
TooltipCategory.CATEGORY_IDE,
TooltipCategory.CATEGORY_JAVA,
TooltipCategory.CATEGORY_KOTLIN,
TooltipCategory.CATEGORY_XML,
)

fun pluginCategory(pluginId: String): String = "$PLUGIN_CATEGORY_PREFIX$pluginId"

fun pluginTooltipTag(pluginId: String, itemId: String): String = "$pluginId.$itemId"
internal fun pluginReadableCategory(
pluginId: String,
category: String,
): String = if (category in IDE_TOOLTIP_CATEGORIES) category else pluginCategory(pluginId)

fun pluginTooltipTag(
pluginId: String,
itemId: String,
): String = "$pluginId.$itemId"
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,58 @@ import android.view.View
import com.itsaky.androidide.idetooltips.TooltipManager
import com.itsaky.androidide.plugins.manager.core.PluginManager
import com.itsaky.androidide.plugins.manager.pluginCategory
import com.itsaky.androidide.plugins.manager.pluginReadableCategory
import com.itsaky.androidide.plugins.services.IdeTooltipService

/**
* Implementation of the tooltip service for plugins.
* Delegates to the main TooltipManager, using "plugin_<pluginId>" as the category
* so plugin entries are stored alongside built-in documentation in documentation.db
* without conflicting with them.
* without conflicting with them. A plugin may also read the IDE's own categories
* (ide, java, kotlin, xml), but never another plugin's.
*/
class IdeTooltipServiceImpl(
private val context: Context,
private val pluginId: String,
private val activityProvider: PluginManager.ActivityProvider?
private val context: Context,
private val pluginId: String,
private val activityProvider: PluginManager.ActivityProvider?,
) : IdeTooltipService {
private val pluginCategory = pluginCategory(pluginId)

private val pluginCategory = pluginCategory(pluginId)
/**
* Returns a context suitable for inflating the tooltip layout.
* Prefers the live Activity (correct Material3 theme + dark mode configuration).
* Falls back to the app context.
*/
private fun resolvedContext(): Context {
activityProvider?.getCurrentActivity()?.let { activity ->
if (!activity.isFinishing && !activity.isDestroyed) return activity
}
return context
}

/**
* Returns a context suitable for inflating the tooltip layout.
* Prefers the live Activity (correct Material3 theme + dark mode configuration).
* Falls back to the app context.
*/
private fun resolvedContext(): Context {
activityProvider?.getCurrentActivity()?.let { activity ->
if (!activity.isFinishing && !activity.isDestroyed) return activity
}
return context
}
override fun showTooltip(
anchorView: View,
category: String,
tag: String,
) {
val readable = pluginReadableCategory(pluginId, category)
try {
TooltipManager.showTooltip(resolvedContext(), anchorView, readable, tag)
} catch (e: android.view.InflateException) {
android.util.Log.e("IdeTooltipService", "Failed to inflate tooltip layout: $readable.$tag", e)
} catch (e: Exception) {
android.util.Log.e("IdeTooltipService", "Failed to show tooltip: $readable.$tag", e)
}
}

override fun showTooltip(anchorView: View, category: String, tag: String) {
try {
TooltipManager.showTooltip(resolvedContext(), anchorView, pluginCategory, tag)
} catch (e: android.view.InflateException) {
android.util.Log.e("IdeTooltipService", "Failed to inflate tooltip layout: $pluginCategory.$tag", e)
} catch (e: Exception) {
android.util.Log.e("IdeTooltipService", "Failed to show tooltip: $pluginCategory.$tag", e)
}
}

override fun showTooltip(anchorView: View, tag: String) {
try {
TooltipManager.showTooltip(resolvedContext(), anchorView, pluginCategory, tag)
} catch (e: Exception) {
android.util.Log.e("IdeTooltipService", "Failed to show tooltip: $pluginCategory.$tag", e)
}
}
override fun showTooltip(
anchorView: View,
tag: String,
) {
try {
TooltipManager.showTooltip(resolvedContext(), anchorView, pluginCategory, tag)
} catch (e: Exception) {
android.util.Log.e("IdeTooltipService", "Failed to show tooltip: $pluginCategory.$tag", e)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.itsaky.androidide.plugins.manager

import com.google.common.truth.Truth.assertWithMessage
import org.junit.Test

class PluginReadableCategoryTest {
private val pluginId = "org.appdevforall.codeonthego.layouteditor"

@Test
fun aPluginReadsTheIdesOwnDocumentationCategories() {
for (category in listOf("ide", "java", "kotlin", "xml")) {
assertWithMessage(category).that(pluginReadableCategory(pluginId, category)).isEqualTo(category)
}
}

@Test
fun anyOtherCategoryReadsThePluginsOwnEntries() {
val own = "plugin_$pluginId"
for (category in listOf(own, "plugin_keystore_generator", "plugin_com.example.other", "Java", "", "layouteditor")) {
assertWithMessage(category).that(pluginReadableCategory(pluginId, category)).isEqualTo(own)
}
}
}
Loading