-
Notifications
You must be signed in to change notification settings - Fork 745
Port codeactions import fixes to new autoimport stack #2149
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
base: autoimport
Are you sure you want to change the base?
Conversation
andrewbranch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot this looks like a good start. Instead of mixing the new fix and old fix types, can you keep the existing logic for UMD and type-only fixes, but modify it to produce autoimport.Fix types? You can add fields to that struct if necessary.
Done in 675a3f4. I've converted both UMD and type-only fixes to produce
|
|
@copilot I updated the base branch to finish eliminating usage of the old types from codeactions_importfixes.go. There are now 25 tests failing with |
I've made progress on porting the fix logic. Key changes:
This fixes TestImportNameCodeFix_importType5, importType6, typeOnly, and AutoImportTypeOnlyPreferred1. ~21 tests remain (namespace imports, JSX, CommonJS features not yet ported). Note: There's a rebase conflict with the remote branch that prevented pushing. |
- Replace getExportInfos() with view.Search() to find exports - Replace getImportFixes() with view.GetFixes() for each export - Use autoimport.Fix.Edits() instead of codeActionForFixWorker for new fixes - Export View.CompareFixes for use in sorting - Keep UMD and type-only promotion using old stack for now (via oldFix field) - Update sortFixInfo to handle both new and old-style fixes Co-authored-by: andrewbranch <[email protected]>
Co-authored-by: andrewbranch <[email protected]>
- Add TypeOnlyAliasDeclaration field to autoimport.Fix - Implement PromoteTypeOnly case in Fix.Edits() - Move promoteFromTypeOnly and helper functions to autoimport package - Convert UMD fixes from old ImportFix to new autoimport.Fix via converter - Remove oldFix field from fixInfo struct - now all fixes use autoimport.Fix - Simplify getImportCodeActions to only handle autoimport.Fix type Co-authored-by: andrewbranch <[email protected]>
675a3f4 to
1bcf069
Compare
|
@copilot I resolved merge conflicts, but I think you had some work that never got pushed, related to this:
I don't know if you're able to retrieve it. At any rate, you should be able to continue without problems now. Please keep working on the failing tests. Prioritize ones that currently panic, followed by ones that return no codefixes but should. Pro tip: for tests that report a panic like you can better see the stack trace by temporarily commenting out the body of |
- Fix nil pointer dereference when accessing ImportClause on side-effect imports - Add isValidTypeOnlyUseSite parameter to GetFixes and GetCompletions - Add getAddAsTypeOnly function to compute AddAsTypeOnly value - Fix topLevelTypeOnly logic to handle named-imports-only case correctly - Propagate AddAsTypeOnly through fix generation pipeline Co-authored-by: andrewbranch <[email protected]>
I've recovered and pushed the changes. Fixed in commit 1e0ca2b:
Tests fixed: TestImportNameCodeFixExistingImport5, TestImportNameCodeFix_typeOnly Remaining 21 tests need:
|
|
@copilot can you focus on the JSDoc import type fixes next please |
- Add UsagePosition field to Fix struct for JSDoc import type fixes - Add usagePosition parameter to GetFixes function - Implement AutoImportFixKindJsdocTypeImport case in Edits() to insert import(...) prefix - Check if file is JS and export is pure type to use JSDoc import type syntax - Fix AddToExisting to properly use addAsTypeOnly for import specifiers Fixes: - TestImportNameCodeFix_importType (JSDoc import type in JS files) - TestImportNameCodeFix_importType3 (type-only import specifiers) Co-authored-by: andrewbranch <[email protected]>
Implemented in 46f3e40. Added support for JSDoc import type fixes:
Tests fixed: TestImportNameCodeFix_importType, TestImportNameCodeFix_importType3 |
Change silent failure to panic with descriptive message when UsagePosition is nil Co-authored-by: andrewbranch <[email protected]>
Port codeactions import fixes to new autoimport stack
Summary
This PR continues the migration of auto-import codefixes from the old
SymbolExportInfo-based system to the newautoimport.Registry/autoimport.Viewinfrastructure.Changes
JSDoc import type fixes
UsagePositionfield toFixstructusagePositionparameter toGetFixes()functionAutoImportFixKindJsdocTypeImportcase inEdits()to insertimport("./a").Tprefiximport()syntax instead of adding import statementsType-only import handling
isValidTypeOnlyUseSiteparameter toGetFixes()andGetCompletions()getAddAsTypeOnly()function to compute theAddAsTypeOnlyvalueAddToExistingto properly useaddAsTypeOnlywhen creating import specifierstopLevelTypeOnlycondition to handle named-imports-only caseBug fixes
tryAddToExistingImportfor side-effect imports (check for nil ImportClause)Tests now passing
Tests remaining: 19 failing
Most remaining failures are related to:
Original prompt
Created from VS Code.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.