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

Proof of Concept - Dead End for Adding EnvFile support for NodeJS. #1

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ allprojects {
version : "2018.3",
pycharm : "PythonCore:2018.3.183.4284.148",
rubymine: "org.jetbrains.plugins.ruby:2018.3.20181121",
goland : "org.jetbrains.plugins.go:183.4284.36.1532"

goland : "org.jetbrains.plugins.go:183.4284.36.1532",
//goland : "org.jetbrains.plugins.go:202.6397.20",
nodejs : "NodeJS"
]
}

Expand All @@ -33,13 +36,20 @@ intellij {
pluginName "EnvFile"
sameSinceUntilBuild false
updateSinceUntilBuild false
// TODO figure out why it needs to be here
type "IU"
plugins "NodeJS:183.4284.122", "JavaScriptLanguage", "JavaScriptDebugger"
//plugins "NodeJS:203.5981.152", "JavaScriptLanguage", "JavaScriptDebugger"
//plugins "NodeJS:202.6397.8", "JavaScriptLanguage", "JavaScriptDebugger"
}


dependencies {
compile project(":envfile-products-idea")
compile project(":envfile-products-pycharm")
compile project(":envfile-products-rubymine")
compile project(":envfile-products-goland")
compile project(":envfile-products-nodejs")
}

wrapper {
Expand Down
17 changes: 17 additions & 0 deletions modules/products/nodejs/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id "java"
id "org.jetbrains.intellij"
}

intellij {
version jetbrains.version
type "IU"
plugins "NodeJS:183.4284.122", "JavaScriptLanguage", "JavaScriptDebugger"
//plugins "NodeJS:203.5981.152", "JavaScriptLanguage", "JavaScriptDebugger"
//plugins "NodeJS:202.6397.8", "JavaScriptLanguage", "JavaScriptDebugger"
}

dependencies {
compile project(":envfile-platform")
compile "org.jetbrains:annotations:16.0.3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package net.ashald.envfile.products.idea;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.configuration.EnvironmentVariablesData;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.RunnerSettings;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterChangeListener;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.util.Consumer;
import com.jetbrains.nodejs.run.NodeJSRunConfigurationExtension;
import com.jetbrains.nodejs.run.NodeJSRuntimeSession;
import com.jetbrains.nodejs.run.NodeJsRunConfiguration;
import net.ashald.envfile.platform.ui.EnvFileConfigurationEditor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class NodeJsEnvFileRunConfigurationExtension extends NodeJSRunConfigurationExtension {

@Nullable
@Override
protected NodeJSRuntimeSession createLocalRuntimeSession(@NotNull final NodeJsRunConfiguration nodeJsRunConfiguration, @NotNull final ExecutionEnvironment executionEnvironment) throws ExecutionException {
updateRunConfiguration(nodeJsRunConfiguration);
return null;
//return new MyNodeJSRuntimeSession(nodeJsRunConfiguration);
}



@Nullable
@Override
protected NodeJSRuntimeSession createRemoteRuntimeSession(@NotNull final NodeJsRunConfiguration nodeJsRunConfiguration,
@NotNull final ExecutionEnvironment executionEnvironment,
@NotNull final com.intellij.javascript.nodejs.NodeFileTransfer nodeFileTransfer) throws ExecutionException {
updateRunConfiguration(nodeJsRunConfiguration);

return null;
//return new MyNodeJSRuntimeSession(nodeJsRunConfiguration);
}

private static void updateRunConfiguration(NodeJsRunConfiguration nodeJsRunConfiguration) throws ExecutionException {
EnvironmentVariablesData evd = nodeJsRunConfiguration.getEnvData();
Map<String, String> newEnv = EnvFileConfigurationEditor.collectEnv(nodeJsRunConfiguration, new LinkedHashMap<>(evd.getEnvs()));

nodeJsRunConfiguration.setEnvData(EnvironmentVariablesData.create(newEnv, evd.isPassParentEnvs()));
}

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

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

@Nullable
public String getEditorTitle() {
return EnvFileConfigurationEditor.getEditorTitle();
}


@Nullable
protected <P extends NodeJsRunConfiguration> SettingsEditor<P> createEditor(@NotNull final P configuration, final Consumer<NodeJsInterpreterChangeListener> listenerRegistrar) {
return new EnvFileConfigurationEditor<>(configuration);
}

private static class MyNodeJSRuntimeSession implements NodeJSRuntimeSession {

private final NodeJsRunConfiguration configuration;

public MyNodeJSRuntimeSession(NodeJsRunConfiguration configuration) {
this.configuration = configuration;
}
@Override
public ProcessHandler createProcessHandler(final GeneralCommandLine commandLine, final int debugPort, final List<Integer> openPorts) throws ExecutionException {
Map<String, String> newEnv = EnvFileConfigurationEditor.collectEnv(configuration, new LinkedHashMap<>(commandLine.getEnvironment()));

commandLine.getEnvironment().putAll(newEnv);
return null;
}
}

}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include (
'modules/platform',
'modules/products/idea',
'modules/products/goland',
'modules/products/nodejs',
'modules/products/pycharm',
'modules/products/rubymine',
)
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/envfile-nodejs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<idea-plugin version="2">
<extensions defaultExtensionNs="NodeJS">
<runConfigurationExtension implementation="com.jetbrains.nodejs.remote.NodeJSRemoteRunConfigurationExtension"/>
</extensions>
</idea-plugin>
12 changes: 11 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

<depends>com.intellij.modules.lang</depends>
<depends optional="true" config-file="">com.intellij.java</depends>

<extensionPoints>
<extensionPoint name="envVarsProvider" beanClass="net.ashald.envfile.platform.EnvVarsProviderExtension">
<with attribute="factory" implements="net.ashald.envfile.EnvVarsProviderFactory"/>
Expand All @@ -79,4 +78,15 @@
<depends optional="true" config-file="envfile-rubymine.xml">com.intellij.modules.ruby</depends>
<depends optional="true" config-file="envfile-goland.xml">org.jetbrains.plugins.go</depends>

<!-- TODO Move to sub file-->
<depends>JavaScript</depends>
<depends>JavaScriptDebugger</depends>
<depends>NodeJS</depends>


<extensions defaultExtensionNs="NodeJS">
<runConfigurationExtension implementation="net.ashald.envfile.products.idea.NodeJsEnvFileRunConfigurationExtension"/>
</extensions>


</idea-plugin>