Dart-code: LSP Auto completion Method or Constructor without parentheses

Created on 2 Aug 2020  路  11Comments  路  Source: Dart-Code/Dart-Code

Problem

I am trying out the new LSP Preview feature. It seems to be faster. but there is one annoying thing that popping up.
when dart.previewLsp is on, any autocompletion for Methods or Constructor the parentheses won't add automatically. I have to type it out manually.

It seems to work fine if I turn off the dart.previewLsp

How It Should be

It would be great if parentheses and required name parameters with placeholder are added automatically at the time of autocompletion.

Details

  1. Dart Code Version: 3.13.1
  2. VS Code Version: 1.47.3
in lsanalysis server is enhancement

Most helpful comment

Thanks for the info. This is actually intended - we use to always add them and it was annoying if you want to pass a function around:

f.map(myFunc);

The goal is to use completion characters properly (we don't yet), so that if you've typed myF above and press ( that it would then complete myFunc( but if you pressed <enter> it would just complete myFunc. That way you could complete with/without just based on which key you use to complete it.

That work is currently incomplete, but I'll try to get to it soon.

All 11 comments

Thanks for the info. This is actually intended - we use to always add them and it was annoying if you want to pass a function around:

f.map(myFunc);

The goal is to use completion characters properly (we don't yet), so that if you've typed myF above and press ( that it would then complete myFunc( but if you pressed <enter> it would just complete myFunc. That way you could complete with/without just based on which key you use to complete it.

That work is currently incomplete, but I'll try to get to it soon.

My 2 cents:

This basically makes the LSP unusable for me, breaks my workflow too bad.

To clarify, is there a difference between accepting the suggestion with <Tab> and <Enter>? (I usually use Tab to complete.) If so, perhaps this could be a configurable setting?

Personally I would much prefer that Tab automatically inserts the brackets() and arguments, as I have come to expect. I dislike having to hit the brackets manually more than necessary, and I would rather occasionally have to hit backspace to remove unwanted brackets than to have to hit ( constantly because there are never brackets automatically added.

There's no difference between tab/enter, they should do the same. Unfortunately we can't make a configurable option because this behaviour is all controlled by VS Code. The intended way to handle this is using trigger characters - if you're calling a function you should use ( to commit the completion - however that hasn't been supported until very recently.

In the very latest SDKs (dev/nightlies) you can enable dart.previewCommitCharacters to enable these for LSP (right now it only includes ( and . but may be extended to include things like , and [ in future), though it'll show as an invalid setting in VS Code until the next release.

I've split the required-named params request into https://github.com/Dart-Code/Dart-Code/issues/2808 as it's more complicated. Will use this issue to track commit characters (which is available as a preview with a new enough SDK).

This isn't currently working as the LSP implementation doesn't work for VS Code (https://github.com/microsoft/vscode-languageserver-node/issues/673).

With https://github.com/Dart-Code/Dart-Code/issues/2125, you can enable commit characters in LSP. This will allow you to type ( to select the completion item instead of tab/enter, and it will both complete the item and insert the parens.

There are other open issues tracking the other issues (https://github.com/Dart-Code/Dart-Code/issues/2808 and https://github.com/Dart-Code/Dart-Code/issues/2823).

This isn't working on my end.

  • dart.previewLsp enabled
  • dart.previewCommitCharacters enabled
  • Dart Code 3.15.1
  • VSCode 1.50.1

Autocomplete with tab gives me a function without parentheses.
Autocomplete with ( just inserts a ( in the middle of the name I was typing.

.. I think my problem with this setting is that it means every single autocomplete will require me to hit Shift+( instead of tab. My pinky finger says this is bad ergonomics for a very regular action.

@Merrit this change is very recent and likely not in the SDK version you're using yet (the most recent commit was just a few days ago). You may need to wait until the next SDK release before it will work (the functionality is in the analysis server, which ships inside the SDK, rather than the VS Code extension).

Got ya, will keep my eyes out for it and test when it drops. Thanks!

I think my problem with this setting is that it means every single autocomplete will require me to hit Shift+( instead of tab. My pinky finger says this is bad ergonomics for a very regular action.

That's true, though it's difficult to solve this - we would previously include the parens automatically but it was very annoying if you wanted to just tear odd the function (foo.map(someFunction)). Using the commit character like this allows you to control what's inserted for each insertion.

That said, there's another open issue related to this (https://github.com/Dart-Code/Dart-Code/issues/2823). It may be that we add a setting that allows you to opt-in to this, and you'll have have to handle deleting the extra characters if you wanted to tear off the function). You can subscribe to that issue for updates on that.

Yeah, I vote option for sure. I am already in the habit that if I know I don't need the parentheses that I do Tab+Backspace to get what I want quick and easy, no modifier key needed. Bonus that personally I need the parentheses way more often than not, so I would love that as an option! :+1: :smiley: :heart:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukepighetti picture lukepighetti  路  4Comments

DanTup picture DanTup  路  4Comments

partounian picture partounian  路  4Comments

DanTup picture DanTup  路  4Comments

shamrin picture shamrin  路  5Comments