Skip to content

Commit

Permalink
Merge pull request #497 from koxudaxi/fix_lsp_enable_button
Browse files Browse the repository at this point in the history
Update LSP client change logic in RuffConfigurable.kt
  • Loading branch information
koxudaxi authored Sep 10, 2024
2 parents bbc659d + bf2090b commit 26c842d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]
- Update LSP client change logic in RuffConfigurable.kt [[#497](https://github.com/koxudaxi/ruff-pycharm-plugin/pull/497)]
- Update LSP4IJ references and version [[#496](https://github.com/koxudaxi/ruff-pycharm-plugin/pull/496)]
- LSP4IJ should be optional [[#494](https://github.com/koxudaxi/ruff-pycharm-plugin/pull/494)]

Expand Down
25 changes: 9 additions & 16 deletions src/com/koxudaxi/ruff/RuffConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,30 @@ class RuffConfigurable internal constructor(val project: Project) : Configurable
val ruffConfigPathChanged = configPanel.ruffConfigPath != configPanel.ruffConfigPath
val useRuffLspChanged = ruffConfigService.useRuffLsp != configPanel.useRuffLsp
val useRuffServerChanged = ruffConfigService.useRuffServer != configPanel.useRuffServer
val lspClientChanged = ruffConfigService.useIntellijLspClient != configPanel.useIntellijLspClient
val lspClientChanged = (ruffConfigService.useIntellijLspClient != configPanel.useIntellijLspClient) ||
(ruffConfigService.useLsp4ij != configPanel.useLsp4ij)
ruffConfigService.ruffConfigPath = configPanel.ruffConfigPath
ruffConfigService.useRuffLsp = configPanel.useRuffLsp
ruffConfigService.useRuffServer = configPanel.useRuffServer
ruffConfigService.useIntellijLspClient = configPanel.useIntellijLspClient
ruffConfigService.useLsp4ij = configPanel.useLsp4ij
val lspEnabledChanged = ruffConfigService.enableLsp != configPanel.enableLsp
ruffConfigService.enableLsp = configPanel.enableLsp
ruffCacheService.setVersion {
if (!lspSupported) return@setVersion
val startLsp = ruffConfigService.enableLsp
var started = false
if (lspClientChanged) {
if (lspClientChanged || (lspEnabledChanged && startLsp)) {
if (ruffConfigService.useLsp4ij) {
ruffLspClientManager.setClient(ClientType.LSP4IJ, startLsp)
} else {
ruffLspClientManager.setClient(ClientType.INTELLIJ, startLsp)
}
started = startLsp
} else {
if (useRuffLspChanged || useRuffServerChanged) {
if (startLsp) {
ruffLspClientManager.start()
started = true
} else {
ruffLspClientManager.stop()
}
}
}

if (!started && ruffConfigPathChanged && startLsp) {
} else if (lspEnabledChanged) {
ruffLspClientManager.stop()
} else if (useRuffLspChanged || useRuffServerChanged || ruffConfigPathChanged) {
if (startLsp) {
ruffLspClientManager.restart()
}
}
// TODO: support ruff global executable path changed pattern
}
Expand Down

0 comments on commit 26c842d

Please sign in to comment.