From c2d0c26a46484735141e8afa8d1cb648e5067710 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 9 Mar 2018 14:50:27 -0800 Subject: [PATCH] Update LKG --- lib/lib.d.ts | 6 +- lib/lib.dom.d.ts | 6 +- lib/lib.es2016.full.d.ts | 6 +- lib/lib.es2017.full.d.ts | 6 +- lib/lib.es2018.full.d.ts | 6 +- lib/lib.es6.d.ts | 6 +- lib/lib.esnext.full.d.ts | 6 +- lib/tsc.js | 2 +- lib/tsserver.js | 124 +++++++++++++++++++++++++++++----- lib/tsserverlibrary.js | 138 +++++++++++++++++++++++++++++++++----- lib/typescript.js | 138 +++++++++++++++++++++++++++++++++----- lib/typescriptServices.js | 138 +++++++++++++++++++++++++++++++++----- 12 files changed, 488 insertions(+), 94 deletions(-) diff --git a/lib/lib.d.ts b/lib/lib.d.ts index 2753a03f350..616a0fc6eda 100644 --- a/lib/lib.d.ts +++ b/lib/lib.d.ts @@ -7811,7 +7811,7 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent /** * Contains information about the current URL. */ - location: Location | string; + location: Location; msCSSOMElementFloatMetrics: boolean; msCapsLockWarningOff: boolean; /** @@ -19066,7 +19066,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window readonly innerWidth: number; readonly isSecureContext: boolean; readonly length: number; - location: Location | string; + location: Location; readonly locationbar: BarProp; readonly menubar: BarProp; readonly msContentScript: ExtensionScriptApis; @@ -19875,7 +19875,7 @@ declare var innerHeight: number; declare var innerWidth: number; declare var isSecureContext: boolean; declare var length: number; -declare var location: Location | string; +declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msContentScript: ExtensionScriptApis; diff --git a/lib/lib.dom.d.ts b/lib/lib.dom.d.ts index 7c0f5332613..2afd43622ca 100644 --- a/lib/lib.dom.d.ts +++ b/lib/lib.dom.d.ts @@ -3674,7 +3674,7 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent /** * Contains information about the current URL. */ - location: Location | string; + location: Location; msCSSOMElementFloatMetrics: boolean; msCapsLockWarningOff: boolean; /** @@ -14929,7 +14929,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window readonly innerWidth: number; readonly isSecureContext: boolean; readonly length: number; - location: Location | string; + location: Location; readonly locationbar: BarProp; readonly menubar: BarProp; readonly msContentScript: ExtensionScriptApis; @@ -15738,7 +15738,7 @@ declare var innerHeight: number; declare var innerWidth: number; declare var isSecureContext: boolean; declare var length: number; -declare var location: Location | string; +declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msContentScript: ExtensionScriptApis; diff --git a/lib/lib.es2016.full.d.ts b/lib/lib.es2016.full.d.ts index ad22c363031..350f4b06a80 100644 --- a/lib/lib.es2016.full.d.ts +++ b/lib/lib.es2016.full.d.ts @@ -3677,7 +3677,7 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent /** * Contains information about the current URL. */ - location: Location | string; + location: Location; msCSSOMElementFloatMetrics: boolean; msCapsLockWarningOff: boolean; /** @@ -14932,7 +14932,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window readonly innerWidth: number; readonly isSecureContext: boolean; readonly length: number; - location: Location | string; + location: Location; readonly locationbar: BarProp; readonly menubar: BarProp; readonly msContentScript: ExtensionScriptApis; @@ -15741,7 +15741,7 @@ declare var innerHeight: number; declare var innerWidth: number; declare var isSecureContext: boolean; declare var length: number; -declare var location: Location | string; +declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msContentScript: ExtensionScriptApis; diff --git a/lib/lib.es2017.full.d.ts b/lib/lib.es2017.full.d.ts index 8b6a5209c01..0419cccd65b 100644 --- a/lib/lib.es2017.full.d.ts +++ b/lib/lib.es2017.full.d.ts @@ -3682,7 +3682,7 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent /** * Contains information about the current URL. */ - location: Location | string; + location: Location; msCSSOMElementFloatMetrics: boolean; msCapsLockWarningOff: boolean; /** @@ -14937,7 +14937,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window readonly innerWidth: number; readonly isSecureContext: boolean; readonly length: number; - location: Location | string; + location: Location; readonly locationbar: BarProp; readonly menubar: BarProp; readonly msContentScript: ExtensionScriptApis; @@ -15746,7 +15746,7 @@ declare var innerHeight: number; declare var innerWidth: number; declare var isSecureContext: boolean; declare var length: number; -declare var location: Location | string; +declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msContentScript: ExtensionScriptApis; diff --git a/lib/lib.es2018.full.d.ts b/lib/lib.es2018.full.d.ts index 214433cb91f..bf0b0762ae6 100644 --- a/lib/lib.es2018.full.d.ts +++ b/lib/lib.es2018.full.d.ts @@ -3678,7 +3678,7 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent /** * Contains information about the current URL. */ - location: Location | string; + location: Location; msCSSOMElementFloatMetrics: boolean; msCapsLockWarningOff: boolean; /** @@ -14933,7 +14933,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window readonly innerWidth: number; readonly isSecureContext: boolean; readonly length: number; - location: Location | string; + location: Location; readonly locationbar: BarProp; readonly menubar: BarProp; readonly msContentScript: ExtensionScriptApis; @@ -15742,7 +15742,7 @@ declare var innerHeight: number; declare var innerWidth: number; declare var isSecureContext: boolean; declare var length: number; -declare var location: Location | string; +declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msContentScript: ExtensionScriptApis; diff --git a/lib/lib.es6.d.ts b/lib/lib.es6.d.ts index 2b5b901d1b8..2b1a5dcb344 100644 --- a/lib/lib.es6.d.ts +++ b/lib/lib.es6.d.ts @@ -9522,7 +9522,7 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent /** * Contains information about the current URL. */ - location: Location | string; + location: Location; msCSSOMElementFloatMetrics: boolean; msCapsLockWarningOff: boolean; /** @@ -20777,7 +20777,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window readonly innerWidth: number; readonly isSecureContext: boolean; readonly length: number; - location: Location | string; + location: Location; readonly locationbar: BarProp; readonly menubar: BarProp; readonly msContentScript: ExtensionScriptApis; @@ -21586,7 +21586,7 @@ declare var innerHeight: number; declare var innerWidth: number; declare var isSecureContext: boolean; declare var length: number; -declare var location: Location | string; +declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msContentScript: ExtensionScriptApis; diff --git a/lib/lib.esnext.full.d.ts b/lib/lib.esnext.full.d.ts index 5b7d168b2a9..c8282d51788 100644 --- a/lib/lib.esnext.full.d.ts +++ b/lib/lib.esnext.full.d.ts @@ -3679,7 +3679,7 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent /** * Contains information about the current URL. */ - location: Location | string; + location: Location; msCSSOMElementFloatMetrics: boolean; msCapsLockWarningOff: boolean; /** @@ -14934,7 +14934,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window readonly innerWidth: number; readonly isSecureContext: boolean; readonly length: number; - location: Location | string; + location: Location; readonly locationbar: BarProp; readonly menubar: BarProp; readonly msContentScript: ExtensionScriptApis; @@ -15743,7 +15743,7 @@ declare var innerHeight: number; declare var innerWidth: number; declare var isSecureContext: boolean; declare var length: number; -declare var location: Location | string; +declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msContentScript: ExtensionScriptApis; diff --git a/lib/tsc.js b/lib/tsc.js index 5cb60a31e56..008165e9b79 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -62135,7 +62135,7 @@ var ts; } if (options.emitDeclarationOnly) { if (!options.declaration) { - createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declarations"); + createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration"); } if (options.noEmit) { createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "emitDeclarationOnly", "noEmit"); diff --git a/lib/tsserver.js b/lib/tsserver.js index a1bfc685e1d..3b0e11b39d6 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -63491,7 +63491,7 @@ var ts; } if (options.emitDeclarationOnly) { if (!options.declaration) { - createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declarations"); + createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration"); } if (options.noEmit) { createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "emitDeclarationOnly", "noEmit"); @@ -66368,6 +66368,88 @@ var ts; return ts.isTemplateLiteralKind(token.kind) && position > token.getStart(sourceFile); } ts.isInTemplateString = isInTemplateString; + function findPrecedingMatchingToken(token, matchingTokenKind, sourceFile) { + var tokenKind = token.kind; + var remainingMatchingTokens = 0; + while (true) { + token = findPrecedingToken(token.getFullStart(), sourceFile); + if (!token) { + return undefined; + } + if (token.kind === matchingTokenKind) { + if (remainingMatchingTokens === 0) { + return token; + } + remainingMatchingTokens--; + } + else if (token.kind === tokenKind) { + remainingMatchingTokens++; + } + } + } + ts.findPrecedingMatchingToken = findPrecedingMatchingToken; + function isPossiblyTypeArgumentPosition(token, sourceFile) { + var remainingLessThanTokens = 0; + while (token) { + switch (token.kind) { + case 27: + token = findPrecedingToken(token.getFullStart(), sourceFile); + var tokenIsIdentifier = token && ts.isIdentifier(token); + if (!remainingLessThanTokens || !tokenIsIdentifier) { + return tokenIsIdentifier; + } + remainingLessThanTokens--; + break; + case 47: + remainingLessThanTokens = +3; + break; + case 46: + remainingLessThanTokens = +2; + break; + case 29: + remainingLessThanTokens++; + break; + case 18: + token = findPrecedingMatchingToken(token, 17, sourceFile); + if (!token) + return false; + break; + case 20: + token = findPrecedingMatchingToken(token, 19, sourceFile); + if (!token) + return false; + break; + case 22: + token = findPrecedingMatchingToken(token, 21, sourceFile); + if (!token) + return false; + break; + case 26: + case 36: + case 71: + case 9: + case 8: + case 101: + case 86: + case 103: + case 85: + case 128: + case 23: + case 49: + case 55: + case 56: + break; + default: + if (ts.isTypeNode(token)) { + break; + } + return false; + } + token = findPrecedingToken(token.getFullStart(), sourceFile); + } + return false; + } + ts.isPossiblyTypeArgumentPosition = isPossiblyTypeArgumentPosition; function isInComment(sourceFile, position, tokenAtPosition, predicate) { return !!ts.formatting.getRangeOfEnclosingComment(sourceFile, position, false, undefined, tokenAtPosition, predicate); } @@ -69110,6 +69192,7 @@ var ts; completionKind = 2; var isTypeLocation = insideJsDocTagTypeExpression || ts.isPartOfTypeNode(node.parent); var isRhsOfImportDeclaration = ts.isInRightSideOfInternalImportEqualsDeclaration(node); + var allowTypeOrValue = isRhsOfImportDeclaration || (!isTypeLocation && ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile)); if (ts.isEntityName(node)) { var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { @@ -69118,7 +69201,7 @@ var ts; var exportedSymbols = ts.Debug.assertEachDefined(typeChecker.getExportsOfModule(symbol), "getExportsOfModule() should all be defined"); var isValidValueAccess_1 = function (symbol) { return typeChecker.isValidPropertyAccess((node.parent), symbol.name); }; var isValidTypeAccess_1 = function (symbol) { return symbolCanBeReferencedAtTypeLocation(symbol); }; - var isValidAccess = isRhsOfImportDeclaration ? + var isValidAccess = allowTypeOrValue ? function (symbol) { return isValidTypeAccess_1(symbol) || isValidValueAccess_1(symbol); } : isTypeLocation ? isValidTypeAccess_1 : isValidValueAccess_1; for (var _i = 0, exportedSymbols_1 = exportedSymbols; _i < exportedSymbols_1.length; _i++) { @@ -69227,8 +69310,9 @@ var ts; } } function filterGlobalCompletion(symbols) { - var isTypeCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (ts.isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); - if (isTypeCompletion) + var isTypeOnlyCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (ts.isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); + var allowTypes = isTypeOnlyCompletion || !isContextTokenValueLocation(contextToken) && ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile); + if (isTypeOnlyCompletion) keywordFilters = 4; ts.filterMutate(symbols, function (symbol) { if (!ts.isSourceFile(location)) { @@ -69239,8 +69323,11 @@ var ts; if (ts.isInRightSideOfInternalImportEqualsDeclaration(location)) { return !!(symbol.flags & 1920); } - if (isTypeCompletion) { - return symbolCanBeReferencedAtTypeLocation(symbol); + if (allowTypes) { + var symbolAllowedAsType = symbolCanBeReferencedAtTypeLocation(symbol); + if (symbolAllowedAsType || isTypeOnlyCompletion) { + return symbolAllowedAsType; + } } } return !!(ts.getCombinedLocalAndExportSymbolFlags(symbol) & 67216319); @@ -69249,7 +69336,7 @@ var ts; function isContextTokenValueLocation(contextToken) { return contextToken && contextToken.kind === 103 && - contextToken.parent.kind === 164; + (contextToken.parent.kind === 164 || ts.isTypeOfExpression(contextToken.parent)); } function isContextTokenTypeLocation(contextToken) { if (contextToken) { @@ -75262,6 +75349,10 @@ var ts; var SymbolDisplay; (function (SymbolDisplay) { function getSymbolKind(typeChecker, symbol, location) { + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location); + if (result !== "") { + return result; + } var flags = ts.getCombinedLocalAndExportSymbolFlags(symbol); if (flags & 32) { return ts.getDeclarationOfKind(symbol, 203) ? @@ -75275,17 +75366,14 @@ var ts; return "interface"; if (flags & 262144) return "type parameter"; - var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location); - if (result === "") { - if (flags & 262144) - return "type parameter"; - if (flags & 8) - return "enum member"; - if (flags & 2097152) - return "alias"; - if (flags & 1536) - return "module"; - } + if (flags & 262144) + return "type parameter"; + if (flags & 8) + return "enum member"; + if (flags & 2097152) + return "alias"; + if (flags & 1536) + return "module"; return result; } SymbolDisplay.getSymbolKind = getSymbolKind; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 5f49baec67b..a77169c43c8 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -79124,7 +79124,7 @@ var ts; } if (options.emitDeclarationOnly) { if (!options.declaration) { - createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declarations"); + createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration"); } if (options.noEmit) { createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "emitDeclarationOnly", "noEmit"); @@ -80373,6 +80373,102 @@ var ts; return ts.isTemplateLiteralKind(token.kind) && position > token.getStart(sourceFile); } ts.isInTemplateString = isInTemplateString; + function findPrecedingMatchingToken(token, matchingTokenKind, sourceFile) { + var tokenKind = token.kind; + var remainingMatchingTokens = 0; + while (true) { + token = findPrecedingToken(token.getFullStart(), sourceFile); + if (!token) { + return undefined; + } + if (token.kind === matchingTokenKind) { + if (remainingMatchingTokens === 0) { + return token; + } + remainingMatchingTokens--; + } + else if (token.kind === tokenKind) { + remainingMatchingTokens++; + } + } + } + ts.findPrecedingMatchingToken = findPrecedingMatchingToken; + function isPossiblyTypeArgumentPosition(token, sourceFile) { + // This function determines if the node could be type argument position + // Since during editing, when type argument list is not complete, + // the tree could be of any shape depending on the tokens parsed before current node, + // scanning of the previous identifier followed by "<" before current node would give us better result + // Note that we also balance out the already provided type arguments, arrays, object literals while doing so + var remainingLessThanTokens = 0; + while (token) { + switch (token.kind) { + case 27 /* LessThanToken */: + // Found the beginning of the generic argument expression + token = findPrecedingToken(token.getFullStart(), sourceFile); + var tokenIsIdentifier = token && ts.isIdentifier(token); + if (!remainingLessThanTokens || !tokenIsIdentifier) { + return tokenIsIdentifier; + } + remainingLessThanTokens--; + break; + case 47 /* GreaterThanGreaterThanGreaterThanToken */: + remainingLessThanTokens = +3; + break; + case 46 /* GreaterThanGreaterThanToken */: + remainingLessThanTokens = +2; + break; + case 29 /* GreaterThanToken */: + remainingLessThanTokens++; + break; + case 18 /* CloseBraceToken */: + // This can be object type, skip untill we find the matching open brace token + // Skip untill the matching open brace token + token = findPrecedingMatchingToken(token, 17 /* OpenBraceToken */, sourceFile); + if (!token) + return false; + break; + case 20 /* CloseParenToken */: + // This can be object type, skip untill we find the matching open brace token + // Skip untill the matching open brace token + token = findPrecedingMatchingToken(token, 19 /* OpenParenToken */, sourceFile); + if (!token) + return false; + break; + case 22 /* CloseBracketToken */: + // This can be object type, skip untill we find the matching open brace token + // Skip untill the matching open brace token + token = findPrecedingMatchingToken(token, 21 /* OpenBracketToken */, sourceFile); + if (!token) + return false; + break; + // Valid tokens in a type name. Skip. + case 26 /* CommaToken */: + case 36 /* EqualsGreaterThanToken */: + case 71 /* Identifier */: + case 9 /* StringLiteral */: + case 8 /* NumericLiteral */: + case 101 /* TrueKeyword */: + case 86 /* FalseKeyword */: + case 103 /* TypeOfKeyword */: + case 85 /* ExtendsKeyword */: + case 128 /* KeyOfKeyword */: + case 23 /* DotToken */: + case 49 /* BarToken */: + case 55 /* QuestionToken */: + case 56 /* ColonToken */: + break; + default: + if (ts.isTypeNode(token)) { + break; + } + // Invalid token in type + return false; + } + token = findPrecedingToken(token.getFullStart(), sourceFile); + } + return false; + } + ts.isPossiblyTypeArgumentPosition = isPossiblyTypeArgumentPosition; /** * Returns true if the cursor at position in sourceFile is within a comment. * @@ -83607,6 +83703,7 @@ var ts; // Since this is qualified name check its a type node location var isTypeLocation = insideJsDocTagTypeExpression || ts.isPartOfTypeNode(node.parent); var isRhsOfImportDeclaration = ts.isInRightSideOfInternalImportEqualsDeclaration(node); + var allowTypeOrValue = isRhsOfImportDeclaration || (!isTypeLocation && ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile)); if (ts.isEntityName(node)) { var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { @@ -83616,7 +83713,7 @@ var ts; var exportedSymbols = ts.Debug.assertEachDefined(typeChecker.getExportsOfModule(symbol), "getExportsOfModule() should all be defined"); var isValidValueAccess_1 = function (symbol) { return typeChecker.isValidPropertyAccess((node.parent), symbol.name); }; var isValidTypeAccess_1 = function (symbol) { return symbolCanBeReferencedAtTypeLocation(symbol); }; - var isValidAccess = isRhsOfImportDeclaration ? + var isValidAccess = allowTypeOrValue ? // Any kind is allowed when dotting off namespace in internal import equals declaration function (symbol) { return isValidTypeAccess_1(symbol) || isValidValueAccess_1(symbol); } : isTypeLocation ? isValidTypeAccess_1 : isValidValueAccess_1; @@ -83766,8 +83863,9 @@ var ts; } } function filterGlobalCompletion(symbols) { - var isTypeCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (ts.isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); - if (isTypeCompletion) + var isTypeOnlyCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (ts.isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); + var allowTypes = isTypeOnlyCompletion || !isContextTokenValueLocation(contextToken) && ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile); + if (isTypeOnlyCompletion) keywordFilters = 4 /* TypeKeywords */; ts.filterMutate(symbols, function (symbol) { if (!ts.isSourceFile(location)) { @@ -83780,9 +83878,12 @@ var ts; if (ts.isInRightSideOfInternalImportEqualsDeclaration(location)) { return !!(symbol.flags & 1920 /* Namespace */); } - if (isTypeCompletion) { + if (allowTypes) { // Its a type, but you can reach it by namespace.type as well - return symbolCanBeReferencedAtTypeLocation(symbol); + var symbolAllowedAsType = symbolCanBeReferencedAtTypeLocation(symbol); + if (symbolAllowedAsType || isTypeOnlyCompletion) { + return symbolAllowedAsType; + } } } // expressions are value space (which includes the value namespaces) @@ -83792,7 +83893,7 @@ var ts; function isContextTokenValueLocation(contextToken) { return contextToken && contextToken.kind === 103 /* TypeOfKeyword */ && - contextToken.parent.kind === 164 /* TypeQuery */; + (contextToken.parent.kind === 164 /* TypeQuery */ || ts.isTypeOfExpression(contextToken.parent)); } function isContextTokenTypeLocation(contextToken) { if (contextToken) { @@ -90968,6 +91069,10 @@ var ts; (function (SymbolDisplay) { // TODO(drosen): use contextual SemanticMeaning. function getSymbolKind(typeChecker, symbol, location) { + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location); + if (result !== "" /* unknown */) { + return result; + } var flags = ts.getCombinedLocalAndExportSymbolFlags(symbol); if (flags & 32 /* Class */) { return ts.getDeclarationOfKind(symbol, 203 /* ClassExpression */) ? @@ -90981,17 +91086,14 @@ var ts; return "interface" /* interfaceElement */; if (flags & 262144 /* TypeParameter */) return "type parameter" /* typeParameterElement */; - var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location); - if (result === "" /* unknown */) { - if (flags & 262144 /* TypeParameter */) - return "type parameter" /* typeParameterElement */; - if (flags & 8 /* EnumMember */) - return "enum member" /* enumMemberElement */; - if (flags & 2097152 /* Alias */) - return "alias" /* alias */; - if (flags & 1536 /* Module */) - return "module" /* moduleElement */; - } + if (flags & 262144 /* TypeParameter */) + return "type parameter" /* typeParameterElement */; + if (flags & 8 /* EnumMember */) + return "enum member" /* enumMemberElement */; + if (flags & 2097152 /* Alias */) + return "alias" /* alias */; + if (flags & 1536 /* Module */) + return "module" /* moduleElement */; return result; } SymbolDisplay.getSymbolKind = getSymbolKind; diff --git a/lib/typescript.js b/lib/typescript.js index 533b461d878..9c5828cc415 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -77087,7 +77087,7 @@ var ts; } if (options.emitDeclarationOnly) { if (!options.declaration) { - createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declarations"); + createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration"); } if (options.noEmit) { createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "emitDeclarationOnly", "noEmit"); @@ -82539,6 +82539,102 @@ var ts; return ts.isTemplateLiteralKind(token.kind) && position > token.getStart(sourceFile); } ts.isInTemplateString = isInTemplateString; + function findPrecedingMatchingToken(token, matchingTokenKind, sourceFile) { + var tokenKind = token.kind; + var remainingMatchingTokens = 0; + while (true) { + token = findPrecedingToken(token.getFullStart(), sourceFile); + if (!token) { + return undefined; + } + if (token.kind === matchingTokenKind) { + if (remainingMatchingTokens === 0) { + return token; + } + remainingMatchingTokens--; + } + else if (token.kind === tokenKind) { + remainingMatchingTokens++; + } + } + } + ts.findPrecedingMatchingToken = findPrecedingMatchingToken; + function isPossiblyTypeArgumentPosition(token, sourceFile) { + // This function determines if the node could be type argument position + // Since during editing, when type argument list is not complete, + // the tree could be of any shape depending on the tokens parsed before current node, + // scanning of the previous identifier followed by "<" before current node would give us better result + // Note that we also balance out the already provided type arguments, arrays, object literals while doing so + var remainingLessThanTokens = 0; + while (token) { + switch (token.kind) { + case 27 /* LessThanToken */: + // Found the beginning of the generic argument expression + token = findPrecedingToken(token.getFullStart(), sourceFile); + var tokenIsIdentifier = token && ts.isIdentifier(token); + if (!remainingLessThanTokens || !tokenIsIdentifier) { + return tokenIsIdentifier; + } + remainingLessThanTokens--; + break; + case 47 /* GreaterThanGreaterThanGreaterThanToken */: + remainingLessThanTokens = +3; + break; + case 46 /* GreaterThanGreaterThanToken */: + remainingLessThanTokens = +2; + break; + case 29 /* GreaterThanToken */: + remainingLessThanTokens++; + break; + case 18 /* CloseBraceToken */: + // This can be object type, skip untill we find the matching open brace token + // Skip untill the matching open brace token + token = findPrecedingMatchingToken(token, 17 /* OpenBraceToken */, sourceFile); + if (!token) + return false; + break; + case 20 /* CloseParenToken */: + // This can be object type, skip untill we find the matching open brace token + // Skip untill the matching open brace token + token = findPrecedingMatchingToken(token, 19 /* OpenParenToken */, sourceFile); + if (!token) + return false; + break; + case 22 /* CloseBracketToken */: + // This can be object type, skip untill we find the matching open brace token + // Skip untill the matching open brace token + token = findPrecedingMatchingToken(token, 21 /* OpenBracketToken */, sourceFile); + if (!token) + return false; + break; + // Valid tokens in a type name. Skip. + case 26 /* CommaToken */: + case 36 /* EqualsGreaterThanToken */: + case 71 /* Identifier */: + case 9 /* StringLiteral */: + case 8 /* NumericLiteral */: + case 101 /* TrueKeyword */: + case 86 /* FalseKeyword */: + case 103 /* TypeOfKeyword */: + case 85 /* ExtendsKeyword */: + case 128 /* KeyOfKeyword */: + case 23 /* DotToken */: + case 49 /* BarToken */: + case 55 /* QuestionToken */: + case 56 /* ColonToken */: + break; + default: + if (ts.isTypeNode(token)) { + break; + } + // Invalid token in type + return false; + } + token = findPrecedingToken(token.getFullStart(), sourceFile); + } + return false; + } + ts.isPossiblyTypeArgumentPosition = isPossiblyTypeArgumentPosition; /** * Returns true if the cursor at position in sourceFile is within a comment. * @@ -85168,6 +85264,7 @@ var ts; // Since this is qualified name check its a type node location var isTypeLocation = insideJsDocTagTypeExpression || ts.isPartOfTypeNode(node.parent); var isRhsOfImportDeclaration = ts.isInRightSideOfInternalImportEqualsDeclaration(node); + var allowTypeOrValue = isRhsOfImportDeclaration || (!isTypeLocation && ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile)); if (ts.isEntityName(node)) { var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { @@ -85177,7 +85274,7 @@ var ts; var exportedSymbols = ts.Debug.assertEachDefined(typeChecker.getExportsOfModule(symbol), "getExportsOfModule() should all be defined"); var isValidValueAccess_1 = function (symbol) { return typeChecker.isValidPropertyAccess((node.parent), symbol.name); }; var isValidTypeAccess_1 = function (symbol) { return symbolCanBeReferencedAtTypeLocation(symbol); }; - var isValidAccess = isRhsOfImportDeclaration ? + var isValidAccess = allowTypeOrValue ? // Any kind is allowed when dotting off namespace in internal import equals declaration function (symbol) { return isValidTypeAccess_1(symbol) || isValidValueAccess_1(symbol); } : isTypeLocation ? isValidTypeAccess_1 : isValidValueAccess_1; @@ -85327,8 +85424,9 @@ var ts; } } function filterGlobalCompletion(symbols) { - var isTypeCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (ts.isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); - if (isTypeCompletion) + var isTypeOnlyCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (ts.isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); + var allowTypes = isTypeOnlyCompletion || !isContextTokenValueLocation(contextToken) && ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile); + if (isTypeOnlyCompletion) keywordFilters = 4 /* TypeKeywords */; ts.filterMutate(symbols, function (symbol) { if (!ts.isSourceFile(location)) { @@ -85341,9 +85439,12 @@ var ts; if (ts.isInRightSideOfInternalImportEqualsDeclaration(location)) { return !!(symbol.flags & 1920 /* Namespace */); } - if (isTypeCompletion) { + if (allowTypes) { // Its a type, but you can reach it by namespace.type as well - return symbolCanBeReferencedAtTypeLocation(symbol); + var symbolAllowedAsType = symbolCanBeReferencedAtTypeLocation(symbol); + if (symbolAllowedAsType || isTypeOnlyCompletion) { + return symbolAllowedAsType; + } } } // expressions are value space (which includes the value namespaces) @@ -85353,7 +85454,7 @@ var ts; function isContextTokenValueLocation(contextToken) { return contextToken && contextToken.kind === 103 /* TypeOfKeyword */ && - contextToken.parent.kind === 164 /* TypeQuery */; + (contextToken.parent.kind === 164 /* TypeQuery */ || ts.isTypeOfExpression(contextToken.parent)); } function isContextTokenTypeLocation(contextToken) { if (contextToken) { @@ -92529,6 +92630,10 @@ var ts; (function (SymbolDisplay) { // TODO(drosen): use contextual SemanticMeaning. function getSymbolKind(typeChecker, symbol, location) { + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location); + if (result !== "" /* unknown */) { + return result; + } var flags = ts.getCombinedLocalAndExportSymbolFlags(symbol); if (flags & 32 /* Class */) { return ts.getDeclarationOfKind(symbol, 203 /* ClassExpression */) ? @@ -92542,17 +92647,14 @@ var ts; return "interface" /* interfaceElement */; if (flags & 262144 /* TypeParameter */) return "type parameter" /* typeParameterElement */; - var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location); - if (result === "" /* unknown */) { - if (flags & 262144 /* TypeParameter */) - return "type parameter" /* typeParameterElement */; - if (flags & 8 /* EnumMember */) - return "enum member" /* enumMemberElement */; - if (flags & 2097152 /* Alias */) - return "alias" /* alias */; - if (flags & 1536 /* Module */) - return "module" /* moduleElement */; - } + if (flags & 262144 /* TypeParameter */) + return "type parameter" /* typeParameterElement */; + if (flags & 8 /* EnumMember */) + return "enum member" /* enumMemberElement */; + if (flags & 2097152 /* Alias */) + return "alias" /* alias */; + if (flags & 1536 /* Module */) + return "module" /* moduleElement */; return result; } SymbolDisplay.getSymbolKind = getSymbolKind; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 533b461d878..9c5828cc415 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -77087,7 +77087,7 @@ var ts; } if (options.emitDeclarationOnly) { if (!options.declaration) { - createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declarations"); + createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration"); } if (options.noEmit) { createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "emitDeclarationOnly", "noEmit"); @@ -82539,6 +82539,102 @@ var ts; return ts.isTemplateLiteralKind(token.kind) && position > token.getStart(sourceFile); } ts.isInTemplateString = isInTemplateString; + function findPrecedingMatchingToken(token, matchingTokenKind, sourceFile) { + var tokenKind = token.kind; + var remainingMatchingTokens = 0; + while (true) { + token = findPrecedingToken(token.getFullStart(), sourceFile); + if (!token) { + return undefined; + } + if (token.kind === matchingTokenKind) { + if (remainingMatchingTokens === 0) { + return token; + } + remainingMatchingTokens--; + } + else if (token.kind === tokenKind) { + remainingMatchingTokens++; + } + } + } + ts.findPrecedingMatchingToken = findPrecedingMatchingToken; + function isPossiblyTypeArgumentPosition(token, sourceFile) { + // This function determines if the node could be type argument position + // Since during editing, when type argument list is not complete, + // the tree could be of any shape depending on the tokens parsed before current node, + // scanning of the previous identifier followed by "<" before current node would give us better result + // Note that we also balance out the already provided type arguments, arrays, object literals while doing so + var remainingLessThanTokens = 0; + while (token) { + switch (token.kind) { + case 27 /* LessThanToken */: + // Found the beginning of the generic argument expression + token = findPrecedingToken(token.getFullStart(), sourceFile); + var tokenIsIdentifier = token && ts.isIdentifier(token); + if (!remainingLessThanTokens || !tokenIsIdentifier) { + return tokenIsIdentifier; + } + remainingLessThanTokens--; + break; + case 47 /* GreaterThanGreaterThanGreaterThanToken */: + remainingLessThanTokens = +3; + break; + case 46 /* GreaterThanGreaterThanToken */: + remainingLessThanTokens = +2; + break; + case 29 /* GreaterThanToken */: + remainingLessThanTokens++; + break; + case 18 /* CloseBraceToken */: + // This can be object type, skip untill we find the matching open brace token + // Skip untill the matching open brace token + token = findPrecedingMatchingToken(token, 17 /* OpenBraceToken */, sourceFile); + if (!token) + return false; + break; + case 20 /* CloseParenToken */: + // This can be object type, skip untill we find the matching open brace token + // Skip untill the matching open brace token + token = findPrecedingMatchingToken(token, 19 /* OpenParenToken */, sourceFile); + if (!token) + return false; + break; + case 22 /* CloseBracketToken */: + // This can be object type, skip untill we find the matching open brace token + // Skip untill the matching open brace token + token = findPrecedingMatchingToken(token, 21 /* OpenBracketToken */, sourceFile); + if (!token) + return false; + break; + // Valid tokens in a type name. Skip. + case 26 /* CommaToken */: + case 36 /* EqualsGreaterThanToken */: + case 71 /* Identifier */: + case 9 /* StringLiteral */: + case 8 /* NumericLiteral */: + case 101 /* TrueKeyword */: + case 86 /* FalseKeyword */: + case 103 /* TypeOfKeyword */: + case 85 /* ExtendsKeyword */: + case 128 /* KeyOfKeyword */: + case 23 /* DotToken */: + case 49 /* BarToken */: + case 55 /* QuestionToken */: + case 56 /* ColonToken */: + break; + default: + if (ts.isTypeNode(token)) { + break; + } + // Invalid token in type + return false; + } + token = findPrecedingToken(token.getFullStart(), sourceFile); + } + return false; + } + ts.isPossiblyTypeArgumentPosition = isPossiblyTypeArgumentPosition; /** * Returns true if the cursor at position in sourceFile is within a comment. * @@ -85168,6 +85264,7 @@ var ts; // Since this is qualified name check its a type node location var isTypeLocation = insideJsDocTagTypeExpression || ts.isPartOfTypeNode(node.parent); var isRhsOfImportDeclaration = ts.isInRightSideOfInternalImportEqualsDeclaration(node); + var allowTypeOrValue = isRhsOfImportDeclaration || (!isTypeLocation && ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile)); if (ts.isEntityName(node)) { var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { @@ -85177,7 +85274,7 @@ var ts; var exportedSymbols = ts.Debug.assertEachDefined(typeChecker.getExportsOfModule(symbol), "getExportsOfModule() should all be defined"); var isValidValueAccess_1 = function (symbol) { return typeChecker.isValidPropertyAccess((node.parent), symbol.name); }; var isValidTypeAccess_1 = function (symbol) { return symbolCanBeReferencedAtTypeLocation(symbol); }; - var isValidAccess = isRhsOfImportDeclaration ? + var isValidAccess = allowTypeOrValue ? // Any kind is allowed when dotting off namespace in internal import equals declaration function (symbol) { return isValidTypeAccess_1(symbol) || isValidValueAccess_1(symbol); } : isTypeLocation ? isValidTypeAccess_1 : isValidValueAccess_1; @@ -85327,8 +85424,9 @@ var ts; } } function filterGlobalCompletion(symbols) { - var isTypeCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (ts.isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); - if (isTypeCompletion) + var isTypeOnlyCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (ts.isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); + var allowTypes = isTypeOnlyCompletion || !isContextTokenValueLocation(contextToken) && ts.isPossiblyTypeArgumentPosition(contextToken, sourceFile); + if (isTypeOnlyCompletion) keywordFilters = 4 /* TypeKeywords */; ts.filterMutate(symbols, function (symbol) { if (!ts.isSourceFile(location)) { @@ -85341,9 +85439,12 @@ var ts; if (ts.isInRightSideOfInternalImportEqualsDeclaration(location)) { return !!(symbol.flags & 1920 /* Namespace */); } - if (isTypeCompletion) { + if (allowTypes) { // Its a type, but you can reach it by namespace.type as well - return symbolCanBeReferencedAtTypeLocation(symbol); + var symbolAllowedAsType = symbolCanBeReferencedAtTypeLocation(symbol); + if (symbolAllowedAsType || isTypeOnlyCompletion) { + return symbolAllowedAsType; + } } } // expressions are value space (which includes the value namespaces) @@ -85353,7 +85454,7 @@ var ts; function isContextTokenValueLocation(contextToken) { return contextToken && contextToken.kind === 103 /* TypeOfKeyword */ && - contextToken.parent.kind === 164 /* TypeQuery */; + (contextToken.parent.kind === 164 /* TypeQuery */ || ts.isTypeOfExpression(contextToken.parent)); } function isContextTokenTypeLocation(contextToken) { if (contextToken) { @@ -92529,6 +92630,10 @@ var ts; (function (SymbolDisplay) { // TODO(drosen): use contextual SemanticMeaning. function getSymbolKind(typeChecker, symbol, location) { + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location); + if (result !== "" /* unknown */) { + return result; + } var flags = ts.getCombinedLocalAndExportSymbolFlags(symbol); if (flags & 32 /* Class */) { return ts.getDeclarationOfKind(symbol, 203 /* ClassExpression */) ? @@ -92542,17 +92647,14 @@ var ts; return "interface" /* interfaceElement */; if (flags & 262144 /* TypeParameter */) return "type parameter" /* typeParameterElement */; - var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location); - if (result === "" /* unknown */) { - if (flags & 262144 /* TypeParameter */) - return "type parameter" /* typeParameterElement */; - if (flags & 8 /* EnumMember */) - return "enum member" /* enumMemberElement */; - if (flags & 2097152 /* Alias */) - return "alias" /* alias */; - if (flags & 1536 /* Module */) - return "module" /* moduleElement */; - } + if (flags & 262144 /* TypeParameter */) + return "type parameter" /* typeParameterElement */; + if (flags & 8 /* EnumMember */) + return "enum member" /* enumMemberElement */; + if (flags & 2097152 /* Alias */) + return "alias" /* alias */; + if (flags & 1536 /* Module */) + return "module" /* moduleElement */; return result; } SymbolDisplay.getSymbolKind = getSymbolKind;