Skip to content

Add ImportAdder API - #1063

Merged
mattwar merged 6 commits into
dotnet:masterfrom
mattwar:ImportAdder
Mar 9, 2015
Merged

Add ImportAdder API#1063
mattwar merged 6 commits into
dotnet:masterfrom
mattwar:ImportAdder

Conversation

@mattwar

@mattwar mattwar commented Mar 5, 2015

Copy link
Copy Markdown
Contributor

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.

@mattwar

mattwar commented Mar 5, 2015

Copy link
Copy Markdown
Contributor Author

@Pilchie, @DustinCampbell, @srivatsn, @jasonmalinowski please review and comment.

@mattwar

mattwar commented Mar 5, 2015

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete?

@gafter gafter added the Area-IDE label Mar 6, 2015

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Class

That 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 Class

or this:

Imports System.Collections

Public Class C

    Public F1 As ArrayList
    Public F2 As Generic.List(Of Integer)

End Class

Which one is more "VB"? Do we need an option to control that behavior?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably a different feature.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@srivatsn

srivatsn commented Mar 7, 2015

Copy link
Copy Markdown
Contributor

👍

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider swapping using Microsoft.CodeAnalysis.Simplification; and using Microsoft.CodeAnalysis.Shared.Extensions; to preserve lexical ordering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants