Skip to content

Commit

Permalink
Filter out json formatting (flutter#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemessick authored Sep 28, 2016
1 parent d7d73f5 commit 725f725
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ file.
* In the project structure dialog, configure an IntelliJ platform SDK
- point it to the `Contents` directory in your just downloaded copy of IntelliJ Community Edition (e.g, `IntelliJ IDEA CE.app/Contents`)
- name it `IntelliJ IDEA Community Edition`
* In order to have the platform sources handy, clone the IntelliJ IDEA Community Edition repo (`git clone https://github.com/JetBrains/intellij-community`) and add a path to your local clone in the `Sourcepaths` tab of your `IntelliJ IDEA Community Edition` SDK and accept all the root folders found by the IDE after scanning.
* In order to have the platform sources handy, clone the IntelliJ IDEA Community Edition repo
(`git clone https://github.com/JetBrains/intellij-community`) and add a path to your local clone in the `Sourcepaths` tab of
your `IntelliJ IDEA Community Edition` SDK and accept all the root folders found by the IDE after scanning.
Do the same for the intellij-plugins repo to get Dart plugin sources.
* Open flutter-intellij project in IntelliJ. Build it using `Build` > `Make Project`
* Try running the plugin; there is an existing launch config for "Flutter IntelliJ".
* If the Flutter Plugin doesn't load, check to see if the Dart Plugin is installed in your runtime workbench; if it's not, install it (`Preferences > Plugins`) and re-launch.
Expand Down
3 changes: 2 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
</actions>

<extensions defaultExtensionNs="com.intellij">


<consoleInputFilterProvider implementation="io.flutter.run.daemon.DaemonJsonInputFilterProvider" />?
<postStartupActivity implementation="io.flutter.FlutterInitializer"/>
<applicationService serviceInterface="io.flutter.run.daemon.FlutterDaemonService"
serviceImplementation="io.flutter.run.daemon.FlutterDaemonService"/>
Expand Down
26 changes: 26 additions & 0 deletions src/io/flutter/run/FlutterAppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,28 @@
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.RuntimeConfigurationError;
import com.intellij.execution.filters.Filter;
import com.intellij.execution.filters.TextConsoleBuilder;
import com.intellij.execution.filters.TextConsoleBuilderImpl;
import com.intellij.execution.filters.UrlFilter;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.Separator;
import com.intellij.openapi.project.Project;
import com.intellij.util.net.NetUtils;
import com.jetbrains.lang.dart.ide.runner.DartConsoleFilter;
import com.jetbrains.lang.dart.ide.runner.DartRelativePathsConsoleFilter;
import com.jetbrains.lang.dart.ide.runner.server.DartCommandLineRunningState;
import com.jetbrains.lang.dart.ide.runner.server.OpenDartObservatoryUrlAction;
import io.flutter.run.daemon.ConnectedDevice;
import io.flutter.run.daemon.FlutterApp;
import io.flutter.run.daemon.FlutterDaemonService;
import io.flutter.run.daemon.RunMode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -31,6 +39,7 @@
public class FlutterAppState extends DartCommandLineRunningState {

private FlutterApp myApp;
private ConsoleView myConsole;

protected FlutterAppState(ExecutionEnvironment environment) throws ExecutionException {
super(environment);
Expand Down Expand Up @@ -74,6 +83,12 @@ protected AnAction[] createActions(final ConsoleView console, final ProcessHandl
return actions.toArray(new AnAction[actions.size()]);
}

protected ConsoleView createConsole(@NotNull final Executor executor) throws ExecutionException {
myConsole = super.createConsole(executor);
myApp.setConsole(myConsole);
return myConsole;
}

protected void addObservatoryActions(List<AnAction> actions, final ProcessHandler processHandler) {
actions.add(new Separator());
actions.add(new OpenDartObservatoryUrlAction(
Expand All @@ -92,4 +107,15 @@ public int getObservatoryPort() {
public FlutterApp getApp() {
return myApp;
}

private static class JsonStringFilter implements Filter {

@Nullable
@Override
public Result applyFilter(String line, int entireLength) {
if (line.startsWith("[{") && line.endsWith("}]\n"))
return new Result(0, entireLength, null);
return null;
}
}
}
37 changes: 37 additions & 0 deletions src/io/flutter/run/daemon/DaemonJsonInputFilterProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2016 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
package io.flutter.run.daemon;

import com.intellij.execution.filters.ConsoleInputFilterProvider;
import com.intellij.execution.filters.InputFilter;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;

public class DaemonJsonInputFilterProvider implements ConsoleInputFilterProvider {

@NotNull
@Override
public InputFilter[] getDefaultFilters(@NotNull Project project) {
return new InputFilter[]{new DaemonJsonInputFilter()};
}

private static class DaemonJsonInputFilter implements InputFilter {
@Nullable
@Override
public List<Pair<String, ConsoleViewContentType>> applyFilter(String text, ConsoleViewContentType contentType) {
if (text.startsWith("[{") && text.endsWith("}]\n")) {
return Collections.singletonList(Pair.create(null, contentType));
}
return Collections.singletonList(Pair.create(text, contentType));
}
}
}
16 changes: 16 additions & 0 deletions src/io/flutter/run/daemon/FlutterApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package io.flutter.run.daemon;

import com.intellij.execution.ui.ConsoleView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -103,6 +104,10 @@ public interface FlutterApp {
* @return Unknown
*/
Object fetchRenderTree();

void setConsole(ConsoleView console);

ConsoleView getConsole();
}

class RunningFlutterApp implements FlutterApp {
Expand All @@ -116,6 +121,7 @@ class RunningFlutterApp implements FlutterApp {
private String myRoute;
private String myTarget;
private int myPort;
private ConsoleView myConsole;

public RunningFlutterApp(@NotNull FlutterDaemonService service,
@NotNull FlutterDaemonController controller,
Expand Down Expand Up @@ -225,4 +231,14 @@ public Object fetchWidgetHierarchy() {
public Object fetchRenderTree() {
throw new NoSuchMethodError("fetchRenderTree");
}

@Override
public void setConsole(ConsoleView console) {
myConsole = console;
}

@Override
public ConsoleView getConsole() {
return myConsole;
}
}
9 changes: 7 additions & 2 deletions src/io/flutter/run/daemon/FlutterAppManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.google.gson.*;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
Expand All @@ -24,6 +25,7 @@

/**
* Keeper of running Flutter apps.
* TODO(messick) Clean up myApps, myResponses as things change
*/
public class FlutterAppManager {

Expand Down Expand Up @@ -275,11 +277,14 @@ private Event eventHandler(@NotNull String eventName, @Nullable String json) {
}

private void eventLogMessage(@NotNull LogMessage message, @NotNull FlutterDaemonController controller) {
myLogger.info(message.message); // TODO(messick) Complete logging.
myLogger.info(message.message);
}

private void eventLogMessage(@NotNull AppLog message, @NotNull FlutterDaemonController controller) {
myLogger.info(message.log); // TODO(messick) Complete logging.
RunningFlutterApp app = findApp(controller, message.appId);
if (app != null && message.log != null) {
app.getConsole().print(message.log + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
}
}

private void eventDeviceAdded(@NotNull DeviceAdded added, @NotNull FlutterDaemonController controller) {
Expand Down

0 comments on commit 725f725

Please sign in to comment.