11
11
import com .intellij .notification .Notification ;
12
12
import com .intellij .notification .NotificationType ;
13
13
import com .intellij .notification .Notifications ;
14
+ import com .intellij .openapi .application .ApplicationManager ;
15
+ import com .intellij .openapi .fileEditor .FileDocumentManager ;
14
16
import com .intellij .openapi .project .Project ;
15
17
import com .intellij .openapi .ui .DialogWrapper ;
16
18
import com .intellij .openapi .vfs .VirtualFile ;
@@ -105,7 +107,7 @@ public String expandVariables(String rawValue) {
105
107
106
108
// If the variable wasn't found in the system try to see if the user has a .env file with the variable
107
109
if (varValue == null || varValue .trim ().isEmpty ()) {
108
- varValue = tryToGetVariableFromDotEnvFile (varName , varValue );
110
+ varValue = tryToGetVariableFromDotEnvFile (varName );
109
111
}
110
112
111
113
// 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) {
125
127
}
126
128
127
129
@ Nullable
128
- private String tryToGetVariableFromDotEnvFile (String varName , String varValue ) {
130
+ private String tryToGetVariableFromDotEnvFile (String varName ) {
131
+ String varValue = null ;
129
132
Dotenv dotenv ;
130
133
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
+
131
140
// Let's try to load the env file closest to the config file first
132
141
if (configFile != null ) {
133
142
VirtualFile parentDir = configFile .getParent ();
0 commit comments