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

convert sdk code to kotlin, and fix edt errors #3631

Merged
merged 1 commit into from
Aug 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/org/elixir_lang/Elixir.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ object Elixir {
environment: Map<String, String>,
workingDirectory: String?,
elixirSdk: Sdk,
erlArgumentList: kotlin.collections.List<String> = emptyList()
erlArgumentList: kotlin.collections.List<String> = emptyList(),
): GeneralCommandLine {
val erlangSdk = elixirSdkToEnsuredErlangSdk(elixirSdk)
val commandLine = org.elixir_lang.Erl.commandLine(
pty = false,
environment = environment,
workingDirectory = workingDirectory,
erlangSdk = erlangSdk
)
val commandLine =
org.elixir_lang.Erl.commandLine(
pty = false,
environment = environment,
workingDirectory = workingDirectory,
erlangSdk = erlangSdk,
)
// MUST be before `addElixir` because it ends with `-extra` which turns off argument parsing for `erl`
commandLine.addParameters(erlArgumentList)
addElixir(commandLine, elixirSdk, erlangSdk)
Expand All @@ -35,13 +36,17 @@ object Elixir {
?: throw MissingErlangSdk(elixirSdk)

fun elixirSdkHasErlangSdk(elixirSdk: Sdk): Boolean = elixirSdkToErlangSdk(elixirSdk) != null
fun elixirSdkToErlangSdk(elixirSdk: Sdk): Sdk? =
elixirSdk.sdkAdditionalData?.let { it as SdkAdditionalData }?.erlangSdk

fun elixirSdkToErlangSdk(elixirSdk: Sdk): Sdk? = elixirSdk.sdkAdditionalData?.let { it as SdkAdditionalData }?.getErlangSdk()

/**
* Adds `-pa ebinDirectory` for those in the `elixirSdk` that aren't in the `erlangSdk`
*/
fun prependNewCodePaths(commandLine: GeneralCommandLine, elixirSdk: Sdk, erlangSdk: Sdk) {
fun prependNewCodePaths(
commandLine: GeneralCommandLine,
elixirSdk: Sdk,
erlangSdk: Sdk,
) {
val elixirEbinDirectories = elixirSdk.ebinDirectories()
val erlangEbinDirectories = erlangSdk.ebinDirectories()
prependNewCodePaths(commandLine, elixirEbinDirectories, erlangEbinDirectories)
Expand All @@ -50,7 +55,11 @@ object Elixir {
/**
* Keep in-suync with [org.elixir_lang.jps.Builder.addElixir]
*/
private fun addElixir(commandLine: GeneralCommandLine, elixirSdk: Sdk, erlangSdk: Sdk) {
private fun addElixir(
commandLine: GeneralCommandLine,
elixirSdk: Sdk,
erlangSdk: Sdk,
) {
prependNewCodePaths(commandLine, elixirSdk, erlangSdk)
commandLine.addParameters("-noshell", "-s", "elixir", "start_cli")
commandLine.addParameters("-elixir", "ansi_enabled", "true")
Expand All @@ -60,7 +69,7 @@ object Elixir {
private fun prependNewCodePaths(
commandLine: GeneralCommandLine,
elixirEbinDirectories: kotlin.collections.List<String>,
erlangEbinDirectories: kotlin.collections.List<String>
erlangEbinDirectories: kotlin.collections.List<String>,
) {
val newEbinDirectories = elixirEbinDirectories - erlangEbinDirectories
prependCodePaths(commandLine, newEbinDirectories)
Expand Down
2 changes: 1 addition & 1 deletion src/org/elixir_lang/facet/configurable/Provider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import com.intellij.openapi.options.ConfigurableProvider
import org.elixir_lang.sdk.ProcessOutput

class Provider(private val project: com.intellij.openapi.project.Project): ConfigurableProvider() {
override fun canCreateConfigurable(): Boolean = ProcessOutput.isSmallIde()
override fun canCreateConfigurable(): Boolean = ProcessOutput.isSmallIde
override fun createConfigurable(): Configurable = Project(project)
}
2 changes: 1 addition & 1 deletion src/org/elixir_lang/facet/sdks/Provider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.intellij.openapi.options.ConfigurableProvider
import org.elixir_lang.sdk.ProcessOutput

abstract class Provider : ConfigurableProvider() {
override fun canCreateConfigurable(): Boolean = ProcessOutput.isSmallIde()
override fun canCreateConfigurable(): Boolean = ProcessOutput.isSmallIde
}
110 changes: 60 additions & 50 deletions src/org/elixir_lang/notification/setup_sdk/Provider.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.elixir_lang.notification.setup_sdk

import com.intellij.ide.actions.ShowSettingsUtilImpl
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleType
Expand All @@ -14,53 +15,63 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager
import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotificationProvider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.elixir_lang.ElixirFileType
import org.elixir_lang.ElixirLanguage
import org.elixir_lang.sdk.ProcessOutput
import org.elixir_lang.sdk.elixir.Type
import java.util.function.Function
import javax.swing.JComponent

/**
* https://github.com/ignatov/intellij-erlang/blob/master/src/org/intellij/erlang/inspection/SetupSDKNotificationProvider.java
*/
class Provider : EditorNotificationProvider {
override fun collectNotificationData(
project: Project,
file: VirtualFile
file: VirtualFile,
): Function<in FileEditor, out JComponent?> =
Function<FileEditor, JComponent?> { createNotificationPanel(file, project) }
Function { fileEditor ->
kotlinx.coroutines.runBlocking {
createNotificationPanel(file, project)
}
}

private fun createNotificationPanel(
private suspend fun createNotificationPanel(
virtualFile: VirtualFile,
project: Project
project: Project,
): EditorNotificationPanel? =
if (virtualFile.fileType is ElixirFileType) {
PsiManager
.getInstance(project)
.findFile(virtualFile)
?.let { psiFile ->
if (psiFile.language === ElixirLanguage &&
Type.mostSpecificSdk(psiFile) == null
) {
createPanel(project, psiFile)
} else {
null
}
withContext(Dispatchers.Default) {
ReadAction.compute<EditorNotificationPanel?, Throwable> {
if (virtualFile.fileType is ElixirFileType) {
PsiManager
.getInstance(project)
.findFile(virtualFile)
?.let { psiFile ->
if (psiFile.language === ElixirLanguage &&
Type.mostSpecificSdk(psiFile) == null
) {
createPanel(project, psiFile)
} else {
null
}
}
} else {
null
}
} else {
null
}
}

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

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

Expand All @@ -78,63 +89,62 @@ class Provider : EditorNotificationProvider {
ShowSettingsUtilImpl.showSettingsDialog(project, "language", "Elixir")
}

private fun createSmallIDEFacetPanel(project: Project): EditorNotificationPanel {
return EditorNotificationPanel().apply {
private fun createSmallIDEFacetPanel(project: Project): EditorNotificationPanel =
EditorNotificationPanel().apply {
text = "Elixir Facet SDK is not defined"
@Suppress("DialogTitleCapitalization")
createActionLabel("Setup Elixir Facet SDK") {
showSmallIDEFacetSettings(project)
}
}
}

private fun createFacetPanel(project: Project): EditorNotificationPanel? {
return if (ProcessOutput.isSmallIde()) {
private fun createFacetPanel(project: Project): EditorNotificationPanel? =
if (ProcessOutput.isSmallIde) {
createSmallIDEFacetPanel(project)
} else {
// TODO Elixir Facet in non-Elixir module in IntelliJ
null
}
}

private fun createModulePanel(project: Project, module: Module): EditorNotificationPanel {
return EditorNotificationPanel().apply {
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? {
private fun createPanel(
project: Project,
psiFile: PsiFile,
): EditorNotificationPanel? {
val module = ModuleUtilCore.findModuleForPsiElement(psiFile)

return if (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)
}
} else {
if (ProcessOutput.isSmallIde()) {
createSmallIDEFacetPanel(project)
} else {
createProjectPanel(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)
} else {
createFacetPanel(project)
}
}
ProcessOutput.isSmallIde -> createSmallIDEFacetPanel(project)
else -> createProjectPanel(project)
}
}

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

}
}
}
102 changes: 0 additions & 102 deletions src/org/elixir_lang/sdk/ProcessOutput.java

This file was deleted.

Loading
Loading