Skip to content

Commit

Permalink
Merge #9097
Browse files Browse the repository at this point in the history
9097: CARGO: support IDEs without `Build Tools` settings r=mchernyavsky a=Undin

Rider doesn't provide `Build | Build Tools` settings. As a result, `Cargo` settings cannot be added as a child of `Build Tools` and the platform adds it to as a root setting panel

The main idea is to keep `Cargo` settings under `Languages & Frameworks | Rust` if `Build | Build Tools` doesn't exist, and add `Build Tools` panel to `Cargo` settings.

<img width="1094" alt="Screen Shot 2022-07-21 at 00 22 33" src="https://user-images.githubusercontent.com/2539310/180084602-e23cf2c6-eb36-42c1-bdd2-7eae88aadc36.png">


To achieve it, `CargoBuildToolConfigurableProvider` and `CargoProjectConfigurableProvider` were introduced since they provide more flexible way to manage when `CargoConfigurable` should be shown and how

Fixes #9077

changelog: Properly add `Cargo` settings in Rider 2022.2


Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
  • Loading branch information
bors[bot] and Undin committed Aug 1, 2022
2 parents e3d24d5 + 33efd70 commit ae11aa6
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 60 deletions.
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

0 comments on commit ae11aa6

Please sign in to comment.