Add ImportAdder API - #1063
Conversation
|
@Pilchie, @DustinCampbell, @srivatsn, @jasonmalinowski please review and comment. |
|
The ImportAdder functions in a manner that should be able to replace the feature of the old code generator that auto-added namespaces for references in new code when it is added. There may be other ways to think about this feature, or better names used to describe it. |
There was a problem hiding this comment.
Are there VB-specific tests needed for partial namespaces? For example:
Imports System.Collections
Public Class C
Public F1 As ArrayList
Public F2 As System.Collections.Generic.List(Of Integer)
End ClassThat code could reduce to this:
Imports System.Collections
Imports System.Collections.Generic
Public Class C
Public F1 As ArrayList
Public F2 As List(Of Integer)
End Classor this:
Imports System.Collections
Public Class C
Public F1 As ArrayList
Public F2 As Generic.List(Of Integer)
End ClassWhich one is more "VB"? Do we need an option to control that behavior?
There was a problem hiding this comment.
That's probably a different feature.
There was a problem hiding this comment.
I wouldn't think so. I would expect it would be an optional style preference that the ImportAdder would respect. We wouldn't need it right now though. I was just wondering if a unit test would be useful to ensure that it's clear what the expected behavior is (I assume it's the first reduction).
|
👍 |
There was a problem hiding this comment.
Consider swapping using Microsoft.CodeAnalysis.Simplification; and using Microsoft.CodeAnalysis.Shared.Extensions; to preserve lexical ordering.
The ImportAdder allows you to promote explicit namespace references in your source into using directives & imports statements, that can then be simplified away using the Simplifier.
Also added the ability to simplify using directives/imports statements via the simplifier. Annotated usings/imports that are unused in the document get removed.