Skip to content

Commit a8d3f98

Browse files
authored
"Pubspec has been edited" is stuck in Android Studio Koala resolution (flutter#7541)
This resolves flutter#7538
1 parent c05f49c commit a8d3f98

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

flutter-idea/src/io/flutter/inspections/FlutterDependencyInspection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private ProblemDescriptor[] createProblemDescriptors(@NotNull final InspectionMa
8787
}
8888

8989
private interface SdkAction {
90-
void run(FlutterSdk sdk, @NotNull PubRoot root, @NotNull Project project);
90+
Process run(FlutterSdk sdk, @NotNull PubRoot root, @NotNull Project project);
9191
}
9292

9393
private static class PackageUpdateFix extends IntentionAndQuickFixAction {
@@ -126,6 +126,8 @@ public void applyFix(@NotNull final Project project, @NotNull final PsiFile psiF
126126

127127
// TODO(skybrian) analytics?
128128
mySdkAction.run(sdk, root, project);
129+
130+
DaemonCodeAnalyzer.getInstance(project).restart(psiFile);
129131
}
130132
}
131133

@@ -158,7 +160,7 @@ public boolean startInWriteAction() {
158160
@Override
159161
public void applyFix(@NotNull final Project project, @NotNull final PsiFile psiFile, @Nullable final Editor editor) {
160162
myIgnoredPubspecPaths.add(myPubspecPath);
161-
DaemonCodeAnalyzer.getInstance(project).restart();
163+
DaemonCodeAnalyzer.getInstance(project).restart(psiFile);
162164
}
163165
}
164166
}

flutter-idea/src/io/flutter/pub/PubRoot.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.jetbrains.annotations.NotNull;
2525
import org.jetbrains.annotations.Nullable;
2626

27+
import java.io.File;
2728
import java.util.List;
2829
import java.util.Map;
2930

@@ -281,7 +282,6 @@ public VirtualFile getPackagesFile() {
281282
if (packages != null && !packages.isDirectory()) {
282283
return packages;
283284
}
284-
285285
return null;
286286
}
287287

@@ -300,19 +300,27 @@ public VirtualFile getPackagesFile() {
300300
}
301301

302302
/**
303-
* Returns true if the packages are up to date wrt pubspec.yaml.
303+
* Returns true if the packages are up-to-date with regard to the `pubspec.yaml`. The `.packages` file is used if no
304+
* `.tool/package_config.json` is found. The default value returned is to return false.
304305
*/
305306
public boolean hasUpToDatePackages() {
307+
// See context at these URLs for the reason we can't use VirtualFile#getTimeStamp()
308+
// https://github.com/flutter/flutter-intellij/issues/7538
309+
// https://intellij-support.jetbrains.com/hc/en-us/community/posts/8009750602514-VirtualFile-is-not-refreshed
310+
306311
final VirtualFile configFile = getPackageConfigFile();
307312
if (configFile != null) {
308-
return pubspec.getTimeStamp() < configFile.getTimeStamp();
313+
long pubspecLastModified = new File(pubspec.getPath()).lastModified();
314+
long configLastModified = new File(configFile.getPath()).lastModified();
315+
return pubspecLastModified < configLastModified;
309316
}
310317
final VirtualFile packagesFile = getPackagesFile();
311-
if (packagesFile == null) {
312-
return false;
318+
if (packagesFile != null) {
319+
long pubspecLastModified = new File(pubspec.getPath()).lastModified();
320+
long packagesLastModified = new File(packagesFile.getPath()).lastModified();
321+
return pubspecLastModified < packagesLastModified;
313322
}
314-
315-
return pubspec.getTimeStamp() < packagesFile.getTimeStamp();
323+
return false;
316324
}
317325

318326
@Nullable

0 commit comments

Comments
 (0)