How to add a JComponent to pre-existing Run configuration editor

Answered

I am not entirely sure this is possible, but I am trying to add a custom component (JButton, JLabel, etc...) to an existing Run Configuration Editor, so far this is what I have tried.

RunManager instance = RunManager.getInstance(project);
RunnerAndConfigurationSettings nodejsTemplate = instance.createConfiguration("my-config-name", NodeJsRunConfigurationType.getInstance());
(NodeJsRunConfiguration) nodejsTemplate.getConfiguration();
nodejsTemplate.getConfiguration().getConfigurationEditor().getComponent();

However this produce an error:

java.lang.UnsupportedOperationException: This method should never be called!

So I guess that is the wrong direction.

I was thinking to create my own class and extends to the

NodeRunConfigurationEditor

However the class is private and I will have to make a lot of plumbing work.

Is there an easy way to achieve this? Thanks

0
7 comments

Please see com.jetbrains.nodejs.run.NodeJSRunConfigurationExtension, EP: NodeJS.runConfigurationExtension.

It extends generic com.intellij.execution.configuration.RunConfigurationExtensionBase (samples: https://plugins.jetbrains.com/intellij-platform-explorer?extensions=com.intellij.runConfigurationExtension), see its javadoc

0

Yann Cebron thanks for answer, could you please expand a little bit on this?
I guess the first thing would be to create a class that extends the

NodeJSRunConfigurationExtension


Like this

public class NodejsExtendedConfigurationEditor extends NodeJSRunConfigurationExtension {
@Override
protected @Nullable NodeJSRuntimeSession createLocalRuntimeSession(@NotNull NodeJsRunConfiguration nodeJsRunConfiguration, @NotNull ExecutionEnvironment executionEnvironment) throws ExecutionException {
return null;
}

@Override
protected @Nullable NodeJSRuntimeSession createRemoteRuntimeSession(@NotNull NodeJsRunConfiguration nodeJsRunConfiguration, @NotNull ExecutionEnvironment executionEnvironment, @NotNull NodeFileTransfer nodeFileTransfer) throws ExecutionException {
return null;
}

@Override
protected @Nullable SettingsEditor<NodeJsRunConfiguration> createEditor(@NotNull NodeJsRunConfiguration configuration, Consumer<NodeJsInterpreterChangeListener> listenerRegistrar) {
return super.createEditor(configuration, listenerRegistrar);
}

@Override
public boolean isApplicableFor(@NotNull NodeJsRunConfiguration configuration) {
return true;
}

@Override
public boolean isEnabledFor(@NotNull NodeJsRunConfiguration applicableConfiguration, @Nullable RunnerSettings runnerSettings) {
return true;
}
}

Maybe modify the create editor function and add my custom component?

@Override
protected @Nullable <P extends NodeJsRunConfiguration> SettingsEditor<P> createEditor(@NotNull P configuration) {
SettingsEditor<P> editor = super.createEditor(configuration);
editor.getComponent().add(new JLabel("Hello"));
return editor;
}


And maybe add it to my plugin.xml as dependency?

<depends config-file="myPluginId-nodejsExtension.xml">NodeJS</depends>
<idea-plugin>
<extensions defaultExtensionNs="NodeJS">
<runConfigurationExtension
implementation="com.github.user.repository.NodejsCustomRunConfigurationExtension"
id="myPluginId-nodejsExtension"
/>
</extensions>
</idea-plugin>



However like this nothing happens, the createEditor won't get called.
Thanks

0

1) com.intellij.execution.configuration.RunConfigurationExtensionBase#createEditor returns null by default, you need to return your custom instance see com.intellij.execution.coverage.CoverageJavaRunConfigurationExtension from Java plugin as sample

2) Override com.intellij.execution.configuration.RunConfigurationExtensionBase#getEditorTitle

3) return false from com.jetbrains.nodejs.run.NodeJSRunConfigurationExtension#showEditorInMainPage

4) your plugin.xml "implementation" doesn't match the class name (

NodejsExtendedConfigurationEditor vs
NodejsCustomRunConfigurationExtension)
0

Was `com.jetbrains.nodejs.run.NodeJSRunConfigurationExtension` (that is mentioned a lot in this thread) removed or something? I get `Unresolved reference: NodeJSRunConfigurationExtension` when I try to import it (but not for `com.jetbrains.nodejs.run.NodeJsRunConfiguration`, so I think I do have the JavaScript plugin).

And where is all of this documented actually, or where is the source code if there's no documentation?

How do people know about those classes and their members?

1

@t4lz The thread above refers to the status of 2021. NodeJS plugin is closed-source and thus cannot be inspected, there is no “official” documentation for it either. The newer variant is com.intellij.javascript.nodejs.execution.runConfiguration.AbstractNodeRunConfigurationExtension in JavaScript.nodeRunConfigurationExtension extension point.

0

Thank you for the clarification, Yann Cebron. Unlike in e.g. `PythonRunConfigurationExtension`, in `AbstractNodeRunConfigurationExtension`, `patchCommandLine` is final. So how can we offer a similar functionality for node?

0

…which throws Do not call AbstractNodeRunConfigurationExtension.patchCommandLine. Node.js uses Targets API, not GeneralCommandLine

See /platform/execution/src/com/intellij/execution/target in IJ Community sources for Target API + some README

0

Please sign in to leave a comment.