Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zpdDG4gta8XKpMCd opened this issue Apr 5, 2017 · 15 comments · Fixed by #31484
Closed
Assignees
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Fixed A PR has been merged for this issue Suggestion An idea for TypeScript VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone

Comments

@zpdDG4gta8XKpMCd
Copy link

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

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@mjbvz mjbvz added the VS Code Tracked There is a VS Code equivalent to this issue label Jun 30, 2017
@mjbvz
Copy link
Contributor

mjbvz commented Jun 30, 2017

This was reported against VSCode recently as well: microsoft/vscode#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
Copy link
Contributor

mhegazy commented Aug 29, 2017

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
Copy link
Contributor

mhegazy commented Aug 29, 2017

@mjbvz thoughts?

@mhegazy mhegazy added Needs More Info The issue still hasn't been fully clarified Suggestion An idea for TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Aug 29, 2017
@lifehackett
Copy link

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
Copy link
Contributor

mjbvz commented Jan 9, 2019

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?

@DanielRosenwasser DanielRosenwasser removed the Needs More Info The issue still hasn't been fully clarified label Jan 10, 2019
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.4.0 milestone Jan 10, 2019
@DanielRosenwasser DanielRosenwasser added the Domain: Completion Lists The issue relates to showing completion lists in an editor label Jan 10, 2019
@mjbvz mjbvz added VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone and removed VS Code Tracked There is a VS Code equivalent to this issue labels Jan 24, 2019
@RyanCavanaugh
Copy link
Member

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

@mjbvz
Copy link
Contributor

mjbvz commented Mar 22, 2019

More VS Code feedback related to suggestion sort order and locality: microsoft/vscode#47727

@zpdDG4gta8XKpMCd
Copy link
Author

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

  • say i needed [].filter but by accident i picked [].fill now the fill gets preference over filter and gets on the way even more often, so i pick it by accident even more, and it all goes in a vicious circle

how do i unfavor some accidental picks?

@SlurpTheo
Copy link

@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
Copy link
Member

RyanCavanaugh commented Apr 18, 2019

The ordering we think might be best:

  • Things from the lexical scope that are declared in the current file (including top-level variables in a script file)
  • Suggested class members
  • Things from global lexical scope and keywords
  • Auto-import suggestions

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

@sheetalkamat
Copy link
Member

@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
Copy link
Contributor

mjbvz commented May 17, 2019

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

  • Merge the class member and lexical scope precedences.
  • Introduce two levels of lexical scoping:
    • Locals (things from inside the current method)
    • class members
    • File Lexical scope
    • global lexical scope and keywords
    • Auto-import suggestions

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
Copy link
Author

zpdDG4gta8XKpMCd commented May 17, 2019

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
Copy link
Author

zpdDG4gta8XKpMCd commented May 17, 2019

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

@zpdDG4gta8XKpMCd
Copy link
Author

zpdDG4gta8XKpMCd commented May 17, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Fixed A PR has been merged for this issue Suggestion An idea for TypeScript VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants