Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove direct dependency on CommandLineParser #1876

Merged
merged 4 commits into from
Apr 4, 2017
Merged

Remove direct dependency on CommandLineParser #1876

merged 4 commits into from
Apr 4, 2017

Conversation

brettfo
Copy link
Member

@brettfo brettfo commented Mar 28, 2017

This is based off of @srivatsn's work in #1670.

I wanted to get this out for review, but since #1670 hasn't been merged yet, I'm including those commits just so that stuff will build. I'll re-base from master before merging, but I really just wanted to get some feedback about this, first. As such, you should only be considering the last commit made by me. Refer to Sri's PR for the rest of the work.

In short, this PR removes the dependence on the type CommandLineParser because it has numerous internal components and deriving from that for F# would either require additional InternalsVisibleTo elements in the Roslyn code base (which we don't want) or it would require making numerous types and APIs public, which seems heavy-handed. So the solution I went with simply adds an interface that has one Parse() method that matches CommandLineParser.Parse() exactly so that F# can play along, too.

This work is dependent on my other PR, dotnet/roslyn#18258.

get { return new VisualBasicParseCommandLineArguments(); }
}

internal class VisualBasicParseCommandLineArguments : IParseCommandLineArguments
Copy link
Member

Choose a reason for hiding this comment

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

Instead of continuing with the Export property approach, turn this inner class into the actual thing that is exporting.


internal class VisualBasicParseCommandLineArguments : IParseCommandLineArguments
{
private VisualBasicCommandLineParser _parser = VisualBasicCommandLineParser.Default;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you even need a field here - why can you just call through Default property in the Parse method?

@davkean
Copy link
Member

davkean commented Mar 29, 2017

While this removes the dependency on CommandLineParser - it still has a dependency on CommandLineArguments won't this suffer the same problem?

Copy link
Member

@davkean davkean left a comment

Choose a reason for hiding this comment

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

As above.

@brettfo
Copy link
Member Author

brettfo commented Mar 29, 2017

I've made some changes as requested by @davkean by factoring out a class that only contains the properties consumed on Microsoft.CodeAnalysis.CommandLineArguments.

There is one oddity, left, however: If I try to export the command line parser classes directly then I get the error:

Attribute 'AppliesToAttribute' comes from a different version of MEF than the export attribute on 'CSharpParseCommandLineArguments'

But I get no error when I use an [ImportingConstructor] and export the property, even though I simply copy/paste the attributes. Any ideas?

Edit:
And the only Roslyn change required to make this work for F# is in dotnet/roslyn#18258. As it stands this will still work for C#/VB.

@srivatsn
Copy link
Contributor

I think that warning comes from a buggy analyzer and the warning's been suppressed in other projects.

@@ -25,6 +25,7 @@
<ProjectReference Include="..\DeployTestDependencies\DeployTestDependencies.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\Microsoft.VisualStudio.ProjectSystem.CSharp\Microsoft.VisualStudio.ProjectSystem.CSharp.csproj" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this right? Seems like a layer violation - managed.unittests shouldn't know about C#

Copy link
Member

Choose a reason for hiding this comment

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

Indeed.

CSharpCommandLineParser.Default.Parse(args, baseDirectory, sdkDirectory: null, additionalReferenceDirectories: null));
}

[Export(typeof(IParseCommandLineArguments))]
Copy link
Member

Choose a reason for hiding this comment

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

Apply this to the class, the property is unneeded.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do; I'll have to disable the analyzer as per @srivatsn's comment.


public CommandLineArguments Parse(IEnumerable<string> args, string baseDirectory)
{
return CommandLineArguments.FromCommonCommandLineArguments(
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why you need this?

Copy link
Member

Choose a reason for hiding this comment

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

I see below why, sync up with me and we can discuss the approach.


namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices
{
public class CSharpParseCommandLineArguments : IParseCommandLineArguments
Copy link
Member

Choose a reason for hiding this comment

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

Mark this internal.


namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices
{
public class CommandLineArguments
Copy link
Member

Choose a reason for hiding this comment

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

You can't do this - your throwing away all options. TBH, I'm not sure how this is compiling - we pass this over to IWorkspaceContext as a CommandLineArguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

I searched for all references to the Microsoft.CodeAnalysis.CommandLineArguments type and only the four properties reflected in this class were ever used.

Copy link
Member

Choose a reason for hiding this comment

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

I see, we used to pass this thing as SetOptions but now we pass a string. I stand corrected. If you're doing the work here to open this up, why do you still need to do this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I need to expose the constructors so F# can create these types that are still used after this PR is merged. I originally looked at opening up the entire Microsoft.CodeAnalysis.CommandLineArguments type but that quickly snowballed (Koala-balled? I'm having trouble coming up with an Australian version of this 😄) into exposing way more stuff than we probably ever wanted too.

Copy link
Member

Choose a reason for hiding this comment

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

@brettfo I'm still confuised, if we're opening up CommandLineArgunents why we do need to wrap the type?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're not opening up CommandLineArguments, because that quickly snowballed into opening up way more internal stuff than we'd like. I'm only opening up the constructors to the structs that this new type contains in its IEnumerable<> properties, and the properties on this class are the only things that were being used, anyways.

Copy link
Member

@davkean davkean left a comment

Choose a reason for hiding this comment

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

As above.

@brettfo
Copy link
Member Author

brettfo commented Mar 30, 2017

Updated with review feedback as per @davkean.

@brettfo
Copy link
Member Author

brettfo commented Apr 4, 2017

Ping for review now that I've fixed the latest merge conflicts.

@davkean
Copy link
Member

davkean commented Apr 4, 2017

Okay, can we change the name of the type CommandLineArguments so that it doesn't conflict with the Code Analysis version and I can sign off.

@brettfo
Copy link
Member Author

brettfo commented Apr 4, 2017

Given that the class doesn't have much to do with the command line any more I propose BuildOptions (maybe DesignTimeBuildOptions?) and I'll also rename IParseCommandLineArguments appropriately.

@davkean
Copy link
Member

davkean commented Apr 4, 2017

BuildOptions sounds good.

@brettfo brettfo merged commit 2e9680b into dotnet:master Apr 4, 2017
@brettfo brettfo deleted the fsharp-support branch April 4, 2017 22:23
@srivatsn srivatsn mentioned this pull request May 25, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants