Skip to content

Commit

Permalink
feat(settings): allow enabling/disabling of language server diagnostics
Browse files Browse the repository at this point in the history
Surface plugin settings to allow setting lint and eval diagnostics.
These settings are passed into the command for running the language
server.

Disabling lint and eval diagnostics significantly improves performance
for large projects.
  • Loading branch information
zzehring committed Mar 2, 2024
1 parent 7ccd094 commit d81432b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class JsonnetLSStartupHandler {
fun start() {

val languageServerRepo = JLSSettingsStateComponent.instance.state.releaseRepository
val enableEvalDiagnostics = JLSSettingsStateComponent.instance.state.enableEvalDiagnostics
val enableLintDiagnostics = JLSSettingsStateComponent.instance.state.enableLintDiagnostics
val platform = getPlatform()
val arch = getArch()

Expand Down Expand Up @@ -95,10 +97,17 @@ class JsonnetLSStartupHandler {
// Configure language server
// TODO: Make --tanka configurable
// TODO: add JPath configuration
var optionalArgs = arrayOf<String>()
if (enableEvalDiagnostics) {
optionalArgs += "--eval-diags"
}
if (enableLintDiagnostics) {
optionalArgs += "--lint"
}
IntellijLanguageClient.addServerDefinition(
RawCommandServerDefinition(
EXTENSIONS,
arrayOf(binFile.toString(), "--tanka", "--lint")
arrayOf(binFile.toString(), "--tanka", *optionalArgs)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.zzehring.intellijjsonnet.settings

import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextField
import com.intellij.util.ui.FormBuilder
Expand All @@ -11,12 +12,18 @@ import javax.swing.JPanel
* Supports creating and managing a {@link JPanel} for the Settings Dialog
*/
class JLSSettingsComponent {
var myMainPanel: JPanel
var repoPanel: JPanel
private val releaseRepository = JBTextField()
private val enableLintDiagnostics = JBCheckBox("Enable lint diagnostics on language server")
private val enableEvalDiagnostics = JBCheckBox("Enable eval diagnostics on language")

init {
this.myMainPanel = FormBuilder.createFormBuilder()
this.repoPanel = FormBuilder.createFormBuilder()
.addLabeledComponent(JBLabel("Release Repo (Github Repository from which to download language server): "), releaseRepository, 1, true)
.addComponent(enableEvalDiagnostics)
.addTooltip("Try to evaluate files to find errors and warnings. Disable on large projects to improve performance. IDE restart required.")
.addComponent(enableLintDiagnostics)
.addTooltip("Enable live linting diagnostics. Disable on large projects to improve performance. IDE restart required.")
.addComponentFillVertically(JPanel(), 0)
.panel
}
Expand All @@ -34,4 +41,20 @@ class JLSSettingsComponent {
releaseRepository.text = newPath
}

fun getEnableLintDiagnostics(): Boolean {
return enableLintDiagnostics.isSelected
}

fun setEnableLintDiagnostics(isSelected: Boolean) {
enableLintDiagnostics.isSelected = isSelected
}

fun getEnableEvalDiagnostics(): Boolean {
return enableEvalDiagnostics.isSelected
}

fun setEnableEvalDiagnostics(isSelected: Boolean) {
enableEvalDiagnostics.isSelected = isSelected
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ class JLSSettingsConfigurable : Configurable {
private lateinit var mySettingsComponent: JLSSettingsComponent

@Nullable
override fun createComponent(): JComponent? {
override fun createComponent(): JComponent {
mySettingsComponent = JLSSettingsComponent()
return mySettingsComponent.myMainPanel
mySettingsComponent.setEnableLintDiagnostics(true)
mySettingsComponent.setEnableEvalDiagnostics(false)
return mySettingsComponent.repoPanel
}

override fun isModified(): Boolean {
val settings = JLSSettingsStateComponent.instance.state
return mySettingsComponent.getReleaseRepository() != settings.releaseRepository
|| mySettingsComponent.getEnableEvalDiagnostics() != settings.enableEvalDiagnostics
|| mySettingsComponent.getEnableLintDiagnostics() != settings.enableLintDiagnostics
}

override fun apply() {
val settings = JLSSettingsStateComponent.instance.state
settings.releaseRepository = mySettingsComponent.getReleaseRepository()
settings.enableEvalDiagnostics = mySettingsComponent.getEnableEvalDiagnostics()
settings.enableLintDiagnostics = mySettingsComponent.getEnableLintDiagnostics()
}

@Nls(capitalization = Nls.Capitalization.Title)
Expand All @@ -37,6 +43,8 @@ class JLSSettingsConfigurable : Configurable {
override fun reset() {
val settings = JLSSettingsStateComponent.instance.state
mySettingsComponent.setReleaseRepository(settings.releaseRepository)
mySettingsComponent.setEnableEvalDiagnostics(settings.enableEvalDiagnostics)
mySettingsComponent.setEnableLintDiagnostics(settings.enableLintDiagnostics)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable

@State(
name = "com.github.zzehring.intellijjsonnet.JLSSettingsState",
storages = [Storage("SdkSettingsPlugin.xml")]
storages = [Storage("JsonnetLsSettingsPlugin.xml")]
)
open class JLSSettingsStateComponent : PersistentStateComponent<JLSSettingsStateComponent.SettingsState> {

Expand All @@ -30,5 +30,7 @@ open class JLSSettingsStateComponent : PersistentStateComponent<JLSSettingsState

class SettingsState {
var releaseRepository = "grafana/jsonnet-language-server"
var enableLintDiagnostics = false
var enableEvalDiagnostics = false
}
}

0 comments on commit d81432b

Please sign in to comment.