fix(52879): No autocompletions after the typeof keyword inside JSDoc comments. (#52973)

This commit is contained in:
Oleksandr T 2023-03-07 20:52:23 +02:00 committed by GitHub
parent 868331f2be
commit 02cf0b68b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 147 additions and 3 deletions

View File

@ -3005,8 +3005,7 @@ function getCompletionData(
// Since this is qualified name check it's a type node location
const isImportType = isLiteralImportTypeNode(node);
const isTypeLocation = insideJsDocTagTypeExpression
|| (isImportType && !(node as ImportTypeNode).isTypeOf)
const isTypeLocation = (isImportType && !(node as ImportTypeNode).isTypeOf)
|| isPartOfTypeNode(node.parent)
|| isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker);
const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration(node);
@ -3029,7 +3028,7 @@ function getCompletionData(
: isRhsOfImportDeclaration ?
// Any kind is allowed when dotting off namespace in internal import equals declaration
symbol => isValidTypeAccess(symbol) || isValidValueAccess(symbol) :
isTypeLocation ? isValidTypeAccess : isValidValueAccess;
isTypeLocation || insideJsDocTagTypeExpression ? isValidTypeAccess : isValidValueAccess;
for (const exportedSymbol of exportedSymbols) {
if (isValidAccess(exportedSymbol)) {
symbols.push(exportedSymbol);
@ -3038,6 +3037,7 @@ function getCompletionData(
// If the module is merged with a value, we must get the type of the class and add its propertes (for inherited static methods).
if (!isTypeLocation &&
!insideJsDocTagTypeExpression &&
symbol.declarations &&
symbol.declarations.some(d => d.kind !== SyntaxKind.SourceFile && d.kind !== SyntaxKind.ModuleDeclaration && d.kind !== SyntaxKind.EnumDeclaration)) {
let type = typeChecker.getTypeOfSymbolAtLocation(symbol, node).getNonOptionalType();

View File

@ -0,0 +1,132 @@
=== /a.js ===
// const foo = {
// bar: {
// baz: 42,
// }
// }
// /** @typedef { typeof foo. } Foo */
// ^
// | ----------------------------------------------------------------------
// | (property) bar: {
// | baz: number;
// | }
// | (warning) baz
// | (warning) foo
// | (warning) Foo
// | ----------------------------------------------------------------------
[
{
"marker": {
"fileName": "/a.js",
"position": 76,
"name": ""
},
"item": {
"flags": 0,
"isGlobalCompletion": false,
"isMemberCompletion": true,
"isNewIdentifierLocation": false,
"entries": [
{
"name": "bar",
"kind": "property",
"kindModifiers": "",
"sortText": "11",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "property",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "bar",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "{",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": " ",
"kind": "space"
},
{
"text": "baz",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
},
{
"text": ";",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "}",
"kind": "punctuation"
}
],
"documentation": []
},
{
"name": "baz",
"kind": "warning",
"kindModifiers": "",
"sortText": "18",
"isFromUncheckedFile": true
},
{
"name": "foo",
"kind": "warning",
"kindModifiers": "",
"sortText": "18",
"isFromUncheckedFile": true
},
{
"name": "Foo",
"kind": "warning",
"kindModifiers": "",
"sortText": "18",
"isFromUncheckedFile": true
}
]
}
}
]

View File

@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />
// @allowJs: true
// @filename: /a.js
////const foo = {
//// bar: {
//// baz: 42,
//// }
////}
/////** @typedef { typeof foo./**/ } Foo */
verify.baselineCompletions();