-
Notifications
You must be signed in to change notification settings - Fork 228
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
Report diagnostics for unused "using" and "import" so that they will be shown properly in ide #5146
Closed
Closed
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
77f8d17
support unused using and import
RodgeFu 0b32b3f
fix some tests
RodgeFu a22902a
Merge remote-tracking branch 'upstream/main' into unused-import-names…
RodgeFu b101142
fix some regressions
RodgeFu c0e36ac
add more test and fix some issues
RodgeFu 0d1d016
some small change
RodgeFu f721971
fix a bug from oldprogram
RodgeFu b0f1db8
handle oldprogram
RodgeFu aab4dd3
only report diagnostics for files in project
RodgeFu 3138407
update to only check unnecessary diagnostics in compiler's test
RodgeFu 603e8ed
some further update
RodgeFu 28b8643
fix sample test
RodgeFu 179c5b4
fix some tests
RodgeFu eb2e1fe
fix some tests
RodgeFu bf90961
fix test
RodgeFu 23933ed
Merge remote-tracking branch 'upstream/main' into unused-import-names…
RodgeFu 8625363
add changelog for change in rest test
RodgeFu 1954c14
Create unused-import-namespace-2024-10-23-11-18-0.md
RodgeFu 3f66d73
Merge branch 'main' into unused-import-namespace
RodgeFu 647f25e
Merge branch 'main' into unused-import-namespace
RodgeFu 9f5a77d
Merge branch 'main' into unused-import-namespace
RodgeFu 8104f1b
update to unused-import and unused-using
RodgeFu 6ab808d
fix failed test
RodgeFu f5db540
Merge branch 'main' into unused-import-namespace
RodgeFu 59182de
Merge branch 'main' into unused-import-namespace
RodgeFu b0af993
Merge remote-tracking branch 'upstream/main' into unused-import-names…
RodgeFu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.chronus/changes/unused-import-namespace-2024-10-18-21-32-11.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
changeKind: feature | ||
packages: | ||
- "@typespec/compiler" | ||
--- | ||
|
||
Support diagnostics for unused import and using statements |
8 changes: 8 additions & 0 deletions
8
.chronus/changes/unused-import-namespace-2024-10-23-11-18-0.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking | ||
changeKind: fix | ||
packages: | ||
- "@typespec/http-specs" | ||
--- | ||
|
||
Remove unnecessary "import" and "using" from tsp code |
7 changes: 7 additions & 0 deletions
7
.chronus/changes/unused-import-namespace-2024-10-23-19-12-55.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
changeKind: internal | ||
packages: | ||
- "@typespec/rest" | ||
--- | ||
|
||
Update test code to handle diagnostics for unnecessary code |
16 changes: 16 additions & 0 deletions
16
packages/compiler/src/core/compiler-code-fixes/remove-unnecessary-code.codefix.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineCodeFix, getSourceLocation } from "../diagnostics.js"; | ||
import { type ImportStatementNode, type UsingStatementNode } from "../types.js"; | ||
|
||
/** | ||
* Quick fix that remove unnecessary code. | ||
*/ | ||
export function removeUnnecessaryCodeCodeFix(node: ImportStatementNode | UsingStatementNode) { | ||
return defineCodeFix({ | ||
id: "remove-unnecessary-code", | ||
label: `Remove unnecessary code`, | ||
fix: (context) => { | ||
const location = getSourceLocation(node); | ||
return context.replaceText(location, ""); | ||
}, | ||
}); | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Nit: Should this be named
unused
? Does it make sense to have import/using - specific messages?I prefer
unused
overunnecessary
since the latter has a subjective connotation, and at least in TS,unused
is common for linter rules.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.
I am fine with "unused", update "unnecessary" to "unused-import" and "unused-using". thanks.