Fsharp: VFPT-like Unused Declaration and Symbol graying

Created on 1 Feb 2017  路  10Comments  路  Source: dotnet/fsharp

The Visual F# Power Tools featured automatic 'graying' of unused open declarations and unused symbols. (Although unused opens wasn't 100% reliable).

I think this would be a great feature to port over to the main extension.

Area-IDE Language Service Feature Request

Most helpful comment

@vasily-kirichenko you're a Roslyn god

All 10 comments

FYI @vasily-kirichenko, there are two issues I've found with the VFPT unused open feature:

  • Type aliases were not considered, so if you had an open just for a type alias, the open would be marked as unused.
  • If SomeNamespace cannot be opened due to a missing reference (e.g. a C# type extension exists in SomeNamespace for a type that is defined in an assembly not referenced by the current F# project), then open SomeNamespace.SubNamespace would always be marked as unused. I'm not too worried about this issue as I've already worked around it by putting the C# type extensions from the referenced project in the same namespace as the types they are extending.

I'm against porting the old VFPT code. It's too inefficient and, in case of graying out opens, is inherently unreliable. We should reimplement it from scratch, on lower level.

@vasily-kirichenko any inkling as to where it would need to be reimplemented? Perhaps it could surface as a lightbulb codefix? I'm not sure how tied to ISymbol the Roslyn code is, but perhaps there's some stuff that could be ported over as well.

I'm not talking about the UI part, it's obviously need to be rewritten, but it's the easy part. I meant the actual algorithm. In VFPT I found all private and internal declarations in a file, then called GetUsesOfSymbolInProject _for each one_, which is not super efficient as we have to iterate all resolution in a project as many times as we have private declarations in a file, see https://github.com/Microsoft/visualfsharp/blob/master/src/fsharp/NameResolution.fs#L1372. Maybe that's not a big deal, but quadratic complexity is not a very good thing in general.

What about graying out unused opens, the implementation is hacky and unreliable and I was fixing it many times and I don't like to go this track one more time. Maybe later, when I know the compiler and the service better, I will re-implement it the right way, but not now.

Sounds perfectly reasonable 馃憤

@vasily-kirichenko just to be clear, are you saying that you don't think greying unused opens is worth it? And that greying unused symbols is worth the effort/is reliable (I've found it to be reliable in 2015 at least)

@saul Yes, graying unused private and internal symbols is reliable and simple, but not very efficient, I'm looking at it now. But unused opens... No, sometime later.

@vasily-kirichenko you're a Roslyn god

Implemented!

Was this page helpful?
0 / 5 - 0 ratings