Skip to content

Commit 537e889

Browse files
committed
feat: allow user to configure node interpreter
This adds configuration for the `<node-interpreter value="project" />` workspace element fixes #241
1 parent a3a9b38 commit 537e889

16 files changed

+162
-50
lines changed

src/main/kotlin/com/emberjs/cli/EmberCli.kt

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.emberjs.cli
22

33
import com.intellij.execution.configurations.GeneralCommandLine
4+
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterRef
45
import com.intellij.openapi.project.Project
56
import org.apache.commons.lang.SystemUtils
67
import java.io.BufferedReader
@@ -9,18 +10,37 @@ import java.util.concurrent.TimeUnit
910
class EmberCli(val project: Project, vararg val parameters: String) {
1011

1112
var workDirectory: String? = null
13+
var nodeInterpreter: String? = null
1214

13-
fun commandLine(): GeneralCommandLine {
15+
private fun nodeCommandLine(): GeneralCommandLine {
16+
val interpreterRef = NodeJsInterpreterRef.create(nodeInterpreter)
17+
val interpreter = interpreterRef.resolve(project)
18+
19+
return GeneralCommandLine(interpreter?.referenceName).also {
20+
it.addParameter("$workDirectory/node_modules/.bin/ember")
21+
}
22+
}
23+
24+
private fun emberBinCommandLine(): GeneralCommandLine {
1425
val suffix = when {
1526
SystemUtils.IS_OS_WINDOWS -> ".cmd"
1627
else -> ""
1728
}
1829

19-
val emberBin = "$workDirectory/node_modules/.bin/ember$suffix"
20-
val workDir = workDirectory
21-
return GeneralCommandLine(emberBin).apply {
22-
addParameters(*parameters)
23-
withWorkDirectory(workDir)
30+
val command = "$workDirectory/node_modules/.bin/ember$suffix"
31+
32+
return GeneralCommandLine(command)
33+
}
34+
35+
fun commandLine(): GeneralCommandLine {
36+
val commandLine = when (nodeInterpreter) {
37+
is String -> nodeCommandLine()
38+
else -> emberBinCommandLine()
39+
}
40+
41+
return commandLine.also {
42+
it.addParameters(*parameters)
43+
it.withWorkDirectory(workDirectory)
2444
}
2545
}
2646

src/main/kotlin/com/emberjs/configuration/BooleanOptionsField.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class BooleanOptionsField(
1414
override fun writeTo(component: Any) {
1515
when (component) {
1616
is JCheckBox -> component.isSelected = value
17-
is Element -> ElementUtils.writeBool(component, this.field, this.value)
17+
is Element -> ElementUtils.writeBool(component, value = this.value, name = this.field)
1818
}
1919
}
2020

2121
override fun readFrom(component: Any) {
2222
when (component) {
2323
is JCheckBox -> value = component.isSelected
24-
is Element -> this.value = ElementUtils.readBool(component, this.field) ?: this.default
24+
is Element -> this.value = ElementUtils.readBool(component, name = this.field) ?: this.default
2525
}
2626
}
2727
}

src/main/kotlin/com/emberjs/configuration/EmberCommandLineState.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ open class EmberCommandLineState(environment: ExecutionEnvironment) : CommandLin
2222
environment.project.basePath
2323

2424
val cmd = EmberCli(environment.project, configuration.command, *argList)
25-
.apply { workDirectory = workingDirectory }
25+
.apply {
26+
workDirectory = workingDirectory
27+
nodeInterpreter = configuration.nodeInterpreter
28+
}
2629
.commandLine()
2730
.apply {
2831
// taken from intellij-rust

src/main/kotlin/com/emberjs/configuration/EmberConfiguration.kt

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ interface EmberConfiguration {
66
val command: String
77
val options: EmberOptions
88
var module: Module?
9+
var nodeInterpreter: String?
910
}

src/main/kotlin/com/emberjs/configuration/EmberConfigurationBase.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ abstract class EmberConfigurationBase(project: Project, factory: ConfigurationFa
1212
RunConfigurationBase<Any>(project, factory, name),
1313
EmberConfiguration {
1414
override var module: Module? = null
15+
override var nodeInterpreter: String? = null
1516

1617
override fun writeExternal(element: Element) {
1718
super.writeExternal(element)
@@ -21,8 +22,13 @@ abstract class EmberConfigurationBase(project: Project, factory: ConfigurationFa
2122

2223
val moduleName = module?.name
2324
when (moduleName) {
24-
is String -> ElementUtils.writeString(element, "NAME", moduleName, "module")
25-
else -> ElementUtils.removeField(element, "NAME", "module")
25+
is String -> ElementUtils.writeString(element, "module", moduleName, "NAME")
26+
else -> ElementUtils.removeField(element, "module", "NAME")
27+
}
28+
29+
when (nodeInterpreter) {
30+
is String -> ElementUtils.writeString(element, "node-interpreter", nodeInterpreter!!)
31+
else -> ElementUtils.removeField(element, "node-interpreter")
2632
}
2733
}
2834

@@ -32,9 +38,12 @@ abstract class EmberConfigurationBase(project: Project, factory: ConfigurationFa
3238
options.fields().forEach { optionsField -> optionsField.readFrom(element) }
3339
}
3440

35-
ElementUtils.readString(element, "NAME", "module")?.let { moduleString ->
41+
ElementUtils.readString(element, "module", "NAME")?.let { moduleString ->
3642
module = ModuleManager.getInstance(project).modules.find { it.name == moduleString }
3743
}
44+
ElementUtils.readString(element, "node-interpreter")?.let { elementNodeInterpreter ->
45+
nodeInterpreter = elementNodeInterpreter
46+
}
3847
}
3948

4049
}

src/main/kotlin/com/emberjs/configuration/OptionsField.kt

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.emberjs.configuration
22

3-
import org.jdom.Element
4-
import javax.swing.JComponent
5-
63
abstract class OptionsField<T>(
74
val default: T,
85
val field: String,

src/main/kotlin/com/emberjs/configuration/StringOptionsField.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class StringOptionsField(
1717

1818
override fun writeTo(component: Any) {
1919
when (component) {
20-
is Element -> ElementUtils.writeString(component, this.field, this.value)
20+
is Element -> ElementUtils.writeString(component, value = this.value, name = this.field)
2121
is EditorTextField -> component.apply {
2222
text = value
2323
setPlaceholder(default)
@@ -37,7 +37,7 @@ class StringOptionsField(
3737

3838
override fun readFrom(component: Any) {
3939
when (component) {
40-
is Element -> value = ElementUtils.readString(component, this.field) ?: this.default
40+
is Element -> value = ElementUtils.readString(component, name = this.field) ?: this.default
4141
is EditorTextField -> value = component.text
4242
is JComboBox<*> -> value = component.selectedItem.toString()
4343
is PublicStringAddEditDeleteListPanel -> value = component.listItems.joinToString(",")

src/main/kotlin/com/emberjs/configuration/serve/EmberServeConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class EmberServeConfiguration(project: Project, factory: ConfigurationFactory, n
2121

2222
@NotNull
2323
override fun getConfigurationEditor(): SettingsEditor<out RunConfiguration> {
24-
return EmberServeSettingsEditor()
24+
return EmberServeSettingsEditor(project)
2525
}
2626

2727
@Nullable

src/main/kotlin/com/emberjs/configuration/serve/ui/EmberServeSettingsEditor.form

+20-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="659" height="493"/>
6+
<xy x="20" y="20" width="659" height="463"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -325,7 +325,7 @@
325325
</component>
326326
</children>
327327
</grid>
328-
<grid id="12771" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
328+
<grid id="12771" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
329329
<margin top="0" left="0" bottom="0" right="0"/>
330330
<constraints>
331331
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -343,12 +343,27 @@
343343
</component>
344344
<component id="e1099" class="com.intellij.application.options.ModulesComboBox" binding="myModulesComboBox">
345345
<constraints>
346-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
347-
<preferred-size width="59" height="30"/>
348-
</grid>
346+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
349347
</constraints>
350348
<properties/>
351349
</component>
350+
<component id="519e" class="javax.swing.JLabel">
351+
<constraints>
352+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
353+
</constraints>
354+
<properties>
355+
<text resource-bundle="com/emberjs/locale/EmberServeConfigurationEditor" key="node.interpreter"/>
356+
</properties>
357+
</component>
358+
<grid id="4ad5a" binding="myNodeSettingsPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
359+
<margin top="0" left="0" bottom="0" right="0"/>
360+
<constraints>
361+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
362+
</constraints>
363+
<properties/>
364+
<border type="none"/>
365+
<children/>
366+
</grid>
352367
</children>
353368
</grid>
354369
</children>

src/main/kotlin/com/emberjs/configuration/serve/ui/EmberServeSettingsEditor.kt

+21-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import com.emberjs.configuration.serve.EmberServeConfiguration
44
import com.emberjs.configuration.serve.EmberServeOptions
55
import com.emberjs.project.EmberModuleType
66
import com.intellij.application.options.ModulesComboBox
7+
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterField
8+
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterRef
79
import com.intellij.openapi.options.SettingsEditor
10+
import com.intellij.openapi.project.Project
811
import com.intellij.ui.CollectionComboBoxModel
912
import com.intellij.ui.EditorTextField
1013
import com.intellij.ui.HideableDecorator
1114
import com.intellij.ui.IdeBorderFactory
1215
import org.jetbrains.annotations.NotNull
1316
import java.util.*
14-
import javax.swing.JCheckBox
15-
import javax.swing.JComboBox
16-
import javax.swing.JComponent
17-
import javax.swing.JPanel
17+
import javax.swing.*
1818

19-
class EmberServeSettingsEditor : SettingsEditor<EmberServeConfiguration>() {
19+
class EmberServeSettingsEditor(
20+
val project: Project
21+
) : SettingsEditor<EmberServeConfiguration>() {
2022
private var myPanel: JPanel? = null
2123
private var advancedSettings: JPanel? = null
2224
private var advancedSettingsWrapper: JPanel? = null
@@ -43,6 +45,8 @@ class EmberServeSettingsEditor : SettingsEditor<EmberServeConfiguration>() {
4345
private var sslCheckBox: JCheckBox? = null
4446

4547
private var myModulesComboBox: ModulesComboBox? = null
48+
private var myNodeSettingsPanel: JPanel? = null
49+
private var myNodeInterpreterField: NodeJsInterpreterField? = null
4650

4751
private val bundle: ResourceBundle = ResourceBundle.getBundle("com.emberjs.locale.EmberServeConfigurationEditor")
4852

@@ -79,13 +83,19 @@ class EmberServeSettingsEditor : SettingsEditor<EmberServeConfiguration>() {
7983
null -> myModulesComboBox?.selectedModule = myModulesComboBox?.model?.getElementAt(0)
8084
else -> myModulesComboBox?.selectedModule = module
8185
}
86+
87+
myNodeInterpreterField?.interpreterRef = when (configuration.nodeInterpreter) {
88+
is String -> NodeJsInterpreterRef.create(configuration.nodeInterpreter)
89+
else -> NodeJsInterpreterRef.createProjectRef()
90+
}
8291
}
8392

8493
override fun applyEditorTo(configuration: EmberServeConfiguration) {
8594
mappings.forEach { (first, second) ->
8695
first?.let { second.get(configuration.options).readFrom(it) }
8796
}
8897
configuration.module = myModulesComboBox?.selectedModule
98+
configuration.nodeInterpreter = myNodeInterpreterField?.interpreterRef?.referenceName
8999
}
90100

91101
@NotNull
@@ -98,6 +108,12 @@ class EmberServeSettingsEditor : SettingsEditor<EmberServeConfiguration>() {
98108
setOn(false)
99109
}
100110

111+
// Add interpreter field to editor
112+
myNodeInterpreterField = NodeJsInterpreterField(project, false)
113+
.apply { interpreterRef = NodeJsInterpreterRef.createProjectRef() }
114+
myNodeSettingsPanel?.layout = BoxLayout(myNodeSettingsPanel, BoxLayout.PAGE_AXIS)
115+
myNodeSettingsPanel?.add(myNodeInterpreterField)
116+
101117
val comboBoxModel = CollectionComboBoxModel<String>().apply {
102118
add("development")
103119
add("production")

src/main/kotlin/com/emberjs/configuration/test/EmberTestConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class EmberTestConfiguration(project: Project, factory: ConfigurationFactory, na
1717

1818
@NotNull
1919
override fun getConfigurationEditor(): SettingsEditor<out RunConfiguration> {
20-
return EmberTestSettingsEditor()
20+
return EmberTestSettingsEditor(project)
2121
}
2222

2323
@Nullable

src/main/kotlin/com/emberjs/configuration/test/ui/EmberTestSettingsEditor.form

+18-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="560" height="688"/>
6+
<xy x="20" y="20" width="560" height="641"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -327,7 +327,7 @@
327327
</grid>
328328
</children>
329329
</grid>
330-
<grid id="74127" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
330+
<grid id="74127" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
331331
<margin top="0" left="0" bottom="0" right="0"/>
332332
<constraints>
333333
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
@@ -345,15 +345,27 @@
345345
</component>
346346
<component id="e1100" class="com.intellij.application.options.ModulesComboBox" binding="myModulesComboBox">
347347
<constraints>
348-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
348+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
349349
</constraints>
350350
<properties/>
351351
</component>
352-
<hspacer id="d6cb0">
352+
<component id="ebaf7" class="javax.swing.JLabel">
353353
<constraints>
354-
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
354+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
355355
</constraints>
356-
</hspacer>
356+
<properties>
357+
<text resource-bundle="com/emberjs/locale/EmberTestConfigurationEditor" key="node.interpreter"/>
358+
</properties>
359+
</component>
360+
<grid id="f4e" binding="myNodeSettingsPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
361+
<margin top="0" left="0" bottom="0" right="0"/>
362+
<constraints>
363+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
364+
</constraints>
365+
<properties/>
366+
<border type="none"/>
367+
<children/>
368+
</grid>
357369
</children>
358370
</grid>
359371
</children>

0 commit comments

Comments
 (0)