
Hitting Ctrl+Space to bring up the IntelliSense completion list occasionally sets the cursor at the middle of the list, and not at the first item, I end up with a lot of StatefulWidget snippet/Undo combinations :)
The behavior here is inconsistent [unless there's some rule it follows that I can't quite figure out], so here's my attempt at explaining what I've seen:
For the following bit of code:
new Container(
width: 300.0,
height: 100.0,
child: sparkline,
),
child: sparkline and then ctrl+space to trigger a completion: Flutter stateful widget is selected.color then hitting return to complete it works as expected.color entry: Flutter stateful widget is selected.color line and hitting backspace to clear it - then hitting ctrl+space to bring up intellisense: color is selected.It seems to me that it always defaults to Flutter stateful widget the very first time the completion list is brought up for this class.
In writing this out I _think_ I've sussed out what's happening: it seems like the default selected item in the list is cached by context, and if vscode hasn't seen the current context before then it defaults to the last completed item from the whole list of available completions.
So: If at any point I use the snippet completion by typing stf then ctrl+space to complete Flutter stateful widget -> this now becomes the default selected item on any completion list that has it [ie all lists].
If I trigger the completion list under new Container and select an item from that list [e.g.: color], then clear the result, this new item becomes the default for all completions triggered within a new Container context. Amusingly [?] if the Container already has this item entered [an entry for color] such that it won't show up in the completion list anymore - it reverts to the previous default [back to Flutter stateful widget]
Oh and the actual expected behavior would be to just default to first item in the list [since those are the ones the analyzer has given us for this context].
Thanks for raising - I've seen this a few times and never investigated. I believe the wonkiness is from Code pre-selecting the last thing you used. I've raised this case saying I think it should never use the remembered value when there is no prefix:
https://github.com/Microsoft/vscode/issues/46047
I suspect they may say to switch to recentlyUsedByPrefix in your settings though (which I don't like, because it means either our users will be frustrated, or we'll have to change the default for Dart on them, neither of which are good).
Actually, based on https://github.com/Microsoft/vscode/issues/41060#issuecomment-364284879 I think this is exactly as it's intended; but maybe it should only happen with . prefixes and not indenting!
Also slightly related: https://github.com/Microsoft/vscode/issues/35551
This should be fixed in Code, but looks like it won't ship until the April release (which is over a month away):
The "editor.snippetSuggestions": is set to inline by default in the defaultSettings.json (the default settings of VS code).
It seems that other VS code extensions that provide additional completion options; change this from inline to 'top' or something other than the default.
I went to my user settings of VSCode settings.json and changed it back to inline and everything works as expected.
As a result, the original VSCode completion options came back to the top of the list and you may use Tab or Enter to select them.
Hope that my answer helps you 馃憤
Kind regards to all,
Max (Anas Alhariri)
Most helpful comment
I found the SOLUTION!
The
"editor.snippetSuggestions":is set toinlineby default in thedefaultSettings.json(the default settings of VS code).It seems that other VS code extensions that provide additional completion options; change this from
inlineto 'top' or something other than the default.I went to my user settings of VSCode
settings.jsonand changed it back toinlineand everything works as expected.As a result, the original VSCode completion options came back to the top of the list and you may use Tab or Enter to select them.
Hope that my answer helps you 馃憤
Kind regards to all,
Max (Anas Alhariri)