diff --git a/CHANGELOG.md b/CHANGELOG.md index de5e046d..7d9a414e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,13 @@ Changelog structure reference: ## [Unreleased] +## [25.0.2] + +### Fixed + +- Project + - ZLS settings not scrollable in the language server list + ## [25.0.1] ### Fixed diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/base/ZigToolchainConfigurable.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/base/ZigToolchainConfigurable.kt index abbd34f7..018b9e7b 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/base/ZigToolchainConfigurable.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/base/ZigToolchainConfigurable.kt @@ -25,6 +25,7 @@ package com.falsepattern.zigbrains.project.toolchain.base import com.falsepattern.zigbrains.project.settings.ZigProjectConfigurationProvider import com.falsepattern.zigbrains.project.toolchain.ui.ImmutableElementPanel import com.falsepattern.zigbrains.project.toolchain.zigToolchainList +import com.falsepattern.zigbrains.shared.ui.UUIDComboBoxDriver.Companion.wrapModal import com.intellij.openapi.ui.NamedConfigurable import com.intellij.openapi.util.Key import com.intellij.openapi.util.NlsContexts @@ -37,7 +38,7 @@ abstract class ZigToolchainConfigurable( val uuid: UUID, tc: T, val data: ZigProjectConfigurationProvider.IUserDataBridge?, - val modal: Boolean + private val modal: Boolean ): NamedConfigurable() { var toolchain: T = tc set(value) { @@ -64,7 +65,7 @@ abstract class ZigToolchainConfigurable( views.forEach { it.attach(this@panel) } }.withMinimumWidth(20) views.forEach { it.reset(toolchain) } - return p + return wrapModal(p, modal) } override fun getEditableObject(): UUID? { diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/downloader/LocalToolchainDownloader.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/downloader/LocalToolchainDownloader.kt index 3cb24106..6a64b47f 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/downloader/LocalToolchainDownloader.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/downloader/LocalToolchainDownloader.kt @@ -24,15 +24,15 @@ package com.falsepattern.zigbrains.project.toolchain.downloader import com.falsepattern.zigbrains.ZigBrainsBundle import com.falsepattern.zigbrains.project.toolchain.local.LocalZigToolchain -import com.falsepattern.zigbrains.project.toolchain.local.getSuggestedLocalToolchainPath +import com.falsepattern.zigbrains.project.toolchain.local.suggestedLocalToolchainPath import com.falsepattern.zigbrains.shared.downloader.Downloader import java.awt.Component class LocalToolchainDownloader(component: Component) : Downloader(component) { override val windowTitle get() = ZigBrainsBundle.message("settings.toolchain.downloader.title") override val versionInfoFetchTitle get() = ZigBrainsBundle.message("settings.toolchain.downloader.progress.fetch") + override val suggestedPath get() = suggestedLocalToolchainPath override fun downloadProgressTitle(version: ZigVersionInfo) = ZigBrainsBundle.message("settings.toolchain.downloader.progress.install", version.version.rawVersion) override fun localSelector() = LocalToolchainSelector(component) override suspend fun downloadVersionList() = ZigVersionInfo.downloadVersionList() - override fun getSuggestedPath() = getSuggestedLocalToolchainPath() } \ No newline at end of file diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/local/LocalZigToolchainPanel.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/local/LocalZigToolchainPanel.kt index d614d361..e1bee5a5 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/local/LocalZigToolchainPanel.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/local/LocalZigToolchainPanel.kt @@ -75,8 +75,8 @@ class LocalZigToolchainPanel() : ImmutableNamedElementPanelBase + val wellKnown = wellKnown.asFlow().flatMapConcat { dir -> runCatching { Files.newDirectoryStream(dir).use { stream -> stream.toList().filterNotNull().asFlow() @@ -112,8 +112,8 @@ class LocalZigToolchainProvider: ZigToolchainProvider { } } -fun getSuggestedLocalToolchainPath(): Path? { - return getWellKnown().getOrNull(0) +val suggestedLocalToolchainPath: Path? by lazy { + wellKnown.getOrNull(0) } /** @@ -130,18 +130,12 @@ fun getSuggestedLocalToolchainPath(): Path? { * * and HOME is the user home path */ -private fun getWellKnown(): List { - val home = System.getProperty("user.home")?.toNioPathOrNull() ?: return emptyList() - val xdgDataHome = when(OS.CURRENT) { - OS.macOS -> home.resolve("Library") - OS.Windows -> System.getenv("LOCALAPPDATA")?.toNioPathOrNull() - else -> System.getenv("XDG_DATA_HOME")?.toNioPathOrNull() ?: home.resolve(Path.of(".local", "share")) - } +private val wellKnown: List by lazy { val res = ArrayList() - if (xdgDataHome != null && xdgDataHome.isDirectory()) { - res.add(xdgDataHome.resolve("zig")) - res.add(xdgDataHome.resolve("zigup")) + xdgDataHome?.let { + res.add(it.resolve("zig")) + res.add(it.resolve("zigup")) } - res.add(home.resolve(".zig")) - return res -} \ No newline at end of file + homePath?.let { res.add(it.resolve(".zig")) } + res +} diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ImmutableElementPanel.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ImmutableElementPanel.kt index 40e62f63..97bc3469 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ImmutableElementPanel.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ImmutableElementPanel.kt @@ -26,7 +26,7 @@ import com.intellij.openapi.Disposable import com.intellij.ui.dsl.builder.Panel interface ImmutableElementPanel: Disposable { - fun attach(p: Panel) + fun attach(panel: Panel) fun isModified(elem: T): Boolean /** * Returned object must be the exact same class as the provided one. diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ImmutableNamedElementPanelBase.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ImmutableNamedElementPanelBase.kt index 5f3906c4..95bd4ce8 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ImmutableNamedElementPanelBase.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ImmutableNamedElementPanelBase.kt @@ -34,7 +34,7 @@ abstract class ImmutableNamedElementPanelBase: ImmutableElementPanel { get() = nameField.text.ifBlank { null } set(value) {nameField.text = value ?: ""} - override fun attach(p: Panel): Unit = with(p) { + override fun attach(panel: Panel): Unit = with(panel) { row(ZigBrainsBundle.message("settings.toolchain.base.name.label")) { cell(nameField).resizableColumn().align(AlignX.FILL) } diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ZigToolchainEditor.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ZigToolchainEditor.kt index 30ec0ae6..a43bc3f3 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ZigToolchainEditor.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/project/toolchain/ui/ZigToolchainEditor.kt @@ -60,7 +60,7 @@ class ZigToolchainEditor(private val sharedState: ZigProjectConfigurationProvide } - override fun attach(p: Panel): Unit = with(p) { + override fun attach(panel: Panel): Unit = with(panel) { row(ZigBrainsBundle.message( if (sharedState.getUserData(PROJECT_KEY)?.isDefault == true) "settings.toolchain.editor.toolchain-default.label" @@ -75,7 +75,7 @@ class ZigToolchainEditor(private val sharedState: ZigProjectConfigurationProvide views.addAll(createZigToolchainExtensionPanels(sharedState, PanelState.ProjectEditor)) myViews = views } - views.forEach { it.attach(p) } + views.forEach { it.attach(panel) } } override fun onSelection(uuid: UUID?) { diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/downloader/Downloader.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/downloader/Downloader.kt index fb81e7a2..b48869d6 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/downloader/Downloader.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/downloader/Downloader.kt @@ -76,10 +76,10 @@ abstract class Downloader(val component: Component) { protected abstract val windowTitle: String protected abstract val versionInfoFetchTitle: @NlsContexts.ProgressTitle String + protected abstract val suggestedPath: Path? protected abstract fun downloadProgressTitle(version: V): @NlsContexts.ProgressTitle String protected abstract fun localSelector(): LocalSelector protected abstract suspend fun downloadVersionList(): List - protected abstract fun getSuggestedPath(): Path? @RequiresEdt private fun selectVersion(info: List, selector: LocalSelector): Pair? { @@ -131,7 +131,7 @@ abstract class Downloader(val component: Component) { }) var archiveSizeCell: Cell<*>? = null fun detect(item: V) { - outputPath.text = getSuggestedPath()?.resolve(item.version.rawVersion)?.pathString ?: "" + outputPath.text = suggestedPath?.resolve(item.version.rawVersion)?.pathString ?: "" val size = item.dist.size val sizeMb = size / (1024f * 1024f) archiveSizeCell?.comment?.text = ZigBrainsBundle.message("settings.shared.downloader.archive-size.text", "%.2fMB".format(sizeMb)) diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/downloader/LocalSelector.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/downloader/LocalSelector.kt index b35130b5..1e5085ce 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/downloader/LocalSelector.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/downloader/LocalSelector.kt @@ -41,11 +41,13 @@ import com.intellij.ui.components.textFieldWithBrowseButton import com.intellij.ui.dsl.builder.AlignX import com.intellij.ui.dsl.builder.panel import com.intellij.util.concurrency.annotations.RequiresEdt +import com.intellij.util.system.OS import java.awt.Component import java.nio.file.Path import java.util.concurrent.atomic.AtomicBoolean import javax.swing.Icon import javax.swing.event.DocumentEvent +import kotlin.io.path.isDirectory import kotlin.io.path.pathString abstract class LocalSelector(val component: Component) { @@ -135,4 +137,16 @@ abstract class LocalSelector(val component: Component) { val errorIcon: Icon, val errorText: String, ) +} + +val homePath: Path? by lazy { + System.getProperty("user.home")?.toNioPathOrNull()?.takeIf { it.isDirectory() } +} + +val xdgDataHome: Path? by lazy { + when(OS.CURRENT) { + OS.macOS -> homePath?.resolve("Library") + OS.Windows -> System.getenv("LOCALAPPDATA")?.toNioPathOrNull() + else -> System.getenv("XDG_DATA_HOME")?.toNioPathOrNull() ?: homePath?.resolve(Path.of(".local", "share")) + }?.takeIf { it.isDirectory() } } \ No newline at end of file diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/UUIDComboBoxDriver.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/UUIDComboBoxDriver.kt index aa7fa261..01a52625 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/UUIDComboBoxDriver.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/UUIDComboBoxDriver.kt @@ -24,8 +24,11 @@ package com.falsepattern.zigbrains.shared.ui import com.falsepattern.zigbrains.shared.UUIDMapSerializable import com.intellij.openapi.ui.NamedConfigurable +import com.intellij.ui.components.JBScrollPane import java.awt.Component +import java.awt.Dimension import java.util.* +import javax.swing.JComponent interface UUIDComboBoxDriver { val theMap: UUIDMapSerializable.Converting @@ -34,4 +37,15 @@ interface UUIDComboBoxDriver { fun createComboBox(model: ZBModel): ZBComboBox suspend fun resolvePseudo(context: Component, elem: ListElem.Pseudo): UUID? fun createNamedConfigurable(uuid: UUID, elem: T): NamedConfigurable + + companion object { + fun wrapModal(component: JComponent, modal: Boolean): JComponent { + if (modal) { + component.preferredSize = Dimension(640, 480) + return component + } else { + return JBScrollPane(component) + } + } + } } \ No newline at end of file diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/UUIDMapSelector.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/UUIDMapSelector.kt index 92f13728..a650670a 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/UUIDMapSelector.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/UUIDMapSelector.kt @@ -161,7 +161,7 @@ abstract class UUIDMapSelector(val driver: UUIDComboBoxDriver): Disposable protected fun attachComboBoxRow(row: Row): Unit = with(row) { cell(comboBox).resizableColumn().align(AlignX.FILL) - button(ZigBrainsBundle.message("settings.toolchain.editor.toolchain.edit-button.name")) { e -> + button(ZigBrainsBundle.message("settings.toolchain.editor.toolchain.edit-button.name")) { zigCoroutineScope.launchWithEDT(comboBox.asContextElement()) { var selectedUUID = comboBox.selectedUUID ?: return@launchWithEDT val elem = driver.theMap[selectedUUID] ?: return@launchWithEDT diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/model.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/model.kt index 717a16d1..4e220ea6 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/model.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/shared/ui/model.kt @@ -250,16 +250,16 @@ abstract class ZBCellRenderer(val getModel: () -> ZBModel) : ColoredListCe } fun renderPathNameComponent(path: String, name: String?, nameFallback: String, component: SimpleColoredComponent, isSuggestion: Boolean, isSelected: Boolean) { - val path = presentDetectedPath(path) + val thePath = presentDetectedPath(path) val primary: String var secondary: String? val tooltip: String? if (isSuggestion) { - primary = path + primary = thePath secondary = name } else { primary = name ?: nameFallback - secondary = path + secondary = thePath } if (isSelected) { tooltip = secondary @@ -277,12 +277,12 @@ fun renderPathNameComponent(path: String, name: String?, nameFallback: String, c fun presentDetectedPath(home: String, maxLength: Int = 50, suffixLength: Int = 30): String { //for macOS, let's try removing Bundle internals - var home = home - home = StringUtil.trimEnd(home, "/Contents/Home") //NON-NLS - home = StringUtil.trimEnd(home, "/Contents/MacOS") //NON-NLS - home = FileUtil.getLocationRelativeToUserHome(home, false) - home = StringUtil.shortenTextWithEllipsis(home, maxLength, suffixLength) - return home + var theHome = home + theHome = StringUtil.trimEnd(theHome, "/Contents/Home") //NON-NLS + theHome = StringUtil.trimEnd(theHome, "/Contents/MacOS") //NON-NLS + theHome = FileUtil.getLocationRelativeToUserHome(theHome, false) + theHome = StringUtil.shortenTextWithEllipsis(theHome, maxLength, suffixLength) + return theHome } private val EMPTY_ICON = EmptyIcon.create(1, 16) \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 541511a8..002a0660 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ pluginName=ZigBrains pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains -pluginVersion=25.0.1 +pluginVersion=25.0.2 pluginSinceBuild=241 pluginUntilBuild=241.* diff --git a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/settings/ZLSSettingsPanel.kt b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/settings/ZLSSettingsPanel.kt index 08daa015..1ce0075b 100644 --- a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/settings/ZLSSettingsPanel.kt +++ b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/settings/ZLSSettingsPanel.kt @@ -65,7 +65,7 @@ class ZLSSettingsPanel() : ImmutableElementPanel { private val build_runner_path = ExtendableTextField() private val global_cache_path = ExtendableTextField() - override fun attach(p: Panel): Unit = with(p) { + override fun attach(panel: Panel): Unit = with(panel) { fancyRow( "settings.zls-config-path.label", "settings.zls-config-path.tooltip" diff --git a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ZLSConfigurable.kt b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ZLSConfigurable.kt index 87c5fb76..2cead1c1 100644 --- a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ZLSConfigurable.kt +++ b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ZLSConfigurable.kt @@ -22,14 +22,14 @@ package com.falsepattern.zigbrains.lsp.zls +import com.falsepattern.zigbrains.shared.ui.UUIDComboBoxDriver.Companion.wrapModal import com.intellij.openapi.ui.NamedConfigurable import com.intellij.openapi.util.NlsContexts import com.intellij.ui.dsl.builder.panel -import java.awt.Dimension import java.util.* import javax.swing.JComponent -class ZLSConfigurable(val uuid: UUID, zls: ZLSVersion): NamedConfigurable() { +class ZLSConfigurable(val uuid: UUID, zls: ZLSVersion, private val modal: Boolean): NamedConfigurable() { var zls: ZLSVersion = zls set(value) { zlsInstallations[uuid] = value @@ -59,8 +59,7 @@ class ZLSConfigurable(val uuid: UUID, zls: ZLSVersion): NamedConfigurable( val p = panel { view.attach(this@panel) } - p.preferredSize = Dimension(640, 480) - return p + return wrapModal(p, modal) } override fun getDisplayName(): @NlsContexts.ConfigurableName String? { diff --git a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ZLSPanel.kt b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ZLSPanel.kt index ba52933f..1c7298b4 100644 --- a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ZLSPanel.kt +++ b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ZLSPanel.kt @@ -63,8 +63,8 @@ class ZLSPanel() : ImmutableNamedElementPanelBase() { private var settingsPanel: ZLSSettingsPanel? = null private var debounce: Job? = null - override fun attach(p: Panel): Unit = with(p) { - super.attach(p) + override fun attach(panel: Panel): Unit = with(panel) { + super.attach(panel) row(ZLSBundle.message("settings.panel.path.label")) { cell(pathToZLS).resizableColumn().align(AlignX.FILL) } @@ -72,27 +72,27 @@ class ZLSPanel() : ImmutableNamedElementPanelBase() { cell(zlsVersion) } val sp = ZLSSettingsPanel() - p.collapsibleGroup(ZLSBundle.message("settings.panel.settings.group.label"), indent = false) { + panel.collapsibleGroup(ZLSBundle.message("settings.panel.settings.group.label"), indent = false) { sp.attach(this@collapsibleGroup) } settingsPanel = sp } - override fun isModified(version: ZLSVersion): Boolean { + override fun isModified(elem: ZLSVersion): Boolean { val name = nameFieldValue ?: return false val path = this.pathToZLS.text.ifBlank { null }?.toNioPathOrNull() ?: return false - return name != version.name || version.path != path || settingsPanel?.isModified(version.settings) == true + return name != elem.name || elem.path != path || settingsPanel?.isModified(elem.settings) == true } - override fun apply(version: ZLSVersion): ZLSVersion? { + override fun apply(elem: ZLSVersion): ZLSVersion? { val path = this.pathToZLS.text.ifBlank { null }?.toNioPathOrNull() ?: return null - return version.copy(path = path, name = nameFieldValue ?: "", settings = settingsPanel?.apply(version.settings) ?: version.settings) + return elem.copy(path = path, name = nameFieldValue ?: "", settings = settingsPanel?.apply(elem.settings) ?: elem.settings) } - override fun reset(version: ZLSVersion?) { - nameFieldValue = version?.name ?: "" - this.pathToZLS.text = version?.path?.pathString ?: "" - settingsPanel?.reset(version?.settings) + override fun reset(elem: ZLSVersion?) { + nameFieldValue = elem?.name ?: "" + this.pathToZLS.text = elem?.path?.pathString ?: "" + settingsPanel?.reset(elem?.settings) dispatchUpdateUI() } diff --git a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/downloader/ZLSDownloader.kt b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/downloader/ZLSDownloader.kt index b03fed30..18d33632 100644 --- a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/downloader/ZLSDownloader.kt +++ b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/downloader/ZLSDownloader.kt @@ -24,7 +24,7 @@ package com.falsepattern.zigbrains.lsp.zls.downloader import com.falsepattern.zigbrains.lsp.ZLSBundle import com.falsepattern.zigbrains.lsp.zls.ZLSVersion -import com.falsepattern.zigbrains.lsp.zls.ui.getSuggestedZLSPath +import com.falsepattern.zigbrains.lsp.zls.ui.suggestedZLSPath import com.falsepattern.zigbrains.project.settings.ZigProjectConfigurationProvider import com.falsepattern.zigbrains.project.settings.ZigProjectConfigurationProvider.IUserDataBridge import com.falsepattern.zigbrains.project.toolchain.base.ZigToolchainConfigurable @@ -34,6 +34,7 @@ import java.awt.Component class ZLSDownloader(component: Component, private val data: IUserDataBridge?) : Downloader(component) { override val windowTitle get() = ZLSBundle.message("settings.downloader.title") override val versionInfoFetchTitle get() = ZLSBundle.message("settings.downloader.progress.fetch") + override val suggestedPath get() = suggestedZLSPath override fun downloadProgressTitle(version: ZLSVersionInfo) = ZLSBundle.message("settings.downloader.progress.install", version.version.rawVersion) override fun localSelector() = ZLSLocalSelector(component) override suspend fun downloadVersionList(): List { @@ -41,5 +42,4 @@ class ZLSDownloader(component: Component, private val data: IUserDataBridge?) : val project = data?.getUserData(ZigProjectConfigurationProvider.PROJECT_KEY) return ZLSVersionInfo.downloadVersionInfoFor(toolchain, project) } - override fun getSuggestedPath() = getSuggestedZLSPath() } \ No newline at end of file diff --git a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ui/ZLSDriver.kt b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ui/ZLSDriver.kt index 01f76706..8997211e 100644 --- a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ui/ZLSDriver.kt +++ b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ui/ZLSDriver.kt @@ -33,14 +33,14 @@ import com.falsepattern.zigbrains.lsp.zls.zlsInstallations import com.falsepattern.zigbrains.project.settings.ZigProjectConfigurationProvider import com.falsepattern.zigbrains.project.toolchain.base.ZigToolchainConfigurable.Companion.TOOLCHAIN_KEY import com.falsepattern.zigbrains.shared.UUIDMapSerializable +import com.falsepattern.zigbrains.shared.downloader.homePath +import com.falsepattern.zigbrains.shared.downloader.xdgDataHome import com.falsepattern.zigbrains.shared.ui.* import com.falsepattern.zigbrains.shared.ui.ListElem.One.Actual import com.falsepattern.zigbrains.shared.withUniqueName import com.intellij.openapi.project.Project import com.intellij.openapi.ui.NamedConfigurable import com.intellij.openapi.util.SystemInfo -import com.intellij.openapi.util.io.toNioPathOrNull -import com.intellij.util.system.OS import com.intellij.util.text.SemVer import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow @@ -67,10 +67,6 @@ sealed interface ZLSDriver: UUIDComboBoxDriver { return ZLSComboBox(model) } - override fun createNamedConfigurable(uuid: UUID, elem: ZLSVersion): NamedConfigurable { - return ZLSConfigurable(uuid, elem) - } - override suspend fun resolvePseudo( context: Component, elem: ListElem.Pseudo @@ -93,6 +89,10 @@ sealed interface ZLSDriver: UUIDComboBoxDriver { return res } + override fun createNamedConfigurable(uuid: UUID, elem: ZLSVersion): NamedConfigurable { + return ZLSConfigurable(uuid, elem, false) + } + override val data: ZigProjectConfigurationProvider.IUserDataBridge? get() = null } @@ -113,6 +113,10 @@ sealed interface ZLSDriver: UUIDComboBoxDriver { res.add(suggestZLSVersions(project, data, toolchainVersion).asPending()) return res } + + override fun createNamedConfigurable(uuid: UUID, elem: ZLSVersion): NamedConfigurable { + return ZLSConfigurable(uuid, elem, true) + } } } @@ -142,16 +146,16 @@ private fun suggestZLSVersions(project: Project? = null, data: ZigProjectConfigu emitIfCompatible(path, toolchainVersion) } val exe = if (SystemInfo.isWindows) "zls.exe" else "zls" - getWellKnownZLS().forEach { wellKnown -> + wellKnownZLS.forEach { wellKnown -> runCatching { Files.newDirectoryStream(wellKnown).use { stream -> - stream.asSequence().filterNotNull().forEach { dir -> + stream.asSequence().filterNotNull().forEach streamForEach@{ dir -> val path = dir.resolve(exe) if (!path.isRegularFile() || !path.isExecutable()) { - return@forEach + return@streamForEach } if (existing.any { it.path == path }) { - return@forEach + return@streamForEach } emitIfCompatible(path, toolchainVersion) } @@ -188,8 +192,8 @@ private fun numericVersionEquals(a: SemVer, b: SemVer): Boolean { } -fun getSuggestedZLSPath(): Path? { - return getWellKnownZLS().getOrNull(0) +val suggestedZLSPath: Path? by lazy { + wellKnownZLS.getOrNull(0) } /** @@ -205,17 +209,9 @@ fun getSuggestedZLSPath(): Path? { * * and HOME is the user home path */ -private fun getWellKnownZLS(): List { - val home = System.getProperty("user.home")?.toNioPathOrNull() ?: return emptyList() - val xdgDataHome = when(OS.CURRENT) { - OS.macOS -> home.resolve("Library") - OS.Windows -> System.getenv("LOCALAPPDATA")?.toNioPathOrNull() - else -> System.getenv("XDG_DATA_HOME")?.toNioPathOrNull() ?: home.resolve(Path.of(".local", "share")) - } +private val wellKnownZLS: List by lazy { val res = ArrayList() - if (xdgDataHome != null && xdgDataHome.isDirectory()) { - res.add(xdgDataHome.resolve("zls")) - } - res.add(home.resolve(".zls")) - return res + xdgDataHome?.let { res.add(it.resolve("zls")) } + homePath?.let { res.add(it.resolve(".zls")) } + res } \ No newline at end of file diff --git a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ui/ZLSEditor.kt b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ui/ZLSEditor.kt index e5355722..68f72e3e 100644 --- a/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ui/ZLSEditor.kt +++ b/lsp/src/main/kotlin/com/falsepattern/zigbrains/lsp/zls/ui/ZLSEditor.kt @@ -55,21 +55,21 @@ class ZLSEditor(private val sharedState: ZigProjectConfiguratio } } - override fun isModified(toolchain: T): Boolean { + override fun isModified(elem: T): Boolean { if (isEmpty) return false - return toolchain.zlsUUID != selectedUUID + return elem.zlsUUID != selectedUUID } - override fun apply(toolchain: T): T { - return toolchain.withZLS(selectedUUID) + override fun apply(elem: T): T { + return elem.withZLS(selectedUUID) } - override fun reset(toolchain: T?) { - selectedUUID = toolchain?.zlsUUID + override fun reset(elem: T?) { + selectedUUID = elem?.zlsUUID zigCoroutineScope.launch { listChanged() - selectedUUID = toolchain?.zlsUUID + selectedUUID = elem?.zlsUUID } }