Skip to content

Commit

Permalink
Revert "Fix reset version and code reformat of SDK (KronicDeth#3632)"
Browse files Browse the repository at this point in the history
This reverts commit c7146e6.
  • Loading branch information
joshuataylor committed Aug 20, 2024
1 parent c7146e6 commit 7161299
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 179 deletions.
2 changes: 2 additions & 0 deletions src/org/elixir_lang/notification/setup_sdk/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleType
import com.intellij.openapi.project.Project
import org.elixir_lang.notification.setup_sdk.Provider.Companion.showFacetSettings
import org.elixir_lang.notification.setup_sdk.Provider.Companion.showModuleSettings

/**
* Created by zyuyou on 15/7/8.
Expand Down
152 changes: 77 additions & 75 deletions src/org/elixir_lang/notification/setup_sdk/Provider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Provider : EditorNotificationProvider {
project: Project,
file: VirtualFile,
): Function<in FileEditor, out JComponent?> =
Function {
Function { fileEditor ->
kotlinx.coroutines.runBlocking {
createNotificationPanel(file, project)
}
Expand Down Expand Up @@ -60,89 +60,91 @@ class Provider : EditorNotificationProvider {
}
}

}

fun showFacetSettings(project: Project) {
if (ProcessOutput.isSmallIde) {
showSmallIDEFacetSettings(project)
}
// TODO Elixir Facet in non-Elixir module in IntelliJ
}

fun showModuleSettings(
project: Project,
module: Module,
) {
ProjectSettingsService.getInstance(project).openModuleSettings(module)
}

private fun showProjectSettings(project: Project) {
SdkPopupFactory.newBuilder()
.withProject(project)
.withSdkType(Type.instance)
.updateProjectSdkFromSelection()
.buildPopup()
.showInFocusCenter()
}

private fun showSmallIDEFacetSettings(project: Project) {
ShowSettingsUtilImpl.showSettingsDialog(project, "language", "Elixir")
}
companion object {
fun showFacetSettings(project: Project) {
if (ProcessOutput.isSmallIde) {
showSmallIDEFacetSettings(project)
}
// TODO Elixir Facet in non-Elixir module in IntelliJ
}

private fun createSmallIDEFacetPanel(project: Project): EditorNotificationPanel =
EditorNotificationPanel().apply {
text = "Elixir Facet SDK is not defined"
@Suppress("DialogTitleCapitalization")
createActionLabel("Setup Elixir Facet SDK") {
showSmallIDEFacetSettings(project)
fun showModuleSettings(
project: Project,
module: Module,
) {
ProjectSettingsService.getInstance(project).openModuleSettings(module)
}
}

private fun createFacetPanel(project: Project): EditorNotificationPanel? =
if (ProcessOutput.isSmallIde) {
createSmallIDEFacetPanel(project)
} else {
// TODO Elixir Facet in non-Elixir module in IntelliJ
null
}
private fun showProjectSettings(project: Project) {
SdkPopupFactory
.newBuilder()
.withProject(project)
.withSdkType(Type.instance)
.updateProjectSdkFromSelection()
.buildPopup()
.showInFocusCenter()
}

private fun createModulePanel(
project: Project,
module: Module,
): EditorNotificationPanel =
EditorNotificationPanel().apply {
text = "Elixir Module SDK is not defined"
@Suppress("DialogTitleCapitalization")
createActionLabel("Setup Elixir Module SDK") {
showModuleSettings(project, module)
private fun showSmallIDEFacetSettings(project: Project) {
ShowSettingsUtilImpl.showSettingsDialog(project, "language", "Elixir")
}
}

private fun createPanel(
project: Project,
psiFile: PsiFile,
): EditorNotificationPanel? {
val module = ModuleUtilCore.findModuleForPsiElement(psiFile)
private fun createSmallIDEFacetPanel(project: Project): EditorNotificationPanel =
EditorNotificationPanel().apply {
text = "Elixir Facet SDK is not defined"
@Suppress("DialogTitleCapitalization")
createActionLabel("Setup Elixir Facet SDK") {
showSmallIDEFacetSettings(project)
}
}

return when {
module != null -> {
// CANNOT use ModuleType.is(module, ElixirModuleType.getInstance()) as ElixirModuleType depends on
// JavaModuleBuilder and so only available in IntelliJ
if (ModuleType.get(module).id == "ELIXIR_MODULE") {
createModulePanel(project, module)
private fun createFacetPanel(project: Project): EditorNotificationPanel? =
if (ProcessOutput.isSmallIde) {
createSmallIDEFacetPanel(project)
} else {
createFacetPanel(project)
// TODO Elixir Facet in non-Elixir module in IntelliJ
null
}

private fun createModulePanel(
project: Project,
module: Module,
): EditorNotificationPanel =
EditorNotificationPanel().apply {
text = "Elixir Module SDK is not defined"
@Suppress("DialogTitleCapitalization")
createActionLabel("Setup Elixir Module SDK") {
showModuleSettings(project, module)
}
}

private fun createPanel(
project: Project,
psiFile: PsiFile,
): EditorNotificationPanel? {
val module = ModuleUtilCore.findModuleForPsiElement(psiFile)

return when {
module != null -> {
// CANNOT use ModuleType.is(module, ElixirModuleType.getInstance()) as ElixirModuleType depends on
// JavaModuleBuilder and so only available in IntelliJ
if (ModuleType.get(module).id == "ELIXIR_MODULE") {
createModulePanel(project, module)
} else {
createFacetPanel(project)
}
}
ProcessOutput.isSmallIde -> createSmallIDEFacetPanel(project)
else -> createProjectPanel(project)
}
}
ProcessOutput.isSmallIde -> createSmallIDEFacetPanel(project)
else -> createProjectPanel(project)

private fun createProjectPanel(project: Project): EditorNotificationPanel =
EditorNotificationPanel().apply {
text = "Project SDK is not defined"
createActionLabel(ProjectBundle.message("project.sdk.setup")) {
showProjectSettings(project)
}
}
}
}

private fun createProjectPanel(project: Project): EditorNotificationPanel =
EditorNotificationPanel().apply {
text = "Project SDK is not defined"
createActionLabel(ProjectBundle.message("project.sdk.setup")) {
showProjectSettings(project)
}
}
6 changes: 2 additions & 4 deletions src/org/elixir_lang/sdk/elixir/Release.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ class Release private constructor(
) : Comparable<Release> {

companion object {
@JvmField
val V_1_0_4 = Release("1", "0", "4", null, null)
@JvmField
val LATEST = Release("1", "6", "0", "dev", null)
@JvmField val V_1_0_4 = Release("1", "0", "4", null, null)
@JvmField val LATEST = Release("1", "6", "0", "dev", null)

private val VERSION_PATTERN = Pattern.compile(
"(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(?:\\-([\\d\\w\\.\\-]+))?(?:\\+([\\d\\w\\-]+))?"
Expand Down
30 changes: 12 additions & 18 deletions src/org/elixir_lang/sdk/elixir/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.util.*
import javax.swing.Icon
import kotlin.Comparator
import kotlin.collections.ArrayList

class Type : org.elixir_lang.sdk.erlang_dependent.Type(SerializerExtension.ELIXIR_SDK_TYPE_ID) {
/**
Expand Down Expand Up @@ -99,8 +101,7 @@ class Type : org.elixir_lang.sdk.erlang_dependent.Type(SerializerExtension.ELIXI

override fun getPresentableName(): String = "Elixir SDK"

override fun getVersionString(sdkHome: String): String =
Release.fromString(File(sdkHome).name)?.version() ?: "Unknown"
override fun getVersionString(sdkHome: String): String = Release.fromString(File(sdkHome).name)?.version() ?: "Unknown"

/**
* Map of home paths to versions in descending version order so that newer versions are favored.
Expand Down Expand Up @@ -147,8 +148,7 @@ class Type : org.elixir_lang.sdk.erlang_dependent.Type(SerializerExtension.ELIXI
return homePathByVersion
}

private fun invalidSdkHomeException(virtualFile: VirtualFile): Exception =
Exception(invalidSdkHomeMessage(virtualFile))
private fun invalidSdkHomeException(virtualFile: VirtualFile): Exception = Exception(invalidSdkHomeMessage(virtualFile))

private fun invalidSdkHomeMessage(virtualFile: VirtualFile): String =
if (virtualFile.isDirectory) {
Expand Down Expand Up @@ -178,10 +178,10 @@ ELIXIR_SDK_HOME
val iex = Elixir.getIExExecutable(path)
val mix = Elixir.mixFile(path)
return elixir.canExecute() &&
elixirc.canExecute() &&
iex.canExecute() &&
mix.canRead() &&
HomePath.hasEbinPath(path)
elixirc.canExecute() &&
iex.canExecute() &&
mix.canRead() &&
HomePath.hasEbinPath(path)
}

override fun setupSdkPaths(sdk: Sdk) {
Expand Down Expand Up @@ -218,8 +218,7 @@ ELIXIR_SDK_HOME
override fun createAdditionalDataConfigurable(
sdkModel: SdkModel,
sdkModificator: SdkModificator,
): com.intellij.openapi.projectRoots.AdditionalDataConfigurable =
AdditionalDataConfigurable(sdkModel, sdkModificator)
): com.intellij.openapi.projectRoots.AdditionalDataConfigurable = AdditionalDataConfigurable(sdkModel, sdkModificator)

override fun saveAdditionalData(
additionalData: com.intellij.openapi.projectRoots.SdkAdditionalData,
Expand Down Expand Up @@ -396,12 +395,7 @@ ELIXIR_SDK_HOME
val configuredRoots = elixirSdkModificator.getRoots(type)
for (internalRoot in internalRoots) {
for (expandedInternalRoot in expandInternalErlangSdkRoot(internalRoot, type)) {
sdkModificatorRootTypeConsumer(
elixirSdkModificator,
configuredRoots,
expandedInternalRoot,
type
)
sdkModificatorRootTypeConsumer(elixirSdkModificator, configuredRoots, expandedInternalRoot, type)
}
}
}
Expand Down Expand Up @@ -498,8 +492,8 @@ ELIXIR_SDK_HOME
@JvmStatic
fun erlangSdkType(): SdkType =
if (ProcessOutput.isSmallIde) {
/* intellij-erlang's "Erlang SDK" does not work in small IDEs because it uses JavadocRoot for documentation,
which isn't available in Small IDEs. */
/* intellij-erlang's "Erlang SDK" does not work in small IDEs because it uses JavadocRoot for documentation,
which isn't available in Small IDEs. */
null
} else {
EP_NAME.extensionList.find { sdkType -> sdkType.name == "Erlang SDK" }
Expand Down
20 changes: 9 additions & 11 deletions src/org/elixir_lang/sdk/erlang/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class Type : SdkType("Erlang SDK for Elixir SDK") {
private const val ERTS_VERSION_PREFIX_LINE = "org.elixir_lang.sdk.erlang.Type ERTS_VERSION:"
private const val PRINT_VERSION_INFO_EXPRESSION =
"io:format(\"~n~s~n~s~n~s~n~s~n\",[" +
"\"$OTP_RELEASE_PREFIX_LINE\"," +
"erlang:system_info(otp_release)," +
"\"$ERTS_VERSION_PREFIX_LINE\"," +
"erlang:system_info(version)" +
"]),erlang:halt()."
"\"$OTP_RELEASE_PREFIX_LINE\"," +
"erlang:system_info(otp_release)," +
"\"$ERTS_VERSION_PREFIX_LINE\"," +
"erlang:system_info(version)" +
"]),erlang:halt()."
private const val WINDOWS_DEFAULT_HOME_PATH = "C:\\Program Files\\erl9.0"
private val NIX_PATTERN = HomePath.nixPattern("erlang")
private const val LINUX_MINT_HOME_PATH = "${HomePath.LINUX_MINT_HOME_PATH}/erlang"
Expand Down Expand Up @@ -78,11 +78,9 @@ class Type : SdkType("Erlang SDK for Elixir SDK") {
HomePath.mergeHomebrew(homePathByVersion, "erlang", VERSION_PATH_TO_HOME_PATH)
HomePath.mergeNixStore(homePathByVersion, NIX_PATTERN, VERSION_PATH_TO_HOME_PATH)
}

SystemInfo.isWindows -> {
putIfDirectory(homePathByVersion, HomePath.UNKNOWN_VERSION, WINDOWS_DEFAULT_HOME_PATH)
}

SystemInfo.isLinux -> {
putIfDirectory(homePathByVersion, HomePath.UNKNOWN_VERSION, LINUX_DEFAULT_HOME_PATH)
putIfDirectory(homePathByVersion, HomePath.UNKNOWN_VERSION, LINUX_MINT_HOME_PATH)
Expand All @@ -108,10 +106,10 @@ class Type : SdkType("Erlang SDK for Elixir SDK") {

override fun isRootTypeApplicable(type: OrderRootType): Boolean =
type == OrderRootType.CLASSES ||
type == OrderRootType.SOURCES ||
type ==
org.elixir_lang.sdk.Type
.documentationRootType()
type == OrderRootType.SOURCES ||
type ==
org.elixir_lang.sdk.Type
.documentationRootType()

override fun setupSdkPaths(sdk: Sdk) {
val sdkModificator = sdk.sdkModificator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.openapi.projectRoots.AdditionalDataConfigurable
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.projectRoots.SdkModel
import com.intellij.openapi.projectRoots.SdkModificator
import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.util.Comparing
import com.intellij.ui.SimpleListCellRenderer
Expand Down Expand Up @@ -189,11 +190,7 @@ class AdditionalDataConfigurable(
)
sdkModificator.sdkAdditionalData = sdkAdditionData
ApplicationManager.getApplication().runWriteAction { sdkModificator.commitChanges() }

// reset the version string to force the sdk to be reloaded
// @todo is this necessary?
this.sdkModificator.versionString = null
this.sdkModificator.commitChanges()
(elixirSdk as ProjectJdkImpl).resetVersionString()
}

override fun reset() {
Expand Down
Loading

0 comments on commit 7161299

Please sign in to comment.