microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.76k stars 12.46k forks source link

favor local types and values in autocomplete popup over ambients declaration #15024

Closed zpdDG4gta8XKpMCd closed 5 years ago

zpdDG4gta8XKpMCd commented 7 years ago

it's not clear to me what drives the order of the list of autocomplete popup suggestions, i wish my local types and values were listed first, and ambients came after them

mjbvz commented 7 years ago

This was reported against VSCode recently as well: https://github.com/Microsoft/vscode/issues/29613

For code such as:

var cancel = 123
can|

The suggestions for can have the same sort text:

 {
        "name": "cancel",
        "kind": "var",
        "kindModifiers": "",
        "sortText": "0"
    },
    {
        "name": "cancelAnimationFrame",
        "kind": "function",
        "kindModifiers": "declare",
        "sortText": "0"
    }

I believe that variables and parameters should have a higher sort text (or that globals should have a lower sort text)

mhegazy commented 7 years ago

A feature that VS has today is remembering the last entry the user selected in the completion list. so the first time you type cancel it does not get it, but next time it gets a preferential treatment. I think this is a general feature that would be beneficial to VSCode users in general given the locality of reference for variables in general, and less disorienting as reordering based on scope.

animation

mhegazy commented 7 years ago

@mjbvz thoughts?

lifehackett commented 7 years ago

I'd still prefer local scope to get higher weighting. The remembering of the last selection only solves a small subset of the use cases that I care about.

mjbvz commented 5 years ago

VS Code has added support for remembering suggestions with the editor.suggestSelection setting.

I still think that adding some basic sorting based on scope would be very helpful. @DanielRosenwasser Can we revisit this feature request?

RyanCavanaugh commented 5 years ago

@sheetalkamat this is something we'd like to deliver for 3.5 specifically

mjbvz commented 5 years ago

More VS Code feedback related to suggestion sort order and locality: https://github.com/Microsoft/vscode/issues/47727

zpdDG4gta8XKpMCd commented 5 years ago

there is also a very annoying thing with remembering-last-entry bonus:

how do i unfavor some accidental picks?

SlurpTheo commented 5 years ago

@zpdDG4gta8XKpMCd

how do i unfavor some accidental picks?

If you Undo (Ctrl+Z) after accidentally selecting fill, I'd expect it to not leave fill in that "last list".

RyanCavanaugh commented 5 years ago

The ordering we think might be best:

Caveat: "real" things (non-suggestions) should always shadow suggestions

sheetalkamat commented 5 years ago

@RyanCavanaugh @mjbvz In example from #30013 making Things from the lexical scope that are declared in the current file (including top-level variables in a script file) as first makes suggested class members render

image

Also what happens to javascript symbols. Current behavior is that everything except JavaScript has "0" and JavaScript symbols are "1". Does JavaScript come after auto import ?

mjbvz commented 5 years ago

Yeah that doesn't feel right. We should either:

The first approach definitely seems more straightforward. VS Code's suggestion sorting should also help out so that better matches are shown first

For the second point, the javascript symbol suggestions (we call them name suggestions in vscode) should probably have the lowest precedence. They are sort of the equivalent of VS Code's word based suggestions, which also have very low precedence and are only really meant to show up when no other suggestions match

zpdDG4gta8XKpMCd commented 5 years ago

how about we give it as a configurable option?

something like:

{
    "auto-completion-priorities": ["locals", "members", "lexical", "ambients", "imports"]
}

or

{
    "auto-completion-priorities": "merged"
}
zpdDG4gta8XKpMCd commented 5 years ago

it would be nice to have some visible separation between the groups (shades of background)

zpdDG4gta8XKpMCd commented 5 years ago

better yet first N.. something items of each group with an option to dig deeper:

aaaa
aaab
aaac
aaad
... more locals
bbba
bbbb
bbbc
bbbd
... more globals

and please make N configurable (per each group)

... looks like an overkill, disregard please