Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/io/flutter/FlutterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ public static boolean declaresFlutter(@NotNull final VirtualFile pubspec) {
*/
public static boolean declaresFlutterWeb(@NotNull final VirtualFile pubspec) {
// It uses Flutter if it contains:
//dependencies:
// flutter_web: any
// dependencies:
// flutter_web:

try {
final Map<String, Object> yamlMap = readPubspecFileToMap(pubspec);
Expand Down
10 changes: 10 additions & 0 deletions src/io/flutter/actions/ReloadFlutterApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ public void actionPerformed(@NotNull AnActionEvent e) {
FlutterReloadManager.getInstance(project).saveAllAndReload(getApp(), FlutterConstants.RELOAD_REASON_MANUAL);
}
}

// Override to disable the hot reload action when running flutter web apps.
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);

if (!getApp().appSupportsHotReload()) {
e.getPresentation().setEnabled(false);
}
}
}
7 changes: 6 additions & 1 deletion src/io/flutter/console/FlutterConsoleFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ public FlutterConsoleFilter(@NotNull Module module) {
@VisibleForTesting
@Nullable
public VirtualFile fileAtPath(@NotNull String pathPart) {

// "lib/main.dart:6"
pathPart = pathPart.split(":")[0];

// We require the pathPart reference to be a file reference, otherwise we'd match things like
// "Build: Running build completed, took 191ms".
if (pathPart.indexOf('.') == -1) {
return null;
}

final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
for (VirtualFile root : roots) {
if (!pathPart.isEmpty()) {
Expand Down
31 changes: 19 additions & 12 deletions src/io/flutter/devtools/DevToolsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io.flutter.utils.JsonUtils;
import org.jetbrains.annotations.NotNull;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -106,16 +108,16 @@ public void onCancel() {
}

public void openBrowser() {
openBrowserImpl(-1);
openBrowserImpl(null);
}

public void openBrowserAndConnect(int port) {
openBrowserImpl(port);
public void openBrowserAndConnect(String uri) {
openBrowserImpl(uri);
}

private void openBrowserImpl(int port) {
private void openBrowserImpl(String uri) {
if (devToolsInstance != null) {
devToolsInstance.openBrowserAndConnect(port);
devToolsInstance.openBrowserAndConnect(uri);
return;
}

Expand All @@ -133,7 +135,7 @@ private void openBrowserImpl(int port) {
DevToolsInstance.startServer(project, sdk, pubRoots.get(0), instance -> {
devToolsInstance = instance;

devToolsInstance.openBrowserAndConnect(port);
devToolsInstance.openBrowserAndConnect(uri);
}, instance -> {
// Listen for closing, null out the devToolsInstance.
devToolsInstance = null;
Expand Down Expand Up @@ -209,15 +211,20 @@ public void processTerminated(@NotNull ProcessEvent event) {
this.devtoolsPort = devtoolsPort;
}

public void openBrowserAndConnect(int serviceProtocolPort) {
if (serviceProtocolPort == -1) {
public void openBrowserAndConnect(String serviceProtocolUri) {
if (serviceProtocolUri == null) {
BrowserLauncher.getInstance().browse("http://" + devtoolsHost + ":" + devtoolsPort + "/?hide=debugger&", null);
}
else {
BrowserLauncher.getInstance().browse(
"http://" + devtoolsHost + ":" + devtoolsPort + "/?hide=debugger&port=" + serviceProtocolPort,
null
);
try {
final String urlParam = URLEncoder.encode(serviceProtocolUri, "UTF-8");
BrowserLauncher.getInstance().browse(
"http://" + devtoolsHost + ":" + devtoolsPort + "/?hide=debugger&uri=" + urlParam,
null
);
}
catch (UnsupportedEncodingException ignored) {
}
}
}
}
Expand Down
53 changes: 31 additions & 22 deletions src/io/flutter/inspector/DiagnosticsNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.xdebugger.XSourcePosition;
import com.jetbrains.lang.dart.analyzer.DartAnalysisServerService;
import io.flutter.server.vmService.frame.DartVmServiceValue;
import io.flutter.run.daemon.FlutterApp;
import io.flutter.server.vmService.frame.DartVmServiceValue;
import io.flutter.utils.CustomIconMaker;
import io.flutter.utils.JsonUtils;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -49,6 +50,8 @@
* also available via the getValue() method.
*/
public class DiagnosticsNode {
private static final Logger LOG = Logger.getInstance(DiagnosticsNode.class);

private static final CustomIconMaker iconMaker = new CustomIconMaker();
private final FlutterApp app;

Expand Down Expand Up @@ -104,7 +107,8 @@ public boolean isDisposed() {
final InspectorService.ObjectGroup service = inspectorService.getNow(null);
// If the service isn't created yet it can't have been disposed.
return service != null && service.isDisposed();
} catch (Exception e) {
}
catch (Exception e) {
// If the service can't be acquired then it is disposed.
return false;
}
Expand Down Expand Up @@ -638,12 +642,13 @@ public CompletableFuture<ArrayList<DiagnosticsNode>> getChildren() {
final JsonArray jsonArray = json.get("children").getAsJsonArray();
final ArrayList<DiagnosticsNode> nodes = new ArrayList<>();
for (JsonElement element : jsonArray) {
DiagnosticsNode child = new DiagnosticsNode(element.getAsJsonObject(), inspectorService, app,false, parent);
DiagnosticsNode child = new DiagnosticsNode(element.getAsJsonObject(), inspectorService, app, false, parent);
child.setParent(this);
nodes.add(child);
}
children = CompletableFuture.completedFuture(nodes);
} else if (hasChildren()) {
}
else if (hasChildren()) {
children = inspectorService.thenComposeAsync((service) -> {
if (service == null) {
return null;
Expand Down Expand Up @@ -720,12 +725,12 @@ ArrayList<DiagnosticsNode> trackPropertiesMatchingParameters(ArrayList<Diagnosti
@NotNull
public CompletableFuture<String> getPropertyDoc() {
if (propertyDocFuture == null) {
propertyDocFuture = createPropertyDocFurure();
propertyDocFuture = createPropertyDocFuture();
}
return propertyDocFuture;
}

private CompletableFuture<String> createPropertyDocFurure() {
private CompletableFuture<String> createPropertyDocFuture() {
final DiagnosticsNode parent = getParent();
if (parent != null) {
return inspectorService.thenComposeAsync((service) -> service.toDartVmServiceValueForSourceLocation(parent.getValueRef())
Expand All @@ -734,23 +739,26 @@ private CompletableFuture<String> createPropertyDocFurure() {
return CompletableFuture.completedFuture(null);
}
return inspectorService.getNow(null).getPropertyLocation(vmValue.getInstanceRef(), getName())
.thenApplyAsync((XSourcePosition sourcePosition) -> {
if (sourcePosition != null) {
final VirtualFile file = sourcePosition.getFile();
final int offset = sourcePosition.getOffset();

final Project project = getProject(file);
if (project != null) {
final List<HoverInformation> hovers =
DartAnalysisServerService.getInstance(project).analysis_getHover(file, offset);
if (!hovers.isEmpty()) {
return hovers.get(0).getDartdoc();
.thenApplyAsync((XSourcePosition sourcePosition) -> {
if (sourcePosition != null) {
final VirtualFile file = sourcePosition.getFile();
final int offset = sourcePosition.getOffset();

final Project project = getProject(file);
if (project != null) {
final List<HoverInformation> hovers =
DartAnalysisServerService.getInstance(project).analysis_getHover(file, offset);
if (!hovers.isEmpty()) {
return hovers.get(0).getDartdoc();
}
}
}
}
return "Unable to find property source";
});
}));
return "Unable to find property source";
});
})).exceptionally(t -> {
LOG.info("ignoring exception from toObjectForSourceLocation: " + t.toString());
return null;
});
}

return CompletableFuture.completedFuture("Unable to find property source");
Expand Down Expand Up @@ -834,7 +842,8 @@ public <T> void safeWhenComplete(CompletableFuture<T> future, BiConsumer<? super
}
group.safeWhenComplete(future, action);
});
} catch (Exception e) {
}
catch (Exception ignored) {
// Nothing to do if the service can't be acquired.
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e -> ignored for IntelliJ inspections.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
Expand Down
2 changes: 1 addition & 1 deletion src/io/flutter/inspector/InspectorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static CompletableFuture<InspectorService> create(@NotNull FlutterApp app
@NotNull FlutterDebugProcess debugProcess,
@NotNull VmService vmService) {
assert app.getVMServiceManager() != null;
Set<String> inspectorLibraryNames = new HashSet<>();
final Set<String> inspectorLibraryNames = new HashSet<>();
inspectorLibraryNames.add("package:flutter/src/widgets/widget_inspector.dart");
inspectorLibraryNames.add("package:flutter_web/src/widgets/widget_inspector.dart");
final EvalOnDartLibrary inspectorLibrary = new EvalOnDartLibrary(
Expand Down
14 changes: 1 addition & 13 deletions src/io/flutter/run/FlutterReloadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindowId;
Expand Down Expand Up @@ -72,10 +71,6 @@
* Handle the mechanics of performing a hot reload on file save.
*/
public class FlutterReloadManager {
private static final String RESTART_SUGGESTED_TEXT =
"Not all changed program elements ran during view reassembly; consider restarting ("
+ (SystemInfo.isMac ? "⇧⌘S" : "⇧^S") + ").";

private static final Logger LOG = Logger.getInstance(FlutterReloadManager.class);

private static final Map<String, NotificationGroup> toolWindowNotificationGroups = new HashMap<>();
Expand Down Expand Up @@ -175,7 +170,7 @@ private void handleSaveAllNotification(@Nullable Editor editor) {
return;
}

if (!app.getLaunchMode().supportsReload()) {
if (!app.getLaunchMode().supportsReload() || !app.appSupportsHotReload()) {
return;
}

Expand Down Expand Up @@ -211,10 +206,6 @@ private void handleSaveAllNotification(@Nullable Editor editor) {
notification.expire();
showRunNotification(app, "Hot Reload Error", result.getMessage(), true);
}
else if (result.isRestartRecommended()) {
notification.expire();
showRunNotification(app, "Reloading…", RESTART_SUGGESTED_TEXT, false);
}
else {
// Make sure the reloading message is displayed for at least 2 seconds (so it doesn't just flash by).
final long delay = Math.max(0, 2000 - (System.currentTimeMillis() - startTime));
Expand All @@ -238,9 +229,6 @@ private void reloadApp(@NotNull FlutterApp app, @NotNull String reason) {
if (!result.ok()) {
showRunNotification(app, "Hot Reload", result.getMessage(), true);
}
else if (result.isRestartRecommended()) {
showRunNotification(app, "Reloading…", RESTART_SUGGESTED_TEXT, false);
}
}).exceptionally(throwable -> {
showRunNotification(app, "Hot Reload", throwable.getMessage(), true);
return null;
Expand Down
Loading