Skip to content
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

IDE highlighting ✨ #56

Merged
merged 23 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6630633
wip highlighting in ide :)
Jolanrensen Nov 27, 2024
52b76bd
moved highlighting logic to processors itself so they can customize i…
Jolanrensen Nov 28, 2024
b8c62fa
moved to Annotator, added CaretListener to highlight matching brackets
Jolanrensen Nov 29, 2024
4d16930
moved to Annotator, added CaretListener to highlight matching brackets
Jolanrensen Nov 29, 2024
fb514ec
Merge remote-tracking branch 'origin/ide-highlighting' into ide-highl…
Jolanrensen Nov 29, 2024
5a30037
updated getDocContentWithMapOrNull to calculate a map back to the ori…
Jolanrensen Dec 2, 2024
bf76b70
refactoring typealias for DocContent into value class
Jolanrensen Dec 2, 2024
cd58fd3
cleaning and catching exceptions
Jolanrensen Dec 3, 2024
65cab2d
split KDocHighlightAnnotator so it's stateless
Jolanrensen Dec 3, 2024
88f5e6e
added ExportAsHtmlAnnotator for k2 mode. Refactored DocProcessorServi…
Jolanrensen Dec 4, 2024
1451e58
made exportAsHtml more efficient by only exporting when the button is…
Jolanrensen Dec 5, 2024
f9dbaf7
WIP autocomplete by KDocCompletionContributor.
Jolanrensen Dec 5, 2024
d0d7ab6
fixed completions and auto invoke completion after writing { or $ in …
Jolanrensen Dec 6, 2024
81630ab
WIP autocomplete in kdocs
Jolanrensen Dec 10, 2024
1ca8350
fixed behavior kdocs autocomplete
Jolanrensen Dec 10, 2024
0896565
small cleanup
Jolanrensen Dec 11, 2024
68a0015
Merge branch 'refs/heads/main' into ide-highlighting
Jolanrensen Dec 17, 2024
bc3d00f
wip kodex icon and CompletionInfo
Jolanrensen Dec 17, 2024
07d32e0
finished CompletionInfo's and providing them to HighlightInfo too, so…
Jolanrensen Dec 18, 2024
51e84b1
fixed clicking on links in rendered kdocs
Jolanrensen Dec 19, 2024
317f1aa
improving the settings and ui panel
Jolanrensen Dec 20, 2024
cc298ea
made sure brackets highlighting matches IDE
Jolanrensen Jan 2, 2025
27b5485
icon and description update
Jolanrensen Jan 2, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ hs_err_pid*
/build/
/.idea/
/doc-processor-gradle-plugin/src/functionalTest/resources/dataframe/
.intellijPlatform
12 changes: 12 additions & 0 deletions KoDEx-K.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package nl.jolanrensen.docProcessor

/**
* Completion info for a tag. Shows up in the completion popup.
*
* @param tag The tag name this completion info belongs to.
* @param blockText The text that will be inserted when the completion is performed at the start of a line.
* @param presentableBlockText The text that will be shown in the completion popup when the completion is performed
* at the start of a line.
* @param moveCaretOffsetBlock The offset to move the caret to after the completion is performed at the start of a line.
* @param inlineText The text that will be inserted when the completion is performed in the middle of a line.
* @param presentableInlineText The text that will be shown in the completion popup when the completion is performed
* in the middle of a line.
* @param moveCaretOffsetInline The offset to move the caret to after the completion is performed in the middle of a line.
* @param tailText The text that will be shown alongside the presentable text in the completion popup.
*/
class CompletionInfo(
val tag: String,
val blockText: String? = "@$tag ",
val presentableBlockText: String? = "@$tag",
val moveCaretOffsetBlock: Int? = 0,
val inlineText: String? = "{@$tag }",
val presentableInlineText: String? = "{@$tag }",
val moveCaretOffsetInline: Int? = -1,
val tailText: String = "",
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.util.ServiceLoader
*/
abstract class DocProcessor : Serializable {

protected val name: String = this::class.simpleName ?: "DocProcessor"
val name: String = this::class.simpleName ?: "DocProcessor"

/** Main logging access point. */
val logger: KLogger = KotlinLogging.logger(name)
Expand Down Expand Up @@ -58,6 +58,49 @@ abstract class DocProcessor : Serializable {
hasRun = true
}
}

/**
* An optional list of [CompletionInfo] information to display
* in the autocomplete of the IDE.
*/
open val completionInfos: List<CompletionInfo>
get() = emptyList()

/**
* Can be overridden to provide custom highlighting for doc content given by [docContent].
*
* NOTE: this can contain '*' characters and indents, so make sure to handle that.
*/
open fun getHighlightsFor(docContent: DocContent): List<HighlightInfo> = emptyList()

/**
* Builds a [HighlightInfo] object with the given parameters in the context of this processor.
* Fills in [HighlightInfo.tagProcessorName] with the name of this processor.
* Builds [HighlightInfo.description] from the [completionInfos] of this processor.
*/
protected fun buildHighlightInfo(
range: IntRange,
type: HighlightType,
tag: String,
description: String = completionInfos // get the description from the completion infos
.find { it.tag == tag }
?.let {
"${
(it.presentableBlockText ?: it.presentableInlineText)
?.surroundWith("\"")
?.plus(": ")
?: ""
}${it.tailText}"
} ?: "",
related: List<HighlightInfo> = emptyList(),
): HighlightInfo =
HighlightInfo(
range = range,
type = type,
related = related,
description = description,
tagProcessorName = name,
)
}

fun findProcessors(fullyQualifiedNames: List<String>, arguments: Map<String, Any?>): List<DocProcessor> {
Expand Down
Loading