From 90afd6d620f30bc47e862970a931ca0e207e6b28 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Fri, 19 Jul 2019 09:01:05 -0700 Subject: [PATCH 1/3] Update user baselines (#32483) --- .../baselines/reference/docker/azure-sdk.log | 58 ++++++------------- .../reference/docker/office-ui-fabric.log | 16 ++--- .../reference/user/adonis-framework.log | 2 +- .../user/chrome-devtools-frontend.log | 3 +- tests/baselines/reference/user/lodash.log | 2 - tests/baselines/reference/user/npmlog.log | 6 +- 6 files changed, 33 insertions(+), 54 deletions(-) diff --git a/tests/baselines/reference/docker/azure-sdk.log b/tests/baselines/reference/docker/azure-sdk.log index a1e33524e6e..a75af93aee1 100644 --- a/tests/baselines/reference/docker/azure-sdk.log +++ b/tests/baselines/reference/docker/azure-sdk.log @@ -5,16 +5,11 @@ Rush Multi-Project Build Tool 5.10.1 - https://rushjs.io Starting "rush rebuild" Executing a maximum of 1 simultaneous processes... [@azure/cosmos] started -npm ERR! code ELIFECYCLE -npm ERR! errno 2 -npm ERR! @azure/cosmos@X.X.X compile: `echo Using TypeScript && tsc --version && tsc -p tsconfig.prod.json --pretty` -npm ERR! Exit status 2 -npm ERR! -npm ERR! Failed at the @azure/cosmos@X.X.X compile script. -npm ERR! This is probably not a problem with npm. There is likely additional logging output above. -npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-15T13_35_10_789Z-debug.log +XX of XX: [@azure/cosmos] completed successfully in ? seconds +[@azure/event-processor-host] started +XX of XX: [@azure/event-processor-host] completed successfully in ? seconds [@azure/service-bus] started +Warning: You have changed the public API signature for this project. Updating review/service-bus.api.md [@azure/storage-blob] started XX of XX: [@azure/storage-blob] completed successfully in ? seconds [@azure/storage-file] started @@ -23,6 +18,8 @@ XX of XX: [@azure/storage-file] completed successfully in ? seconds XX of XX: [@azure/storage-queue] completed successfully in ? seconds [@azure/template] started XX of XX: [@azure/template] completed successfully in ? seconds +[testhub] started +XX of XX: [testhub] completed successfully in ? seconds [@azure/abort-controller] started XX of XX: [@azure/abort-controller] completed successfully in ? seconds [@azure/core-asynciterator-polyfill] started @@ -38,7 +35,7 @@ npm ERR! npm ERR! Failed at the @azure/core-http@X.X.X-preview.1 build:tsc script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-15T13_36_24_862Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-19T13_40_31_496Z-debug.log ERROR: "build:tsc" exited with 2. npm ERR! code ELIFECYCLE npm ERR! errno 1 @@ -48,20 +45,17 @@ npm ERR! npm ERR! Failed at the @azure/core-http@X.X.X-preview.1 build:lib script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-15T13_36_24_938Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-19T13_40_31_533Z-debug.log ERROR: "build:lib" exited with 1. [@azure/core-paging] started XX of XX: [@azure/core-paging] completed successfully in ? seconds -[@azure/event-processor-host] started -XX of XX: [@azure/event-processor-host] completed successfully in ? seconds -[testhub] started -XX of XX: [testhub] completed successfully in ? seconds -SUCCESS (10) +SUCCESS (11) ================================ @azure/abort-controller (? seconds) @azure/core-asynciterator-polyfill (? seconds) @azure/core-auth (? seconds) @azure/core-paging (? seconds) +@azure/cosmos (? seconds) @azure/event-processor-host (? seconds) @azure/storage-blob (? seconds) @azure/storage-file (? seconds) @@ -69,6 +63,11 @@ SUCCESS (10) @azure/template (? seconds) testhub (? seconds) ================================ +SUCCESS WITH WARNINGS (1) +================================ +@azure/service-bus (? seconds) +Warning: You have changed the public API signature for this project. Updating review/service-bus.api.md +================================ BLOCKED (7) ================================ @azure/core-amqp @@ -79,7 +78,7 @@ BLOCKED (7) @azure/keyvault-keys @azure/keyvault-secrets ================================ -FAILURE (3) +FAILURE (1) ================================ @azure/core-http (? seconds) npm ERR! code ELIFECYCLE @@ -90,7 +89,7 @@ npm ERR! npm ERR! Failed at the @azure/core-http@X.X.X-preview.1 build:tsc script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-15T13_36_24_862Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-19T13_40_31_496Z-debug.log ERROR: "build:tsc" exited with 2. npm ERR! code ELIFECYCLE npm ERR! errno 1 @@ -100,24 +99,8 @@ npm ERR! npm ERR! Failed at the @azure/core-http@X.X.X-preview.1 build:lib script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-15T13_36_24_938Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-19T13_40_31_533Z-debug.log ERROR: "build:lib" exited with 1. -@azure/cosmos ( ? seconds) -npm ERR! code ELIFECYCLE -npm ERR! errno 2 -npm ERR! @azure/cosmos@X.X.X compile: `echo Using TypeScript && tsc --version && tsc -p tsconfig.prod.json --pretty` -npm ERR! Exit status 2 -npm ERR! -npm ERR! Failed at the @azure/cosmos@X.X.X compile script. -npm ERR! This is probably not a problem with npm. There is likely additional logging output above. -npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-15T13_35_10_789Z-debug.log -@azure/service-bus ( ? seconds) ->>> @azure/service-bus -tsc -p . && rollup -c 2>&1 && npm run extract-api -error TS2318: Cannot find global type 'AsyncGenerator'. -src/receiver.ts(193,32): error TS2739: Type '{}' is missing the following properties from type 'AsyncIterableIterator': [Symbol.asyncIterator], next -src/receiver.ts(742,32): error TS2322: Type '{}' is not assignable to type 'AsyncIterableIterator'. ================================ Error: Project(s) failed to build rush rebuild - Errors! ( ? seconds) @@ -126,8 +109,7 @@ rush rebuild - Errors! ( ? seconds) Standard error: Your version of Node.js (X.X.X) has not been tested with this release of Rush. The Rush team will not accept issue reports for it. Please consider upgrading Rush or downgrading Node.js. -XX of XX: [@azure/cosmos] failed to build! -XX of XX: [@azure/service-bus] failed to build! +XX of XX: [@azure/service-bus] completed with warnings in ? seconds XX of XX: [@azure/core-http] failed to build! XX of XX: [@azure/core-arm] blocked by [@azure/core-http]! XX of XX: [@azure/identity] blocked by [@azure/core-http]! @@ -137,5 +119,3 @@ XX of XX: [@azure/keyvault-certificates] blocked by [@azure/core-http]! XX of XX: [@azure/keyvault-keys] blocked by [@azure/core-http]! XX of XX: [@azure/keyvault-secrets] blocked by [@azure/core-http]! [@azure/core-http] Returned error code: 1 -[@azure/cosmos] Returned error code: 2 -[@azure/service-bus] Returned error code: 2 diff --git a/tests/baselines/reference/docker/office-ui-fabric.log b/tests/baselines/reference/docker/office-ui-fabric.log index c3a55fc3f6b..888e20cac4b 100644 --- a/tests/baselines/reference/docker/office-ui-fabric.log +++ b/tests/baselines/reference/docker/office-ui-fabric.log @@ -12,11 +12,11 @@ XX of XX: [@uifabric/tslint-rules] completed successfully in ? seconds ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. PASS src/__tests__/codepenTransform.test.ts codepen transform - ✓ handles examples with function components (225ms) + ✓ handles examples with function components (256ms) ✓ handles examples with class components (38ms) - ✓ handles examples importing exampleData (115ms) - ✓ handles examples importing TestImages (45ms) - ✓ handles examples importing PeopleExampleData (288ms) + ✓ handles examples importing exampleData (125ms) + ✓ handles examples importing TestImages (33ms) + ✓ handles examples importing PeopleExampleData (270ms) Test Suites: 1 passed, 1 total Tests: 5 passed, 5 total Snapshots: 4 passed, 4 total @@ -246,11 +246,11 @@ SUCCESS WITH WARNINGS (5) ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. PASS src/__tests__/codepenTransform.test.ts codepen transform - ✓ handles examples with function components (225ms) + ✓ handles examples with function components (256ms) ✓ handles examples with class components (38ms) - ✓ handles examples importing exampleData (115ms) - ✓ handles examples importing TestImages (45ms) - ✓ handles examples importing PeopleExampleData (288ms) + ✓ handles examples importing exampleData (125ms) + ✓ handles examples importing TestImages (33ms) + ✓ handles examples importing PeopleExampleData (270ms) Test Suites: 1 passed, 1 total Tests: 5 passed, 5 total Snapshots: 4 passed, 4 total diff --git a/tests/baselines/reference/user/adonis-framework.log b/tests/baselines/reference/user/adonis-framework.log index e3b19b5de04..6243a7a15db 100644 --- a/tests/baselines/reference/user/adonis-framework.log +++ b/tests/baselines/reference/user/adonis-framework.log @@ -30,7 +30,7 @@ node_modules/adonis-framework/src/Encryption/index.js(87,15): error TS2304: Cann node_modules/adonis-framework/src/Encryption/index.js(101,21): error TS2769: No overload matches this call. Overload 1 of 4, '(data: Binary, input_encoding: undefined, output_encoding: Utf8AsciiBinaryEncoding): string', gave the following error. Argument of type '"base64"' is not assignable to parameter of type 'undefined'. - Overload 2 of 4, '(data: string, input_encoding: "binary" | "base64" | "hex" | undefined, output_encoding: Utf8AsciiBinaryEncoding): string', gave the following error. + Overload 2 of 4, '(data: string, input_encoding: "base64" | "binary" | "hex" | undefined, output_encoding: Utf8AsciiBinaryEncoding): string', gave the following error. Argument of type 'string' is not assignable to parameter of type 'Utf8AsciiBinaryEncoding'. node_modules/adonis-framework/src/Encryption/index.js(114,15): error TS2304: Cannot find name 'Mixed'. node_modules/adonis-framework/src/Encryption/index.js(119,23): error TS2554: Expected 2 arguments, but got 1. diff --git a/tests/baselines/reference/user/chrome-devtools-frontend.log b/tests/baselines/reference/user/chrome-devtools-frontend.log index 3f4fa8d5b95..2d4e456d759 100644 --- a/tests/baselines/reference/user/chrome-devtools-frontend.log +++ b/tests/baselines/reference/user/chrome-devtools-frontend.log @@ -6501,7 +6501,8 @@ node_modules/chrome-devtools-frontend/front_end/formatter_worker/acorn/acorn_loo node_modules/chrome-devtools-frontend/front_end/formatter_worker/acorn/acorn_loose.js(258,55): error TS2339: Property 'end' does not exist on type 'true'. node_modules/chrome-devtools-frontend/front_end/formatter_worker/acorn/acorn_loose.js(1365,5): error TS2339: Property 'next' does not exist on type 'LooseParser'. node_modules/chrome-devtools-frontend/front_end/formatter_worker/acorn/acorn_loose.js(1366,12): error TS2339: Property 'parseTopLevel' does not exist on type 'LooseParser'. -node_modules/chrome-devtools-frontend/front_end/har_importer/HARImporter.js(26,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'page' must be of type 'any', but here has type 'HARPage'. +node_modules/chrome-devtools-frontend/front_end/har_importer/HARImporter.js(16,32): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +node_modules/chrome-devtools-frontend/front_end/har_importer/HARImporter.js(16,52): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. node_modules/chrome-devtools-frontend/front_end/har_importer/HARImporter.js(46,5): error TS2322: Type 'Date' is not assignable to type 'number'. node_modules/chrome-devtools-frontend/front_end/heap_profiler_test_runner/HeapProfilerTestRunner.js(320,70): error TS2339: Property 'heap_profiler' does not exist on type 'any[]'. node_modules/chrome-devtools-frontend/front_end/heap_profiler_test_runner/HeapProfilerTestRunner.js(321,35): error TS2339: Property 'heap_profiler' does not exist on type 'any[]'. diff --git a/tests/baselines/reference/user/lodash.log b/tests/baselines/reference/user/lodash.log index 954077ce729..1c358238f8d 100644 --- a/tests/baselines/reference/user/lodash.log +++ b/tests/baselines/reference/user/lodash.log @@ -382,8 +382,6 @@ node_modules/lodash/nthArg.js(28,26): error TS2345: Argument of type 'number | u node_modules/lodash/omit.js(48,32): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. node_modules/lodash/orderBy.js(18,10): error TS1003: Identifier expected. node_modules/lodash/orderBy.js(18,10): error TS8024: JSDoc '@param' tag has name '', but there is no parameter with that name. -node_modules/lodash/org.js(8,22): error TS2307: Cannot find module 'moment'. -node_modules/lodash/org.js(9,19): error TS2307: Cannot find module 'ncp'. node_modules/lodash/parseInt.js(24,10): error TS1003: Identifier expected. node_modules/lodash/parseInt.js(24,10): error TS8024: JSDoc '@param' tag has name '', but there is no parameter with that name. node_modules/lodash/partial.js(48,9): error TS2339: Property 'placeholder' does not exist on type 'Function'. diff --git a/tests/baselines/reference/user/npmlog.log b/tests/baselines/reference/user/npmlog.log index 1e6284674e3..6b6e315d996 100644 --- a/tests/baselines/reference/user/npmlog.log +++ b/tests/baselines/reference/user/npmlog.log @@ -8,9 +8,9 @@ node_modules/npmlog/log.js(194,37): error TS2345: Argument of type 'any[]' is no Property '0' is missing in type 'any[]' but required in type '[any, ...any[]]'. node_modules/npmlog/log.js(218,12): error TS2551: Property '_paused' does not exist on type 'typeof EventEmitter'. Did you mean 'pause'? node_modules/npmlog/log.js(271,16): error TS2769: No overload matches this call. - Overload 1 of 2, '(buffer: string | Uint8Array | Buffer, cb?: ((err?: Error | null | undefined) => void) | undefined): boolean', gave the following error. - Argument of type 'string | undefined' is not assignable to parameter of type 'string | Uint8Array | Buffer'. - Type 'undefined' is not assignable to type 'string | Uint8Array | Buffer'. + Overload 1 of 2, '(buffer: string | Uint8Array, cb?: ((err?: Error | null | undefined) => void) | undefined): boolean', gave the following error. + Argument of type 'string | undefined' is not assignable to parameter of type 'string | Uint8Array'. + Type 'undefined' is not assignable to type 'string | Uint8Array'. Overload 2 of 2, '(str: string, encoding?: string | undefined, cb?: ((err?: Error | null | undefined) => void) | undefined): boolean', gave the following error. Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'. From e543d8bc5a17bdee931ac1a0d2b9ddd32a7164a9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 19 Jul 2019 15:22:04 -0700 Subject: [PATCH 2/3] Fix type keyword completions (#32474) * Fix type keyword completions 1. In functions, type keywords were omitted. 2. In All context, no keywords were omitted. (1) fixes #28737 (2) removes 17 keywords that should not be suggested, even at the toplevel of a typescript file: * private * protected * public * static * abstract * as * constructor * get * infer * is * namespace * require * set * type * from * global * of I don't know whether we have a bug tracking this or not. * Change keyword filter in filterGlobalCompletion Instead of changing FunctionLikeBodyKeywords * Add more tests cases * Make type-only completions after < more common Because isPossiblyTypeArgumentPosition doesn't give false positives now that it uses type information. --- src/harness/fourslash.ts | 43 +------------------ src/services/completions.ts | 38 +++++++++------- ...FunctionLikeBody_includesPrimitiveTypes.ts | 27 ++++++++++++ .../completionListInUnclosedTypeArguments.ts | 9 ++-- .../completionListIsGlobalCompletion.ts | 2 +- ...mpletionsIsPossiblyTypeArgumentPosition.ts | 17 +++----- tests/cases/fourslash/fourslash.ts | 1 - tests/cases/user/prettier/prettier | 2 +- 8 files changed, 64 insertions(+), 75 deletions(-) create mode 100644 tests/cases/fourslash/completionInFunctionLikeBody_includesPrimitiveTypes.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index aa764e74cdc..f12506be2fb 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -797,7 +797,7 @@ namespace FourSlash { for (const include of toArray(options.includes)) { const name = typeof include === "string" ? include : include.name; const found = nameToEntries.get(name); - if (!found) throw this.raiseError(`No completion ${name} found`); + if (!found) throw this.raiseError(`Includes: completion '${name}' not found.`); assert(found.length === 1); // Must use 'exact' for multiple completions with same name this.verifyCompletionEntry(ts.first(found), include); } @@ -806,7 +806,7 @@ namespace FourSlash { for (const exclude of toArray(options.excludes)) { assert(typeof exclude === "string"); if (nameToEntries.has(exclude)) { - this.raiseError(`Did not expect to get a completion named ${exclude}`); + this.raiseError(`Excludes: unexpected completion '${exclude}' found.`); } } } @@ -4827,40 +4827,23 @@ namespace FourSlashInterface { "interface", "let", "package", - "private", - "protected", - "public", - "static", "yield", - "abstract", - "as", "any", "async", "await", "boolean", - "constructor", "declare", - "get", - "infer", - "is", "keyof", "module", - "namespace", "never", "readonly", - "require", "number", "object", - "set", "string", "symbol", - "type", "unique", "unknown", - "from", - "global", "bigint", - "of", ].map(keywordEntry); export const statementKeywords: ReadonlyArray = statementKeywordsWithTypes.filter(k => { @@ -5041,40 +5024,23 @@ namespace FourSlashInterface { "interface", "let", "package", - "private", - "protected", - "public", - "static", "yield", - "abstract", - "as", "any", "async", "await", "boolean", - "constructor", "declare", - "get", - "infer", - "is", "keyof", "module", - "namespace", "never", "readonly", - "require", "number", "object", - "set", "string", "symbol", - "type", "unique", "unknown", - "from", - "global", "bigint", - "of", ].map(keywordEntry); export const globalInJsKeywords = getInJsKeywords(globalKeywords); @@ -5127,11 +5093,6 @@ namespace FourSlashInterface { export const insideMethodInJsKeywords = getInJsKeywords(insideMethodKeywords); - export const globalKeywordsPlusUndefined: ReadonlyArray = (() => { - const i = ts.findIndex(globalKeywords, x => x.name === "unique"); - return [...globalKeywords.slice(0, i), keywordEntry("undefined"), ...globalKeywords.slice(i)]; - })(); - export const globals: ReadonlyArray = [ globalThisEntry, ...globalsVars, diff --git a/src/services/completions.ts b/src/services/completions.ts index b5c412a788a..e9a38fb1516 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -947,11 +947,13 @@ namespace ts.Completions { // Right of dot member completion list completionKind = CompletionKind.PropertyAccess; - // Since this is qualified name check its a type node location + // Since this is qualified name check it's a type node location const isImportType = isLiteralImportTypeNode(node); - const isTypeLocation = insideJsDocTagTypeExpression || (isImportType && !(node as ImportTypeNode).isTypeOf) || isPartOfTypeNode(node.parent); + const isTypeLocation = insideJsDocTagTypeExpression + || (isImportType && !(node as ImportTypeNode).isTypeOf) + || isPartOfTypeNode(node.parent) + || isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker); const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration(node); - const allowTypeOrValue = isRhsOfImportDeclaration || (!isTypeLocation && isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker)); if (isEntityName(node) || isImportType) { const isNamespaceName = isModuleDeclaration(node.parent); if (isNamespaceName) isNewIdentifierLocation = true; @@ -968,7 +970,7 @@ namespace ts.Completions { isNamespaceName // At `namespace N.M/**/`, if this is the only declaration of `M`, don't include `M` as a completion. ? symbol => !!(symbol.flags & SymbolFlags.Namespace) && !symbol.declarations.every(d => d.parent === node.parent) - : allowTypeOrValue ? + : isRhsOfImportDeclaration ? // Any kind is allowed when dotting off namespace in internal import equals declaration symbol => isValidTypeAccess(symbol) || isValidValueAccess(symbol) : isTypeLocation ? isValidTypeAccess : isValidValueAccess; @@ -1181,7 +1183,6 @@ namespace ts.Completions { function filterGlobalCompletion(symbols: Symbol[]): void { const isTypeOnly = isTypeOnlyCompletion(); - const allowTypes = isTypeOnly || !isContextTokenValueLocation(contextToken) && isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker); if (isTypeOnly) { keywordFilters = isTypeAssertion() ? KeywordCompletionFilters.TypeAssertionKeywords @@ -1202,12 +1203,9 @@ namespace ts.Completions { return !!(symbol.flags & SymbolFlags.Namespace); } - if (allowTypes) { - // Its a type, but you can reach it by namespace.type as well - const symbolAllowedAsType = symbolCanBeReferencedAtTypeLocation(symbol); - if (symbolAllowedAsType || isTypeOnly) { - return symbolAllowedAsType; - } + if (isTypeOnly) { + // It's a type, but you can reach it by namespace.type as well + return symbolCanBeReferencedAtTypeLocation(symbol); } } @@ -1221,7 +1219,11 @@ namespace ts.Completions { } function isTypeOnlyCompletion(): boolean { - return insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); + return insideJsDocTagTypeExpression + || !isContextTokenValueLocation(contextToken) && + (isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker) + || isPartOfTypeNode(location) + || isContextTokenTypeLocation(contextToken)); } function isContextTokenValueLocation(contextToken: Node) { @@ -2060,16 +2062,18 @@ namespace ts.Completions { case KeywordCompletionFilters.None: return false; case KeywordCompletionFilters.All: - return kind === SyntaxKind.AsyncKeyword || SyntaxKind.AwaitKeyword || !isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind) || kind === SyntaxKind.DeclareKeyword || kind === SyntaxKind.ModuleKeyword + return isFunctionLikeBodyKeyword(kind) + || kind === SyntaxKind.DeclareKeyword + || kind === SyntaxKind.ModuleKeyword || isTypeKeyword(kind) && kind !== SyntaxKind.UndefinedKeyword; + case KeywordCompletionFilters.FunctionLikeBodyKeywords: + return isFunctionLikeBodyKeyword(kind); case KeywordCompletionFilters.ClassElementKeywords: return isClassMemberCompletionKeyword(kind); case KeywordCompletionFilters.InterfaceElementKeywords: return isInterfaceOrTypeLiteralCompletionKeyword(kind); case KeywordCompletionFilters.ConstructorParameterKeywords: return isParameterPropertyModifier(kind); - case KeywordCompletionFilters.FunctionLikeBodyKeywords: - return isFunctionLikeBodyKeyword(kind); case KeywordCompletionFilters.TypeAssertionKeywords: return isTypeKeyword(kind) || kind === SyntaxKind.ConstKeyword; case KeywordCompletionFilters.TypeKeywords: @@ -2132,7 +2136,9 @@ namespace ts.Completions { } function isFunctionLikeBodyKeyword(kind: SyntaxKind) { - return kind === SyntaxKind.AsyncKeyword || kind === SyntaxKind.AwaitKeyword || !isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind); + return kind === SyntaxKind.AsyncKeyword + || kind === SyntaxKind.AwaitKeyword + || !isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind); } function keywordForNode(node: Node): SyntaxKind { diff --git a/tests/cases/fourslash/completionInFunctionLikeBody_includesPrimitiveTypes.ts b/tests/cases/fourslash/completionInFunctionLikeBody_includesPrimitiveTypes.ts new file mode 100644 index 00000000000..bc94936ab43 --- /dev/null +++ b/tests/cases/fourslash/completionInFunctionLikeBody_includesPrimitiveTypes.ts @@ -0,0 +1,27 @@ +/// + +//// class Foo { } +//// class Bar { } +//// function includesTypes() { +//// new Foo ////f -////f(); +////f(); //// ////f2 ////f2 -////f2(); +////f2(); //// ////f2 { const markerName = test.markerName(marker) || ""; - const typeOnly = markerName.endsWith("TypeOnly") || marker.data && marker.data.typeOnly; const valueOnly = markerName.endsWith("ValueOnly"); verify.completions({ marker, - includes: typeOnly ? "Type" : valueOnly ? "x" : ["Type", "x"], - excludes: typeOnly ? "x" : valueOnly ? "Type" : [], + includes: valueOnly ? "x" : "Type", + excludes: valueOnly ? "Type" : "x", isNewIdentifierLocation: marker.data && marker.data.newId || false, }); }); diff --git a/tests/cases/fourslash/completionListIsGlobalCompletion.ts b/tests/cases/fourslash/completionListIsGlobalCompletion.ts index ea89155a771..91cd1a0f9c7 100644 --- a/tests/cases/fourslash/completionListIsGlobalCompletion.ts +++ b/tests/cases/fourslash/completionListIsGlobalCompletion.ts @@ -48,5 +48,5 @@ verify.completions( { marker: "13", exact: globals, isGlobalCompletion: false }, { marker: "15", exact: globals, isGlobalCompletion: true, isNewIdentifierLocation: true }, { marker: "16", exact: [...x, completion.globalThisEntry, ...completion.globalsVars, completion.undefinedVarEntry], isGlobalCompletion: false }, - { marker: "17", exact: completion.globalKeywordsPlusUndefined, isGlobalCompletion: false }, + { marker: "17", exact: completion.globalKeywords, isGlobalCompletion: false }, ); diff --git a/tests/cases/fourslash/completionsIsPossiblyTypeArgumentPosition.ts b/tests/cases/fourslash/completionsIsPossiblyTypeArgumentPosition.ts index 1ea8416d70b..704fe0d8347 100644 --- a/tests/cases/fourslash/completionsIsPossiblyTypeArgumentPosition.ts +++ b/tests/cases/fourslash/completionsIsPossiblyTypeArgumentPosition.ts @@ -9,25 +9,22 @@ ////x + {| "valueOnly": true |} ////x < {| "valueOnly": true |} ////f < {| "valueOnly": true |} -////g < {| "valueOnly": false |} -////const something: C<{| "typeOnly": true |}; -////const something2: C(): callAndConstruct; (): string; }; ////interface callAndConstruct {} ////new callAndConstruct; export const insideMethodKeywords: ReadonlyArray; export const insideMethodInJsKeywords: ReadonlyArray; - export const globalKeywordsPlusUndefined: ReadonlyArray; export const globalsVars: ReadonlyArray; export function globalsInsideFunction(plus: ReadonlyArray): ReadonlyArray; export function globalsInJsInsideFunction(plus: ReadonlyArray): ReadonlyArray; diff --git a/tests/cases/user/prettier/prettier b/tests/cases/user/prettier/prettier index 1e471a00796..7f938c71ffd 160000 --- a/tests/cases/user/prettier/prettier +++ b/tests/cases/user/prettier/prettier @@ -1 +1 @@ -Subproject commit 1e471a007968b7490563b91ed6909ae6046f3fe8 +Subproject commit 7f938c71ffda293eb1b69adf8bd12b7c11f9113b From aab3069e643952f5ddfe750fe3e5f196c16c3915 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 19 Jul 2019 15:55:22 -0700 Subject: [PATCH 3/3] Fix the assert of reporting file infos still attached to the project for circular json reference --- src/server/editorServices.ts | 19 ++++++++++++++++++- src/testRunner/unittests/tsserver/projects.ts | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 81c56bb179b..df9f0e3ee01 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1087,7 +1087,24 @@ namespace ts.server { project.close(); if (Debug.shouldAssert(AssertionLevel.Normal)) { - this.filenameToScriptInfo.forEach(info => Debug.assert(!info.isAttached(project), "Found script Info still attached to project", () => `${project.projectName}: ScriptInfos still attached: ${JSON.stringify(mapDefined(arrayFrom(this.filenameToScriptInfo.values()), info => info.isAttached(project) ? info : undefined))}`)); + this.filenameToScriptInfo.forEach(info => Debug.assert( + !info.isAttached(project), + "Found script Info still attached to project", + () => `${project.projectName}: ScriptInfos still attached: ${JSON.stringify( + arrayFrom( + mapDefinedIterator( + this.filenameToScriptInfo.values(), + info => info.isAttached(project) ? + { + fileName: info.fileName, + projects: info.containingProjects.map(p => p.projectName), + hasMixedContent: info.hasMixedContent + } : undefined + ) + ), + /*replacer*/ undefined, + " " + )}`)); } // Remove the project from pending project updates this.pendingProjectUpdates.delete(project.getProjectName()); diff --git a/src/testRunner/unittests/tsserver/projects.ts b/src/testRunner/unittests/tsserver/projects.ts index 409ce5c525f..abb21669f8a 100644 --- a/src/testRunner/unittests/tsserver/projects.ts +++ b/src/testRunner/unittests/tsserver/projects.ts @@ -1467,5 +1467,22 @@ var x = 10;` openFilesForSession([{ file, projectRootPath }], session); } }); + + it("assert when removing project", () => { + const host = createServerHost([commonFile1, commonFile2, libFile]); + const service = createProjectService(host); + service.openClientFile(commonFile1.path); + const project = service.inferredProjects[0]; + checkProjectActualFiles(project, [commonFile1.path, libFile.path]); + // Intentionally create scriptinfo and attach it to project + const info = service.getOrCreateScriptInfoForNormalizedPath(commonFile2.path as server.NormalizedPath, /*openedByClient*/ false)!; + info.attachToProject(project); + try { + service.applyChangesInOpenFiles(/*openFiles*/ undefined, /*changedFiles*/ undefined, [commonFile1.path]); + } + catch (e) { + assert.isTrue(e.message.indexOf("Debug Failure. False expression: Found script Info still attached to project") === 0); + } + }); }); }