Use auto-imports for isolatedDeclarations fixes#4422
Open
DanielRosenwasser wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the isolatedDeclarations “missing type annotation on exports” code fix to use the auto-import system so that the fix can add required imports (including import type) when the inferred annotation references types from files that aren’t currently imported (Fixes #4411).
Changes:
- Wire
autoimport.ImportAdderinto the isolated-declarations type annotation fixer and include its edits in produced code actions (single-fix and fix-all). - Propagate
createImportAdder/auto-import preparation errors through the code action pipeline. - Add a new fourslash regression test covering annotation + auto-import when the type originates in an unimported file.
Show a summary per file
| File | Description |
|---|---|
| internal/ls/codeactions_fixmissingtypeannotation.go | Use ImportAdder to add imports for synthesized types during isolatedDeclarations annotation fixes. |
| internal/fourslash/tests/codeFixMissingTypeAnnotationOnExportsUsingTypeFromUnimportedFile_test.go | Regression test ensuring the fix adds a type annotation and a new import type when needed. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 1
Comment on lines
1217
to
+1221
| referenceTypeNode, importableSymbols := autoimport.TryGetAutoImportableReferenceFromTypeNode(typeNode, idToSymbol) | ||
| if referenceTypeNode != nil { | ||
| typeNode = referenceTypeNode | ||
| f.symbolsToImport = append(f.symbolsToImport, importableSymbols...) | ||
| if f.importAdder != nil { | ||
| for _, symbol := range importableSymbols { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4411.