Skip to content

Commit 7d4bf10

Browse files
committed
Save documents before .env file reading
1 parent 3f5cc84 commit 7d4bf10

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/com/intellij/lang/jsgraphql/ide/project/graphqlconfig/model/GraphQLConfigVariableAwareEndpoint.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import com.intellij.notification.Notification;
1212
import com.intellij.notification.NotificationType;
1313
import com.intellij.notification.Notifications;
14+
import com.intellij.openapi.application.ApplicationManager;
15+
import com.intellij.openapi.fileEditor.FileDocumentManager;
1416
import com.intellij.openapi.project.Project;
1517
import com.intellij.openapi.ui.DialogWrapper;
1618
import com.intellij.openapi.vfs.VirtualFile;
@@ -105,7 +107,7 @@ public String expandVariables(String rawValue) {
105107

106108
// If the variable wasn't found in the system try to see if the user has a .env file with the variable
107109
if (varValue == null || varValue.trim().isEmpty()) {
108-
varValue = tryToGetVariableFromDotEnvFile(varName, varValue);
110+
varValue = tryToGetVariableFromDotEnvFile(varName);
109111
}
110112

111113
// If it still wasn't found present the user with a dialog to enter the variable
@@ -125,9 +127,16 @@ public String expandVariables(String rawValue) {
125127
}
126128

127129
@Nullable
128-
private String tryToGetVariableFromDotEnvFile(String varName, String varValue) {
130+
private String tryToGetVariableFromDotEnvFile(String varName) {
131+
String varValue = null;
129132
Dotenv dotenv;
130133

134+
// commit changes to the file system before the Dotenv is used
135+
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
136+
if (ApplicationManager.getApplication().isDispatchThread() && fileDocumentManager.getUnsavedDocuments().length > 0) {
137+
fileDocumentManager.saveAllDocuments();
138+
}
139+
131140
// Let's try to load the env file closest to the config file first
132141
if (configFile != null) {
133142
VirtualFile parentDir = configFile.getParent();

0 commit comments

Comments
 (0)