8000 Add special case to object creation completion to not commit 'object' on '{' by DustinCampbell · Pull Request #4117 · dotnet/roslyn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add special case to object creation completion to not commit 'object' on '{' #4117

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

Merged
merged 3 commits into from
Jul 27, 2015

Conversation

DustinCampbell
Copy link
Member

When completion preselects 'object', it becomes very cumbersome for a user to type 'new {' to create an anonymous object. Instead, they get 'new object {' inserted into the editor, which is never really desirable since System.Object doesn't have any properties. This tweak changes completion not to commit in the very specific case of typing '{' when the underlying preselected completion item is System.Object.

Fixes issue #4115.

… on '{'.

When completion preselects 'object', it becomes very cumbersome for a user to type 'new {' to create an anonymous object. Instead, they get 'new object {' inserted into the editor, which is never really desirable since System.Object doesn't have any properties. This tweak changes completion not to commit in the very specific case of typing '{' when the underlying preselected completion item is System.Object.

Fixes issue dotnet#4115.
@DustinCampbell
Copy link
Member Author

Reviewers: @rchande, @dpoeschl, @Pilchie, @jasonmalinowski.

void M1()
{
M2(new
}
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem right to me. Shouldn't { be in the editor after this?

Copy link
Member

Choose a reason for hiding this comment

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

If { isn't a commit chat, does the list actually dismiss, or does it stay up with nothing selected?

Copy link
Member Author

Choose a reason for hiding this comment

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

The unit test infrastructure is weird here. We're testing the TextChange that gets inserted by the completion item but it doesn't actually type the character into the editor.

Copy link
Member Author

Choose a reason for hiding this comment

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

'{' should dismiss the completion list since we're no longer typing a word.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. As long as you have verified that behavior, I'll 👍

Maybe a comment about the expected result in the test here though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing. I'm not really keen on this test infrastructure. I may take a look at cleaning that up to better state expectations.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I went ahead and updated the unit test infrastructure.

@dpoeschl
Copy link
Contributor

👍

…characters

Ensure that the VerifyProviderCommit helper correctly inserts commit characters into the editor (or at least a reasonable approximation) to allow unit tests using this helper to better state their expectations.
// properties, the user never really wants to commit 'new object {' anyway.
var namedTypeSymbol = (completionItem as SymbolCompletionItem)?.Symbols.FirstOrDefault() as INamedTypeSymbol;
if (namedTypeSymbol?.SpecialType == SpecialType.System_Object)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you verify that this item was really preselected (either by checking the preselect bit or the type of the provider)? What if I'm trying to commit "object" with '{' and it wasn't preselected (not that anyone necessarily does 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.

Because this rule is only for items returned by the ObjectCreationCompletionProvider, all of the items are preselected. Other "objects" that appear in the list will come from different providers (like the symbol or keyword completion providers) and not have this rule. Thus, they continue to commit on '{'.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. I'd forgotten that you had made that change.

@rchande
Copy link
Contributor
rchande commented Jul 27, 2015

👍

@DustinCampbell
Copy link
Member Author

jenkins, retest this please.

@DustinCampbell DustinCampbell added this to the 1.1 milestone Jul 27, 2015
@DustinCampbell DustinCampbell self-assigned this Jul 27, 2015
DustinCampbell added a commit that referenced this pull request Jul 27, 2015
Add special case to object creation completion to not commit 'object' on '{'
@DustinCampbell DustinCampbell merged commit 4643ff5 into dotnet:master Jul 27, 2015
@DustinCampbell DustinCampbell deleted the fix-4115 branch July 27, 2015 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0