Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CARGO: support IDEs without Build Tools settings #9097

Merged
merged 1 commit into from Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/221/main/resources/META-INF/platform-rust-core.xml
@@ -1,7 +1,2 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<projectConfigurable instance="org.rust.cargo.project.configurable.CargoConfigurable"
parentId="language.rust"
id="language.rust.cargo"/>
</extensions>
</idea-plugin>

This file was deleted.

8 changes: 0 additions & 8 deletions src/222/main/resources/META-INF/platform-rust-core.xml
Expand Up @@ -3,14 +3,6 @@
<externalIconProvider key="Cargo"
implementationClass="org.rust.cargo.project.model.impl.CargoExternalSystemIconProvider"/>

<projectConfigurable instance="org.rust.cargo.project.configurable.CargoConfigurable"
parentId="build.tools"
id="language.rust.cargo"/>

<projectConfigurable instance="org.rust.cargo.project.configurable.CargoPlaceholderConfigurable"
parentId="language.rust"
id="language.rust.cargoPlaceholder"/>

<registryKey key="org.rust.cargo.new.auto.import"
defaultValue="true"
description="Enable new Cargo project model reloading"
Expand Down
@@ -0,0 +1,26 @@
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/

package org.rust.cargo.project.configurable

import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.ConfigurableProvider
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.BuildNumber

class CargoBuildToolConfigurableProvider(private val project: Project) : ConfigurableProvider() {

override fun canCreateConfigurable(): Boolean {
return ApplicationInfo.getInstance().build >= BUILD_222 && CargoConfigurable.buildToolsConfigurableExists(project)
}

override fun createConfigurable(): Configurable = CargoConfigurable(project, isPlaceholder = false)

companion object {
// BACKCOMPAT: 2022.1
private val BUILD_222: BuildNumber = BuildNumber.fromString("222")!!
}
}
Expand Up @@ -5,15 +5,42 @@

package org.rust.cargo.project.configurable

import com.intellij.ide.DataManager
import com.intellij.openapi.externalSystem.service.settings.ExternalSystemGroupConfigurable
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.ex.Settings
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.dsl.builder.BottomGap
import com.intellij.ui.dsl.builder.bindSelected
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
import org.rust.RsBundle
import org.rust.cargo.project.model.isNewProjectModelImportEnabled
import java.awt.Component

class CargoConfigurable(
project: Project,
private val isPlaceholder: Boolean
) : RsConfigurableBase(project, RsBundle.message("settings.rust.cargo.name")) {

override fun createPanel(): DialogPanel {
return if (isPlaceholder) createPlaceholderPanel() else createSettingsPanel()
}

private fun createSettingsPanel(): DialogPanel = panel {
// Rider doesn't provide `Build, Execution, Deployment | Build Tools` settings panel at all.
// Let's add the corresponding settings manually as a temporary workaround
if (isNewProjectModelImportEnabled && !buildToolsConfigurableExists(project)) {
val panel = ExternalSystemGroupConfigurable(project).createPanel()
row {
cell(panel)
.onApply { panel.apply() }
.onIsModified { panel.isModified() }
.onReset { panel.reset() }
}.bottomGap(BottomGap.MEDIUM)
}

class CargoConfigurable(project: Project) : RsConfigurableBase(project, RsBundle.message("settings.rust.cargo.name")) {
override fun createPanel(): DialogPanel = panel {
row {
checkBox(RsBundle.message("settings.rust.cargo.show.first.error.label"))
.bindSelected(state::autoShowErrorsInEditor)
Expand All @@ -32,9 +59,41 @@ class CargoConfigurable(project: Project) : RsConfigurableBase(project, RsBundle
.bindSelected(state::compileAllTargets)
}
row {
checkBox(RsBundle.message("settings.rust.cargo.offline.mode.label"),)
checkBox(RsBundle.message("settings.rust.cargo.offline.mode.label"))
.comment(RsBundle.message("settings.rust.cargo.offline.mode.comment"))
.bindSelected(state::useOffline)
}
}

private fun createPlaceholderPanel(): DialogPanel {
var callback = { }

val panel = panel {
row {
link(RsBundle.message("settings.rust.cargo.moved.label")) { callback() }
.resizableColumn()
.horizontalAlign(HorizontalAlign.CENTER)
}.resizableRow()
}

callback = { openCargoSettings(panel) }

return panel
}

private fun openCargoSettings(component: Component) {
val dataContext = DataManager.getInstance().getDataContext(component)
val settings = Settings.KEY.getData(dataContext)
if (settings != null) {
val configurable = settings.find("language.rust.build.tool.cargo")
settings.select(configurable)
}
}

companion object {
fun buildToolsConfigurableExists(project: Project): Boolean {
val buildToolsConfigurable = Configurable.PROJECT_CONFIGURABLE.findFirstSafe(project) { it.id == "build.tools" }
return buildToolsConfigurable != null
}
}
}
@@ -0,0 +1,25 @@
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/

package org.rust.cargo.project.configurable

import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.ConfigurableProvider
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.BuildNumber

class CargoProjectConfigurableProvider(private val project: Project) : ConfigurableProvider() {

override fun createConfigurable(): Configurable {
val isPlaceholder = ApplicationInfo.getInstance().build >= BUILD_222 && CargoConfigurable.buildToolsConfigurableExists(project)
return CargoConfigurable(project, isPlaceholder)
}

companion object {
// BACKCOMPAT: 2022.1
private val BUILD_222: BuildNumber = BuildNumber.fromString("222")!!
}
}
8 changes: 8 additions & 0 deletions src/main/resources/META-INF/rust-core.xml
Expand Up @@ -1025,6 +1025,14 @@
groupId="language"
id="language.rust"/>

<projectConfigurable provider="org.rust.cargo.project.configurable.CargoBuildToolConfigurableProvider"
parentId="build.tools"
id="language.rust.build.tool.cargo"/>

<projectConfigurable provider="org.rust.cargo.project.configurable.CargoProjectConfigurableProvider"
parentId="language.rust"
id="language.rust.cargo"/>

<projectConfigurable instance="org.rust.cargo.project.configurable.RsExternalLinterConfigurable"
parentId="language.rust"
id="language.rust.cargo.check"/>
Expand Down