15
15
import de .php_perfect .intellij .ddev .dockerCompose .DockerComposeCredentialProvider ;
16
16
import org .jetbrains .annotations .NotNull ;
17
17
18
+ import java .util .Collection ;
18
19
import java .util .List ;
19
20
20
21
public final class NodeInterpreterProviderImpl implements NodeInterpreterProvider {
@@ -28,9 +29,27 @@ public NodeInterpreterProviderImpl(final @NotNull Project project) {
28
29
29
30
public void configureNodeInterpreter (final @ NotNull NodeInterpreterConfig nodeInterpreterConfig ) {
30
31
final NodeRemoteInterpreters nodeRemoteInterpreters = NodeRemoteInterpreters .getInstance ();
32
+ final Collection <NodeJSRemoteSdkAdditionalData > interpreters = nodeRemoteInterpreters .getInterpreters ();
31
33
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
+ }
34
53
}
35
54
36
55
LOG .debug ("Creating nodejs interpreter" );
@@ -60,4 +79,19 @@ private PathMappingSettings loadPathMappings(NodeJSRemoteSdkAdditionalData sdkDa
60
79
return null ;
61
80
}
62
81
}
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
+ }
63
97
}
0 commit comments