Skip to content

Commit e699f85

Browse files
committed
Recreate branch due to git pilot error
1 parent ecf5560 commit e699f85

File tree

14 files changed

+951
-21
lines changed

14 files changed

+951
-21
lines changed

flutter-idea/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ dependencies {
7777
testImplementation(fileTree(mapOf("dir" to "${project.rootDir}/artifacts/ideaIC/plugins/git4idea/lib",
7878
"include" to listOf("*.jar"))))
7979
}
80+
compileOnly("com.google.guava:guava:31.0.1-jre")
81+
compileOnly("com.google.code.gson:gson:2.9.0")
82+
testImplementation("com.google.guava:guava:31.0.1-jre")
83+
testImplementation("com.google.code.gson:gson:2.9.0")
8084
compileOnly(fileTree(mapOf("dir" to "${project.rootDir}/third_party/lib/jxbrowser",
8185
"include" to listOf("*.jar"))))
8286
testImplementation(fileTree(mapOf("dir" to "${project.rootDir}/third_party/lib/jxbrowser",

flutter-idea/src/io/flutter/FlutterInitializer.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import com.intellij.openapi.roots.ProjectRootManager;
2626
import com.intellij.openapi.startup.StartupActivity;
2727
import com.intellij.openapi.vfs.VirtualFile;
28+
import com.jetbrains.lang.dart.analyzer.DartAnalysisServerService;
2829
import io.flutter.analytics.Analytics;
30+
import io.flutter.analytics.FlutterAnalysisServerListener;
2931
import io.flutter.analytics.ToolWindowTracker;
3032
import io.flutter.android.IntelliJAndroidSdk;
3133
import io.flutter.bazel.WorkspaceCache;
@@ -206,15 +208,15 @@ public void moduleAdded(@NotNull Project project, @NotNull Module module) {
206208
}
207209
}
208210
});
211+
boolean finalHasFlutterModule = hasFlutterModule;
209212
//noinspection DialogTitleCapitalization
210213
notification.addAction(new AnAction("Sounds good!") {
211214
@Override
212215
public void actionPerformed(@NotNull AnActionEvent event) {
213216
notification.expire();
214-
final Analytics analytics = getAnalytics();
215217
// We only track for flutter projects.
216-
if (FlutterModuleUtils.declaresFlutter(project)) {
217-
ToolWindowTracker.track(project, analytics);
218+
if (finalHasFlutterModule) {
219+
enableAnalytics(project);
218220
}
219221
}
220222
});
@@ -230,12 +232,17 @@ public void actionPerformed(@NotNull AnActionEvent event) {
230232
}
231233
else {
232234
// We only track for flutter projects.
233-
if (FlutterModuleUtils.declaresFlutter(project)) {
234-
ToolWindowTracker.track(project, getAnalytics());
235+
if (hasFlutterModule) {
236+
enableAnalytics(project);
235237
}
236238
}
237239
}
238240

241+
private static void enableAnalytics(@NotNull Project project) {
242+
ToolWindowTracker.track(project, getAnalytics());
243+
DartAnalysisServerService.getInstance(project).addAnalysisServerListener(FlutterAnalysisServerListener.getInstance(project));
244+
}
245+
239246
private void initializeToolWindows(@NotNull Project project) {
240247
// Start watching for Flutter debug active events.
241248
FlutterViewFactory.init(project);

flutter-idea/src/io/flutter/analytics/Analytics.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void setCanSend(boolean value) {
7575
/**
7676
* Public for testing.
7777
*/
78-
public void setTransport(Transport transport) {
78+
public void setTransport(@NotNull Transport transport) {
7979
this.transport = transport;
8080
}
8181

@@ -85,38 +85,56 @@ public void sendScreenView(@NotNull String viewName) {
8585
sendPayload("screenview", args, null);
8686
}
8787

88-
public void sendEvent(String category, String action) {
88+
public void sendEvent(@NotNull String category, @NotNull String action) {
8989
sendEvent(category, action, null);
9090
}
9191

92-
public void sendEvent(String category, String action, @Nullable FlutterSdk flutterSdk) {
92+
public void sendEvent(@NotNull String category, @NotNull String action, @Nullable FlutterSdk flutterSdk) {
9393
final Map<String, String> args = new HashMap<>();
9494
args.put("ec", category);
9595
args.put("ea", action);
9696
sendPayload("event", args, flutterSdk);
9797
}
9898

99-
public void sendEventMetric(String category, String action, int value) {
99+
public void sendEventWithSdk(@NotNull String category, @NotNull String action, @NotNull String sdkVersion) {
100+
final Map<String, String> args = new HashMap<>();
101+
args.put("ec", category);
102+
args.put("ea", action);
103+
sendPayload("event", args, null, sdkVersion);
104+
}
105+
106+
public void sendEventMetric(@NotNull String category, @NotNull String action, int value) {
100107
final Map<String, String> args = new HashMap<>();
101108
args.put("ec", category);
102109
args.put("ea", action);
103110
args.put("ev", Integer.toString(value));
104111
sendPayload("event", args, null);
105112
}
106113

107-
public void sendTiming(String category, String variable, long timeMillis) {
114+
public void sendEvent(@NotNull String category, @NotNull String action, @NotNull String label, @NotNull String value) {
115+
final Map<String, String> args = new HashMap<>();
116+
args.put("ec", category);
117+
args.put("ea", action);
118+
if (!label.isEmpty()) {
119+
args.put("el", label);
120+
}
121+
args.put("ev", value);
122+
sendPayload("event", args, null);
123+
}
124+
125+
public void sendTiming(@NotNull String category, @NotNull String variable, long timeMillis) {
108126
final Map<String, String> args = new HashMap<>();
109127
args.put("utc", category);
110128
args.put("utv", variable);
111129
args.put("utt", Long.toString(timeMillis));
112130
sendPayload("timing", args, null);
113131
}
114132

115-
public void sendExpectedException(String location, Throwable throwable) {
133+
public void sendExpectedException(@NotNull String location, @NotNull Throwable throwable) {
116134
sendEvent("expected-exception", location + ":" + throwable.getClass().getName());
117135
}
118136

119-
public void sendException(String throwableText, boolean isFatal) {
137+
public void sendException(@NotNull String throwableText, boolean isFatal) {
120138
String description = throwableText;
121139
description = description.replaceAll("com.intellij.openapi.", "c.i.o.");
122140
description = description.replaceAll("com.intellij.", "c.i.");
@@ -133,6 +151,10 @@ public void sendException(String throwableText, boolean isFatal) {
133151
}
134152

135153
private void sendPayload(@NotNull String hitType, @NotNull Map<String, String> args, @Nullable FlutterSdk flutterSdk) {
154+
sendPayload(hitType, args, flutterSdk, null);
155+
}
156+
157+
private void sendPayload(@NotNull String hitType, @NotNull Map<String, String> args, @Nullable FlutterSdk flutterSdk, @Nullable String sdkVersion) {
136158
if (!canSend()) {
137159
return;
138160
}
@@ -156,6 +178,8 @@ private void sendPayload(@NotNull String hitType, @NotNull Map<String, String> a
156178
if (flutterVersion.getVersionText() != null) {
157179
args.put("cd2", flutterVersion.getVersionText());
158180
}
181+
} else if (sdkVersion != null) {
182+
args.put("cd2", sdkVersion);
159183
}
160184

161185
// Record whether this client uses bazel.
@@ -259,4 +283,4 @@ public void send(String url, Map<String, String> values) {
259283
});
260284
}
261285
}
262-
}
286+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package io.flutter.analytics;
2+
3+
import com.intellij.openapi.project.Project;
4+
import com.intellij.openapi.project.ProjectManager;
5+
6+
import com.jetbrains.lang.dart.ide.completion.DartCompletionTimerExtension;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
import java.time.Instant;
11+
12+
/**
13+
* Implementation of the {@link DartCompletionTimerExtension} which allows the Flutter plugin to
14+
* measure the total time to present a code completion to the user.
15+
*/
16+
public class DartCompletionTimerListener extends DartCompletionTimerExtension {
17+
@Nullable FlutterAnalysisServerListener dasListener;
18+
@Nullable Long startTimeMS;
19+
20+
@Override
21+
public void dartCompletionStart() {
22+
if (dasListener == null) {
23+
Project project = ProjectManager.getInstance().getDefaultProject();
24+
dasListener = FlutterAnalysisServerListener.getInstance(project);
25+
}
26+
startTimeMS = Instant.now().toEpochMilli();
27+
}
28+
29+
@Override
30+
public void dartCompletionEnd() {
31+
if (dasListener != null && startTimeMS != null) {
32+
long durationTimeMS = Instant.now().toEpochMilli() - startTimeMS;
33+
dasListener.logE2ECompletionSuccessMS(durationTimeMS); // test: logE2ECompletionSuccessMS()
34+
startTimeMS = null;
35+
}
36+
}
37+
38+
/**
39+
* The parameters match those of {@link org.dartlang.analysis.server.protocol.RequestError}, they
40+
* are not used currently because our hypothesis is that this method will never be called.
41+
*/
42+
@Override
43+
public void dartCompletionError(
44+
@NotNull String code, @NotNull String message, @NotNull String stackTrace) {
45+
if (dasListener != null && startTimeMS != null) {
46+
long durationTimeMS = Instant.now().toEpochMilli() - startTimeMS;
47+
dasListener.logE2ECompletionErrorMS(durationTimeMS); // test: logE2ECompletionErrorMS()
48+
startTimeMS = null;
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)