Skip to content

Commit

Permalink
[Release] v0.0.8
Browse files Browse the repository at this point in the history
[Features]
- Preview for simple constant fields is now renders also in code completion popup
[Bug Fixes]
- Unspecified color is now excluded from rendering
- Switched to using the kotlin IDE's built-in stdlib instead of the explicit one
  • Loading branch information
zTrap committed Apr 29, 2024
1 parent 664d43e commit 9dfc098
Show file tree
Hide file tree
Showing 60 changed files with 375 additions and 131 deletions.
File renamed without changes
Binary file added .github/preview2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions .run/Publish Plugin.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Publish Plugin" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="--no-build-cache --no-configuration-cache" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="clean" />
<option value=":compose-color-preview-plugin:publishPlugin" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false" />
<option name="IS_SUBST" value="false" />
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
<option name="IS_IGNORE_MISSING_FILES" value="false" />
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
</ENTRIES>
</extension>
</EXTENSION>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
24 changes: 0 additions & 24 deletions .run/Run IDE with Plugin.run.xml

This file was deleted.

37 changes: 37 additions & 0 deletions .run/Run Plugin.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Plugin" type="GradleRunConfiguration" factoryName="Gradle">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value=":compose-color-preview-plugin:runIde" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false" />
<option name="IS_SUBST" value="false" />
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
<option name="IS_IGNORE_MISSING_FILES" value="false" />
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
</ENTRIES>
</extension>
</EXTENSION>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## [0.0.8] - 29-04-2024

### Added

- Preview for simple constant fields is now renders also in code completion popup

### Fixed

- Unspecified color is now excluded from rendering
- Switched to using the kotlin IDE's built-in stdlib instead of the explicit one

## [0.0.7] - 23-04-2024

### Fixed
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
[![Plugin version](https://img.shields.io/jetbrains/plugin/v/21298-compose-color-preview)](https://plugins.jetbrains.com/plugin/21298-compose-color-preview)

# ![Preview](./src/main/resources/META-INF/pluginIcon.svg) Compose color preview plugin for JetBrains IDE family
# ![Preview](plugin/src/main/resources/META-INF/pluginIcon.svg) Compose color preview plugin for JetBrains IDE family

This plugin draws colors on editor's gutter. You can modify colors by clicking on the icons
This plugin draws colors on editor's gutter and code completion popup. You can modify them by clicking on the icons in the gutter

It works with `androidx.compose.ui.graphics.Color` from
[Jetpack Compose](https://developer.android.com/develop/ui/compose) or
[Compose Multiplatform](https://www.jetbrains.com/lp/compose-multiplatform)

## Features

- [x] Show preview in code completion popup for simple constant fields
- [x] Show preview in places simple constant fields usage with type `Color`
- [x] Show preview for results of `compositeOver`, `copy`, `convert` and `lerp` functions
- [x] Show preview in `Color` creation places
- [x] ULong constructor
- [x] Long function "constructor"
Expand All @@ -23,10 +26,9 @@ It works with `androidx.compose.ui.graphics.Color` from
- [x] hsv "constructor"
- [x] Show palette by clicking on preview to change color
- [x] Change color with saving original numeral system
- [x] Show preview in places fields usage with type `Color`
- [x] Show preview for results of `compositeOver`, `copy`, `convert` and `lerp` functions

![Preview](./.github/preview.png)
![Preview1](./.github/preview1.png)
![Preview2](./.github/preview2.png)

## Installation

Expand Down
67 changes: 5 additions & 62 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,63 +1,6 @@
fun prop(key: String) = project.findProperty(key).toString()

plugins {
id("java")
id("org.jetbrains.intellij") version "1.17.3"
// https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library
id("org.jetbrains.kotlin.jvm") version "1.7.0"
}

val ideMinVersion = "223"
val pluginMajorVersion = "0.0.7"

group = "ru.ztrap.plugin.idea"
version = "$pluginMajorVersion-$ideMinVersion"

repositories {
mavenCentral()
}

// See https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
version = "2022.3"
type = "IC"

plugins = listOf(
"com.intellij.java",
"org.jetbrains.kotlin",
)
}

val jvmVersion = JavaVersion.VERSION_17.toString()

tasks {
buildSearchableOptions {
enabled = false
}

// Set the JVM compatibility versions
compileJava {
sourceCompatibility = jvmVersion
targetCompatibility = jvmVersion
}

compileKotlin {
kotlinOptions.jvmTarget = jvmVersion
}

patchPluginXml {
version = project.version.toString()
sinceBuild = ideMinVersion
untilBuild = "223.*"
}

signPlugin {
certificateChainFile = file(prop("publishing.plugin.key.chain"))
privateKeyFile = file(prop("publishing.plugin.key"))
password = prop("publishing.plugin.password")
}

publishPlugin {
token = prop("publishing.plugin.token")
}
}
alias(deps.plugins.intellij) apply false
alias(deps.plugins.kotlin.forPlugin) apply false
alias(deps.plugins.compose) apply false
alias(deps.plugins.kotlin.forSample) apply false
}
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib
kotlin.stdlib.default.dependency=false
# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
org.gradle.configuration-cache=true
# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching=true
org.gradle.configuration-cache=true
18 changes: 18 additions & 0 deletions gradle/deps.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[versions]
# https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library
kotlin-forPlugin = "1.7.0"
kotlin-forSample = "1.9.23"
intellij = "1.17.3"
compose = "1.6.2"

plugin = "0.0.8"
idea-name = "2022.3"
idea-code-min = "223"
idea-code-max = "223"
jvm = "17"

[plugins]
kotlin-forPlugin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-forPlugin" }
kotlin-forSample = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin-forSample" }
intellij = { id = "org.jetbrains.intellij", version.ref = "intellij" }
compose = { id = "org.jetbrains.compose", version.ref = "compose" }
59 changes: 59 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
plugins {
java
alias(deps.plugins.intellij)
alias(deps.plugins.kotlin.forPlugin)
}

group = "ru.ztrap.plugin.idea"
version = "${deps.versions.plugin.get()}-${deps.versions.idea.code.min.get()}"

// See https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
version = deps.versions.idea.name
type = "IC"

plugins = listOf(
"com.intellij.java",
"org.jetbrains.kotlin",
)
}

val jvmVersion = deps.versions.jvm.get()

tasks {
buildSearchableOptions {
enabled = false
}

// Set the JVM compatibility versions
compileJava {
sourceCompatibility = jvmVersion
targetCompatibility = jvmVersion
}

compileKotlin {
kotlinOptions.jvmTarget = jvmVersion
}

patchPluginXml {
version = project.version.toString()
sinceBuild = deps.versions.idea.code.min
untilBuild = "${deps.versions.idea.code.max.get()}.*"
}

signPlugin {
certificateChainFile = file(prop("publishing.plugin.key.chain"))
privateKeyFile = file(prop("publishing.plugin.key"))
password = prop("publishing.plugin.password")
}

publishPlugin {
token = prop("publishing.plugin.token")
}
}

fun prop(key: String) = project.findProperty(key).toString()

repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,9 @@ private fun saturate(v: Float): Float {
fun Color.toArgb(): Int {
return (convert(ColorSpaces.Srgb).value shr 32).toInt()
}

/**
* `false` when this is [Color.Unspecified].
*/
/*@Stable*/
inline val Color.isSpecified: Boolean get() = value != Color.Unspecified.value
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ru.ztrap.plugin.idea.compose.color.preview
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.colorspace.Rgb
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.graphics.isSpecified
import androidx.compose.ui.graphics.lerp
import androidx.compose.ui.graphics.toArgb
import com.intellij.openapi.application.runWriteAction
Expand Down Expand Up @@ -44,7 +45,7 @@ internal sealed class ColorFunction(protected val callExpression: KtCallExpressi

abstract fun setNewColor(color: Color, factory: KtPsiFactory)

fun getColor(): Color? = runCatching { getColorInternal() }.getOrNull()
fun getColor(): Color? = runCatching { getColorInternal()?.takeIf { it.isSpecified } }.getOrNull()

protected abstract fun getColorInternal(): Color?

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ru.ztrap.plugin.idea.compose.color.preview.codeInsight.completion

import com.intellij.codeInsight.completion.CompletionContributor
import com.intellij.codeInsight.completion.CompletionParameters
import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementDecorator
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.util.ui.ColorIcon
import javax.swing.Icon
import org.jetbrains.kotlin.psi.KtProperty
import ru.ztrap.plugin.idea.compose.color.preview.utils.getColorOrNull
import ru.ztrap.plugin.idea.compose.color.preview.utils.resolveKtProperty
import ru.ztrap.plugin.idea.compose.color.preview.utils.safeCast
import ru.ztrap.plugin.idea.compose.color.preview.utils.toAwtColor

class ComposeColorCompletionContributor : CompletionContributor() {

override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
result.runRemainingContributors(parameters) { completionResult ->
val lookupElement = completionResult.lookupElement

val newResult = lookupElement.psiElement
?.navigationElement
?.safeCast<KtProperty>()
?.let(::resolveKtProperty)
?.getColorOrNull()
?.toAwtColor()
?.let { ColorIcon(16, 12, it, true) }
?.let { ComposeColorLookupElementDecorator(lookupElement, it) }
?.let(completionResult::withLookupElement)
?: completionResult

result.passResult(newResult)
}
}

private class ComposeColorLookupElementDecorator(
delegate: LookupElement,
private val icon: Icon,
) : LookupElementDecorator<LookupElement>(delegate) {
override fun renderElement(presentation: LookupElementPresentation) {
super.renderElement(presentation)
presentation.icon = icon
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.ztrap.plugin.idea.compose.color.preview.line.marker.provider
package ru.ztrap.plugin.idea.compose.color.preview.codeInsight.daemon

import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
import com.intellij.codeInsight.daemon.MergeableLineMarkerInfo
Expand Down
Loading

0 comments on commit 9dfc098

Please sign in to comment.