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

Support a 'recommended' completion entry #20020

Merged
6 commits merged into from
Dec 1, 2017
Merged

Support a 'recommended' completion entry #20020

6 commits merged into from
Dec 1, 2017

Conversation

ghost
Copy link

@ghost ghost commented Nov 14, 2017

Fixes #19855
This adds an isRecommended boolean to one (or no) completion entry, when that entry is for a enum or (non-abstract) class and the context indicates that that's the only allowed type.

@ghost ghost requested a review from armanio123 November 14, 2017 22:24
@ghost ghost force-pushed the completionsRecommended branch 3 times, most recently from bd04056 to bfb1538 Compare November 15, 2017 02:47
@ghost ghost force-pushed the completionsRecommended branch from bfb1538 to 22123aa Compare November 15, 2017 03:02
!!(localSymbol.flags & SymbolFlags.ExportValue) && checker.getExportSymbolOfSymbol(localSymbol) === recommendedCompletion;
}

function trueOrUndef(b: boolean): true | undefined {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid abbreviations.


function getFirstSymbolInChain(symbol: Symbol, enclosingDeclaration: Node, checker: TypeChecker): Symbol | undefined {
const chain = checker.getAccessibleSymbolChain(symbol, enclosingDeclaration, /*meaning*/ SymbolFlags.All, /*useOnlyExternalAliasing*/ false);
return chain
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested shorthands are hard to read. Consider if else, or switch statement.

@ghost ghost force-pushed the completionsRecommended branch from ccfe89d to d1abfbe Compare November 17, 2017 15:28
@ghost
Copy link
Author

ghost commented Nov 17, 2017

Should probably get review from @mjbvz

@ghost ghost requested a review from mjbvz November 17, 2017 23:04
@mjbvz
Copy link
Contributor

mjbvz commented Nov 17, 2017

Just to confirm, the expected UX here would be that we surface the recommended completion first? Should that also happen if the user has already started typing something? Would sort order be enough here then?

@@ -13876,6 +13859,12 @@ namespace ts {
case SyntaxKind.AmpersandAmpersandToken:
case SyntaxKind.CommaToken:
return node === right ? getContextualType(binaryExpression) : undefined;
case SyntaxKind.EqualsEqualsEqualsToken:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this changes what contextual type mean in the language. we should talk about this first

case SyntaxKind.NewExpression:
return getContextualTypeForArgument(<CallExpression>parent, node);
if (node.kind === SyntaxKind.NewKeyword) { // for completions after `new `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one too

sortText: string;
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this comment removed

replacementSpan?: TextSpan;
hasAction?: true;
source?: string;
isRecommended?: true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would rather we put this on the CompletionInfo instead. i understand for the server we have to put it on the entry.. but for VS for example, it makes more sense to have it on the info..
Please check with @amcasey about this too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not intimately familiar with these types. The info is the wrapper object containing a list of entries? Assuming that's the case, having it on the entry is the most convenient place for VS.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's defined at interface CompletionInfo in services/types.ts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, yes, the entry would be preferable to the info. I've created a PR with the VS change if you'd like to test it.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 20, 2017

Just to confirm, the expected UX here would be that we surface the recommended completion first? Should that also happen if the user has already started typing something? Would sort order be enough here then?

Visual Studio will show the recommended completion as selected if nothing is typed. the order does not change. I would recommend doing the same for VSCode; changing the order is disorienting.

animation

@ghost ghost force-pushed the completionsRecommended branch from 32ca804 to c37427c Compare December 1, 2017 00:11
@ghost
Copy link
Author

ghost commented Dec 1, 2017

@amcasey Good to go?

@amcasey
Copy link
Member

amcasey commented Dec 1, 2017

@andy-ms, have you tried it in VS? If not, I will. Otherwise, yes.

@amcasey
Copy link
Member

amcasey commented Dec 1, 2017

So far, it's not working.

console.log('Hello world');

class CA { }
class CB { }

const c: CB = //caret
  1. If I invoke completion there, the recommended completion is "CB". I actually wanted "new".
  2. "CB" isn't pre-selected. I'm still investigating why not.

@amcasey
Copy link
Member

amcasey commented Dec 1, 2017

I've confirmed that the flag is getting to Roslyn, but I have yet to figure out why it's having no effect.

@amcasey
Copy link
Member

amcasey commented Dec 1, 2017

Looks like a problem in the managed component. I think you're good to go.

@ghost
Copy link
Author

ghost commented Dec 1, 2017

@amcasey Thanks!

@ghost ghost merged commit fd4d8ab into master Dec 1, 2017
@ghost ghost deleted the completionsRecommended branch December 1, 2017 21:00
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants