typespec
typespec copied to clipboard
[IDE] For unused `using` statement, strike thru with yellow line and offer a 💡 quick fix to remove used ones
Clear and concise description of the problem
- It has been very prevalent for folks to copy .tsp files around and kept bunch of unused
usingstatements. These has causing compilation failures with recent deprecation causing name conflict from different namespaces. - The import statement also suffers from this with people importing existing files/packages in TSP. It will be great to de-dup the import and only keep the ones in main.tsp
Checklist
- [X] Follow our Code of Conduct
- [X] Read the docs.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
it shouldn't be a warning unless you have a linter that does that, but it can be fadeout like typescript with unused variables.
This is also something not simple to implement as it would need to be a core change in the checker to keep track of used using per file and then a way for the lsp to collect that. The LSP shouldn't try to find after the fact if something is unused as this will be very costly.
Earlier issue to add linter rule: https://github.com/microsoft/typespec/issues/2196
Did some investigation, the fadeout in vscode is actually done through the diagnostic directly, so when we have linter to report diagnostic for these unused stuff (with DiagnosticTag.Unnecessary tagged), they will be fade out automatically.
I think its a little more than a linter, our diagnostic do not have this tag we can add, so would need to design how we want to report such things and how to collect them
More doc about the diagnostic tag from vscode: https://vscode-api.js.org/enums/vscode.DiagnosticTag.html#Unnecessary
How about having one more item in the SymbolLinks to record reference relationship when checker doing the check? It feels a little similar to the relationship between template and its instantiations. And also, this info would be very helpful for other cases like FindAllReferences especially in perf.