Skip to content

Commit

Permalink
Save documents before .env file reading
Browse files Browse the repository at this point in the history
  • Loading branch information
vepanimas committed Feb 10, 2021
1 parent 3f5cc84 commit 7d4bf10
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.vfs.VirtualFile;
Expand Down Expand Up @@ -105,7 +107,7 @@ public String expandVariables(String rawValue) {

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

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

@Nullable
private String tryToGetVariableFromDotEnvFile(String varName, String varValue) {
private String tryToGetVariableFromDotEnvFile(String varName) {
String varValue = null;
Dotenv dotenv;

// commit changes to the file system before the Dotenv is used
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
if (ApplicationManager.getApplication().isDispatchThread() && fileDocumentManager.getUnsavedDocuments().length > 0) {
fileDocumentManager.saveAllDocuments();
}

// Let's try to load the env file closest to the config file first
if (configFile != null) {
VirtualFile parentDir = configFile.getParent();
Expand Down

0 comments on commit 7d4bf10

Please sign in to comment.