Skip to content

Support "Add Dependency" quickfix when a dev_dependency is used in a public file#5914

Merged
DanTup merged 1 commit intomasterfrom
fix-add-dep-quickfix
Feb 19, 2026
Merged

Support "Add Dependency" quickfix when a dev_dependency is used in a public file#5914
DanTup merged 1 commit intomasterfrom
fix-add-dep-quickfix

Conversation

@DanTup
Copy link
Member

@DanTup DanTup commented Feb 19, 2026

Fixes #5913

@DanTup DanTup added this to the v3.130.0 milestone Feb 19, 2026
@DanTup DanTup added is bug fix in editor Relates to code editing or language features labels Feb 19, 2026
@DanTup DanTup requested a review from Copilot February 19, 2026 14:12
@DanTup
Copy link
Member Author

DanTup commented Feb 19, 2026

@codex review

/gemini review

@gemini-code-assist
Copy link

I've reviewed this pull request, and the changes look good. The implementation correctly addresses the issue of conditionally offering "Add Dependency" quickfixes based on the file's location.

Overall Feedback

The changes are well-structured and directly solve the problem described in the pull request title and linked issue. The introduction of the includeDevDependencies flag centralizes the logic for determining whether to consider dev_dependencies, which improves readability and maintainability. The new test case effectively validates the intended behavior.

Detailed Review

File: src/extension/providers/add_dependency_code_action_provider.ts

  • Relocation of projectRoot and pubspecPath initialization (Diff 1): Moving these operations after the initial diagnostic filtering is a good optimization, as they are only needed if relevant diagnostics exist. (Severity: low)
  • Logic for includeDevDependencies (Diff 1): The condition !(document.uri.path.includes("/lib/") || document.uri.path.includes("/bin/")) accurately determines if the file is in a public-facing directory, which is crucial for the PR's objective. (Severity: none)
  • Parameter Propagation (Diffs 1, 2, 3): The includeDevDependencies flag is correctly passed through getDependenciesForPubspec and createActions using object destructuring, which is a clean way to handle new parameters. (Severity: none)
  • Conditional dev_dependencies inclusion (Diff 2): The includeDevDependencies && yaml?.dev_dependencies check ensures that dev_dependencies are only processed when appropriate, aligning with the PR's goal. (Severity: none)
  • Centralized Logic (Diff 4): Replacing the direct path check with the includeDevDependencies flag in createActions improves consistency and maintainability. (Severity: none)

File: src/test/dart/pub/add.test.ts

  • New Test Case (Diff 1): The added test case "can add from a quick fix if listed only in dev_dependencies and imported from lib" provides excellent coverage for the new logic, specifically verifying that the correct quickfix options are presented based on the file's location. (Severity: none)

Style Guide Adherence

I've reviewed the code with general TypeScript best practices in mind. The changes adhere to a clear and consistent coding style, using meaningful variable names and clear logic. No specific style guide violations were found.

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #5913 where the "Add 'package' to dependencies" quickfix was not showing when a dev_dependency was used in a public file (lib/ or bin/). The fix ensures that when a package exists only in dev_dependencies but is imported from lib/ or bin/, the quickfix offers to add it to dependencies (and doesn't offer the dev_dependencies option, since that would be incorrect for public files).

Changes:

  • Modified the dependency filtering logic to exclude dev_dependencies when determining if a package already exists in the pubspec, for files in lib/ or bin/
  • Adjusted the code action creation to only offer the dev_dependencies option for files outside lib/ and bin/
  • Added test coverage to verify that the fix works correctly for packages listed only in dev_dependencies when imported from lib/

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/extension/providers/add_dependency_code_action_provider.ts Added logic to determine whether to include dev_dependencies based on file location (lib/bin vs other), and updated filtering and action creation accordingly
src/test/dart/pub/add.test.ts Added test case to verify that quickfix correctly offers only "Add to dependencies" (not "Add to dev_dependencies") when a dev_dependency is used in lib/

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.60%. Comparing base (4b88acb) to head (011bcd5).

Files with missing lines Patch % Lines
...n/providers/add_dependency_code_action_provider.ts 37.50% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5914      +/-   ##
==========================================
- Coverage   67.64%   67.60%   -0.04%     
==========================================
  Files         169      169              
  Lines       12979    12980       +1     
  Branches     2566     2567       +1     
==========================================
- Hits         8779     8775       -4     
- Misses       3745     3749       +4     
- Partials      455      456       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DanTup DanTup force-pushed the fix-add-dep-quickfix branch from 011bcd5 to f5f86e7 Compare February 19, 2026 15:02
@DanTup DanTup merged commit e378249 into master Feb 19, 2026
41 of 43 checks passed
@DanTup DanTup deleted the fix-add-dep-quickfix branch February 19, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in editor Relates to code editing or language features is bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add 'package' to dependencies - false-negative

2 participants