typespec icon indicating copy to clipboard operation
typespec copied to clipboard

[IDE] For unused `using` statement, strike thru with yellow line and offer a 💡 quick fix to remove used ones

Open allenjzhang opened this issue 1 year ago • 1 comments

Clear and concise description of the problem

  • It has been very prevalent for folks to copy .tsp files around and kept bunch of unused using statements. 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.

allenjzhang avatar May 16 '24 08:05 allenjzhang

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.

timotheeguerin avatar May 16 '24 15:05 timotheeguerin

Earlier issue to add linter rule: https://github.com/microsoft/typespec/issues/2196

mikeharder avatar May 23 '24 01:05 mikeharder

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.

RodgeFu avatar Jun 04 '24 03:06 RodgeFu

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

timotheeguerin avatar Jun 04 '24 15:06 timotheeguerin

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.

RodgeFu avatar Jun 05 '24 03:06 RodgeFu