Skip to content

Commit aa21e2f

Browse files
committed
Add run configurations to IntelliJ plugin and update PipelineDemo to use |> operator
1 parent 8390cf0 commit aa21e2f

File tree

12 files changed

+479
-55
lines changed

12 files changed

+479
-55
lines changed

Editor/intellij-aro/src/main/java/com/arolang/aro/AROLspServerDescriptor.java

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
import java.util.ArrayList;
1616
import java.util.List;
17-
import java.nio.file.Files;
18-
import java.nio.file.Path;
1917

2018
/**
2119
* LSP server factory for ARO language support.
@@ -24,17 +22,10 @@
2422
@SuppressWarnings("UnstableApiUsage")
2523
public class AROLspServerDescriptor implements LanguageServerFactory {
2624

27-
// Common installation paths for ARO
28-
private static final String[] COMMON_PATHS = {
29-
"/opt/homebrew/bin/aro",
30-
"/usr/local/bin/aro",
31-
"/usr/bin/aro"
32-
};
33-
3425
@Override
3526
public @NotNull StreamConnectionProvider createConnectionProvider(@NotNull Project project) {
3627
AROSettingsState settings = AROSettingsState.getInstance();
37-
String aroPath = resolveAroPath(settings.aroPath);
28+
String aroPath = AROPathResolver.resolve(settings.aroPath);
3829

3930
List<String> commands = new ArrayList<>();
4031
commands.add(aroPath);
@@ -56,33 +47,6 @@ public class AROLspServerDescriptor implements LanguageServerFactory {
5647
return provider;
5748
}
5849

59-
/**
60-
* Resolve the ARO binary path.
61-
* If the configured path is just "aro", try common installation paths.
62-
*/
63-
private String resolveAroPath(String configuredPath) {
64-
// If it's an absolute path that exists, use it directly
65-
if (configuredPath != null && !configuredPath.isEmpty()) {
66-
Path path = Path.of(configuredPath);
67-
if (path.isAbsolute() && Files.exists(path) && Files.isExecutable(path)) {
68-
return configuredPath;
69-
}
70-
}
71-
72-
// If path is "aro" or not configured, check common installation paths
73-
if (configuredPath == null || configuredPath.isEmpty() || configuredPath.equals("aro")) {
74-
for (String pathStr : COMMON_PATHS) {
75-
Path path = Path.of(pathStr);
76-
if (Files.exists(path) && Files.isExecutable(path)) {
77-
return pathStr;
78-
}
79-
}
80-
}
81-
82-
// Fall back to the configured path (may work if it's in PATH)
83-
return configuredPath != null ? configuredPath : "aro";
84-
}
85-
8650
@Override
8751
public @NotNull Class<? extends LanguageServer> getServerInterface() {
8852
return LanguageServer.class;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.arolang.aro;
2+
3+
import com.arolang.aro.settings.AROSettingsState;
4+
5+
import java.nio.file.Files;
6+
import java.nio.file.Path;
7+
8+
/**
9+
* Resolves the ARO binary path from settings with fallback to common installation paths.
10+
*/
11+
public final class AROPathResolver {
12+
13+
private static final String[] COMMON_PATHS = {
14+
"/opt/homebrew/bin/aro",
15+
"/usr/local/bin/aro",
16+
"/usr/bin/aro"
17+
};
18+
19+
private AROPathResolver() {}
20+
21+
public static String resolve() {
22+
return resolve(AROSettingsState.getInstance().aroPath);
23+
}
24+
25+
public static String resolve(String configuredPath) {
26+
// If it's an absolute path that exists, use it directly
27+
if (configuredPath != null && !configuredPath.isEmpty()) {
28+
Path path = Path.of(configuredPath);
29+
if (path.isAbsolute() && Files.exists(path) && Files.isExecutable(path)) {
30+
return configuredPath;
31+
}
32+
}
33+
34+
// If path is "aro" or not configured, check common installation paths
35+
if (configuredPath == null || configuredPath.isEmpty() || configuredPath.equals("aro")) {
36+
for (String pathStr : COMMON_PATHS) {
37+
Path path = Path.of(pathStr);
38+
if (Files.exists(path) && Files.isExecutable(path)) {
39+
return pathStr;
40+
}
41+
}
42+
}
43+
44+
// Fall back to the configured path (may work if it's in PATH)
45+
return configuredPath != null ? configuredPath : "aro";
46+
}
47+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.arolang.aro.run;
2+
3+
public enum AROCommandType {
4+
RUN("run", "Run"),
5+
BUILD("build", "Build"),
6+
CHECK("check", "Check");
7+
8+
private final String command;
9+
private final String displayName;
10+
11+
AROCommandType(String command, String displayName) {
12+
this.command = command;
13+
this.displayName = displayName;
14+
}
15+
16+
public String getCommand() {
17+
return command;
18+
}
19+
20+
public String getDisplayName() {
21+
return displayName;
22+
}
23+
24+
public static AROCommandType fromCommand(String command) {
25+
for (AROCommandType type : values()) {
26+
if (type.command.equals(command)) {
27+
return type;
28+
}
29+
}
30+
return RUN;
31+
}
32+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.arolang.aro.run;
2+
3+
import com.intellij.execution.Executor;
4+
import com.intellij.execution.configurations.*;
5+
import com.intellij.execution.runners.ExecutionEnvironment;
6+
import com.intellij.openapi.options.SettingsEditor;
7+
import com.intellij.openapi.project.Project;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
import java.io.File;
12+
13+
public class ARORunConfiguration extends RunConfigurationBase<ARORunConfigurationOptions> {
14+
15+
protected ARORunConfiguration(@NotNull Project project, @NotNull ConfigurationFactory factory, @Nullable String name) {
16+
super(project, factory, name);
17+
}
18+
19+
@Override
20+
protected @NotNull ARORunConfigurationOptions getOptions() {
21+
return (ARORunConfigurationOptions) super.getOptions();
22+
}
23+
24+
public AROCommandType getCommandType() {
25+
return AROCommandType.fromCommand(getOptions().getCommandType());
26+
}
27+
28+
public void setCommandType(AROCommandType type) {
29+
getOptions().setCommandType(type.getCommand());
30+
}
31+
32+
public String getApplicationDirectory() {
33+
return getOptions().getApplicationDirectory();
34+
}
35+
36+
public void setApplicationDirectory(String path) {
37+
getOptions().setApplicationDirectory(path);
38+
}
39+
40+
@Override
41+
public @NotNull SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
42+
return new ARORunConfigurationEditor(getProject());
43+
}
44+
45+
@Override
46+
public void checkConfiguration() throws RuntimeConfigurationException {
47+
String dir = getApplicationDirectory();
48+
if (dir == null || dir.isEmpty()) {
49+
throw new RuntimeConfigurationError("Application directory is not specified");
50+
}
51+
File file = new File(dir);
52+
if (!file.exists() || !file.isDirectory()) {
53+
throw new RuntimeConfigurationError("Application directory does not exist: " + dir);
54+
}
55+
// Check for .aro files
56+
File[] aroFiles = file.listFiles((d, name) -> name.endsWith(".aro"));
57+
if (aroFiles == null || aroFiles.length == 0) {
58+
// Also check subdirectories (sources/ convention)
59+
boolean found = hasAroFilesRecursive(file, 3);
60+
if (!found) {
61+
throw new RuntimeConfigurationWarning("No .aro files found in: " + dir);
62+
}
63+
}
64+
}
65+
66+
private boolean hasAroFilesRecursive(File dir, int maxDepth) {
67+
if (maxDepth <= 0) return false;
68+
File[] files = dir.listFiles();
69+
if (files == null) return false;
70+
for (File f : files) {
71+
if (f.isFile() && f.getName().endsWith(".aro")) return true;
72+
if (f.isDirectory() && hasAroFilesRecursive(f, maxDepth - 1)) return true;
73+
}
74+
return false;
75+
}
76+
77+
@Override
78+
public @Nullable RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) {
79+
return new ARORunState(environment, this);
80+
}
81+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.arolang.aro.run;
2+
3+
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
4+
import com.intellij.openapi.options.SettingsEditor;
5+
import com.intellij.openapi.project.Project;
6+
import com.intellij.openapi.ui.ComboBox;
7+
import com.intellij.openapi.ui.TextBrowseFolderListener;
8+
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
9+
import com.intellij.ui.components.JBLabel;
10+
import com.intellij.util.ui.FormBuilder;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import javax.swing.*;
14+
import java.awt.*;
15+
16+
public class ARORunConfigurationEditor extends SettingsEditor<ARORunConfiguration> {
17+
18+
private final ComboBox<AROCommandType> commandTypeCombo;
19+
private final TextFieldWithBrowseButton directoryField;
20+
21+
public ARORunConfigurationEditor(Project project) {
22+
commandTypeCombo = new ComboBox<>(AROCommandType.values());
23+
commandTypeCombo.setRenderer(new DefaultListCellRenderer() {
24+
@Override
25+
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
26+
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
27+
if (value instanceof AROCommandType type) {
28+
setText(type.getDisplayName());
29+
}
30+
return this;
31+
}
32+
});
33+
34+
directoryField = new TextFieldWithBrowseButton();
35+
directoryField.addBrowseFolderListener(
36+
new TextBrowseFolderListener(
37+
FileChooserDescriptorFactory.createSingleFolderDescriptor()
38+
.withTitle("Select ARO Application Directory")
39+
)
40+
);
41+
}
42+
43+
@Override
44+
protected void resetEditorFrom(@NotNull ARORunConfiguration config) {
45+
commandTypeCombo.setSelectedItem(config.getCommandType());
46+
directoryField.setText(config.getApplicationDirectory());
47+
}
48+
49+
@Override
50+
protected void applyEditorTo(@NotNull ARORunConfiguration config) {
51+
config.setCommandType((AROCommandType) commandTypeCombo.getSelectedItem());
52+
config.setApplicationDirectory(directoryField.getText().trim());
53+
}
54+
55+
@Override
56+
protected @NotNull JComponent createEditor() {
57+
return FormBuilder.createFormBuilder()
58+
.addLabeledComponent(new JBLabel("Command:"), commandTypeCombo, 1, false)
59+
.addLabeledComponent(new JBLabel("Application directory:"), directoryField, 1, false)
60+
.addComponentFillVertically(new JPanel(), 0)
61+
.getPanel();
62+
}
63+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.arolang.aro.run;
2+
3+
import com.intellij.execution.configurations.RunConfigurationOptions;
4+
import com.intellij.openapi.components.StoredProperty;
5+
6+
public class ARORunConfigurationOptions extends RunConfigurationOptions {
7+
8+
private final StoredProperty<String> commandType =
9+
string("run").provideDelegate(this, "commandType");
10+
11+
private final StoredProperty<String> applicationDirectory =
12+
string("").provideDelegate(this, "applicationDirectory");
13+
14+
public String getCommandType() {
15+
return commandType.getValue(this);
16+
}
17+
18+
public void setCommandType(String value) {
19+
commandType.setValue(this, value);
20+
}
21+
22+
public String getApplicationDirectory() {
23+
return applicationDirectory.getValue(this);
24+
}
25+
26+
public void setApplicationDirectory(String value) {
27+
applicationDirectory.setValue(this, value);
28+
}
29+
}

0 commit comments

Comments
 (0)