-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
605 additions
and
382 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/insyncwithfoo/ryecharm/DocumentationURI.kt
This file contains 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,38 @@ | ||
package insyncwithfoo.ryecharm | ||
|
||
import com.intellij.platform.backend.documentation.DocumentationLinkHandler | ||
import insyncwithfoo.ryecharm.ruff.documentation.RuffDocumentationLinkHandler | ||
import java.net.URI | ||
import java.net.URISyntaxException | ||
|
||
|
||
/** | ||
* A custom RyeCharm URI, as used by documentation popups, | ||
* to be handled by [DocumentationLinkHandler]s. | ||
* | ||
* @property path The URI's path, but without the preceding slash. | ||
* | ||
* @see RuffDocumentationLinkHandler | ||
*/ | ||
internal class DocumentationURI(val host: String, val path: String) { | ||
|
||
override fun toString() = | ||
"${RyeCharm.ID}://$host/$path" | ||
|
||
companion object { | ||
fun parse(text: String): DocumentationURI? { | ||
val uri = try { | ||
URI(text) | ||
} catch (_: URISyntaxException) { | ||
return null | ||
} | ||
|
||
if (uri.scheme != RyeCharm.ID) { | ||
return null | ||
} | ||
|
||
return DocumentationURI(uri.host, uri.path.removePrefix("/")) | ||
} | ||
} | ||
|
||
} |
This file contains 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 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 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 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 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 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 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 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
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/insyncwithfoo/ryecharm/ruff/documentation/RuffDocumentationLinkHandler.kt
This file contains 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,43 @@ | ||
package insyncwithfoo.ryecharm.ruff.documentation | ||
|
||
import com.intellij.platform.backend.documentation.DocumentationLinkHandler | ||
import com.intellij.platform.backend.documentation.DocumentationTarget | ||
import com.intellij.platform.backend.documentation.LinkResolveResult | ||
import insyncwithfoo.ryecharm.DocumentationURI | ||
import insyncwithfoo.ryecharm.ruff.documentation.targets.RuffDocumentationTarget | ||
import insyncwithfoo.ryecharm.ruff.documentation.targets.RuffOptionDocumentationTarget | ||
|
||
|
||
internal const val RUFF_OPTION_HOST = "ruff.option" | ||
|
||
|
||
private typealias URL = String | ||
|
||
|
||
private fun URL.toRuffOptionURI() = | ||
DocumentationURI.parse(this)?.takeIf { it.host == RUFF_OPTION_HOST } | ||
|
||
|
||
/** | ||
* Show a new popup in-place when certain links | ||
* in documentation popups are clicked. | ||
*/ | ||
internal class RuffDocumentationLinkHandler : DocumentationLinkHandler { | ||
|
||
override fun resolveLink(target: DocumentationTarget, url: String): LinkResolveResult? { | ||
if (target !is RuffDocumentationTarget) { | ||
return null | ||
} | ||
|
||
return resolveLink(target, url)?.let { | ||
LinkResolveResult.resolvedTarget(it) | ||
} | ||
} | ||
|
||
private fun resolveLink(target: RuffDocumentationTarget, url: URL): RuffDocumentationTarget? { | ||
val newOption = url.toRuffOptionURI()?.path ?: return null | ||
|
||
return RuffOptionDocumentationTarget(target.element, newOption) | ||
} | ||
|
||
} |
Oops, something went wrong.