6
6
package io .flutter .utils ;
7
7
8
8
//import static com.android.tools.idea.gradle.project.importing.GradleProjectImporter.ANDROID_PROJECT_TYPE;
9
+
9
10
import static com .intellij .util .ReflectionUtil .findAssignableField ;
10
11
import static io .flutter .actions .AttachDebuggerAction .ATTACH_IS_ACTIVE ;
11
12
import static io .flutter .actions .AttachDebuggerAction .findRunConfig ;
18
19
import com .intellij .debugger .impl .DebuggerManagerListener ;
19
20
import com .intellij .debugger .impl .DebuggerSession ;
20
21
import com .intellij .execution .RunManagerEx ;
22
+ import com .intellij .execution .configurations .RunConfiguration ;
21
23
import com .intellij .openapi .actionSystem .DataContext ;
22
24
import com .intellij .openapi .application .Application ;
23
25
import com .intellij .openapi .application .ApplicationManager ;
24
26
import com .intellij .openapi .module .Module ;
25
- import com .intellij .openapi .project .ModuleListener ;
26
- import com .intellij .openapi .project .Project ;
27
- import com .intellij .openapi .project .ProjectType ;
28
- import com .intellij .openapi .project .ProjectTypeService ;
27
+ import com .intellij .openapi .project .*;
28
+ import com .intellij .openapi .vfs .LocalFileSystem ;
29
+ import com .intellij .openapi .vfs .VirtualFile ;
29
30
import com .intellij .util .ThreeState ;
30
31
import com .intellij .util .concurrency .AppExecutorUtil ;
31
32
import com .intellij .util .messages .MessageBusConnection ;
32
33
import com .intellij .util .messages .Topic ;
33
34
import io .flutter .FlutterUtils ;
34
35
import io .flutter .actions .AttachDebuggerAction ;
35
36
import io .flutter .pub .PubRoot ;
37
+ import io .flutter .run .SdkAttachConfig ;
36
38
import io .flutter .run .SdkRunConfig ;
37
39
import io .flutter .sdk .FlutterSdk ;
40
+ import com .intellij .openapi .diagnostic .Logger ;
41
+
38
42
import java .lang .reflect .Field ;
39
43
import java .lang .reflect .Modifier ;
40
44
import java .util .List ;
41
45
import java .util .Objects ;
46
+
42
47
import org .jetbrains .annotations .NonNls ;
43
48
import org .jetbrains .annotations .NotNull ;
44
49
import org .jetbrains .annotations .Nullable ;
45
50
46
51
public class AddToAppUtils {
52
+ //private static final Logger LOG = Logger.getInstance(AddToAppUtils.class);
47
53
48
54
private AddToAppUtils () {
49
55
}
@@ -126,7 +132,6 @@ public void sourceGenerationFinished(@NotNull Project project) {
126
132
127
133
@ NotNull
128
134
private static DebuggerManagerListener makeAddToAppAttachListener (@ NotNull Project project ) {
129
-
130
135
return new DebuggerManagerListener () {
131
136
132
137
DebugProcessListener dpl = new DebugProcessListener () {
@@ -144,22 +149,22 @@ public void processAttached(@NotNull DebugProcess process) {
144
149
return ;
145
150
}
146
151
// Launch flutter attach if a run config can be found.
147
- if (findRunConfig (project ) == null ) {
152
+ @ Nullable RunConfiguration runConfig = findRunConfig (project );
153
+ if (runConfig == null ) {
148
154
// Either there is no Flutter run config or there are more than one.
149
- if (RunManagerEx .getInstanceEx (project ).getSelectedConfiguration () instanceof SdkRunConfig ) {
150
- // The selected run config at this point is not Flutter, so we can't start the process automatically.
151
- return ;
152
- }
155
+ return ;
156
+ }
157
+ if (!(runConfig instanceof SdkAttachConfig )) {
158
+ // The selected run config at this point is not Flutter, so we can't start the process automatically.
159
+ return ;
153
160
}
154
161
FlutterSdk sdk = FlutterSdk .getFlutterSdk (project );
155
162
if (sdk == null ) {
156
163
return ;
157
164
}
158
165
// If needed, DataContext could be saved by FlutterReloadManager.beforeActionPerformed() in project user data.
159
166
DataContext context = DataContext .EMPTY_CONTEXT ;
160
- List <Module > modules = FlutterModuleUtils .findModulesWithFlutterContents (project );
161
- assert modules .size () == 1 ; // TODO(messick) Need to change this if multiple :flutter sub-projects supported.
162
- PubRoot pubRoot = PubRoot .forDirectory (Objects .requireNonNull (modules .get (0 ).getModuleFile ()).getParent ());
167
+ PubRoot pubRoot = ((SdkAttachConfig )runConfig ).pubRoot ;
163
168
Application app = ApplicationManager .getApplication ();
164
169
project .putUserData (ATTACH_IS_ACTIVE , ThreeState .fromBoolean (true ));
165
170
// Note: Using block comments to preserve formatting.
0 commit comments