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

Add new keyword code fix #2077

Merged
merged 3 commits into from
Dec 22, 2016

Conversation

vasily-kirichenko
Copy link
Contributor

image

@forki
Copy link
Contributor

forki commented Dec 22, 2016

Cool,should it also change let to use?

@@ -108,6 +108,7 @@ type internal FSharpAddOpenCodeFixProvider
assemblyContentProvider: AssemblyContentProvider
) =
inherit CodeFixProvider()
let fixableDiagnosticIds = ["FS0039"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please apply the same pattern to the other fix provider?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean? Introduce an extra field for diagnostic codes? why?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think both should follow similar pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's maybe better to introduce a base class, but, you know...

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't say that ;-)
Just saying if we find a common pattern than this is beneficial.

Copy link
Contributor

Choose a reason for hiding this comment

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

This acts upon FS0760

@vasily-kirichenko
Copy link
Contributor Author

Cool,should it also change let to use?

No. I think it was discussed somewhere on github, in short it's not always feasible to use use instead of let because it's completely legible to create a disposable object, but not bind it with use.

@forki
Copy link
Contributor

forki commented Dec 22, 2016

Yeah, but if we suggest with reasonable explanation then it can still be useful. And people can ignore suggestions, right?

@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in Filename... should be AddNewKeywordToDisposableConstructorInvocation.fs

Copy link
Contributor Author

@vasily-kirichenko vasily-kirichenko Dec 22, 2016

Choose a reason for hiding this comment

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

Thanks :)

@vasily-kirichenko
Copy link
Contributor Author

Yeah, but if we suggest with reasonable explanation then it can still be useful. And people can ignore suggestions, right?

This require writing an Analyzer which would emit special warning, then a Code Fix should be written, which suggests possible fixes. This PR is so simple because the compiler emits a warning itself.

@forki
Copy link
Contributor

forki commented Dec 22, 2016 via email

@cartermp
Copy link
Contributor

cartermp commented Dec 22, 2016

This is fantastic. With respect to use, I think it's one of those areas of the language where we'll have to make a decision on what we want people to ultimately be using. Both usages are valid, but if we agree that there is a preferred way that the IDE should drive you towards, we can modify this to suggest that way.

This is somewhat related to work that the C#/VB IDE team is doing, where code fixes recognize older patterns and attempt to push people towards adoption of newer language features.


override this.RegisterCodeFixesAsync context : Task =
async {
let title = "Add \"new\" keyword"
Copy link
Member

@KevinRansom KevinRansom Dec 22, 2016

Choose a reason for hiding this comment

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

Localizable text ?

Copy link
Contributor Author

@vasily-kirichenko vasily-kirichenko Dec 22, 2016

Choose a reason for hiding this comment

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

Yes. Could you explain how to do it? (maybe it's worth to add a guide somewhere into DEVGUIDE.md?)

Copy link
Member

Choose a reason for hiding this comment

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

@vasily-kirichenko
I will submit a PR with the fix and then we can have a document that points to commit with the changes ... that seems like the most straightforward approach.

Kevin

@smoothdeveloper
Copy link
Contributor

@cartermp, both use and let are valid and have different semantics so I don't think there is a way to have a single selection.

I agree having both proposed (let being first) would make sense.

@cartermp
Copy link
Contributor

@smoothdeveloper Right, but this is why I think it's worth having a discussion about how to approach code fixes in general. There are lots of cases where there are multiple valid ways to do something. In some cases it's best to show all options, and in other cases it may be best to show the preferred option. This is something we'll just have to evaluate on a case-by-case basis.

@KevinRansom KevinRansom merged commit 162e572 into dotnet:master Dec 22, 2016
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
* "add 'new' keyword" code fix

* "add open" code fix returns FS0039 as "fixed" diagnostics (only)

* fix a typo in file name
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.

7 participants