Skip to content

Commit

Permalink
feat: notify user if Navie isn't fully functional (#595)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Trotta <[email protected]>
  • Loading branch information
jansorg and ahtrotta authored Mar 1, 2024
1 parent ab556b1 commit 9b5f184
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@
import appland.cli.AppLandCommandLineService;
import appland.notifications.AppMapNotifications;
import appland.webviews.WebviewEditorProvider;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiManager;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -71,6 +76,12 @@ public static void openEditor(@NotNull Project project, @NotNull DataContext con
KEY_CODE_SELECTION.set(file, codeSelection);

FileEditorManager.getInstance(project).openFile(file, true);

var hideMessagePropertyKey = "appmap.navie.hideIsBrokenMessage";
var properties = PropertiesComponent.getInstance();
if (isNavieWebviewSupportBroken() && !properties.getBoolean(hideMessagePropertyKey, false)) {
showNavieWebviewBrokenMessage(project, properties, hideMessagePropertyKey);
}
});
}

Expand Down Expand Up @@ -151,4 +162,35 @@ public Icon getEditorIcon() {
private interface ShowNavieConsumer {
void openNavie(@Nullable Integer indexerPort, @Nullable NavieCodeSelection codeSelection);
}

private static boolean isNavieWebviewSupportBroken() {
var buildBaseline = ApplicationInfo.getInstance().getBuild().getBaselineVersion();

// Linux <= 2023.1 is broken,
// https://youtrack.jetbrains.com/issue/JBR-5348/JCEF-OSR-Keyboard-doesnt-work-on-Linux
if (SystemInfo.isLinux && buildBaseline <= 231) {
return true;
}

return false;
}

@SuppressWarnings("removal")
private static void showNavieWebviewBrokenMessage(@NotNull Project project, PropertiesComponent properties, String hideMessagePropertyKey) {
ApplicationManager.getApplication().invokeLater(() -> {
Messages.showDialog(project,
AppMapBundle.get("webview.navie.webviewBroken.message"),
AppMapBundle.get("webview.navie.webviewBroken.title"),
new String[]{Messages.getOkButton()},
0,
Messages.getWarningIcon(),
// already deprecated in 2022.1, but there's no alternative API in Messages.
new DialogWrapper.DoNotAskOption.Adapter() {
@Override
public void rememberChoice(boolean isSelected, int exitCode) {
properties.setValue(hideMessagePropertyKey, isSelected, false);
}
});
}, ModalityState.any());
}
}
2 changes: 2 additions & 0 deletions plugin-core/src/main/resources/messages/appland.properties
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ webview.findingDetails.appMapNotFound.message=The AppMap file could not be found
webview.navie.title=AppMap AI: Explain
webview.navie.chooseAppMapModule.title=Choose AppMap module
webview.navie.webviewBroken.title=AppMap Navie
webview.navie.webviewBroken.message=Please update your IDE to version 2023.2 or later.\nNavie will not work with versions prior to 2023.2 because there is an IDE issue that prevents typing into input fields.
codeObjects.codeTopLevel.label=Code
codeObjects.navigation.locatingFiles=Locating AppMaps....
Expand Down

0 comments on commit 9b5f184

Please sign in to comment.