-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Conversation
bd04056
to
bfb1538
Compare
bfb1538
to
22123aa
Compare
src/services/completions.ts
Outdated
!!(localSymbol.flags & SymbolFlags.ExportValue) && checker.getExportSymbolOfSymbol(localSymbol) === recommendedCompletion; | ||
} | ||
|
||
function trueOrUndef(b: boolean): true | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid abbreviations.
src/services/completions.ts
Outdated
|
||
function getFirstSymbolInChain(symbol: Symbol, enclosingDeclaration: Node, checker: TypeChecker): Symbol | undefined { | ||
const chain = checker.getAccessibleSymbolChain(symbol, enclosingDeclaration, /*meaning*/ SymbolFlags.All, /*useOnlyExternalAliasing*/ false); | ||
return chain |
There was a problem hiding this comment.
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.
ccfe89d
to
d1abfbe
Compare
Should probably get review from @mjbvz |
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: |
There was a problem hiding this comment.
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 ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one too
src/services/types.ts
Outdated
sortText: string; | ||
/** |
There was a problem hiding this comment.
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
src/services/types.ts
Outdated
replacementSpan?: TextSpan; | ||
hasAction?: true; | ||
source?: string; | ||
isRecommended?: true; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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. |
32ca804
to
c37427c
Compare
@amcasey Good to go? |
@andy-ms, have you tried it in VS? If not, I will. Otherwise, yes. |
So far, it's not working. console.log('Hello world');
class CA { }
class CB { }
const c: CB = //caret
|
I've confirmed that the flag is getting to Roslyn, but I have yet to figure out why it's having no effect. |
Looks like a problem in the managed component. I think you're good to go. |
@amcasey Thanks! |
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.