1111import com .intellij .notification .Notification ;
1212import com .intellij .notification .NotificationType ;
1313import com .intellij .notification .Notifications ;
14+ import com .intellij .openapi .application .ApplicationManager ;
15+ import com .intellij .openapi .fileEditor .FileDocumentManager ;
1416import com .intellij .openapi .project .Project ;
1517import com .intellij .openapi .ui .DialogWrapper ;
1618import 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