-
Notifications
You must be signed in to change notification settings - Fork 230
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
Add a diagnostic for unused imports in nargo language server #4762
Comments
Additional Context: |
This would be a great DevEx add 👍 If anyone is interested in contributing, feel free to create a PR / comment below. |
# Description ## Problem Resolves #4762 ## Summary The compiler now produces a warning on unused imports. ## Additional Context I don't know if this is the correct approach. I added a new HashSet to track imported names, then those are removed as we import things. I thought about tracking this in `ItemScope` but it's tricky because the way things are they include imported and self things. There's another thing: eventually it would be nice to warn on unused types, like in Rust. For that maybe it would make sense to track this in `ItemScope`... but given that we currently don't have visibility modifiers for types, it can't be done right now. So maybe doing it just for imports with specific code is fine. I had to refactor a bit `resolve_path` because some paths were looked up not using that method and so some things weren't marked as used... but now `StandardPathResolver::new` is used in exactly one place in the compiler. ## Documentation Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
Problem
When refactoring Noir code, developers face the challenge of manually adjusting imports, as there is currently no automated way to generate required imports or remove unused ones. This manual process results in tedious and error-prone import management.
Noir Docs
Example Noir Code with Modules
Happy Case
The Noir VSCode extension has the potential to alleviate this problem by communicating with the Nargo language server. This communication enables the extension to provide import-related diagnostics and actions, streamlining the import management process for developers.
Project Impact
While not critical, integrating automated import management into the Noir VSCode extension would greatly enhance the development experience by reducing manual effort and improving code cleanliness.
Impact Context
Without automated import management, developers must spend significant time and effort managing imports manually during refactoring, which hampers productivity and introduces the risk of errors.
Workaround
None
Workaround Description
No response
Additional Context
Noir already supports unused variables diagnostic and it's very useful
Existing Functionality
Noir already has a language server implemented, residing in the repository under tooling/lsp. This server provides some functionality, such as reporting unused variables, which are highlighted in the IDE by the Noir extension. However, it currently does not report unused imports. Adding support for this functionality is the focus of this issue.
Proposal for Resolution
Integrate automated import management features into the Noir VSCode extension, leveraging the capabilities of the existing Noir language server. This includes adding support for reporting and addressing unused imports, similar to the existing functionality for unused variables.
Would you like to submit a PR for this Issue?
Maybe
Support Needs
While the implementation of this feature is feasible, it may require collaboration with the community and feedback from project maintainers to ensure alignment with project goals and standards.
The text was updated successfully, but these errors were encountered: