Skip to content

Fix the FlutterDependencyInspection for the analyzer workspaces #8428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/io/flutter/FlutterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
Expand Down Expand Up @@ -61,6 +62,7 @@ public static class FlutterPubspecInfo {

private boolean flutter = false;
private boolean plugin = false;
private boolean resolutionWorkspace = false;

FlutterPubspecInfo(long modificationStamp) {
this.modificationStamp = modificationStamp;
Expand All @@ -74,6 +76,10 @@ public boolean isFlutterPlugin() {
return plugin;
}

public boolean isResolutionWorkspace() {
return resolutionWorkspace;
}

public long getModificationStamp() {
return modificationStamp;
}
Expand Down Expand Up @@ -360,6 +366,13 @@ public static FlutterPubspecInfo getFlutterPubspecInfo(@NotNull final VirtualFil
if (flutterEntry instanceof Map) {
info.plugin = ((Map<?, ?>)flutterEntry).containsKey("plugin");
}

// Check for resolution configuration.
// https://dart.dev/tools/pub/workspaces
final Object resolutionEntry = yamlMap.get("resolution");
if (resolutionEntry instanceof String) {
info.resolutionWorkspace = StringUtil.equals((String)resolutionEntry, "workspace");
}
}
}
catch (IOException e) {
Expand Down
3 changes: 1 addition & 2 deletions src/io/flutter/inspections/FlutterDependencyInspection.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
public class FlutterDependencyInspection extends LocalInspectionTool {
private final Set<String> myIgnoredPubspecPaths = new HashSet<>(); // remember for the current session only, do not serialize

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
public ProblemDescriptor @Nullable [] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
if (!isOnTheFly) return null;

if (!(psiFile instanceof DartFile)) return null;
Expand Down
19 changes: 18 additions & 1 deletion src/io/flutter/pub/PubRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ public boolean declaresFlutter() {
return cachedPubspecInfo.declaresFlutter();
}

/**
* Returns true if the pubspec declares "resolution: workspace".
*/
public boolean declaresResolutionWorkspace() {
validateUpdateCachedPubspecInfo();
assert cachedPubspecInfo != null;
return cachedPubspecInfo.isResolutionWorkspace();
}

/**
* Check if the cache needs to be updated.
*/
Expand Down Expand Up @@ -274,7 +283,15 @@ public boolean isNonEditableFlutterModule() {

@Nullable
public VirtualFile getPackageConfigFile() {
final VirtualFile tools = root.findChild(DOT_DART_TOOL);
VirtualFile rootToExpectToolsDirectory = root;

// If this package.yaml file has resolution:workspace declared, check in the parent directory for
// the .dart_tool/ directory.
// https://github.com/flutter/flutter-intellij/issues/7623
if (cachedPubspecInfo.isResolutionWorkspace()) {
rootToExpectToolsDirectory = root.getParent();
}
final VirtualFile tools = rootToExpectToolsDirectory.findChild(DOT_DART_TOOL);
if (tools == null || !tools.isDirectory()) {
return null;
}
Expand Down