-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NixSymbolSettings for user customization
- Loading branch information
1 parent
2ec6a06
commit bb3fd03
Showing
9 changed files
with
185 additions
and
12 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
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
67 changes: 67 additions & 0 deletions
67
src/main/java/org/nixos/idea/settings/NixSymbolConfigurable.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,67 @@ | ||
package org.nixos.idea.settings | ||
|
||
import com.intellij.openapi.options.BoundSearchableConfigurable | ||
import com.intellij.openapi.options.Configurable | ||
import com.intellij.openapi.ui.DialogPanel | ||
import com.intellij.ui.components.JBCheckBox | ||
import com.intellij.ui.dsl.builder.Cell | ||
import com.intellij.ui.dsl.builder.bind | ||
import com.intellij.ui.dsl.builder.bindSelected | ||
import com.intellij.ui.dsl.builder.panel | ||
import com.intellij.ui.dsl.builder.selected | ||
|
||
class NixSymbolConfigurable : | ||
BoundSearchableConfigurable("Nix Symbols", "org.nixos.idea.settings.NixSymbolConfigurable"), | ||
Configurable.Beta { | ||
|
||
override fun createPanel(): DialogPanel { | ||
val settings = NixSymbolSettings.getInstance() | ||
lateinit var enabledCheckBox: Cell<JBCheckBox> | ||
return panel { | ||
row { | ||
enabledCheckBox = checkBox("Use Symbol API to resolve references and find usages") | ||
.bindSelected(settings::enabled) | ||
} | ||
rowsRange { | ||
groupRowsRange("Go To Declaration") { | ||
buttonsGroup { | ||
row { | ||
radioButton("Go to first declaration", true) | ||
radioButton("Ask when symbol has multiple declarations", false) | ||
}.rowComment( | ||
""" | ||
Attribute sets and <code>let</code>-expressions may contain | ||
multiple indirect declarations of the same symbol. | ||
""".trimIndent() | ||
).contextHelp( | ||
""" | ||
The following code block contains three | ||
declarations of “<code>common</code>”: | ||
<pre> | ||
let | ||
zero = 0; | ||
common.a = 1; | ||
common.b = 2; | ||
common.c = 3; | ||
in | ||
common | ||
</pre> | ||
If you run <em>Go To Declaration</em> on the last line, | ||
this setting defines whether | ||
the action jumps directly to <code>common.a</code> | ||
(the first declaration), | ||
or opens a popup asking which declaration you want to see. | ||
""".trimIndent() | ||
) | ||
}.bind(settings::jumpToFirstDeclaration) | ||
} | ||
groupRowsRange("Find Usages") { | ||
row { | ||
checkBox("Show declarations as part of the results") | ||
.bindSelected(settings::showDeclarationsAsUsages) | ||
} | ||
} | ||
}.enabledIf(enabledCheckBox.selected) | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/org/nixos/idea/settings/NixSymbolSettings.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,30 @@ | ||
package org.nixos.idea.settings | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.components.BaseState | ||
import com.intellij.openapi.components.SimplePersistentStateComponent | ||
import com.intellij.openapi.components.State | ||
import com.intellij.openapi.components.Storage | ||
import org.nixos.idea.settings.SimplePersistentStateComponentHelper.delegate | ||
|
||
@State(name = "NixSymbolSettings", storages = [Storage("nix-idea.xml")]) | ||
class NixSymbolSettings : SimplePersistentStateComponent<NixSymbolSettings.State>(State()) { | ||
|
||
class State : BaseState() { | ||
var enabled by property(true) | ||
var jumpToFirstDeclaration by property(true) | ||
var showDeclarationsAsUsages by property(false) | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun getInstance(): NixSymbolSettings { | ||
return ApplicationManager.getApplication().getService(NixSymbolSettings::class.java) | ||
} | ||
} | ||
|
||
var enabled: Boolean by delegate(State::enabled) | ||
var jumpToFirstDeclaration by delegate(State::jumpToFirstDeclaration) | ||
var showDeclarationsAsUsages: Boolean by delegate(State::showDeclarationsAsUsages) | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/org/nixos/idea/settings/SimplePersistentStateComponentHelper.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 org.nixos.idea.settings | ||
|
||
import com.intellij.openapi.components.BaseState | ||
import com.intellij.openapi.components.SimplePersistentStateComponent | ||
import kotlin.properties.ReadWriteProperty | ||
import kotlin.reflect.KMutableProperty1 | ||
import kotlin.reflect.KProperty | ||
|
||
internal object SimplePersistentStateComponentHelper { | ||
|
||
/** | ||
* Creates property which delegates every access to the given property of the state. | ||
* | ||
* ```kotlin | ||
* @State(name = "SomeSettings", storages = [Storage(...)]) | ||
* class SomeSettings : SimplePersistentStateComponent<SomeSettings.State>(State()) { | ||
* class State : BaseState() { | ||
* // The internal storage of the configured values | ||
* var enabled by property(true) | ||
* } | ||
* | ||
* // Makes the property publicly accessible | ||
* var enabled: Boolean by delegate(State::enabled) | ||
* } | ||
* ``` | ||
*/ | ||
fun <S : BaseState, V> delegate(prop: KMutableProperty1<S, V>): ReadWriteProperty<SimplePersistentStateComponent<S>, V> { | ||
return object : ReadWriteProperty<SimplePersistentStateComponent<S>, V> { | ||
override fun getValue(thisRef: SimplePersistentStateComponent<S>, property: KProperty<*>): V { | ||
return prop.get(thisRef.state) | ||
} | ||
|
||
override fun setValue(thisRef: SimplePersistentStateComponent<S>, property: KProperty<*>, value: V) { | ||
prop.set(thisRef.state, value) | ||
} | ||
} | ||
} | ||
} |
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