Skip to content

Commit 7adfbad

Browse files
authored
Fix the FlutterDependencyInspection for the analyzer workspaces (#8428)
This resolves #7623 Additional work may be needed for non-flutter pubspecs (i.e. the Dart IJ plugin)
1 parent 8788eac commit 7adfbad

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/io/flutter/FlutterUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.intellij.openapi.project.Project;
1717
import com.intellij.openapi.project.ProjectManager;
1818
import com.intellij.openapi.roots.*;
19+
import com.intellij.openapi.util.text.StringUtil;
1920
import com.intellij.openapi.vfs.LocalFileSystem;
2021
import com.intellij.openapi.vfs.VfsUtil;
2122
import com.intellij.openapi.vfs.VirtualFile;
@@ -61,6 +62,7 @@ public static class FlutterPubspecInfo {
6162

6263
private boolean flutter = false;
6364
private boolean plugin = false;
65+
private boolean resolutionWorkspace = false;
6466

6567
FlutterPubspecInfo(long modificationStamp) {
6668
this.modificationStamp = modificationStamp;
@@ -74,6 +76,10 @@ public boolean isFlutterPlugin() {
7476
return plugin;
7577
}
7678

79+
public boolean isResolutionWorkspace() {
80+
return resolutionWorkspace;
81+
}
82+
7783
public long getModificationStamp() {
7884
return modificationStamp;
7985
}
@@ -360,6 +366,13 @@ public static FlutterPubspecInfo getFlutterPubspecInfo(@NotNull final VirtualFil
360366
if (flutterEntry instanceof Map) {
361367
info.plugin = ((Map<?, ?>)flutterEntry).containsKey("plugin");
362368
}
369+
370+
// Check for resolution configuration.
371+
// https://dart.dev/tools/pub/workspaces
372+
final Object resolutionEntry = yamlMap.get("resolution");
373+
if (resolutionEntry instanceof String) {
374+
info.resolutionWorkspace = StringUtil.equals((String)resolutionEntry, "workspace");
375+
}
363376
}
364377
}
365378
catch (IOException e) {

src/io/flutter/inspections/FlutterDependencyInspection.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
public class FlutterDependencyInspection extends LocalInspectionTool {
3939
private final Set<String> myIgnoredPubspecPaths = new HashSet<>(); // remember for the current session only, do not serialize
4040

41-
@Nullable
4241
@Override
43-
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
42+
public ProblemDescriptor @Nullable [] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
4443
if (!isOnTheFly) return null;
4544

4645
if (!(psiFile instanceof DartFile)) return null;

src/io/flutter/pub/PubRoot.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ public boolean declaresFlutter() {
245245
return cachedPubspecInfo.declaresFlutter();
246246
}
247247

248+
/**
249+
* Returns true if the pubspec declares "resolution: workspace".
250+
*/
251+
public boolean declaresResolutionWorkspace() {
252+
validateUpdateCachedPubspecInfo();
253+
assert cachedPubspecInfo != null;
254+
return cachedPubspecInfo.isResolutionWorkspace();
255+
}
256+
248257
/**
249258
* Check if the cache needs to be updated.
250259
*/
@@ -274,7 +283,15 @@ public boolean isNonEditableFlutterModule() {
274283

275284
@Nullable
276285
public VirtualFile getPackageConfigFile() {
277-
final VirtualFile tools = root.findChild(DOT_DART_TOOL);
286+
VirtualFile rootToExpectToolsDirectory = root;
287+
288+
// If this package.yaml file has resolution:workspace declared, check in the parent directory for
289+
// the .dart_tool/ directory.
290+
// https://github.com/flutter/flutter-intellij/issues/7623
291+
if (cachedPubspecInfo.isResolutionWorkspace()) {
292+
rootToExpectToolsDirectory = root.getParent();
293+
}
294+
final VirtualFile tools = rootToExpectToolsDirectory.findChild(DOT_DART_TOOL);
278295
if (tools == null || !tools.isDirectory()) {
279296
return null;
280297
}

0 commit comments

Comments
 (0)