-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
1 parent
095f5e9
commit 79a43ab
Showing
8 changed files
with
241 additions
and
367 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,52 @@ | ||
package org.nixos.idea.lsp | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.components.BaseState | ||
import com.intellij.openapi.components.RoamingType | ||
import com.intellij.openapi.components.SimplePersistentStateComponent | ||
import com.intellij.openapi.components.State | ||
import com.intellij.openapi.components.Storage | ||
import com.intellij.openapi.util.text.Strings | ||
import org.nixos.idea.settings.NixStoragePaths | ||
import org.nixos.idea.settings.SimplePersistentStateComponentHelper.delegate | ||
import java.util.ArrayDeque | ||
import java.util.Collections | ||
import java.util.Deque | ||
|
||
@State(name = "NixLspSettings", storages = [Storage(value = NixStoragePaths.TOOLS, roamingType = RoamingType.LOCAL)]) | ||
class NixLspSettings : SimplePersistentStateComponent<NixLspSettings.State>(State()) { | ||
|
||
class State : BaseState() { | ||
var enabled by property(false) | ||
var command by string() | ||
var history: Deque<String> by property(ArrayDeque(), { it.isEmpty() }) | ||
} | ||
|
||
var isEnabled: Boolean by delegate(State::enabled) | ||
var command: String | ||
get() = Strings.notNullize(state.command) | ||
set(command) { | ||
state.command = command | ||
addToHistory(command) | ||
} | ||
val commandHistory: Collection<String> | ||
get() = Collections.unmodifiableCollection(state.history) | ||
|
||
private fun addToHistory(command: String) { | ||
val history = state.history | ||
history.remove(command) | ||
history.addFirst(command) | ||
while (history.size > MAX_HISTORY_SIZE) { | ||
history.removeLast() | ||
} | ||
} | ||
|
||
companion object { | ||
private const val MAX_HISTORY_SIZE = 5 | ||
|
||
@JvmStatic | ||
fun getInstance(): NixLspSettings { | ||
return ApplicationManager.getApplication().getService(NixLspSettings::class.java) | ||
} | ||
} | ||
} |
106 changes: 0 additions & 106 deletions
106
src/main/java/org/nixos/idea/lsp/NixLspSettingsConfigurable.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
src/main/java/org/nixos/idea/lsp/NixLspSettingsConfigurable.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,70 @@ | ||
package org.nixos.idea.lsp | ||
|
||
import com.intellij.openapi.options.BoundSearchableConfigurable | ||
import com.intellij.openapi.options.Configurable | ||
import com.intellij.openapi.project.ProjectManager | ||
import com.intellij.openapi.ui.DialogPanel | ||
import com.intellij.platform.lsp.api.LspServerManager | ||
import com.intellij.ui.RawCommandLineEditor | ||
import com.intellij.ui.components.JBCheckBox | ||
import com.intellij.ui.dsl.builder.AlignX | ||
import com.intellij.ui.dsl.builder.Cell | ||
import com.intellij.ui.dsl.builder.bindSelected | ||
import com.intellij.ui.dsl.builder.panel | ||
import com.intellij.ui.dsl.builder.selected | ||
import com.intellij.ui.dsl.builder.toMutableProperty | ||
import org.nixos.idea.lsp.ui.CommandSuggestionsPopup | ||
|
||
class NixLspSettingsConfigurable : | ||
BoundSearchableConfigurable("Language Server (LSP)", "org.nixos.idea.lsp.NixLspSettingsConfigurable"), | ||
Configurable.Beta { | ||
|
||
override fun createPanel(): DialogPanel { | ||
val settings = NixLspSettings.getInstance() | ||
lateinit var enabledCheckBox: Cell<JBCheckBox> | ||
return panel { | ||
row { | ||
enabledCheckBox = checkBox("Enable language server") | ||
.bindSelected(settings::isEnabled) | ||
} | ||
groupRowsRange("Language Server Configuration") { | ||
row("Command:") { | ||
cell(RawCommandLineEditor()).applyToComponent { | ||
editorField.emptyText.setText("Command to start Language Server") | ||
editorField.accessibleContext.accessibleName = "Command to start Language Server" | ||
// TODO What about the following line? | ||
//editorField.margin = myEnabled!!.margin | ||
CommandSuggestionsPopup( | ||
this, | ||
settings.commandHistory, | ||
BUILTIN_SUGGESTIONS | ||
).install() | ||
}.bind( | ||
RawCommandLineEditor::getText, | ||
RawCommandLineEditor::setText, | ||
settings::command.toMutableProperty() | ||
).align(AlignX.FILL) | ||
} | ||
}.enabledIf(enabledCheckBox.selected) | ||
} | ||
} | ||
|
||
@Suppress("UnstableApiUsage") | ||
override fun apply() { | ||
super.apply() | ||
for (project in ProjectManager.getInstance().openProjects) { | ||
LspServerManager.getInstance(project).stopAndRestartIfNeeded(NixLspServerSupportProvider::class.java) | ||
} | ||
} | ||
} | ||
|
||
private val BUILTIN_SUGGESTIONS: List<CommandSuggestionsPopup.Suggestion> = listOf( | ||
CommandSuggestionsPopup.Suggestion.builtin( | ||
"<html>Use <b>nil</b> from nixpkgs</html>", | ||
"nix --extra-experimental-features \"nix-command flakes\" run nixpkgs#nil" | ||
), | ||
CommandSuggestionsPopup.Suggestion.builtin( | ||
"<html>Use <b>nixd</b> from nixpkgs</html>", | ||
"nix --extra-experimental-features \"nix-command flakes\" run nixpkgs#nixd" | ||
) | ||
) |
76 changes: 0 additions & 76 deletions
76
src/main/java/org/nixos/idea/settings/NixExternalFormatterSettings.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.