1515import de .php_perfect .intellij .ddev .dockerCompose .DockerComposeCredentialProvider ;
1616import org .jetbrains .annotations .NotNull ;
1717
18+ import java .util .Collection ;
1819import java .util .List ;
1920
2021public final class NodeInterpreterProviderImpl implements NodeInterpreterProvider {
@@ -28,9 +29,27 @@ public NodeInterpreterProviderImpl(final @NotNull Project project) {
2829
2930 public void configureNodeInterpreter (final @ NotNull NodeInterpreterConfig nodeInterpreterConfig ) {
3031 final NodeRemoteInterpreters nodeRemoteInterpreters = NodeRemoteInterpreters .getInstance ();
32+ final Collection <NodeJSRemoteSdkAdditionalData > interpreters = nodeRemoteInterpreters .getInterpreters ();
3133
32- if (!nodeRemoteInterpreters .getInterpreters ().isEmpty ()) {
33- return ;
34+ // Normalize the target compose file path for comparison
35+ String normalizedTargetPath = normalizePath (nodeInterpreterConfig .composeFilePath ());
36+
37+ // Check if we already have the remote interpreter set up
38+ if (!interpreters .isEmpty ()) {
39+ for (NodeJSRemoteSdkAdditionalData interpreter : interpreters ) {
40+ Object credentialsObj = interpreter .connectionCredentials ().getCredentials ();
41+ // Check if the credentials are of the expected type
42+ if (credentialsObj instanceof DockerComposeCredentialsHolder credentials && credentials .getComposeFilePaths () != null ) {
43+ for (String composeFilePath : credentials .getComposeFilePaths ()) {
44+ // Normalize the existing compose file path for comparison
45+ String normalizedExistingPath = normalizePath (composeFilePath );
46+ if (normalizedExistingPath .contains (normalizedTargetPath )) {
47+ LOG .debug ("Found existing nodejs interpreter" );
48+ return ;
49+ }
50+ }
51+ }
52+ }
3453 }
3554
3655 LOG .debug ("Creating nodejs interpreter" );
@@ -60,4 +79,19 @@ private PathMappingSettings loadPathMappings(NodeJSRemoteSdkAdditionalData sdkDa
6079 return null ;
6180 }
6281 }
82+
83+ /**
84+ * Normalizes a file path by replacing backslashes with forward slashes
85+ * and ensuring consistent path separators for comparison.
86+ *
87+ * @param path The path to normalize
88+ * @return The normalized path
89+ */
90+ private String normalizePath (String path ) {
91+ if (path == null ) {
92+ return "" ;
93+ }
94+ // Replace backslashes with forward slashes for consistent comparison
95+ return path .replace ('\\' , '/' );
96+ }
6397}
0 commit comments