Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Hover Updates (#5)
Browse files Browse the repository at this point in the history
* fix external documentation link
* Update Hover
  • Loading branch information
InTheCloudDan authored Dec 8, 2020
1 parent 1cf7a11 commit bf50a9c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 30 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

# intellij-plugin-ld Changelog

## [0.1.9-alpha]
### Removed
- Defaults from treeview

### Added
- External link for hovers
- Show default rule rollout percentage on hover

### Changed
- Hover layout

## [0.1.8-alpha]
### Changed
- Minor updates to Java Documentation Hover Provider
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repositories {

dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.10.0-RC1")
implementation("com.launchdarkly:api-client:3.1.0")
implementation("com.launchdarkly:api-client:3.10.0")
implementation("com.launchdarkly:launchdarkly-java-server-sdk:5.+")
implementation("com.google.code.gson:gson:2.7")
implementation("com.googlecode.json-simple", "json-simple", "1.1.1")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -> https://www.jetbrains.org/intellij/sdk/docs/reference_guide/intellij_artifacts.html
pluginGroup=com.github.intheclouddan.intellijpluginld
pluginName=intellij-plugin-ld
pluginVersion=0.1.8-alpha
pluginVersion=0.1.9-alpha
pluginSinceBuild=201
pluginUntilBuild=203.*
platformType=IC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.intheclouddan.intellijpluginld

import com.github.intheclouddan.intellijpluginld.featurestore.FlagConfiguration
import com.github.intheclouddan.intellijpluginld.settings.LaunchDarklyMergedSettings
import com.intellij.lang.documentation.AbstractDocumentationProvider
import com.intellij.openapi.components.service
import com.intellij.psi.PsiElement
Expand All @@ -16,7 +17,8 @@ class LDDocumentationProvider : AbstractDocumentationProvider() {
val flag: FeatureFlag? = getFlags.flags.items.find { it.key == element.text.drop(1).dropLast(1) }

if (flag != null) {
return listOf(flag.links!!.self.href)
val settings = LaunchDarklyMergedSettings.getInstance(element.project)
return listOf("${settings.baseUri.removePrefix("https://")}${flag.environments[settings.environment]!!.site.href}")
}

return null
Expand All @@ -27,6 +29,7 @@ class LDDocumentationProvider : AbstractDocumentationProvider() {
return null
}
val getFlags = element.project.service<FlagStore>()

val flag: FeatureFlag? = getFlags.flags.items.find { it.key == element.text.drop(1).dropLast(1) }
if (flag != null) {
val env: FlagConfiguration = getFlags.flagConfigs[element.text.drop(1).dropLast(1)]!!
Expand All @@ -41,9 +44,9 @@ class LDDocumentationProvider : AbstractDocumentationProvider() {
if (env.targets.isNotEmpty()) {
targets += "<b>Targets</b><br /> "
env.targets.forEachIndexed { i, t ->
targets += "${flag.variations[t.variation as Int].name ?: flag.variations[t.variation as Int].value} ${t.values.size} "
targets += "${flag.variations[t.variation as Int].name ?: flag.variations[t.variation as Int].value} ${t.values.size}"
if (i != env.targets.lastIndex) {
targets += "\u2022 "
targets += " \u2022 "
}
}
targets += "<br />"
Expand All @@ -66,24 +69,30 @@ class LDDocumentationProvider : AbstractDocumentationProvider() {
"<img src=\"${LDIcons.TOGGLE_OFF}\" alt=\"Off\">"
}
result.append("$enabledIcon ${flag.description}<br />")
//result.append("<pre>")
result.append(buildEnvString)
result.append("<br /><b>Variations</b><br />")
result.append("<br /><b>Variations ${if (env.fallthrough?.rollout != null) " ◆ Rollout Configured" else ""}</b><br />")
flag.variations.mapIndexed { i, it ->
val rolloutPercentage: Double = if (env.fallthrough?.rollout != null) {
val rollout = env.fallthrough?.rollout
val foundVariation = rollout!!.variations.filter { it.variation == i }
(foundVariation[0].weight.toDouble() / 1000)
} else -1.000
var variationOut = "$i"
if (it.name != "" && it.name != null) {
variationOut += "${it.name}"
}
variationOut += " ◆ <code>Return value:</code> <code>${it.value}</code>"
variationOut += "${if (rolloutPercentage != null && rolloutPercentage != -1.000) "Rollout $rolloutPercentage% ◆ " else ""}<code>Return value:</code> <code>${it.value}</code><br />"
result.append(variationOut)
if (env.offVariation != null && env.offVariation == i) {
result.append("<p><b>Off Variation</b></p>")
}
if (env.fallthrough?.variation != null && env.fallthrough?.variation == i) {
result.append("<p><b>Fallthrough Variation</b></p>")
}
if (it.description != "" && it.description != null) {
result.append("<p>${it.description ?: ""}</p><br />")
} else {
result.append("<p><br /></p>")
}
//result.append("<p>${it.value}</p>")
}
//result.append("</pre>")
result.append("</html>")

return result.toString()
Expand Down
63 changes: 51 additions & 12 deletions src/main/kotlin/com/github/intheclouddan/intellijpluginld/Icons.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,59 @@
package com.github.intheclouddan.intellijpluginld

import com.intellij.openapi.util.IconLoader
import com.intellij.util.ImageLoader
import com.intellij.util.ui.JBImageIcon

class LDIcons {
companion object {
val DEFAULT_VARIATION = IconLoader.getIcon("/icons/variationDefault.svg")
val DESCRIPTION = IconLoader.getIcon("/icons/description.svg")
val FLAG = IconLoader.getIcon("/icons/flag.svg")
val FLAG_KEY = IconLoader.getIcon("/icons/flagKey.svg")
val OFF_VARIATION = IconLoader.getIcon("/icons/offVariation.svg")
val PREREQUISITE = IconLoader.getIcon("/icons/prereq.svg")
val RULES = IconLoader.getIcon("/icons/rules.svg")
val TAGS = IconLoader.getIcon("/icons/tags.svg")
val TARGETS = IconLoader.getIcon("/icons/targets.svg")
val TOGGLE_OFF = IconLoader.getIcon("/icons/toggleoff.svg")
val TOGGLE_ON = IconLoader.getIcon("/icons/toggleon.svg")
val VARIATION = IconLoader.getIcon("/icons/variation.svg")
@JvmField
val DEFAULT_VARIATION = IconLoader.getIcon("/icons/variationDefault.svg", javaClass)

@JvmField
val DESCRIPTION = IconLoader.getIcon("/icons/description.svg", javaClass)

@JvmField
val FLAG = IconLoader.getIcon(LDIconsPath.FLAG, javaClass)

@JvmField
val FLAG_KEY = IconLoader.getIcon("/icons/flagKey.svg", javaClass)

@JvmField
val OFF_VARIATION = IconLoader.getIcon("/icons/offVariation.svg", javaClass)

@JvmField
val PREREQUISITE = IconLoader.getIcon("/icons/prereq.svg", javaClass)

@JvmField
val RULES = IconLoader.getIcon("/icons/rules.svg", javaClass)

@JvmField
val TAGS = IconLoader.getIcon("/icons/tags.svg", javaClass)

@JvmField
val TARGETS = IconLoader.getIcon("/icons/targets.svg", javaClass)

@JvmField
val TOGGLE_OFF = IconLoader.getIcon("/icons/toggleoff.svg", javaClass)

@JvmField
val TOGGLE_ON = IconLoader.getIcon("/icons/toggleon.svg", javaClass)

@JvmField
val VARIATION = IconLoader.getIcon("/icons/variation.svg", javaClass)


fun imageLoader(path: String): JBImageIcon {
val image = ImageLoader.loadFromResource(path);
return JBImageIcon(image!!);
}
}
}

class LDIconsPath {
companion object {
val FLAG = "/icons/flag.svg"
val TOGGLE_OFF = "/icons/toggleoff.svg"
val TOGGLE_ON = "/icons/toggleon.svg"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import com.intellij.openapi.project.Project

class ConfigNotifier {
private val notificationGroup = NotificationGroup("Launchdarkly Configuration", NotificationDisplayType.BALLOON, true)
// fun notify(content: String?): Notification {
// return notify(null, content)
// }

fun notify(project: Project?, content: String?): Notification {
val notification: Notification = notificationGroup.createNotification(content!!, NotificationType.ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class FlagNodeParent(FFlag: FeatureFlag, private var flags: FeatureFlags, myProj
if (flag.tags.size > 0) {
children.add(FlagNodeTags(flag.tags))
}
if (flag.defaults != null) {
children.add(FlagNodeDefaults(flag))
}
}

override fun update(data: PresentationData) {
Expand Down

0 comments on commit bf50a9c

Please sign in to comment.