-
-
Notifications
You must be signed in to change notification settings - Fork 34
ADFA-4867: Point Kotlin code actions at their own tooltip tags #1582
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
itsaky-adfa
wants to merge
6
commits into
stage
Choose a base branch
from
fix/ADFA-4867
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
6 commits
Select commit
Hold shift + click to select a range
f79a1ce
ADFA-4867: Extract computeImportCandidates so lsp:kotlin tests compile
itsaky-adfa 8436ce8
ADFA-4867: Point Kotlin code actions at their own tooltip tags
itsaky-adfa 22de019
Merge branch 'stage' into fix/ADFA-4867
itsaky-adfa d202e77
ADFA-4867: Rename the add-import tag and single-source action ids
itsaky-adfa c7c209b
ADFA-4867: Retag Implement members as implementmembers, not overrides…
itsaky-adfa ca0e0db
ADFA-4867: Use importclass, the tag name Elissa specified
itsaky-adfa 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
180 changes: 94 additions & 86 deletions
180
lsp/api/src/main/java/com/itsaky/androidide/lsp/actions/CommentLineAction.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 |
|---|---|---|
| @@ -1,86 +1,94 @@ | ||
| /* | ||
| * 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.lsp.actions | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.drawable.Drawable | ||
| import com.itsaky.androidide.actions.ActionData | ||
| import com.itsaky.androidide.actions.ActionItem | ||
| import com.itsaky.androidide.actions.EditorActionItem | ||
| import com.itsaky.androidide.actions.hasRequiredData | ||
| import com.itsaky.androidide.actions.markInvisible | ||
| import com.itsaky.androidide.actions.requireContext | ||
| import com.itsaky.androidide.actions.requireEditor | ||
| import com.itsaky.androidide.actions.requireFile | ||
| import com.itsaky.androidide.idetooltips.TooltipTag | ||
| import com.itsaky.androidide.resources.R | ||
| import io.github.rosemoe.sora.text.batchEdit | ||
| import java.io.File | ||
|
|
||
| /** @author Akash Yadav */ | ||
| class CommentLineAction( | ||
| lang: String, | ||
| private val targetFileExtensions: List<String>, | ||
| private val lineCommentToken: String, | ||
| ) : EditorActionItem { | ||
|
|
||
| constructor(lang: String, extension: String, lineCommentToken: String) : | ||
| this(lang, listOf(extension), lineCommentToken) | ||
| override val id: String = "ide.editor.lsp.$lang.commentLine" | ||
| override var label: String = "" | ||
|
|
||
| override var visible = true | ||
| override var enabled = true | ||
| override var icon: Drawable? = null | ||
| override var location: ActionItem.Location = ActionItem.Location.EDITOR_CODE_ACTIONS | ||
| override var requiresUIThread: Boolean = true | ||
| override var tooltipTag: String = TooltipTag.EDITOR_CODE_ACTIONS_COMMENT | ||
|
|
||
| override fun prepare(data: ActionData) { | ||
| super.prepare(data) | ||
|
|
||
| if (!data.hasRequiredData(Context::class.java, File::class.java)) { | ||
| markInvisible() | ||
| return | ||
| } | ||
|
|
||
| val context = data.requireContext() | ||
| label = context.getString(R.string.action_comment_line) | ||
|
|
||
| val file = data.requireFile() | ||
| if (file.extension !in targetFileExtensions) { | ||
| markInvisible() | ||
| return | ||
| } | ||
| } | ||
|
|
||
| override suspend fun execAction(data: ActionData): Boolean { | ||
| val editor = data.requireEditor() | ||
| val text = editor.text | ||
| val cursor = editor.cursor | ||
|
|
||
| text.batchEdit { | ||
| for (line in cursor.leftLine..cursor.rightLine) { | ||
| text.insert(line, 0, lineCommentToken) | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| override fun dismissOnAction() = true | ||
| } | ||
| /* | ||
| * 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.lsp.actions | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.drawable.Drawable | ||
| import com.itsaky.androidide.actions.ActionData | ||
| import com.itsaky.androidide.actions.ActionItem | ||
| import com.itsaky.androidide.actions.EditorActionItem | ||
| import com.itsaky.androidide.actions.hasRequiredData | ||
| import com.itsaky.androidide.actions.markInvisible | ||
| import com.itsaky.androidide.actions.requireContext | ||
| import com.itsaky.androidide.actions.requireEditor | ||
| import com.itsaky.androidide.actions.requireFile | ||
| import com.itsaky.androidide.resources.R | ||
| import io.github.rosemoe.sora.text.batchEdit | ||
| import java.io.File | ||
|
|
||
| /** @author Akash Yadav */ | ||
| class CommentLineAction( | ||
| lang: String, | ||
| private val targetFileExtensions: List<String>, | ||
| private val lineCommentToken: String, | ||
| tag: String, | ||
| ) : EditorActionItem { | ||
| companion object { | ||
| /** The id is per-language, since one instance is registered per language. */ | ||
| fun idFor(lang: String) = "ide.editor.lsp.$lang.commentLine" | ||
| } | ||
|
|
||
| constructor(lang: String, extension: String, lineCommentToken: String, tag: String) : | ||
| this(lang, listOf(extension), lineCommentToken, tag) | ||
|
|
||
| override val id: String = idFor(lang) | ||
| override var label: String = "" | ||
|
|
||
| override var visible = true | ||
| override var enabled = true | ||
| override var icon: Drawable? = null | ||
| override var location: ActionItem.Location = ActionItem.Location.EDITOR_CODE_ACTIONS | ||
| override var requiresUIThread: Boolean = true | ||
|
|
||
| // Required, not defaulted: one instance is registered per language, and a default would let a | ||
| // new language silently inherit another language's tooltip. | ||
| override var tooltipTag: String = tag | ||
|
|
||
| override fun prepare(data: ActionData) { | ||
| super.prepare(data) | ||
|
|
||
| if (!data.hasRequiredData(Context::class.java, File::class.java)) { | ||
| markInvisible() | ||
| return | ||
| } | ||
|
|
||
| val context = data.requireContext() | ||
| label = context.getString(R.string.action_comment_line) | ||
|
|
||
| val file = data.requireFile() | ||
| if (file.extension !in targetFileExtensions) { | ||
| markInvisible() | ||
| return | ||
| } | ||
| } | ||
|
|
||
| override suspend fun execAction(data: ActionData): Boolean { | ||
| val editor = data.requireEditor() | ||
| val text = editor.text | ||
| val cursor = editor.cursor | ||
|
|
||
| text.batchEdit { | ||
| for (line in cursor.leftLine..cursor.rightLine) { | ||
| text.insert(line, 0, lineCommentToken) | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| override fun dismissOnAction() = true | ||
| } | ||
190 changes: 98 additions & 92 deletions
190
lsp/api/src/main/java/com/itsaky/androidide/lsp/actions/UncommentLineAction.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 |
|---|---|---|
| @@ -1,92 +1,98 @@ | ||
| /* | ||
| * 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.lsp.actions | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.drawable.Drawable | ||
| import com.itsaky.androidide.actions.ActionData | ||
| import com.itsaky.androidide.actions.ActionItem | ||
| import com.itsaky.androidide.actions.EditorActionItem | ||
| import com.itsaky.androidide.actions.hasRequiredData | ||
| import com.itsaky.androidide.actions.markInvisible | ||
| import com.itsaky.androidide.actions.requireContext | ||
| import com.itsaky.androidide.actions.requireEditor | ||
| import com.itsaky.androidide.actions.requireFile | ||
| import com.itsaky.androidide.idetooltips.TooltipTag | ||
| import com.itsaky.androidide.resources.R | ||
| import io.github.rosemoe.sora.text.batchEdit | ||
| import java.io.File | ||
|
|
||
| /** @author Akash Yadav */ | ||
| class UncommentLineAction( | ||
| lang: String, | ||
| private val targetFileExtensions: List<String>, | ||
| private val lineCommentToken: String, | ||
| ) : EditorActionItem { | ||
|
|
||
| constructor(lang: String, extension: String, lineCommentToken: String) : | ||
| this(lang, listOf(extension), lineCommentToken) | ||
|
|
||
| override val id: String = "ide.editor.lsp.$lang.uncommentLine" | ||
| override var label: String = "" | ||
|
|
||
| override var visible = true | ||
| override var enabled = true | ||
| override var icon: Drawable? = null | ||
| override var location: ActionItem.Location = ActionItem.Location.EDITOR_CODE_ACTIONS | ||
| override var requiresUIThread: Boolean = true | ||
| override var tooltipTag: String = TooltipTag.EDITOR_CODE_ACTIONS_UNCOMMENT | ||
|
|
||
|
|
||
| override fun prepare(data: ActionData) { | ||
| super.prepare(data) | ||
|
|
||
| if (!data.hasRequiredData(Context::class.java, File::class.java)) { | ||
| markInvisible() | ||
| return | ||
| } | ||
|
|
||
| val context = data.requireContext() | ||
| label = context.getString(R.string.action_uncomment_line) | ||
|
|
||
| val file = data.requireFile() | ||
| if (file.extension !in targetFileExtensions) { | ||
| markInvisible() | ||
| return | ||
| } | ||
| } | ||
|
|
||
| override suspend fun execAction(data: ActionData): Boolean { | ||
| val editor = data.requireEditor() | ||
| val text = editor.text | ||
| val cursor = editor.cursor | ||
|
|
||
| text.batchEdit { | ||
| for (line in cursor.leftLine..cursor.rightLine) { | ||
| val l = text.getLineString(line) | ||
| if (l.trim().startsWith(lineCommentToken)) { | ||
| val i = l.indexOf(lineCommentToken) | ||
| text.delete(line, i, line, i + 2) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| override fun dismissOnAction() = true | ||
| } | ||
| /* | ||
| * 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.lsp.actions | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.drawable.Drawable | ||
| import com.itsaky.androidide.actions.ActionData | ||
| import com.itsaky.androidide.actions.ActionItem | ||
| import com.itsaky.androidide.actions.EditorActionItem | ||
| import com.itsaky.androidide.actions.hasRequiredData | ||
| import com.itsaky.androidide.actions.markInvisible | ||
| import com.itsaky.androidide.actions.requireContext | ||
| import com.itsaky.androidide.actions.requireEditor | ||
| import com.itsaky.androidide.actions.requireFile | ||
| import com.itsaky.androidide.resources.R | ||
| import io.github.rosemoe.sora.text.batchEdit | ||
| import java.io.File | ||
|
|
||
| /** @author Akash Yadav */ | ||
| class UncommentLineAction( | ||
| lang: String, | ||
| private val targetFileExtensions: List<String>, | ||
| private val lineCommentToken: String, | ||
| tag: String, | ||
| ) : EditorActionItem { | ||
| companion object { | ||
| /** The id is per-language, since one instance is registered per language. */ | ||
| fun idFor(lang: String) = "ide.editor.lsp.$lang.uncommentLine" | ||
| } | ||
|
|
||
| constructor(lang: String, extension: String, lineCommentToken: String, tag: String) : | ||
| this(lang, listOf(extension), lineCommentToken, tag) | ||
|
|
||
| override val id: String = idFor(lang) | ||
| override var label: String = "" | ||
|
|
||
| override var visible = true | ||
| override var enabled = true | ||
| override var icon: Drawable? = null | ||
| override var location: ActionItem.Location = ActionItem.Location.EDITOR_CODE_ACTIONS | ||
| override var requiresUIThread: Boolean = true | ||
|
|
||
| // Required, not defaulted: one instance is registered per language, and a default would let a | ||
| // new language silently inherit another language's tooltip. | ||
| override var tooltipTag: String = tag | ||
|
|
||
| override fun prepare(data: ActionData) { | ||
| super.prepare(data) | ||
|
|
||
| if (!data.hasRequiredData(Context::class.java, File::class.java)) { | ||
| markInvisible() | ||
| return | ||
| } | ||
|
|
||
| val context = data.requireContext() | ||
| label = context.getString(R.string.action_uncomment_line) | ||
|
|
||
| val file = data.requireFile() | ||
| if (file.extension !in targetFileExtensions) { | ||
| markInvisible() | ||
| return | ||
| } | ||
| } | ||
|
|
||
| override suspend fun execAction(data: ActionData): Boolean { | ||
| val editor = data.requireEditor() | ||
| val text = editor.text | ||
| val cursor = editor.cursor | ||
|
|
||
| text.batchEdit { | ||
| for (line in cursor.leftLine..cursor.rightLine) { | ||
| val l = text.getLineString(line) | ||
| if (l.trim().startsWith(lineCommentToken)) { | ||
| val i = l.indexOf(lineCommentToken) | ||
| text.delete(line, i, line, i + 2) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| override fun dismissOnAction() = true | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Document the new required per-language tooltip-tag API.
Both public action constructors gained a mandatory tag parameter, so their KDoc should define its per-language requirement and tooltip behavior.
lsp/api/src/main/java/com/itsaky/androidide/lsp/actions/CommentLineAction.kt#L34-L41: document the comment action contract and requiredtag.lsp/api/src/main/java/com/itsaky/androidide/lsp/actions/UncommentLineAction.kt#L34-L41: document the uncomment action contract and requiredtag.📍 Affects 2 files
lsp/api/src/main/java/com/itsaky/androidide/lsp/actions/CommentLineAction.kt#L34-L41(this comment)lsp/api/src/main/java/com/itsaky/androidide/lsp/actions/UncommentLineAction.kt#L34-L41🤖 Prompt for AI Agents
Source: Coding guidelines