Skip to content

Commit 13d102a

Browse files
committed
fix: node.js auto-configuration not supporting multiple projects
1 parent b78d12e commit 13d102a

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/main/java/de/php_perfect/intellij/ddev/node/NodeInterpreterProviderImpl.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import de.php_perfect.intellij.ddev.dockerCompose.DockerComposeCredentialProvider;
1616
import org.jetbrains.annotations.NotNull;
1717

18+
import java.util.Collection;
1819
import java.util.List;
1920

2021
public 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

Comments
 (0)