Dart-code: LSP code completion should have an option to include parens and/or args

Created on 27 Sep 2020  ·  13Comments  ·  Source: Dart-Code/Dart-Code

Describe the bug
I'm unable to add parenthesis and give parameters to a function using tab to go to the next parameter.

To Reproduce

  1. Define a function that accepts one or more parameters.
  2. Try to call the function by starting typing it's name and autocompleting it.
  3. See that the only thing that is autocompleted is the name of the function.

Below is a recording of my screen that demonstrates the issue.

Screen Recording 2020-09-27 at 05 35 10

Expected behavior
Below is a recording of my screen while I autocomplete a simple console.log() statement. This is how the autocomplemetion on Dart code should've worked.

Screen Recording 2020-09-27 at 05 33 24

Insert Argument Placeholder option is enabled and enableCompletionCommitCharacters option is disabled.

Versions (please complete the following information):

  • VS Code version: 1.49.2
  • Dart extension version: 3.14.1
  • Dart/Flutter SDK version: Dart - 2.9.2 / Flutter - 1.20.4
in editor in lsanalysis server is enhancement

Most helpful comment

I have the same issue, when I disable Dart:Preview LSP then the code completion with parens and/or args works!

All 13 comments

Do you have the dart.previewLsp setting enabled? Right now, for LSP commit characters do not work but the general behaviour for completing on functions is to not insert parens, because it's awkward if you don't want to call the function (for example onTap: _handleTap).

The expected fix (once commit characters work correctly) is that you press ( to commit the completion (instead of tab) when you want the parens - that will both commit the highlighted item and insert parens. That way it's easy to control whether they're inserted (enter/tab to just get the name, and ( to invoke).

I couldn't actually repro your TS example - when I complete on console.log I also do not get the parens. If there's some setting you've set that controls this, perhaps we can align the Dart behaviour+settings with it to make it more discoverable. If you know what this is, please let me know!

Yes. I have the dart.previewLsp enabled. The way to complete console.log statement is to enable Complete Function Calls of JS extension. Do commit characters not work right now on Dart Code side?

Commit characters don't currently work on either LSP or not. I'd like to have them working on LSP, though I hit a problem in VS Code that I haven't fixed yet. Hoping to progress that soon.

Fixed by https://github.com/dart-lang/sdk/commit/8687aa6145c35fae6e1aaa076de7f2a19da7e38c.

When using a new SDK that includes that change, the dart.completeFunctionCalls setting will insert parens/required args (as long as commit characters is not enabled).

Fantastic! Thank you for making this a reality. Look forward to trying it ❤️

Should this be available at this point?

❯ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, 1.25.0-4.0.pre, on Microsoft Windows [Version 10.0.19042.662], locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.2)
[✓] Android Studio (version 4.1.0)
[✓] VS Code (version 1.51.1)
[✓] Connected device (5 available)

• No issues found!

dart-code 3.17.0

image

Still isn't adding parentheses or argument placeholders.

@Merrit Have you got the LSP preview enabled, and reloaded VS Code since enabling it? I tested with the same version of Flutter and it seems to be included there:

Dec-07-2020 11-50-12

If you're still not seeing it with LSP enabled, please file a new issue and we can capture some logs to understand what's happening. Thanks!

Double checked LSP seems to be enabled.

This does seem to work with something like a function I wrote myself, but not some other things like print() or widgets.

I opened an issue: #2992

Ah, I see. I'll do some digging and follow up in that issue. Thanks!

I have the same issue, when I disable Dart:Preview LSP then the code completion with parens and/or args works!

@JoyEnergiser see the comment above. There's a new setting to control this in LSP, but it requires an SDK that includes the setting (which is not currently true of Flutter's stable branch, although it should be in the next major stable release).

still not working for me... tried disabling LSP, tried the recommended

still not working for me... tried disabling LSP, tried the recommended

Sorry got it working, you have to uncheck commit characters as well.

Was this page helpful?
0 / 5 - 0 ratings