dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.92k stars 4.02k forks source link

IDE: Intellisense: Insert full method call #12363

Open WrongBit opened 8 years ago

WrongBit commented 8 years ago

When you type "object.fu", Intellisense inserts just "function", while full syntax is "object.function();". Why these parens and semicolon are skipped? I know sometimes I should insert arguments, but even in this case for me IDE could help jumping between parens (to continue typing) than skipping all punctuations at all.

Of course I don't ask it as an absolute behavior - let me choice option in IDE settings.

vbcodec commented 8 years ago

Improvement Not only Intellisense should write braces and semicolon, but also place cursor between braces (if function require parameters) with showing context menu, or behind semicolon (if function does not require parameters)

AlexBar commented 6 years ago

Resharper has such behavior by default from very beginning. It automatically adds "()" and "<>()" (for generics) and put cursor between braces. It's really sad that vs2017 doesn't have such option. Any chance it will be added in near future?

WrongBit commented 6 years ago

A whole year past and all MS did is.... contrast scheme! Definitely playing with colors is more easier than writing useful code.

CyrusNajmabadi commented 6 years ago

@WrongBit Would you be interested in contributing this feature yourself? I could help guide you on how you could go about implementing it!

Neme12 commented 6 years ago

This definitely needs to be configurable. I don't think I'd want this behavior personally.

WrongBit commented 6 years ago

@Neme12 : before dirtying conversation, read carefully original text:

Of course I don't ask it as an absolute behavior - let me choice option in IDE settings.

WrongBit commented 6 years ago

@CyrusNajmabadi : I can try (in a spare time), please give guide. MS just spread resources on useless features, while IDE (where we spend 99% time) is abandoned for 3rd party hobbyists.

CyrusNajmabadi commented 6 years ago

@WrongBit If you'd like, feel free to join the dotnet/roslyn gitter channel. I'm also @CyrusNajmabadi over there. I can help you out.

Note: i disagree with your assessment. Roslyn has done a ton of feature work over the past few years. Just take a look at the releases (or use github to diff things) to see how much has been added! :)

Neme12 commented 6 years ago

@WrongBit Sorry, it's my fault I missed that. I was just politely expressing my opinion, you don't need to take it personally. I'd be happy with you contributing this.

WrongBit commented 6 years ago

@Neme12 : sorry too, dude! When something really useful AT LAST requested for IDE, I expect people understand importance and HELP me, instead of expressing "I don't like that". It is useful, I cannot find even one scenario you wouldn't like behaviour I offered. Any comments??

WrongBit commented 6 years ago

@CyrusNajmabadi : I measure QUALITY, not "changed LOC". As a desktop/server developer I see very few useful things appear in IDE. Moreover: most of 'em HAD to be done in a first years VS exists at all. Say, "filtering members by type" in IntelliSense. I bet my eye this thing immediately was demanded, but mediocres sacrifice it in favor of other stupid features.

CyrusNajmabadi commented 6 years ago

I expect people understand importance and HELP me

I offered to help :) Feel free to come over to gitter.im and we can discuss things there.

As a desktop/server developer I see very few useful things appear in IDE.

Everyone is different. While you may not have found useful things appear, many others may have. A lot of work has gone in over the years into the Roslyn IDE (just check my own contributions, as well as the contributions of many community members, if you want to see :)). You may personally not have found them valuable, but that doesn't mean they haven't substantively contributed to a much better experience for many other customers.

I bet my eye this thing immediately was demanded, but mediocres sacrifice it in favor of other stupid features.

It would be really helpful if the conversation was kept civil. It doesn't help at all to demean people, nor does it make someone want to help you out with improving the features here. No one is calling you names, or stating that the things you care about are 'stupid'. The golden rule goes a long way. Thanks!

WrongBit commented 6 years ago

@CyrusNajmabadi : hiding behind "civil behaviour" don't eliminate GUILTY of some people for making mistakes, especially when they was warned about mistake. Would you hire again people who "mistakenly" put door upside down? Sure, not. Why you protect same people in IT? And if door is easy to fix, mistakes in language design cost us YEARS! Are you Duncan Mclaud to forgive everybody?? :) Me - not, I wish I could bar every guilty person from language team and redesign stuff. I know we all do mistakes, but one mistake made by lack of information, while other just because "I'm boss - I want to!". I despise such workers and unfortunately we have more and more such in IT. :( Wanna sample? Azure and about. Dead, "money suckers" technology. Count how many MS invest there!

CyrusNajmabadi commented 6 years ago

You catch more with honey than vinegar. 😄 Again, i'm available to chat about how you implement this feature over on gitter.im. If you would like to actually work toward this stated feature, i'm happy to help out over there.

I am not interested in debating with you your personal beliefs as to the quality of the work this team has produced or whether or not their decision have suited you or not. I don't think it's helpful or constructive. Thanks! :)

leandroklein commented 5 years ago

That will help a lot!

jinujoseph commented 5 years ago

Adding more notes

For example, if typing out a LINQ statement starting Array.Empty().Select( and pressing tab, define a skeleton lambda expression for the Func argument

grandslammer commented 5 years ago

I recently started learning C# after having used Eclipse for Java. I'm very surprised and disappointed that this option is not available in Visual Studio (without having to install the ReSharper plugin). In fact, I think that not only should this option be available, but it should also be enabled by default! There are many features I enjoy about Visual Studio over Eclipse, however, this is certainly the one thing I dislike about VS to date.

GuilhermeMorais commented 5 years ago

Guys, this issue it's close or still available to be implemented? If the help wanted still stand please say something. ;-)

CyrusNajmabadi commented 5 years ago

If the help wanted still stand please say something. ;-)

The 'help wanted' still stands.

WrongBit commented 5 years ago

Unfortunately until MS waste resources on games with "clouds" or Git, they will never have resources for really necessary things. So you need help not in coding, but eliminate mismanagement. Too much low qualified people in "top"! Note on date of issue: 3 YEARS(!) you cannot sit and organize team for this feature. Do you really think something can help you??

CyrusNajmabadi commented 5 years ago

@wrongbit my offer still stands. I'm helping @guilhermeMorais Over in gitter. Would you like to contribute your time and energy in a positive fashion instead of a negative one?

CyrusNajmabadi commented 5 years ago

Note on date of issue: 3 YEARS(!)

Many issues are far older. Length of issue is not the deciding factor. The concern is value to the community. Efforts are spent where there is the most bang/buck for the community and ecosystem as a whole. Thanks

rsujatinov commented 4 years ago

This single issue prevents me from using VS Code as my default editor for already 3 years. Will continue to work in WebStorm / Rider until this is fixed.

I think this is a big problem for every developer who is used to work with ReSharper - I would assume for majority of .NET developers.

Parentheses auto-opening has the same importance as parentheses and tags auto-closing. Imagine VS Code didn't have tags auto-closing, that would be a deal-breaker, and not a minor problem. Issues with typing experience should have the highest priority, as this is the main feature of code editors.

WrongBit commented 4 years ago

VS team even not assigned this issue to anybody. Guys, you don't need more people - you need more smart management of things you're busy with NOW. Fancy animation CAN WAIT. Azure CAN WAIT. Code editor CANNOT wait, because it's used for hours(!) (like @sujatinov said). You have huge problem with evaluating priorities. Feature I requested had to be done maybe after 2 years after VS was introduced. Fast coding is the primary goal of IDE, esp. when it eliminates syntax errors too.

Dreamescaper commented 4 years ago

Braces completion is fine (even though currently you can get it by using ( instead of Enter to commit completion). Especially would be great for that to work if I use ; or . to commit completion instead of Enter.

It's not clear to me how semicolon completion should work though. How should it behave if you want to continue method chain instead?

CyrusNajmabadi commented 4 years ago

@WrongBit my offer still stands. Would you like to contribute your time and energy in a positive fashion instead of a negative one? Feel free to come to to gitter or discord and we can work through this.

CyrusNajmabadi commented 4 years ago

Issues with typing experience should have the highest priority, as this is the main feature of code editors.

VS is more than a code editor. And tehre are millions of customers with many different needs. The primary needs of one group do not equate to being the primary needs for the entire ecosystem.

CyrusNajmabadi commented 4 years ago

VS team even not assigned this issue to anybody.

Correct. This is a 'help wanted' issue. i.e. it would accept a contribution from someone for whom this is important enough. @WrongBit you've expressed many times that this is a super important feature for you. If that's the case, would you be willing ton provide a contribution here? Given the extremely weight you give this work over others, it would make sense as something you could then give your own resources toward solving instead of demanding it from others.

Thanks!

CyrusNajmabadi commented 4 years ago

For gitter, you can go to: https://gitter.im/dotnet/roslyn For discord, the channel is #roslyn on the C# server.

Lots of people willing to discuss things and help out there. Cheers!

WrongBit commented 4 years ago

Still "help wanted"?!! Maybe you'll stop wasting time on sh**t like Azure (or Git) and make important feature?

CyrusNajmabadi commented 4 years ago

@sharwell I'd like to bring this to the next design meeting. It's very highly upvoted and would likely be something we could get done with hopefully low cost.

sharwell commented 4 years ago

Proposal:

  1. Consider allowing ;, when used as a completion character, to insert (); for calls
  2. Consider updating Smart Break Line to insert the full call (similar to ;), followed by a new line
  3. Consider adding an IntelliSense option (disabled by default), which modifies the completion behavior of Tab to behave the same as ( does today
  4. Consider using Tab, Tab to push an argument inference session onto the stack
    • An argument inference session shows a placeholder for each argument, and infers the initial value
    • Pressing Tab moves to the next argument
    • The argument inference session would bring up a Signature Help session showing overloads
    • Pressing Up or Down would cycle through the overloads
    • Each time an overload is selected, all unmodified arguments at or after the current position are re-inferred to match the new signature
    • Pressing Tab or ) at the end of the last argument completes the current argument inference session and pops it off the stack
    • Pressing ; performs the semicolon insertion logic, and completes/dismisses all argument inference sessions within the completed statement
CyrusNajmabadi commented 4 years ago

Note: i would personally prioritize the first three as simple tweaks to the existing model to get most/all of hte benefit that people seem to want. It seems like we could try those out and flight them very quickly to get feedback from people on how this feels (as i imagine we'll have to tweak things once people start really using it).

the TabTab idea is very novel and i think very high value. But it feels like a lot more work and may be something much more difficult to get people to adopt.

Fortunately, i think these approaches are complimentary. So doing one generally should not limit the other. So it's up to you what order you want to target things @sharwell

andreakarasho commented 4 years ago

i suggest to act as Resharper does:

sharwell commented 4 years ago

i suggest to act as Resharper does:

  • writing the method
  • tooltip appears
  • press TAB

@andreakarasho This is listed as part 3 of the proposal I listed.

allisonchou commented 4 years ago

Proposal for semicolon method completion

(To be discussed at 6/1/20 design meeting)

When used as a completion character, we propose allowing the inserting of of a semicolon character ; to complete method calls. The exception to this would be if we are assigning to a delegate type, in which case we would either maintain the existing behavior, or insert the just the semicolon.

Caret placement:

  1. If the method has a void return type and takes in no parameters, we insert the caret after the semicolon, e.g.
    Method();[||]
  2. If the method takes in any parameters, we insert the caret between the parentheses, e.g.
Method([||]);

with the ); likely having to be in brace completion mode.

  1. If the method has a non-void return type and takes in no parameters - see question below.

Questions: When using semicolon completion to complete a method with a non-void return type and no parameters, do we insert the caret before or after the semicolon? e.g.:

var x = Method()[||];

vs.

var x = Method();[||]
tetious commented 4 years ago

I like this!

One question: if a method has only optional parameters, will it behave as if it takes no parameters?

For your question: IMO, with a non-void return, the caret should go before the semicolon.

AdmiralSnyder commented 4 years ago

hey, if this issue gets to HelpWanted again, i'd be glad to work on it.

ashysh commented 4 years ago

@allisonchou well, that should be obvious: if you complete with ';' - put cursor at the end, put '();' before it. if you complete with '.' - put cursor at the end, put '().' before it. if you complete with tab/enter - make configurable option of if you should place ';' at all, and leave cursor at the end.

allisonchou commented 3 years ago

Notes from today's design meeting (10/26): @Cosifne is planning on implementing the items in Sam's proposal, in addition to implementing items 1-5 in Sam's SmartBreakLine proposal.

sharwell commented 3 years ago

I'm in the middle of implementing item (4) from https://github.com/dotnet/roslyn/issues/12363#issuecomment-602865938.

🚧 This comment is a work in progress for my ongoing implementation notes.

General items to resolve

Concerns about the Tab, Tab trigger

Pressing Tab twice works well for avoiding interference with historical completion behavior, but it doesn't translate well to nesting scenarios. After the user is already inside a Full Method Call snippet, the Tab key will move to the next snippet field instead of starting a nested snippet.

The most straightforward resolution to this is switching to single-Tab for invoking the Full Method Call snippet directly from the completion list, but we run the risk of users turning it off. Another possible resolution is defaulting to only triggering via a snippet trigger, but allowing the user to trigger directly from the completion list with an option. Nested snippet behavior would only be usable for the latter.

lorenpaulsen commented 3 years ago

For calls with no arguments (e.g. ToString()), where does the caret go when the action is triggered? Currently, I've implemented it using a placeholder argument, e.g. ToString($$)

My vote would be after the ), which I believe would be intuitive and efficient when there are no arguments, as it would put you in the best position to add a semicolon, chain another method, etc, afterward.

sharwell commented 3 years ago

as it would put you in the best position to add a semicolon, chain another method, etc, afterward.

Note that placing it inside the parentheses is equally as good for this. Typing ; at this location already moves the caret outside the (), and upcoming work from @Cosifne will make it do the same for ..

The major advantage for placing inside parentheses is it better handles cases of multiple overloads, where one of the signatures has no arguments but others do.

sharwell commented 3 years ago

Short demo showing the trigger, cycling through overloads, and finally pressing ; to accept the suggestion and complete the statement:

FullMethodCall

lorenpaulsen commented 3 years ago

As someone that has been monitoring this issue for a long time, this looks great!

ghost commented 3 years ago

As another person that has been monitoring this issue for some time, I also think this looks good.

I think it would be even better if after ; keypress the insertion point only moved to after the ; if the chosen overload has no arguments. e.g.

list.BinarySort();|

When the chosen overload has arguments it would be nicer if the insertion point was on first argument e.g.

list.BinarySearch(|index);
sharwell commented 3 years ago

@acrov We reviewed the caret positioning for ; and opted for consistency over trying to be too smart (and potentially confusing).

Considering that each item in completion may represent more than one symbol (overloaded methods with the same name), the above bindings do a great job of providing both predictability and flexibility for a variety of work strategies.

NTaylorMullen commented 3 years ago

Lots of talk on how this should work / concerns / suggestions. Recorded them in our design notes.

It was a very open discussion so not too many concrete conclusions to be summarized down to. That being said the general feel was in the effort to make the feature as solid as possible.

TanvirArjel commented 3 years ago

@sharwell Thank you so much for all the hard work you have done so far. However, could you please make sure that your current implementation putting the parentheses on the method call from IntelliSense? The gif you shared does not show anything like that.

Remember: Putting parenthesis automatically on method call is the first and foremost requirement, then others.

sharwell commented 3 years ago

However, could you please make sure that your current implementation putting the parentheses on the method call from IntelliSense?

This is not part of this round of the feature. This change would affect a primary muscle memory path going back 20 years for Visual Studio users, so it's going to be difficult and time consuming to get through the required design process and user studies. In the meantime, we have developed the feature shown above as a slight deviation from this but does not interfere with historical behaviors.

Note that even though the parentheses are not visible in completion lists, pressing Tab, Tab will automatically insert them. Related work from @Cosifne will also insert the parentheses automatically when ; or . is pressed.