Skip to content
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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

RodgeFu
Copy link
Contributor

@RodgeFu RodgeFu commented Nov 19, 2024

When "using" and "import" are not needed, dim them and provide quickfix in IDE.

related issues:
#3373 , #4861

@RodgeFu RodgeFu changed the title Unused import namespace When "using" and "import" are not needed, dim them and provide quickfix in IDE. Nov 19, 2024
@RodgeFu RodgeFu changed the title When "using" and "import" are not needed, dim them and provide quickfix in IDE. Report diagnostics for unused "using" and "import" so that they will be shown properly in ide Nov 19, 2024
@azure-sdk
Copy link
Collaborator

azure-sdk commented Nov 19, 2024

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - feature ✏️

Support diagnostics for unused import and using statements

@RodgeFu RodgeFu added the ide Issues for VS, VSCode, Monaco, etc. label Nov 19, 2024
// the projection statements will only be processed when applying projection. There is no way to determine
// whether "import" or "using" is referenced from them, so we just skip here to avoid providing incorrect suggestions (diagnostics)
// This should be fine for now considering projection is an experiemental feature.
for (const node of processedProjections) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timotheeguerin , I tried to check the project part code and can't find a way to identify the references as commented here. Please let me know if there is some way I missed to count them considering my knowledge in compiler is still limited. thanks.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs

@@ -164,6 +169,7 @@ export async function createSourceLoader(
if (options?.getCachedScript) {
const old = options.getCachedScript(file);
if (old?.file === file && deepEquals(old.parseOptions, options.parseOptions)) {
mutate(old).importedBy = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timotheeguerin , I am not very comfortable modifying the old object here, but I can't find a better place to put the importedBy information. Any suggestion here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ide Issues for VS, VSCode, Monaco, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants