Skip to content

Fixed auto completion after a < token to return types not values. #32382

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,9 @@ namespace ts.Completions {
case SyntaxKind.AsKeyword:
return parentKind === SyntaxKind.AsExpression;

case SyntaxKind.LessThanToken:
return parentKind === SyntaxKind.TypeReference;

case SyntaxKind.ExtendsKeyword:
return parentKind === SyntaxKind.TypeParameter;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/cases/fourslash/completionsAfterLessThanToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />

//// function f() {
//// const k: Record</**/
//// }

goTo.marker();
verify.completions({
includes: [
{ name: "string", sortText: completion.SortText.GlobalsOrKeywords }
]
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
////x < {| "valueOnly": true |}
////f < {| "valueOnly": true |}
////g < {| "valueOnly": false |}
////const something: C<{| "valueOnly": false |};
////const something2: C<C<{| "valueOnly": false |};
////const something: C<{| "typeOnly": true |};
////const something2: C<C<{| "typeOnly": true |};
////new C<{| "valueOnly": false |};
////new C<C<{| "valueOnly": false |};
////
Expand All @@ -20,7 +20,10 @@
////new callAndConstruct<callAndConstruct</*callAndConstruct*/

for (const marker of test.markers()) {
if (marker.data && marker.data.valueOnly) {
if (marker.data && marker.data.typeOnly) {
verify.completions({ marker, includes: "T", excludes: "x" });
Copy link

Choose a reason for hiding this comment

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

Sorry for the noob question: does "T" and "x" stand for "Type" and "Value" respectively? I'm trying to understand a little bit of the code by checking some PR's (yours is pretty cool!)

Copy link
Contributor Author

@dragomirtitian dragomirtitian Jul 15, 2019

Choose a reason for hiding this comment

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

@diguifi They do not intrinsically stand for type and value. In this test they are used as stand-ins for type and value, but only because they are defined as such above:

////const x = 0;
////type T = number;

}
else if (marker.data && marker.data.valueOnly) {
verify.completions({ marker, includes: "x", excludes: "T" });
}
else {
Expand Down