From cd993897a6e82a4192775c645f492164695320cd Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 23 Dec 2020 23:18:14 +0800 Subject: [PATCH 01/53] Add signature arguments label support --- src/compiler/checker.ts | 3 ++ src/compiler/types.ts | 1 + src/harness/client.ts | 12 +++++ src/harness/harnessLanguageService.ts | 3 ++ src/server/protocol.ts | 14 ++++++ src/server/session.ts | 14 ++++++ src/services/services.ts | 17 +++++++ src/services/shims.ts | 8 ++++ src/services/signatureArgumentsLabel.ts | 45 +++++++++++++++++++ src/services/tsconfig.json | 1 + src/services/types.ts | 14 ++++++ src/testRunner/parallel/worker.ts | 2 +- src/testRunner/unittests/tsserver/session.ts | 1 + .../reference/api/tsserverlibrary.d.ts | 25 ++++++++++- tests/baselines/reference/api/typescript.d.ts | 11 +++++ 15 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 src/services/signatureArgumentsLabel.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1c3bc622b0c75..a89c2fcd623c1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -432,6 +432,9 @@ namespace ts { return node ? getTypeFromTypeNode(node) : errorType; }, getParameterType: getTypeAtPosition, + getParameterNameAtPosition: (nodeIn, pos) => { + return unescapeLeadingUnderscores(getParameterNameAtPosition(nodeIn, pos)); + }, getPromisedTypeOfPromise, getAwaitedType: type => getAwaitedType(type), getReturnTypeOfSignature, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 81181164a7971..accd064959a46 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4019,6 +4019,7 @@ namespace ts { * Returns `any` if the index is not valid. */ /* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type; + /* @internal */ getParameterNameAtPosition(signature: Signature, parameterIndex: number): string; getNullableType(type: Type, flags: TypeFlags): Type; getNonNullableType(type: Type): Type; /* @internal */ getNonOptionalType(type: Type): Type; diff --git a/src/harness/client.ts b/src/harness/client.ts index 4bdb316b6b47d..da86247bfb7e3 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -635,6 +635,18 @@ namespace ts.server { applyCodeActionCommand = notImplemented; + provideSignatureArgumentsLabel(file: string): SignatureArgumentsLabel[] { + const args: protocol.FileRequestArgs = { file }; + + const request = this.processRequest(CommandNames.ProvideSignatureArgumentsLabel, args); + const response = this.processResponse(request); + + return response.body!.map(item => ({ // TODO: GH#18217 + name: item.name, + position: this.lineOffsetToPosition(file, item.position) + })); + } + private createFileLocationOrRangeRequestArgs(positionOrRange: number | TextRange, fileName: string): protocol.FileLocationOrRangeRequestArgs { return typeof positionOrRange === "number" ? this.createFileLocationRequestArgs(fileName, positionOrRange) diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 85164d58bb122..0157889a910af 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -599,6 +599,9 @@ namespace Harness.LanguageService { provideCallHierarchyOutgoingCalls(fileName: string, position: number) { return unwrapJSONCallResult(this.shim.provideCallHierarchyOutgoingCalls(fileName, position)); } + provideSignatureArgumentsLabel(fileName: string) { + return unwrapJSONCallResult(this.shim.provideSignatureArgumentsLabel(fileName)); + } getEmitOutput(fileName: string): ts.EmitOutput { return unwrapJSONCallResult(this.shim.getEmitOutput(fileName)); } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index ad8926470a5b0..89046b6fe642a 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -154,6 +154,7 @@ namespace ts.server.protocol { PrepareCallHierarchy = "prepareCallHierarchy", ProvideCallHierarchyIncomingCalls = "provideCallHierarchyIncomingCalls", ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls", + ProvideSignatureArgumentsLabel = "provideSignatureArgumentsLabel" // NOTE: If updating this, be sure to also update `allCommandNames` in `testRunner/unittests/tsserver/session.ts`. } @@ -2473,6 +2474,19 @@ namespace ts.server.protocol { body?: SignatureHelpItems; } + export interface ProvideSignatureArgumentsLabelRequest extends FileRequest { + command: CommandTypes.ProvideSignatureArgumentsLabel; + } + + export interface SignatureArgumentsLabelItem { + name: string + position: Location + } + + export interface ProvideSignatureArgumentsLabelResponse extends Response { + body?: SignatureArgumentsLabelItem[]; + } + /** * Synchronous request for semantic diagnostics of one file. */ diff --git a/src/server/session.ts b/src/server/session.ts index 267b1c44ce3f3..5e0457a8f3e40 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1421,6 +1421,17 @@ namespace ts.server { }); } + private provideSignatureArgumentsLabel(args: protocol.FileRequestArgs) { + const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args); + const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; + const labels = languageService.provideSignatureArgumentsLabel(file); + + return labels.map(label => ({ + name: label.name, + position: scriptInfo.positionToLineOffset(label.position) + })); + } + private setCompilerOptionsForInferredProjects(args: protocol.SetCompilerOptionsForInferredProjectsArgs): void { this.projectService.setCompilerOptionsForInferredProjects(args.options, args.projectRootPath); } @@ -2899,6 +2910,9 @@ namespace ts.server { [CommandNames.UncommentSelectionFull]: (request: protocol.UncommentSelectionRequest) => { return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/ false)); }, + [CommandNames.ProvideSignatureArgumentsLabel]: (request: protocol.ProvideSignatureArgumentsLabelRequest) => { + return this.requiredResponse(this.provideSignatureArgumentsLabel(request.arguments)); + } })); public addProtocolHandler(command: string, handler: (request: protocol.Request) => HandlerResponse) { diff --git a/src/services/services.ts b/src/services/services.ts index fa0e3770d9049..e22c1a1969e2c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1196,6 +1196,7 @@ namespace ts { "prepareCallHierarchy", "provideCallHierarchyIncomingCalls", "provideCallHierarchyOutgoingCalls", + "provideSignatureArgumentsLabel" ]; const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [ @@ -2466,6 +2467,15 @@ namespace ts { }; } + function getSignatureArgumentsLabelContext(file: SourceFile): SignatureArgumentsLabelContext { + return { + file, + program: getProgram()!, + host, + cancellationToken, + }; + } + function getSmartSelectionRange(fileName: string, position: number): SelectionRange { return SmartSelectionRange.getSmartSelectionRange(position, syntaxTreeCache.getCurrentSourceFile(fileName)); } @@ -2509,6 +2519,12 @@ namespace ts { return declaration ? CallHierarchy.getOutgoingCalls(program, declaration) : []; } + function provideSignatureArgumentsLabel(fileName: string): SignatureArgumentsLabel[] { + synchronizeHostData(); + const sourceFile = getValidSourceFile(fileName); + return SignatureArgumentsLabel.provideSignatureArgumentsLabel(getSignatureArgumentsLabelContext(sourceFile)); + } + const ls: LanguageService = { dispose, cleanupSemanticCache, @@ -2574,6 +2590,7 @@ namespace ts { toggleMultilineComment, commentSelection, uncommentSelection, + provideSignatureArgumentsLabel, }; switch (languageServiceMode) { diff --git a/src/services/shims.ts b/src/services/shims.ts index 30144210271ea..97bca4082c2cd 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -280,6 +280,7 @@ namespace ts { prepareCallHierarchy(fileName: string, position: number): string; provideCallHierarchyIncomingCalls(fileName: string, position: number): string; provideCallHierarchyOutgoingCalls(fileName: string, position: number): string; + provideSignatureArgumentsLabel(fileName: string): string; getEmitOutput(fileName: string): string; getEmitOutputObject(fileName: string): EmitOutput; @@ -1067,6 +1068,13 @@ namespace ts { ); } + public provideSignatureArgumentsLabel(fileName: string): string { + return this.forwardJSONCall( + `provideSignatureArgumentsLabel('${fileName}')`, + () => this.languageService.provideSignatureArgumentsLabel(fileName) + ); + } + /// Emit public getEmitOutput(fileName: string): string { return this.forwardJSONCall( diff --git a/src/services/signatureArgumentsLabel.ts b/src/services/signatureArgumentsLabel.ts new file mode 100644 index 0000000000000..800e69a3269db --- /dev/null +++ b/src/services/signatureArgumentsLabel.ts @@ -0,0 +1,45 @@ +/* @internal */ +namespace ts.SignatureArgumentsLabel { + interface ArgumentsInfo { + name: string + position: number + } + + export function provideSignatureArgumentsLabel(context: SignatureArgumentsLabelContext): ArgumentsInfo[] { + const { file, program } = context; + + const checker = program.getTypeChecker(); + const result: ArgumentsInfo[] = []; + + visitor(file); + + return result; + + function visitor(node: Node): true | undefined | void { + if (isTypeNode(node)) { + return; + } + + if (isCallExpression(node) || isNewExpression(node)) { + visitCallOrNewExpression(node); + } + return forEachChild(node, visitor); + } + + function visitCallOrNewExpression(expr: CallExpression | NewExpression) { + const candidates: Signature[] = []; + const signature = checker.getResolvedSignatureForSignatureHelp(expr, candidates); + if (!signature || !candidates.length || !expr.arguments || !expr.arguments.length) { + return; + } + + for (let i = 0; i < expr.arguments.length; ++i) { + const name = checker.getParameterNameAtPosition(signature, i); + result.push({ + name, + position: expr.arguments[i].pos + }); + } + } + } +} \ No newline at end of file diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 079b8e6ed4f73..d46174c467711 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -33,6 +33,7 @@ "rename.ts", "smartSelection.ts", "signatureHelp.ts", + "signatureArgumentsLabel.ts", "sourcemaps.ts", "suggestionDiagnostics.ts", "symbolDisplay.ts", diff --git a/src/services/types.ts b/src/services/types.ts index 35815ade6f53f..671f48948cad2 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -481,6 +481,8 @@ namespace ts { provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; + provideSignatureArgumentsLabel(fileName: string): SignatureArgumentsLabel[] + getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -685,6 +687,11 @@ namespace ts { fromSpans: TextSpan[]; } + export interface SignatureArgumentsLabel { + name: string, + position: number + } + export interface TodoCommentDescriptor { text: string; priority: number; @@ -1481,4 +1488,11 @@ namespace ts { preferences: UserPreferences; triggerReason?: RefactorTriggerReason; } + + export interface SignatureArgumentsLabelContext { + file: SourceFile; + program: Program; + cancellationToken?: CancellationToken; + host: LanguageServiceHost; + } } diff --git a/src/testRunner/parallel/worker.ts b/src/testRunner/parallel/worker.ts index 21570ab3e1e62..5d457d0ecdea0 100644 --- a/src/testRunner/parallel/worker.ts +++ b/src/testRunner/parallel/worker.ts @@ -223,7 +223,7 @@ namespace Harness.Parallel.Worker { }) .on("end", () => { hookUncaughtExceptions(); - runner.dispose(); + (runner as any).dispose(); }) .run(() => { fn({ task, errors, passes, passing: passes.length, duration: +new Date() - start }); diff --git a/src/testRunner/unittests/tsserver/session.ts b/src/testRunner/unittests/tsserver/session.ts index 96bae928817db..a716adacaec69 100644 --- a/src/testRunner/unittests/tsserver/session.ts +++ b/src/testRunner/unittests/tsserver/session.ts @@ -278,6 +278,7 @@ namespace ts.server { CommandNames.ToggleMultilineComment, CommandNames.CommentSelection, CommandNames.UncommentSelection, + CommandNames.ProvideSignatureArgumentsLabel ]; it("should not throw when commands are executed with invalid arguments", () => { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 984c51fa8542a..9c41a489d1afd 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5543,6 +5543,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; + provideSignatureArgumentsLabel(fileName: string): SignatureArgumentsLabel[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -5707,6 +5708,10 @@ declare namespace ts { to: CallHierarchyItem; fromSpans: TextSpan[]; } + interface SignatureArgumentsLabel { + name: string; + position: number; + } interface TodoCommentDescriptor { text: string; priority: number; @@ -6316,6 +6321,12 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24, bigintLiteral = 25 } + interface SignatureArgumentsLabelContext { + file: SourceFile; + program: Program; + cancellationToken?: CancellationToken; + host: LanguageServiceHost; + } } declare namespace ts { /** The classifier is used for syntactic highlighting in editors via the TSServer */ @@ -6592,7 +6603,8 @@ declare namespace ts.server.protocol { UncommentSelection = "uncommentSelection", PrepareCallHierarchy = "prepareCallHierarchy", ProvideCallHierarchyIncomingCalls = "provideCallHierarchyIncomingCalls", - ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls" + ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls", + ProvideSignatureArgumentsLabel = "provideSignatureArgumentsLabel" } /** * A TypeScript Server message @@ -8373,6 +8385,16 @@ declare namespace ts.server.protocol { interface SignatureHelpResponse extends Response { body?: SignatureHelpItems; } + interface ProvideSignatureArgumentsLabelRequest extends FileRequest { + command: CommandTypes.ProvideSignatureArgumentsLabel; + } + interface SignatureArgumentsLabelItem { + name: string; + position: Location; + } + interface ProvideSignatureArgumentsLabelResponse extends Response { + body?: SignatureArgumentsLabelItem[]; + } /** * Synchronous request for semantic diagnostics of one file. */ @@ -9991,6 +10013,7 @@ declare namespace ts.server { private getSuggestionDiagnosticsSync; private getJsxClosingTag; private getDocumentHighlights; + private provideSignatureArgumentsLabel; private setCompilerOptionsForInferredProjects; private getProjectInfo; private getProjectInfoWorker; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 35116f0ddb732..db094bc5cceff 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5543,6 +5543,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; + provideSignatureArgumentsLabel(fileName: string): SignatureArgumentsLabel[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -5707,6 +5708,10 @@ declare namespace ts { to: CallHierarchyItem; fromSpans: TextSpan[]; } + interface SignatureArgumentsLabel { + name: string; + position: number; + } interface TodoCommentDescriptor { text: string; priority: number; @@ -6316,6 +6321,12 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24, bigintLiteral = 25 } + interface SignatureArgumentsLabelContext { + file: SourceFile; + program: Program; + cancellationToken?: CancellationToken; + host: LanguageServiceHost; + } } declare namespace ts { /** The classifier is used for syntactic highlighting in editors via the TSServer */ From ab3c9379923e5cdc8ff795991ab8b361761ccc4d Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 24 Dec 2020 14:25:21 +0800 Subject: [PATCH 02/53] Support rest parameters and destruction --- src/compiler/checker.ts | 3 --- src/compiler/types.ts | 1 - src/services/signatureArgumentsLabel.ts | 33 ++++++++++++++++++++----- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a89c2fcd623c1..1c3bc622b0c75 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -432,9 +432,6 @@ namespace ts { return node ? getTypeFromTypeNode(node) : errorType; }, getParameterType: getTypeAtPosition, - getParameterNameAtPosition: (nodeIn, pos) => { - return unescapeLeadingUnderscores(getParameterNameAtPosition(nodeIn, pos)); - }, getPromisedTypeOfPromise, getAwaitedType: type => getAwaitedType(type), getReturnTypeOfSignature, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index accd064959a46..81181164a7971 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4019,7 +4019,6 @@ namespace ts { * Returns `any` if the index is not valid. */ /* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type; - /* @internal */ getParameterNameAtPosition(signature: Signature, parameterIndex: number): string; getNullableType(type: Type, flags: TypeFlags): Type; getNonNullableType(type: Type): Type; /* @internal */ getNonOptionalType(type: Type): Type; diff --git a/src/services/signatureArgumentsLabel.ts b/src/services/signatureArgumentsLabel.ts index 800e69a3269db..e4d6d41b16e40 100644 --- a/src/services/signatureArgumentsLabel.ts +++ b/src/services/signatureArgumentsLabel.ts @@ -29,17 +29,38 @@ namespace ts.SignatureArgumentsLabel { function visitCallOrNewExpression(expr: CallExpression | NewExpression) { const candidates: Signature[] = []; const signature = checker.getResolvedSignatureForSignatureHelp(expr, candidates); - if (!signature || !candidates.length || !expr.arguments || !expr.arguments.length) { + if (!signature || !candidates.length) { return; } + getCallArgumentsLabels(expr, signature); + } + + function getCallArgumentsLabels(expr: CallExpression | NewExpression, signature: Signature) { + if (!expr.arguments || !expr.arguments.length) { + return; + } + + const hasRestParameter = signatureHasRestParameter(signature); + const paramCount = signature.parameters.length - (hasRestParameter ? 1 : 0); + for (let i = 0; i < expr.arguments.length; ++i) { - const name = checker.getParameterNameAtPosition(signature, i); - result.push({ - name, - position: expr.arguments[i].pos - }); + const parameterSymbol = signature.parameters[i]; + if (isParameterDeclarationWithName(parameterSymbol)) { + const name = unescapeLeadingUnderscores(parameterSymbol.escapedName); + result.push({ + name, + position: expr.arguments[i].getStart() + }); + } + if (i >= paramCount) { + break; + } } } + + function isParameterDeclarationWithName (symbol: Symbol) { + return symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isIdentifier(symbol.valueDeclaration.name) + } } } \ No newline at end of file From d91b2f709ec322951faf83199b7bf03c98a2c787 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 24 Dec 2020 14:28:42 +0800 Subject: [PATCH 03/53] make lint --- src/services/signatureArgumentsLabel.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/signatureArgumentsLabel.ts b/src/services/signatureArgumentsLabel.ts index e4d6d41b16e40..495337a0f9f18 100644 --- a/src/services/signatureArgumentsLabel.ts +++ b/src/services/signatureArgumentsLabel.ts @@ -59,8 +59,8 @@ namespace ts.SignatureArgumentsLabel { } } - function isParameterDeclarationWithName (symbol: Symbol) { - return symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isIdentifier(symbol.valueDeclaration.name) + function isParameterDeclarationWithName(symbol: Symbol) { + return symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isIdentifier(symbol.valueDeclaration.name); } } } \ No newline at end of file From 8388adde0165537224e49ea856867616d8d81ad0 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 24 Dec 2020 16:56:54 +0800 Subject: [PATCH 04/53] Fix tuple rest parameters --- src/compiler/checker.ts | 29 +++++++++++++++++++++++++ src/compiler/types.ts | 1 + src/services/signatureArgumentsLabel.ts | 27 +++++++++-------------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1c3bc622b0c75..c74e16c70af20 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -432,6 +432,7 @@ namespace ts { return node ? getTypeFromTypeNode(node) : errorType; }, getParameterType: getTypeAtPosition, + getParameterIdentifierNameAtPosition, getPromisedTypeOfPromise, getAwaitedType: type => getAwaitedType(type), getReturnTypeOfSignature, @@ -28929,6 +28930,34 @@ namespace ts { return restParameter.escapedName; } + function getParameterIdentifierNameAtPosition(signature: Signature, pos: number): __String | undefined { + const paramCount = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0); + if (pos < paramCount) { + const param = signature.parameters[pos]; + return isParameterDeclarationWithIdentifierName(param) ? param.escapedName : undefined; + } + + const restParameter = signature.parameters[paramCount] || unknownSymbol; + if (!isParameterDeclarationWithIdentifierName(restParameter)) { + return undefined; + } + + const restType = getTypeOfSymbol(restParameter); + if (isTupleType(restType)) { + const associatedNames = ((restType).target).labeledElementDeclarations; + const index = pos - paramCount; + return associatedNames ? getTupleElementLabel(associatedNames[index]) : undefined; + } + + if (pos === paramCount) { + return restParameter.escapedName; + } + return undefined; + } + + function isParameterDeclarationWithIdentifierName(symbol: Symbol) { + return symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isIdentifier(symbol.valueDeclaration.name); + } function isValidDeclarationForTupleLabel(d: Declaration): d is NamedTupleMember | (ParameterDeclaration & { name: Identifier }) { return d.kind === SyntaxKind.NamedTupleMember || (isParameter(d) && d.name && isIdentifier(d.name)); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 81181164a7971..47b3c0bbf42c1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4019,6 +4019,7 @@ namespace ts { * Returns `any` if the index is not valid. */ /* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type; + /* @internal */ getParameterIdentifierNameAtPosition(signature: Signature, parameterIndex: number): __String | undefined; getNullableType(type: Type, flags: TypeFlags): Type; getNonNullableType(type: Type): Type; /* @internal */ getNonOptionalType(type: Type): Type; diff --git a/src/services/signatureArgumentsLabel.ts b/src/services/signatureArgumentsLabel.ts index 495337a0f9f18..cee1bf57f7752 100644 --- a/src/services/signatureArgumentsLabel.ts +++ b/src/services/signatureArgumentsLabel.ts @@ -41,26 +41,19 @@ namespace ts.SignatureArgumentsLabel { return; } - const hasRestParameter = signatureHasRestParameter(signature); - const paramCount = signature.parameters.length - (hasRestParameter ? 1 : 0); - for (let i = 0; i < expr.arguments.length; ++i) { - const parameterSymbol = signature.parameters[i]; - if (isParameterDeclarationWithName(parameterSymbol)) { - const name = unescapeLeadingUnderscores(parameterSymbol.escapedName); - result.push({ - name, - position: expr.arguments[i].getStart() - }); - } - if (i >= paramCount) { - break; + const parameterName = checker.getParameterIdentifierNameAtPosition(signature, i); + if (parameterName) { + const arg = expr.arguments[i]; + const argumentName = isIdentifier(arg) ? arg.text : undefined; + if (!argumentName || argumentName !== parameterName) { + result.push({ + name: unescapeLeadingUnderscores(parameterName), + position: expr.arguments[i].getStart() + }); + } } } } - - function isParameterDeclarationWithName(symbol: Symbol) { - return symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isIdentifier(symbol.valueDeclaration.name); - } } } \ No newline at end of file From 1058fdd74f14c193e11bee97c17e1f24168200c4 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Dec 2020 00:37:52 +0800 Subject: [PATCH 05/53] Adjust name styles --- src/services/signatureArgumentsLabel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/signatureArgumentsLabel.ts b/src/services/signatureArgumentsLabel.ts index cee1bf57f7752..b2559536f0ad1 100644 --- a/src/services/signatureArgumentsLabel.ts +++ b/src/services/signatureArgumentsLabel.ts @@ -48,7 +48,7 @@ namespace ts.SignatureArgumentsLabel { const argumentName = isIdentifier(arg) ? arg.text : undefined; if (!argumentName || argumentName !== parameterName) { result.push({ - name: unescapeLeadingUnderscores(parameterName), + name: `${unescapeLeadingUnderscores(parameterName)}:`, position: expr.arguments[i].getStart() }); } From 1517b1f75a37c2cb0f070f4f1de42c083ff48257 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Dec 2020 01:10:41 +0800 Subject: [PATCH 06/53] Rename to inline hints --- src/harness/client.ts | 8 +++---- src/harness/harnessLanguageService.ts | 4 ++-- src/server/protocol.ts | 14 +++++------ src/server/session.ts | 14 +++++------ ...natureArgumentsLabel.ts => inlineHints.ts} | 16 ++++++------- src/services/services.ts | 10 ++++---- src/services/shims.ts | 8 +++---- src/services/tsconfig.json | 2 +- src/services/types.ts | 8 +++---- src/testRunner/unittests/tsserver/session.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 24 +++++++++---------- tests/baselines/reference/api/typescript.d.ts | 8 +++---- 12 files changed, 59 insertions(+), 59 deletions(-) rename src/services/{signatureArgumentsLabel.ts => inlineHints.ts} (75%) diff --git a/src/harness/client.ts b/src/harness/client.ts index da86247bfb7e3..68097e8aa5f31 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -635,14 +635,14 @@ namespace ts.server { applyCodeActionCommand = notImplemented; - provideSignatureArgumentsLabel(file: string): SignatureArgumentsLabel[] { + provideInlineHints(file: string): InlineHint[] { const args: protocol.FileRequestArgs = { file }; - const request = this.processRequest(CommandNames.ProvideSignatureArgumentsLabel, args); - const response = this.processResponse(request); + const request = this.processRequest(CommandNames.ProvideInlineHints, args); + const response = this.processResponse(request); return response.body!.map(item => ({ // TODO: GH#18217 - name: item.name, + text: item.text, position: this.lineOffsetToPosition(file, item.position) })); } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 0157889a910af..ffa918e9065fd 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -599,8 +599,8 @@ namespace Harness.LanguageService { provideCallHierarchyOutgoingCalls(fileName: string, position: number) { return unwrapJSONCallResult(this.shim.provideCallHierarchyOutgoingCalls(fileName, position)); } - provideSignatureArgumentsLabel(fileName: string) { - return unwrapJSONCallResult(this.shim.provideSignatureArgumentsLabel(fileName)); + provideInlineHints(fileName: string) { + return unwrapJSONCallResult(this.shim.provideInlineHints(fileName)); } getEmitOutput(fileName: string): ts.EmitOutput { return unwrapJSONCallResult(this.shim.getEmitOutput(fileName)); diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 89046b6fe642a..1371c25630250 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -154,7 +154,7 @@ namespace ts.server.protocol { PrepareCallHierarchy = "prepareCallHierarchy", ProvideCallHierarchyIncomingCalls = "provideCallHierarchyIncomingCalls", ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls", - ProvideSignatureArgumentsLabel = "provideSignatureArgumentsLabel" + ProvideInlineHints = "provideInlineHints" // NOTE: If updating this, be sure to also update `allCommandNames` in `testRunner/unittests/tsserver/session.ts`. } @@ -2474,17 +2474,17 @@ namespace ts.server.protocol { body?: SignatureHelpItems; } - export interface ProvideSignatureArgumentsLabelRequest extends FileRequest { - command: CommandTypes.ProvideSignatureArgumentsLabel; + export interface ProvideInlineHintsRequest extends FileRequest { + command: CommandTypes.ProvideInlineHints; } - export interface SignatureArgumentsLabelItem { - name: string + export interface HintItem { + text: string position: Location } - export interface ProvideSignatureArgumentsLabelResponse extends Response { - body?: SignatureArgumentsLabelItem[]; + export interface ProvideInlineHintsResponse extends Response { + body?: HintItem[]; } /** diff --git a/src/server/session.ts b/src/server/session.ts index 5e0457a8f3e40..37a8602bac929 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1421,14 +1421,14 @@ namespace ts.server { }); } - private provideSignatureArgumentsLabel(args: protocol.FileRequestArgs) { + private provideInlineHints(args: protocol.FileRequestArgs) { const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args); const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; - const labels = languageService.provideSignatureArgumentsLabel(file); + const hints = languageService.provideInlineHints(file); - return labels.map(label => ({ - name: label.name, - position: scriptInfo.positionToLineOffset(label.position) + return hints.map(hint => ({ + text: hint.text, + position: scriptInfo.positionToLineOffset(hint.position) })); } @@ -2910,8 +2910,8 @@ namespace ts.server { [CommandNames.UncommentSelectionFull]: (request: protocol.UncommentSelectionRequest) => { return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.ProvideSignatureArgumentsLabel]: (request: protocol.ProvideSignatureArgumentsLabelRequest) => { - return this.requiredResponse(this.provideSignatureArgumentsLabel(request.arguments)); + [CommandNames.ProvideInlineHints]: (request: protocol.ProvideInlineHintsRequest) => { + return this.requiredResponse(this.provideInlineHints(request.arguments)); } })); diff --git a/src/services/signatureArgumentsLabel.ts b/src/services/inlineHints.ts similarity index 75% rename from src/services/signatureArgumentsLabel.ts rename to src/services/inlineHints.ts index b2559536f0ad1..6121fc68ab563 100644 --- a/src/services/signatureArgumentsLabel.ts +++ b/src/services/inlineHints.ts @@ -1,15 +1,15 @@ /* @internal */ -namespace ts.SignatureArgumentsLabel { - interface ArgumentsInfo { - name: string +namespace ts.InlineHints { + interface HintInfo { + text: string position: number } - export function provideSignatureArgumentsLabel(context: SignatureArgumentsLabelContext): ArgumentsInfo[] { + export function provideInlineHints(context: InlineHintsContext): HintInfo[] { const { file, program } = context; const checker = program.getTypeChecker(); - const result: ArgumentsInfo[] = []; + const result: HintInfo[] = []; visitor(file); @@ -33,10 +33,10 @@ namespace ts.SignatureArgumentsLabel { return; } - getCallArgumentsLabels(expr, signature); + getCallArgumentsHints(expr, signature); } - function getCallArgumentsLabels(expr: CallExpression | NewExpression, signature: Signature) { + function getCallArgumentsHints(expr: CallExpression | NewExpression, signature: Signature) { if (!expr.arguments || !expr.arguments.length) { return; } @@ -48,7 +48,7 @@ namespace ts.SignatureArgumentsLabel { const argumentName = isIdentifier(arg) ? arg.text : undefined; if (!argumentName || argumentName !== parameterName) { result.push({ - name: `${unescapeLeadingUnderscores(parameterName)}:`, + text: `${unescapeLeadingUnderscores(parameterName)}:`, position: expr.arguments[i].getStart() }); } diff --git a/src/services/services.ts b/src/services/services.ts index e22c1a1969e2c..388c28c2d4163 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1196,7 +1196,7 @@ namespace ts { "prepareCallHierarchy", "provideCallHierarchyIncomingCalls", "provideCallHierarchyOutgoingCalls", - "provideSignatureArgumentsLabel" + "provideInlineHints" ]; const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [ @@ -2467,7 +2467,7 @@ namespace ts { }; } - function getSignatureArgumentsLabelContext(file: SourceFile): SignatureArgumentsLabelContext { + function getInlineHintsContext(file: SourceFile): InlineHintsContext { return { file, program: getProgram()!, @@ -2519,10 +2519,10 @@ namespace ts { return declaration ? CallHierarchy.getOutgoingCalls(program, declaration) : []; } - function provideSignatureArgumentsLabel(fileName: string): SignatureArgumentsLabel[] { + function provideInlineHints(fileName: string): InlineHint[] { synchronizeHostData(); const sourceFile = getValidSourceFile(fileName); - return SignatureArgumentsLabel.provideSignatureArgumentsLabel(getSignatureArgumentsLabelContext(sourceFile)); + return InlineHints.provideInlineHints(getInlineHintsContext(sourceFile)); } const ls: LanguageService = { @@ -2590,7 +2590,7 @@ namespace ts { toggleMultilineComment, commentSelection, uncommentSelection, - provideSignatureArgumentsLabel, + provideInlineHints, }; switch (languageServiceMode) { diff --git a/src/services/shims.ts b/src/services/shims.ts index 97bca4082c2cd..c21c588841b01 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -280,7 +280,7 @@ namespace ts { prepareCallHierarchy(fileName: string, position: number): string; provideCallHierarchyIncomingCalls(fileName: string, position: number): string; provideCallHierarchyOutgoingCalls(fileName: string, position: number): string; - provideSignatureArgumentsLabel(fileName: string): string; + provideInlineHints(fileName: string): string; getEmitOutput(fileName: string): string; getEmitOutputObject(fileName: string): EmitOutput; @@ -1068,10 +1068,10 @@ namespace ts { ); } - public provideSignatureArgumentsLabel(fileName: string): string { + public provideInlineHints(fileName: string): string { return this.forwardJSONCall( - `provideSignatureArgumentsLabel('${fileName}')`, - () => this.languageService.provideSignatureArgumentsLabel(fileName) + `provideInlineHints('${fileName}')`, + () => this.languageService.provideInlineHints(fileName) ); } diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index d46174c467711..a8759648709a4 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -33,7 +33,7 @@ "rename.ts", "smartSelection.ts", "signatureHelp.ts", - "signatureArgumentsLabel.ts", + "inlineHints.ts", "sourcemaps.ts", "suggestionDiagnostics.ts", "symbolDisplay.ts", diff --git a/src/services/types.ts b/src/services/types.ts index 671f48948cad2..0bc75f4cd65b1 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -481,7 +481,7 @@ namespace ts { provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideSignatureArgumentsLabel(fileName: string): SignatureArgumentsLabel[] + provideInlineHints(fileName: string): InlineHint[] getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; @@ -687,8 +687,8 @@ namespace ts { fromSpans: TextSpan[]; } - export interface SignatureArgumentsLabel { - name: string, + export interface InlineHint { + text: string, position: number } @@ -1489,7 +1489,7 @@ namespace ts { triggerReason?: RefactorTriggerReason; } - export interface SignatureArgumentsLabelContext { + export interface InlineHintsContext { file: SourceFile; program: Program; cancellationToken?: CancellationToken; diff --git a/src/testRunner/unittests/tsserver/session.ts b/src/testRunner/unittests/tsserver/session.ts index a716adacaec69..476474bacff66 100644 --- a/src/testRunner/unittests/tsserver/session.ts +++ b/src/testRunner/unittests/tsserver/session.ts @@ -278,7 +278,7 @@ namespace ts.server { CommandNames.ToggleMultilineComment, CommandNames.CommentSelection, CommandNames.UncommentSelection, - CommandNames.ProvideSignatureArgumentsLabel + CommandNames.ProvideInlineHints ]; it("should not throw when commands are executed with invalid arguments", () => { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 9c41a489d1afd..2047842833c46 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5543,7 +5543,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideSignatureArgumentsLabel(fileName: string): SignatureArgumentsLabel[]; + provideInlineHints(fileName: string): InlineHint[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -5708,8 +5708,8 @@ declare namespace ts { to: CallHierarchyItem; fromSpans: TextSpan[]; } - interface SignatureArgumentsLabel { - name: string; + interface InlineHint { + text: string; position: number; } interface TodoCommentDescriptor { @@ -6321,7 +6321,7 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24, bigintLiteral = 25 } - interface SignatureArgumentsLabelContext { + interface InlineHintsContext { file: SourceFile; program: Program; cancellationToken?: CancellationToken; @@ -6604,7 +6604,7 @@ declare namespace ts.server.protocol { PrepareCallHierarchy = "prepareCallHierarchy", ProvideCallHierarchyIncomingCalls = "provideCallHierarchyIncomingCalls", ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls", - ProvideSignatureArgumentsLabel = "provideSignatureArgumentsLabel" + ProvideInlineHints = "provideInlineHints" } /** * A TypeScript Server message @@ -8385,15 +8385,15 @@ declare namespace ts.server.protocol { interface SignatureHelpResponse extends Response { body?: SignatureHelpItems; } - interface ProvideSignatureArgumentsLabelRequest extends FileRequest { - command: CommandTypes.ProvideSignatureArgumentsLabel; + interface ProvideInlineHintsRequest extends FileRequest { + command: CommandTypes.ProvideInlineHints; } - interface SignatureArgumentsLabelItem { - name: string; + interface HintItem { + text: string; position: Location; } - interface ProvideSignatureArgumentsLabelResponse extends Response { - body?: SignatureArgumentsLabelItem[]; + interface ProvideInlineHintsResponse extends Response { + body?: HintItem[]; } /** * Synchronous request for semantic diagnostics of one file. @@ -10013,7 +10013,7 @@ declare namespace ts.server { private getSuggestionDiagnosticsSync; private getJsxClosingTag; private getDocumentHighlights; - private provideSignatureArgumentsLabel; + private provideInlineHints; private setCompilerOptionsForInferredProjects; private getProjectInfo; private getProjectInfoWorker; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index db094bc5cceff..a397de52cac1a 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5543,7 +5543,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideSignatureArgumentsLabel(fileName: string): SignatureArgumentsLabel[]; + provideInlineHints(fileName: string): InlineHint[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -5708,8 +5708,8 @@ declare namespace ts { to: CallHierarchyItem; fromSpans: TextSpan[]; } - interface SignatureArgumentsLabel { - name: string; + interface InlineHint { + text: string; position: number; } interface TodoCommentDescriptor { @@ -6321,7 +6321,7 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24, bigintLiteral = 25 } - interface SignatureArgumentsLabelContext { + interface InlineHintsContext { file: SourceFile; program: Program; cancellationToken?: CancellationToken; From fd9b09f4c8a186db55c4b5d18d37019b10bed2fd Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Dec 2020 11:33:10 +0800 Subject: [PATCH 07/53] Partition inline hints --- src/harness/client.ts | 5 +++-- src/harness/harnessLanguageService.ts | 4 ++-- src/server/protocol.ts | 14 +++++++++++++- src/server/session.ts | 4 ++-- src/services/inlineHints.ts | 21 +++++++++++++++++---- src/services/services.ts | 7 ++++--- src/services/shims.ts | 9 ++++----- src/services/types.ts | 5 +++-- 8 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 68097e8aa5f31..3cd6752ffed93 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -635,8 +635,9 @@ namespace ts.server { applyCodeActionCommand = notImplemented; - provideInlineHints(file: string): InlineHint[] { - const args: protocol.FileRequestArgs = { file }; + provideInlineHints(file: string, span: TextSpan): InlineHint[] { + const { start, length } = span; + const args: protocol.ProvideInlineHintsRequestArgs = { file, start, length }; const request = this.processRequest(CommandNames.ProvideInlineHints, args); const response = this.processResponse(request); diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index ffa918e9065fd..7788d9b225098 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -599,8 +599,8 @@ namespace Harness.LanguageService { provideCallHierarchyOutgoingCalls(fileName: string, position: number) { return unwrapJSONCallResult(this.shim.provideCallHierarchyOutgoingCalls(fileName, position)); } - provideInlineHints(fileName: string) { - return unwrapJSONCallResult(this.shim.provideInlineHints(fileName)); + provideInlineHints(fileName: string, span: ts.TextSpan) { + return unwrapJSONCallResult(this.shim.provideInlineHints(fileName, span)); } getEmitOutput(fileName: string): ts.EmitOutput { return unwrapJSONCallResult(this.shim.getEmitOutput(fileName)); diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 1371c25630250..55031391bedc7 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2474,8 +2474,20 @@ namespace ts.server.protocol { body?: SignatureHelpItems; } - export interface ProvideInlineHintsRequest extends FileRequest { + export interface ProvideInlineHintsRequestArgs extends FileRequestArgs { + /** + * Start position of the span. + */ + start: number; + /** + * Length of the span. + */ + length: number; + } + + export interface ProvideInlineHintsRequest extends Request { command: CommandTypes.ProvideInlineHints; + arguments: ProvideInlineHintsRequestArgs; } export interface HintItem { diff --git a/src/server/session.ts b/src/server/session.ts index 37a8602bac929..2f76a65c588d7 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1421,10 +1421,10 @@ namespace ts.server { }); } - private provideInlineHints(args: protocol.FileRequestArgs) { + private provideInlineHints(args: protocol.ProvideInlineHintsRequestArgs) { const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args); const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; - const hints = languageService.provideInlineHints(file); + const hints = languageService.provideInlineHints(file, args); return hints.map(hint => ({ text: hint.text, diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 6121fc68ab563..c72c4e178eba2 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -6,16 +6,29 @@ namespace ts.InlineHints { } export function provideInlineHints(context: InlineHintsContext): HintInfo[] { - const { file, program } = context; + const { file, program, span, cancellationToken } = context; const checker = program.getTypeChecker(); const result: HintInfo[] = []; - + visitor(file); - return result; - function visitor(node: Node): true | undefined | void { + switch(node.kind) { + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + cancellationToken.throwIfCancellationRequested(); + } + + if (!node || !textSpanIntersectsWith(span, node.pos, node.getFullWidth()) || node.getFullWidth() === 0) { + return; + } + if (isTypeNode(node)) { return; } diff --git a/src/services/services.ts b/src/services/services.ts index 388c28c2d4163..8a81775bfa606 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2467,11 +2467,12 @@ namespace ts { }; } - function getInlineHintsContext(file: SourceFile): InlineHintsContext { + function getInlineHintsContext(file: SourceFile, span: TextSpan): InlineHintsContext { return { file, program: getProgram()!, host, + span, cancellationToken, }; } @@ -2519,10 +2520,10 @@ namespace ts { return declaration ? CallHierarchy.getOutgoingCalls(program, declaration) : []; } - function provideInlineHints(fileName: string): InlineHint[] { + function provideInlineHints(fileName: string, span: TextSpan): InlineHint[] { synchronizeHostData(); const sourceFile = getValidSourceFile(fileName); - return InlineHints.provideInlineHints(getInlineHintsContext(sourceFile)); + return InlineHints.provideInlineHints(getInlineHintsContext(sourceFile, span)); } const ls: LanguageService = { diff --git a/src/services/shims.ts b/src/services/shims.ts index c21c588841b01..c013e1b16d12e 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -280,8 +280,7 @@ namespace ts { prepareCallHierarchy(fileName: string, position: number): string; provideCallHierarchyIncomingCalls(fileName: string, position: number): string; provideCallHierarchyOutgoingCalls(fileName: string, position: number): string; - provideInlineHints(fileName: string): string; - + provideInlineHints(fileName: string, span: TextSpan): string; getEmitOutput(fileName: string): string; getEmitOutputObject(fileName: string): EmitOutput; @@ -1068,10 +1067,10 @@ namespace ts { ); } - public provideInlineHints(fileName: string): string { + public provideInlineHints(fileName: string, span: TextSpan): string { return this.forwardJSONCall( - `provideInlineHints('${fileName}')`, - () => this.languageService.provideInlineHints(fileName) + `provideInlineHints('${fileName}', '${JSON.stringify(span)}')`, + () => this.languageService.provideInlineHints(fileName, span) ); } diff --git a/src/services/types.ts b/src/services/types.ts index 0bc75f4cd65b1..052ade3302dca 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -481,7 +481,7 @@ namespace ts { provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideInlineHints(fileName: string): InlineHint[] + provideInlineHints(fileName: string, span: TextSpan): InlineHint[] getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; @@ -1492,7 +1492,8 @@ namespace ts { export interface InlineHintsContext { file: SourceFile; program: Program; - cancellationToken?: CancellationToken; + cancellationToken: CancellationToken; host: LanguageServiceHost; + span: TextSpan; } } From 23afce28fbd2cc624d6cae577b1dfe6819fca1d2 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Dec 2020 12:18:26 +0800 Subject: [PATCH 08/53] Adjust range pred --- src/services/inlineHints.ts | 13 +++++++++---- .../reference/api/tsserverlibrary.d.ts | 18 +++++++++++++++--- tests/baselines/reference/api/typescript.d.ts | 5 +++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index c72c4e178eba2..39230e7662176 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -10,10 +10,14 @@ namespace ts.InlineHints { const checker = program.getTypeChecker(); const result: HintInfo[] = []; - + visitor(file); return result; function visitor(node: Node): true | undefined | void { + if (!node || node.getFullWidth() === 0) { + return; + } + switch(node.kind) { case SyntaxKind.ModuleDeclaration: case SyntaxKind.ClassDeclaration: @@ -21,12 +25,13 @@ namespace ts.InlineHints { case SyntaxKind.FunctionDeclaration: case SyntaxKind.ClassExpression: case SyntaxKind.FunctionExpression: + case SyntaxKind.MethodDeclaration: case SyntaxKind.ArrowFunction: cancellationToken.throwIfCancellationRequested(); - } - if (!node || !textSpanIntersectsWith(span, node.pos, node.getFullWidth()) || node.getFullWidth() === 0) { - return; + if (!textSpanIntersectsWith(span, node.pos, node.getFullWidth())) { + return; + } } if (isTypeNode(node)) { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 2047842833c46..17483436e009a 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5543,7 +5543,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideInlineHints(fileName: string): InlineHint[]; + provideInlineHints(fileName: string, span: TextSpan): InlineHint[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -6324,8 +6324,9 @@ declare namespace ts { interface InlineHintsContext { file: SourceFile; program: Program; - cancellationToken?: CancellationToken; + cancellationToken: CancellationToken; host: LanguageServiceHost; + span: TextSpan; } } declare namespace ts { @@ -8385,8 +8386,19 @@ declare namespace ts.server.protocol { interface SignatureHelpResponse extends Response { body?: SignatureHelpItems; } - interface ProvideInlineHintsRequest extends FileRequest { + interface ProvideInlineHintsRequestArgs extends FileRequestArgs { + /** + * Start position of the span. + */ + start: number; + /** + * Length of the span. + */ + length: number; + } + interface ProvideInlineHintsRequest extends Request { command: CommandTypes.ProvideInlineHints; + arguments: ProvideInlineHintsRequestArgs; } interface HintItem { text: string; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index a397de52cac1a..c8f20da898d89 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5543,7 +5543,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideInlineHints(fileName: string): InlineHint[]; + provideInlineHints(fileName: string, span: TextSpan): InlineHint[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -6324,8 +6324,9 @@ declare namespace ts { interface InlineHintsContext { file: SourceFile; program: Program; - cancellationToken?: CancellationToken; + cancellationToken: CancellationToken; host: LanguageServiceHost; + span: TextSpan; } } declare namespace ts { From ee6527e611e2a0395827de23233d95a5f2cd8244 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Dec 2020 18:42:39 +0800 Subject: [PATCH 09/53] Add function expression like hints --- src/server/protocol.ts | 6 +- src/server/session.ts | 4 +- src/services/inlineHints.ts | 67 ++++++++++++++++--- src/services/types.ts | 6 +- .../reference/api/tsserverlibrary.d.ts | 4 ++ tests/baselines/reference/api/typescript.d.ts | 2 + 6 files changed, 73 insertions(+), 16 deletions(-) diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 55031391bedc7..41df1664d5b05 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2491,8 +2491,10 @@ namespace ts.server.protocol { } export interface HintItem { - text: string - position: Location + text: string; + position: Location; + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; } export interface ProvideInlineHintsResponse extends Response { diff --git a/src/server/session.ts b/src/server/session.ts index 2f76a65c588d7..024ea5af5d0dd 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1428,7 +1428,9 @@ namespace ts.server { return hints.map(hint => ({ text: hint.text, - position: scriptInfo.positionToLineOffset(hint.position) + position: scriptInfo.positionToLineOffset(hint.position), + whitespaceBefore: hint.whitespaceBefore, + whitespaceAfter: hint.whitespaceAfter })); } diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 39230e7662176..3f20683d227e2 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -1,8 +1,10 @@ /* @internal */ namespace ts.InlineHints { interface HintInfo { - text: string - position: number + text: string; + position: number; + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; } export function provideInlineHints(context: InlineHintsContext): HintInfo[] { @@ -41,21 +43,20 @@ namespace ts.InlineHints { if (isCallExpression(node) || isNewExpression(node)) { visitCallOrNewExpression(node); } + else if (isArrowFunction(node) || isFunctionExpression(node)) { + visitFunctionExpressionLike(node); + } return forEachChild(node, visitor); } function visitCallOrNewExpression(expr: CallExpression | NewExpression) { - const candidates: Signature[] = []; - const signature = checker.getResolvedSignatureForSignatureHelp(expr, candidates); - if (!signature || !candidates.length) { + if (!expr.arguments || !expr.arguments.length) { return; } - getCallArgumentsHints(expr, signature); - } - - function getCallArgumentsHints(expr: CallExpression | NewExpression, signature: Signature) { - if (!expr.arguments || !expr.arguments.length) { + const candidates: Signature[] = []; + const signature = checker.getResolvedSignatureForSignatureHelp(expr, candidates); + if (!signature || !candidates.length) { return; } @@ -67,11 +68,55 @@ namespace ts.InlineHints { if (!argumentName || argumentName !== parameterName) { result.push({ text: `${unescapeLeadingUnderscores(parameterName)}:`, - position: expr.arguments[i].getStart() + position: expr.arguments[i].getStart(), + whitespaceAfter: true, }); } } } } + + function visitFunctionExpressionLike(expr: ArrowFunction | FunctionExpression) { + if (!expr.parameters.length || expr.parameters.every(param => param.type)) { + return; + } + + const contextualType = checker.getContextualType(expr); + if (!contextualType) { + return; + } + + const signatures = checker.getSignaturesOfType(contextualType, SignatureKind.Call); + const signature = firstOrUndefined(signatures); + if (!signature) { + return; + } + + for (let i = 0; i < expr.parameters.length && i < signature.parameters.length; ++i) { + const param = expr.parameters[i]; + if (param.type) { + continue; + } + + const signatureParam = signature.parameters[i]; + const signatureParamType = checker.getTypeOfSymbolAtLocation(signatureParam, signatureParam.valueDeclaration); + + const valueDeclaration = signatureParam.valueDeclaration; + if (!valueDeclaration || !isParameter(valueDeclaration) || !valueDeclaration.type) { + continue; + } + + const typeDisplayString = displayPartsToString(typeToDisplayParts(checker, signatureParamType)); + if (!typeDisplayString) { + continue; + } + + result.push({ + text: `:${typeDisplayString}`, + position: param.end, + whitespaceBefore: true, + }); + } + } } } \ No newline at end of file diff --git a/src/services/types.ts b/src/services/types.ts index 052ade3302dca..1e71b50d4b42f 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -688,8 +688,10 @@ namespace ts { } export interface InlineHint { - text: string, - position: number + text: string; + position: number; + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; } export interface TodoCommentDescriptor { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 17483436e009a..47081ebb5af0b 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5711,6 +5711,8 @@ declare namespace ts { interface InlineHint { text: string; position: number; + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; } interface TodoCommentDescriptor { text: string; @@ -8403,6 +8405,8 @@ declare namespace ts.server.protocol { interface HintItem { text: string; position: Location; + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; } interface ProvideInlineHintsResponse extends Response { body?: HintItem[]; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index c8f20da898d89..4271d9fd0df98 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5711,6 +5711,8 @@ declare namespace ts { interface InlineHint { text: string; position: number; + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; } interface TodoCommentDescriptor { text: string; From 679b58dcc145c7ee4640ebead971e6542a0bf685 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Dec 2020 23:25:42 +0800 Subject: [PATCH 10/53] Support configure inline hints --- src/compiler/types.ts | 3 + src/harness/harnessLanguageService.ts | 4 +- src/server/session.ts | 2 +- src/services/inlineHints.ts | 82 ++++++++++++++----- src/services/services.ts | 7 +- src/services/shims.ts | 8 +- src/services/types.ts | 9 +- .../reference/api/tsserverlibrary.d.ts | 11 ++- tests/baselines/reference/api/typescript.d.ts | 11 ++- 9 files changed, 102 insertions(+), 35 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 47b3c0bbf42c1..546007cb87b17 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8245,6 +8245,9 @@ namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; + readonly includeInlineParameterName?: boolean; + readonly includeInlineFunctionParameterType?: boolean; + readonly includeInlineVariableType?: boolean; } /** Represents a bigint literal value without requiring bigint support */ diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 7788d9b225098..bc75929556c0a 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -599,8 +599,8 @@ namespace Harness.LanguageService { provideCallHierarchyOutgoingCalls(fileName: string, position: number) { return unwrapJSONCallResult(this.shim.provideCallHierarchyOutgoingCalls(fileName, position)); } - provideInlineHints(fileName: string, span: ts.TextSpan) { - return unwrapJSONCallResult(this.shim.provideInlineHints(fileName, span)); + provideInlineHints(fileName: string, span: ts.TextSpan, preference: ts.InlineHintsOptions) { + return unwrapJSONCallResult(this.shim.provideInlineHints(fileName, span, preference)); } getEmitOutput(fileName: string): ts.EmitOutput { return unwrapJSONCallResult(this.shim.getEmitOutput(fileName)); diff --git a/src/server/session.ts b/src/server/session.ts index 024ea5af5d0dd..5825f4893411b 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1424,7 +1424,7 @@ namespace ts.server { private provideInlineHints(args: protocol.ProvideInlineHintsRequestArgs) { const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args); const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; - const hints = languageService.provideInlineHints(file, args); + const hints = languageService.provideInlineHints(file, args, this.getPreferences(file)); return hints.map(hint => ({ text: hint.text, diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 3f20683d227e2..f29443a5a4219 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -7,8 +7,10 @@ namespace ts.InlineHints { whitespaceAfter?: boolean; } + const maxHintsLength = 20; + export function provideInlineHints(context: InlineHintsContext): HintInfo[] { - const { file, program, span, cancellationToken } = context; + const { file, program, span, cancellationToken, preferences } = context; const checker = program.getTypeChecker(); const result: HintInfo[] = []; @@ -40,15 +42,46 @@ namespace ts.InlineHints { return; } - if (isCallExpression(node) || isNewExpression(node)) { + if (preferences.includeInlineParameterName && (isCallExpression(node) || isNewExpression(node))) { visitCallOrNewExpression(node); } - else if (isArrowFunction(node) || isFunctionExpression(node)) { + else if (preferences.includeInlineFunctionParameterType && (isArrowFunction(node) || isFunctionExpression(node))) { visitFunctionExpressionLike(node); } + else if (preferences.includeInlineVariableType && (isVariableDeclaration(node))) { + visitVariableDeclaration(node); + } return forEachChild(node, visitor); } + function addNameHints(text: string, position: number) { + result.push({ + text: `${truncation(text, maxHintsLength)}:`, + position, + whitespaceAfter: true, + }); + } + + function addTypeHints(text: string, position: number) { + result.push({ + text: `:${truncation(text, maxHintsLength)}`, + position, + whitespaceBefore: true, + }); + } + + function visitVariableDeclaration(decl: VariableDeclaration) { + if (decl.type || !decl.initializer) { + return; + } + + const initializerType = checker.getTypeAtLocation(decl.initializer); + const typeDisplayString = displayPartsToString(typeToDisplayParts(checker, initializerType)); + if (typeDisplayString) { + addTypeHints(typeDisplayString, decl.name.end); + } + } + function visitCallOrNewExpression(expr: CallExpression | NewExpression) { if (!expr.arguments || !expr.arguments.length) { return; @@ -66,11 +99,7 @@ namespace ts.InlineHints { const arg = expr.arguments[i]; const argumentName = isIdentifier(arg) ? arg.text : undefined; if (!argumentName || argumentName !== parameterName) { - result.push({ - text: `${unescapeLeadingUnderscores(parameterName)}:`, - position: expr.arguments[i].getStart(), - whitespaceAfter: true, - }); + addNameHints(unescapeLeadingUnderscores(parameterName), expr.arguments[i].getStart()); } } } @@ -98,25 +127,34 @@ namespace ts.InlineHints { continue; } - const signatureParam = signature.parameters[i]; - const signatureParamType = checker.getTypeOfSymbolAtLocation(signatureParam, signatureParam.valueDeclaration); - - const valueDeclaration = signatureParam.valueDeclaration; - if (!valueDeclaration || !isParameter(valueDeclaration) || !valueDeclaration.type) { - continue; - } - - const typeDisplayString = displayPartsToString(typeToDisplayParts(checker, signatureParamType)); + const typeDisplayString = getParameterDeclarationTypeDisplayString(signature.parameters[i]); if (!typeDisplayString) { continue; } - result.push({ - text: `:${typeDisplayString}`, - position: param.end, - whitespaceBefore: true, - }); + addTypeHints(typeDisplayString, param.end); + } + } + + function getParameterDeclarationTypeDisplayString(symbol: Symbol) { + const valueDeclaration = symbol.valueDeclaration; + if (!valueDeclaration || !isParameter(valueDeclaration)) { + return undefined; + } + + if (valueDeclaration.type) { + return valueDeclaration.type.getText(); + } + + const signatureParamType = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration); + return displayPartsToString(typeToDisplayParts(checker, signatureParamType)); + } + + function truncation(text: string, maxLength: number) { + if (text.length > maxLength) { + return text.substr(0, maxLength - "...".length) + "..."; } + return text; } } } \ No newline at end of file diff --git a/src/services/services.ts b/src/services/services.ts index 8a81775bfa606..5d23111098f59 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2467,12 +2467,13 @@ namespace ts { }; } - function getInlineHintsContext(file: SourceFile, span: TextSpan): InlineHintsContext { + function getInlineHintsContext(file: SourceFile, span: TextSpan, preferences: UserPreferences): InlineHintsContext { return { file, program: getProgram()!, host, span, + preferences, cancellationToken, }; } @@ -2520,10 +2521,10 @@ namespace ts { return declaration ? CallHierarchy.getOutgoingCalls(program, declaration) : []; } - function provideInlineHints(fileName: string, span: TextSpan): InlineHint[] { + function provideInlineHints(fileName: string, span: TextSpan, preferences: InlineHintsOptions = emptyOptions): InlineHint[] { synchronizeHostData(); const sourceFile = getValidSourceFile(fileName); - return InlineHints.provideInlineHints(getInlineHintsContext(sourceFile, span)); + return InlineHints.provideInlineHints(getInlineHintsContext(sourceFile, span, preferences)); } const ls: LanguageService = { diff --git a/src/services/shims.ts b/src/services/shims.ts index c013e1b16d12e..2cf285e05bee3 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -280,7 +280,7 @@ namespace ts { prepareCallHierarchy(fileName: string, position: number): string; provideCallHierarchyIncomingCalls(fileName: string, position: number): string; provideCallHierarchyOutgoingCalls(fileName: string, position: number): string; - provideInlineHints(fileName: string, span: TextSpan): string; + provideInlineHints(fileName: string, span: TextSpan, preference: InlineHintsOptions | undefined): string; getEmitOutput(fileName: string): string; getEmitOutputObject(fileName: string): EmitOutput; @@ -1067,10 +1067,10 @@ namespace ts { ); } - public provideInlineHints(fileName: string, span: TextSpan): string { + public provideInlineHints(fileName: string, span: TextSpan, preference: InlineHintsOptions | undefined): string { return this.forwardJSONCall( - `provideInlineHints('${fileName}', '${JSON.stringify(span)}')`, - () => this.languageService.provideInlineHints(fileName, span) + `provideInlineHints('${fileName}', '${JSON.stringify(span)}', ${JSON.stringify(preference)})`, + () => this.languageService.provideInlineHints(fileName, span, preference) ); } diff --git a/src/services/types.ts b/src/services/types.ts index 1e71b50d4b42f..86b09c9fa1b8c 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -481,7 +481,7 @@ namespace ts { provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideInlineHints(fileName: string, span: TextSpan): InlineHint[] + provideInlineHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlineHint[] getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; @@ -564,6 +564,12 @@ namespace ts { includeInsertTextCompletions?: boolean; } + export interface InlineHintsOptions extends UserPreferences { + readonly includeInlineParameterName?: boolean; + readonly includeInlineFunctionParameterType?: boolean, + readonly includeInlineVariableType?: boolean; + } + export type SignatureHelpTriggerCharacter = "," | "(" | "<"; export type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; @@ -1497,5 +1503,6 @@ namespace ts { cancellationToken: CancellationToken; host: LanguageServiceHost; span: TextSpan; + preferences: UserPreferences; } } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 47081ebb5af0b..f6ef11de94044 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3872,6 +3872,9 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; + readonly includeInlineParameterName?: boolean; + readonly includeInlineFunctionParameterType?: boolean; + readonly includeInlineVariableType?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5543,7 +5546,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideInlineHints(fileName: string, span: TextSpan): InlineHint[]; + provideInlineHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlineHint[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -5603,6 +5606,11 @@ declare namespace ts { /** @deprecated Use includeCompletionsWithInsertText */ includeInsertTextCompletions?: boolean; } + interface InlineHintsOptions extends UserPreferences { + readonly includeInlineParameterName?: boolean; + readonly includeInlineFunctionParameterType?: boolean; + readonly includeInlineVariableType?: boolean; + } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; interface SignatureHelpItemsOptions { @@ -6329,6 +6337,7 @@ declare namespace ts { cancellationToken: CancellationToken; host: LanguageServiceHost; span: TextSpan; + preferences: UserPreferences; } } declare namespace ts { diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 4271d9fd0df98..48a3578fe79b5 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3872,6 +3872,9 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; + readonly includeInlineParameterName?: boolean; + readonly includeInlineFunctionParameterType?: boolean; + readonly includeInlineVariableType?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5543,7 +5546,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideInlineHints(fileName: string, span: TextSpan): InlineHint[]; + provideInlineHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlineHint[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -5603,6 +5606,11 @@ declare namespace ts { /** @deprecated Use includeCompletionsWithInsertText */ includeInsertTextCompletions?: boolean; } + interface InlineHintsOptions extends UserPreferences { + readonly includeInlineParameterName?: boolean; + readonly includeInlineFunctionParameterType?: boolean; + readonly includeInlineVariableType?: boolean; + } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; interface SignatureHelpItemsOptions { @@ -6329,6 +6337,7 @@ declare namespace ts { cancellationToken: CancellationToken; host: LanguageServiceHost; span: TextSpan; + preferences: UserPreferences; } } declare namespace ts { From 446bee46f5417e8db4bd56edc542821fd94be9ad Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 26 Dec 2020 00:40:19 +0800 Subject: [PATCH 11/53] Display hints in single line --- src/services/inlineHints.ts | 39 ++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index f29443a5a4219..87b07268d000a 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -76,7 +76,7 @@ namespace ts.InlineHints { } const initializerType = checker.getTypeAtLocation(decl.initializer); - const typeDisplayString = displayPartsToString(typeToDisplayParts(checker, initializerType)); + const typeDisplayString = printTypeInSingleLine(initializerType); if (typeDisplayString) { addTypeHints(typeDisplayString, decl.name.end); } @@ -143,11 +143,11 @@ namespace ts.InlineHints { } if (valueDeclaration.type) { - return valueDeclaration.type.getText(); + return printNodeInSingleLine(valueDeclaration.type); } const signatureParamType = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration); - return displayPartsToString(typeToDisplayParts(checker, signatureParamType)); + return printTypeInSingleLine(signatureParamType); } function truncation(text: string, maxLength: number) { @@ -156,5 +156,38 @@ namespace ts.InlineHints { } return text; } + + function createSignleLineWriter(writer: DisplayPartsSymbolWriter): DisplayPartsSymbolWriter { + return { + ...writer, + writeLine: () => writer.writeSpace(" ") + }; + } + + function printTypeInSingleLine(type: Type) { + const flags = NodeBuilderFlags.IgnoreErrors | TypeFormatFlags.AllowUniqueESSymbolType | TypeFormatFlags.UseAliasDefinedOutsideCurrentScope; + const displayParts = mapToDisplayParts(writer => { + const singleLineWriter = createSignleLineWriter(writer); + const typeNode = checker.typeToTypeNode(type, /*enclosingDeclaration*/ undefined, flags, singleLineWriter); + Debug.assertIsDefined(typeNode, "should always get typenode"); + + writeNodeInSignleLine(typeNode, singleLineWriter); + }); + return displayPartsToString(displayParts); + } + + function printNodeInSingleLine(node: Node) { + const displayParts = mapToDisplayParts(writer => { + const singleLineWriter = createSignleLineWriter(writer); + writeNodeInSignleLine(node, singleLineWriter); + }); + return displayPartsToString(displayParts); + } + + function writeNodeInSignleLine(node: Node, writer: DisplayPartsSymbolWriter) { + const options: PrinterOptions = { removeComments: true }; + const printer = createPrinter(options); + printer.writeNode(EmitHint.Unspecified, node, /*sourceFile*/ file, writer); + } } } \ No newline at end of file From d2fbd1e6e5ce39a6207f992a2bae435976cc9347 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 27 Dec 2020 21:15:10 +0800 Subject: [PATCH 12/53] Add test suits and tests --- src/harness/fourslashImpl.ts | 12 ++++++ src/harness/fourslashInterfaceImpl.ts | 11 ++++++ src/services/inlineHints.ts | 2 +- tests/cases/fourslash/fourslash.ts | 14 +++++++ .../cases/fourslash/inlineHintsShouldWork1.ts | 20 ++++++++++ .../fourslash/inlineHintsShouldWork10.ts | 9 +++++ .../fourslash/inlineHintsShouldWork11.ts | 24 ++++++++++++ .../fourslash/inlineHintsShouldWork12.ts | 23 ++++++++++++ .../fourslash/inlineHintsShouldWork13.ts | 16 ++++++++ .../fourslash/inlineHintsShouldWork14.ts | 8 ++++ .../fourslash/inlineHintsShouldWork15.ts | 14 +++++++ .../fourslash/inlineHintsShouldWork16.ts | 14 +++++++ .../fourslash/inlineHintsShouldWork17.ts | 14 +++++++ .../fourslash/inlineHintsShouldWork18.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork19.ts | 14 +++++++ .../cases/fourslash/inlineHintsShouldWork2.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork20.ts | 7 ++++ .../fourslash/inlineHintsShouldWork21.ts | 7 ++++ .../fourslash/inlineHintsShouldWork22.ts | 14 +++++++ .../fourslash/inlineHintsShouldWork23.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork24.ts | 20 ++++++++++ .../fourslash/inlineHintsShouldWork25.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork26.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork27.ts | 22 +++++++++++ .../fourslash/inlineHintsShouldWork28.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork29.ts | 33 +++++++++++++++++ .../cases/fourslash/inlineHintsShouldWork3.ts | 20 ++++++++++ .../fourslash/inlineHintsShouldWork30.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork31.ts | 18 +++++++++ .../cases/fourslash/inlineHintsShouldWork4.ts | 29 +++++++++++++++ .../cases/fourslash/inlineHintsShouldWork5.ts | 26 +++++++++++++ .../cases/fourslash/inlineHintsShouldWork6.ts | 16 ++++++++ .../cases/fourslash/inlineHintsShouldWork7.ts | 30 +++++++++++++++ .../cases/fourslash/inlineHintsShouldWork8.ts | 30 +++++++++++++++ .../cases/fourslash/inlineHintsShouldWork9.ts | 37 +++++++++++++++++++ 35 files changed, 608 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/inlineHintsShouldWork1.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork10.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork11.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork12.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork13.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork14.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork15.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork16.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork17.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork18.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork19.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork2.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork20.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork21.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork22.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork23.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork24.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork25.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork26.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork27.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork28.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork29.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork3.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork30.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork31.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork4.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork5.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork6.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork7.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork8.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork9.ts diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 551ac9aef1889..5815de1d14ab4 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -824,6 +824,18 @@ namespace FourSlash { }); } + public verifyInlineHints(expected: readonly FourSlashInterface.VerifyInlineHintsOptions[], span: ts.TextSpan = { start: 0, length: this.activeFile.content.length }, preference?: ts.InlineHintsOptions) { + const hints = this.languageService.provideInlineHints(this.activeFile.fileName, span, preference); + assert.equal(hints.length, expected.length, "Number of hints"); + const sortHints = (a: ts.InlineHint, b: ts.InlineHint) => a.position - b.position; + ts.zipWith(hints.sort(sortHints), [...expected].sort(sortHints), (actual, expected) => { + assert.equal(actual.text, expected.text, "Text"); + assert.equal(actual.position, expected.position, "Position"); + assert.equal(actual.whitespaceBefore, expected.whitespaceBefore, "whitespaceBefore"); + assert.equal(actual.whitespaceAfter, expected.whitespaceAfter, "whitespaceAfter"); + }); + } + public verifyCompletions(options: FourSlashInterface.VerifyCompletionsOptions) { if (options.marker === undefined) { this.verifyCompletionsWorker(options); diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 6fd2d834039d2..d2b226f6ef129 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -243,6 +243,10 @@ namespace FourSlashInterface { } } + public getInlineHints(expected: readonly VerifyInlineHintsOptions[], span: ts.TextSpan, preference?: ts.InlineHintsOptions) { + this.state.verifyInlineHints(expected, span, preference); + } + public quickInfoIs(expectedText: string, expectedDocumentation?: string) { this.state.verifyQuickInfoString(expectedText, expectedDocumentation); } @@ -1645,6 +1649,13 @@ namespace FourSlashInterface { readonly containerKind?: ts.ScriptElementKind; } + export interface VerifyInlineHintsOptions { + text: string; + position: number + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; + } + export type ArrayOrSingle = T | readonly T[]; export interface VerifyCompletionListContainsOptions extends ts.UserPreferences { diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 87b07268d000a..18fe79f7a3aa4 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -7,7 +7,7 @@ namespace ts.InlineHints { whitespaceAfter?: boolean; } - const maxHintsLength = 20; + const maxHintsLength = 30; export function provideInlineHints(context: InlineHintsContext): HintInfo[] { const { file, program, span, cancellationToken, preferences } = context; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index d2ea70036a4b5..9918613ae0c8d 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -381,6 +381,7 @@ declare namespace FourSlashInterface { start: number; length: number; }, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: { name: string, text?: string }[] | undefined): void; + getInlineHints(expected: readonly VerifyInlineHintsOptions[], span?: TextSpan, preference?: InlineHintsOptions); getSyntacticDiagnostics(expected: ReadonlyArray): void; getSemanticDiagnostics(expected: ReadonlyArray): void; getSuggestionDiagnostics(expected: ReadonlyArray): void; @@ -614,6 +615,11 @@ declare namespace FourSlashInterface { readonly importModuleSpecifierPreference?: "shortest" | "project-relative" | "relative" | "non-relative"; readonly importModuleSpecifierEnding?: "minimal" | "index" | "js"; } + interface InlineHintsOptions extends UserPreferences { + readonly includeInlineParameterName?: boolean; + readonly includeInlineFunctionParameterType?: boolean; + readonly includeInlineVariableType?: boolean; + } interface CompletionsOptions { readonly marker?: ArrayOrSingle; readonly isNewIdentifierLocation?: boolean; @@ -711,6 +717,14 @@ declare namespace FourSlashInterface { readonly commands?: ReadonlyArray<{}>; } + export interface VerifyInlineHintsOptions { + text: string; + position: number + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; + } + + interface VerifyNavigateToOptions { readonly pattern: string; readonly fileName?: string; diff --git a/tests/cases/fourslash/inlineHintsShouldWork1.ts b/tests/cases/fourslash/inlineHintsShouldWork1.ts new file mode 100644 index 0000000000000..2a4fd5e60b85b --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork1.ts @@ -0,0 +1,20 @@ +/// + +//// function foo (a: number, b: number) {} +//// foo(/*a*/1, /*b*/2); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork10.ts b/tests/cases/fourslash/inlineHintsShouldWork10.ts new file mode 100644 index 0000000000000..5cbe1a8309604 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork10.ts @@ -0,0 +1,9 @@ +/// + +//// declare const unknownCall: any; +//// unknownCall(); + +const markers = test.markers(); +verify.getInlineHints([], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork11.ts b/tests/cases/fourslash/inlineHintsShouldWork11.ts new file mode 100644 index 0000000000000..f8af60f41d19a --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork11.ts @@ -0,0 +1,24 @@ +/// + +//// function foo(a: number) { +//// return (b: number) => { +//// return a + b +//// } +//// } +//// foo(/*a*/1)(/*b*/2); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + }, +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork12.ts b/tests/cases/fourslash/inlineHintsShouldWork12.ts new file mode 100644 index 0000000000000..2ad65c3e1a7b1 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork12.ts @@ -0,0 +1,23 @@ +/// + +//// function foo(a: (b: number) => number) { +//// return a(/*a*/1) + 2 +//// } + +//// foo(/*b*/(c: number) => c + 1); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'b:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'a:', + position: markers[1].position, + whitespaceAfter: true + }, +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork13.ts b/tests/cases/fourslash/inlineHintsShouldWork13.ts new file mode 100644 index 0000000000000..e88e0ffb02e3b --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork13.ts @@ -0,0 +1,16 @@ +/// + +//// function foo (a: number, b: number) {} +//// declare const a: 1; +//// foo(a, /*b*/2); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'b:', + position: markers[0].position, + whitespaceAfter: true + }, +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork14.ts b/tests/cases/fourslash/inlineHintsShouldWork14.ts new file mode 100644 index 0000000000000..4181305b842a7 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork14.ts @@ -0,0 +1,8 @@ +/// + +//// function foo (a: number, b: number) {} +//// foo(1, 2); + +verify.getInlineHints([], undefined, { + includeInlineParameterName: false +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork15.ts b/tests/cases/fourslash/inlineHintsShouldWork15.ts new file mode 100644 index 0000000000000..5668f2eaec8ac --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork15.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = 123; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':123', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork16.ts b/tests/cases/fourslash/inlineHintsShouldWork16.ts new file mode 100644 index 0000000000000..5668f2eaec8ac --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork16.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = 123; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':123', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork17.ts b/tests/cases/fourslash/inlineHintsShouldWork17.ts new file mode 100644 index 0000000000000..32dfbf4b66363 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork17.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = { a: 123 }; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':{ a: number; }', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork18.ts b/tests/cases/fourslash/inlineHintsShouldWork18.ts new file mode 100644 index 0000000000000..dfec616b21c40 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork18.ts @@ -0,0 +1,15 @@ +/// + +//// class Class {} +//// const a/*a*/ = new Class(); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':Class', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork19.ts b/tests/cases/fourslash/inlineHintsShouldWork19.ts new file mode 100644 index 0000000000000..e7ebbc99f84e1 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork19.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = () => 123; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':() => number', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork2.ts b/tests/cases/fourslash/inlineHintsShouldWork2.ts new file mode 100644 index 0000000000000..3f52c17e0153b --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork2.ts @@ -0,0 +1,15 @@ +/// + +//// function foo (a: number, { c }: any) {} +//// foo(/*a*/1, { c: 1}); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork20.ts b/tests/cases/fourslash/inlineHintsShouldWork20.ts new file mode 100644 index 0000000000000..db6719bfbfcdb --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork20.ts @@ -0,0 +1,7 @@ +/// + +//// const a = 123; + +verify.getInlineHints([], undefined, { + includeInlineVariableType: false +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork21.ts b/tests/cases/fourslash/inlineHintsShouldWork21.ts new file mode 100644 index 0000000000000..15b92c2096ac3 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork21.ts @@ -0,0 +1,7 @@ +/// + +//// const a; + +verify.getInlineHints([], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork22.ts b/tests/cases/fourslash/inlineHintsShouldWork22.ts new file mode 100644 index 0000000000000..4b26abd6c202d --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork22.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = "I'm very very very very very very very very very long"; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: `:"I'm very very very very ve...`, + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork23.ts b/tests/cases/fourslash/inlineHintsShouldWork23.ts new file mode 100644 index 0000000000000..7a9536da8d8bf --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork23.ts @@ -0,0 +1,15 @@ +/// + +//// function foo (Im_very_very_very_very_very_very_very_long: number) {} +//// foo(/*a*/1); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'Im_very_very_very_very_very...:', + position: markers[0].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork24.ts b/tests/cases/fourslash/inlineHintsShouldWork24.ts new file mode 100644 index 0000000000000..527b5b17c28ee --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork24.ts @@ -0,0 +1,20 @@ +/// + +//// type F = (a: string, b: number) => void +//// const f: F = (a/*a*/, b/*b*/) => { } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':string', + position: markers[0].position, + whitespaceBefore: true + }, + { + text: ':number', + position: markers[1].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork25.ts b/tests/cases/fourslash/inlineHintsShouldWork25.ts new file mode 100644 index 0000000000000..a75947f8e6eae --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork25.ts @@ -0,0 +1,15 @@ +/// + +//// function foo (cb: (a: string) => void) {} +//// foo((a/*a*/) => { }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':string', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork26.ts b/tests/cases/fourslash/inlineHintsShouldWork26.ts new file mode 100644 index 0000000000000..5165e0462c89a --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork26.ts @@ -0,0 +1,15 @@ +/// + +//// function foo (cb: (a: Exclude<1 | 2 | 3, 1>) => void) {} +//// foo((a/*a*/) => { }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':Exclude<1 | 2 | 3, 1>', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork27.ts b/tests/cases/fourslash/inlineHintsShouldWork27.ts new file mode 100644 index 0000000000000..e637fd55b7a0d --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork27.ts @@ -0,0 +1,22 @@ +/// + +//// function foo (a: (b: (c: (d: Exclude<1 | 2 | 3, 1>) => void) => void) => void) {} +//// foo(a/*a*/ => { +//// a(d/*b*/ => {}) +//// }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':(c: (d: Exclude<1 | 2 | 3, ...', + position: markers[0].position, + whitespaceBefore: true + }, + { + text: ':Exclude<1 | 2 | 3, 1>', + position: markers[1].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork28.ts b/tests/cases/fourslash/inlineHintsShouldWork28.ts new file mode 100644 index 0000000000000..b04c846cd49c4 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork28.ts @@ -0,0 +1,15 @@ +/// + +//// type F = (a: string, b: number) => void +//// const f: F = (a/*a*/, b: number) => { } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':string', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork29.ts b/tests/cases/fourslash/inlineHintsShouldWork29.ts new file mode 100644 index 0000000000000..12d0f7d44cad5 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork29.ts @@ -0,0 +1,33 @@ +/// + +//// function foo (a: (b: (c: (d: Exclude<1 | 2 | 3, 1>) => void) => void) => void) {} +//// foo(/*a*/a/*b*/ => { +//// a(/*c*/d/*d*/ => {}) +//// }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: ':(c: (d: Exclude<1 | 2 | 3, ...', + position: markers[1].position, + whitespaceBefore: true + }, + { + text: 'c:', + position: markers[2].position, + whitespaceAfter: true + }, + { + text: ':Exclude<1 | 2 | 3, 1>', + position: markers[3].position, + whitespaceBefore: true + } +], undefined, { + includeInlineParameterName: true, + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork3.ts b/tests/cases/fourslash/inlineHintsShouldWork3.ts new file mode 100644 index 0000000000000..4efe2728d1b13 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork3.ts @@ -0,0 +1,20 @@ +/// + +//// function foo (a: number, ...b: number[]) {} +//// foo(/*a*/1, /*b*/1, 1, 1); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork30.ts b/tests/cases/fourslash/inlineHintsShouldWork30.ts new file mode 100644 index 0000000000000..1d8af95a9e687 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork30.ts @@ -0,0 +1,15 @@ +/// + +//// function f(v: T, a: (v: T) => void) {} +//// f(1, a/*a*/ => { }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':T', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork31.ts b/tests/cases/fourslash/inlineHintsShouldWork31.ts new file mode 100644 index 0000000000000..9f015881eb216 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork31.ts @@ -0,0 +1,18 @@ +/// + +//// type F = (a: { +//// a: number +//// b: string +//// }) => void +//// const f: F = (a/*a*/) => { } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':{ a: number; b: string; }', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork4.ts b/tests/cases/fourslash/inlineHintsShouldWork4.ts new file mode 100644 index 0000000000000..1686b08d6e8d3 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork4.ts @@ -0,0 +1,29 @@ +/// + +//// declare function foo(w: number): void +//// declare function foo(a: number, b: number): void; +//// declare function foo(a: number | undefined, b: number | undefined): void; + +//// foo(/*a*/1) +//// foo(/*b*/1, /*c*/2) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'w:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'a:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[2].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork5.ts b/tests/cases/fourslash/inlineHintsShouldWork5.ts new file mode 100644 index 0000000000000..9d4582b541040 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork5.ts @@ -0,0 +1,26 @@ +/// + +//// type Args = [a: number, b: number] +//// declare function foo(c: number, ...args: Args); +//// foo(/*a*/1, /*b*/2, /*c*/3) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'c:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'a:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[2].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork6.ts b/tests/cases/fourslash/inlineHintsShouldWork6.ts new file mode 100644 index 0000000000000..388e1286f6247 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork6.ts @@ -0,0 +1,16 @@ +/// + +//// type Args = [number, number] +//// declare function foo(c: number, ...args: Args); +//// foo(/*a*/1, 2, 3) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'c:', + position: markers[0].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork7.ts b/tests/cases/fourslash/inlineHintsShouldWork7.ts new file mode 100644 index 0000000000000..624914c83e89d --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork7.ts @@ -0,0 +1,30 @@ +/// + +//// interface Call { +//// (a: number): void +//// (b: number, c: number): void +//// } +//// declare const call: Call; +//// call(/*a*/1); +//// call(/*b*/1, /*c*/2); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'c:', + position: markers[2].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork8.ts b/tests/cases/fourslash/inlineHintsShouldWork8.ts new file mode 100644 index 0000000000000..77fe2067182f9 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork8.ts @@ -0,0 +1,30 @@ +/// + +//// class Class { +//// constructor(a: number); +//// constructor(b: number, c: number); +//// constructor(b: number, c?: number) { } +//// } +//// new Class(/*a*/1) +//// new Class(/*b*/1, /*c*/2) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'c:', + position: markers[2].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork9.ts b/tests/cases/fourslash/inlineHintsShouldWork9.ts new file mode 100644 index 0000000000000..84ec6d92574cb --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork9.ts @@ -0,0 +1,37 @@ +/// + +//// interface Call { +//// (a: number): void +//// (b: number, c: number): void +//// new (d: number): Call +//// } +//// declare const call: Call; +//// call(/*a*/1); +//// call(/*b*/1, /*c*/2); +//// new call(/*d*/1); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'c:', + position: markers[2].position, + whitespaceAfter: true + }, + { + text: 'd:', + position: markers[3].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); From c4abb871c8ae7c18311188a56fe002609c9e235e Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 28 Dec 2020 13:35:42 +0800 Subject: [PATCH 13/53] Add range tests --- tests/cases/fourslash/fourslash.ts | 5 +++- .../fourslash/inlineHintsShouldWork32.ts | 30 +++++++++++++++++++ .../fourslash/inlineHintsShouldWork33.ts | 30 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/inlineHintsShouldWork32.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork33.ts diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 9918613ae0c8d..ce01cd46c15d2 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -381,7 +381,10 @@ declare namespace FourSlashInterface { start: number; length: number; }, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: { name: string, text?: string }[] | undefined): void; - getInlineHints(expected: readonly VerifyInlineHintsOptions[], span?: TextSpan, preference?: InlineHintsOptions); + getInlineHints(expected: readonly VerifyInlineHintsOptions[], textSpan?: { + start: number; + length: number; + }, preference?: InlineHintsOptions); getSyntacticDiagnostics(expected: ReadonlyArray): void; getSemanticDiagnostics(expected: ReadonlyArray): void; getSuggestionDiagnostics(expected: ReadonlyArray): void; diff --git a/tests/cases/fourslash/inlineHintsShouldWork32.ts b/tests/cases/fourslash/inlineHintsShouldWork32.ts new file mode 100644 index 0000000000000..aca7d443714ed --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork32.ts @@ -0,0 +1,30 @@ +/// + +//// function foo1 (a: number, b: number) {} +//// function foo2 (c: number, d: number) {} +//// function foo3 (e: number, f: number) {} +//// function foo4 (g: number, h: number) {} +//// function foo5 (i: number, j: number) {} +//// function foo6 (k: number, i: number) {} + +//// function c1 () { foo1(/*a*/1, /*b*/2); } +//// function c2 () { foo2(/*c*/1, /*d*/2); } +//// function c3 () { foo3(/*e*/1, /*f*/2); } +//// function c4 () { foo4(/*g*/1, /*h*/2); } +//// function c5 () { foo5(/*i*/1, /*j*/2); } +//// function c6 () { foo6(/*k*/1, /*l*/2); } + +const start = test.markerByName('c'); +const end = test.markerByName('h'); +const span = { start: start.position, length: end.position - start.position }; + +verify.getInlineHints( + ['c', 'd', 'e', 'f', 'g', 'h'].map(mark => { + return { + text: `${mark}:`, + position: test.markerByName(mark).position, + whitespaceAfter: true + } + }), span, { + includeInlineParameterName: true +}) diff --git a/tests/cases/fourslash/inlineHintsShouldWork33.ts b/tests/cases/fourslash/inlineHintsShouldWork33.ts new file mode 100644 index 0000000000000..64fdbc4208794 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork33.ts @@ -0,0 +1,30 @@ +/// + +//// function foo1 (a: number, b: number) {} +//// function foo2 (c: number, d: number) {} +//// function foo3 (e: number, f: number) {} +//// function foo4 (g: number, h: number) {} +//// function foo5 (i: number, j: number) {} +//// function foo6 (k: number, l: number) {} + +//// foo1(/*a*/1, /*b*/2); +//// foo2(/*c*/1, /*d*/2); +//// foo3(/*e*/1, /*f*/2); +//// foo4(/*g*/1, /*h*/2); +//// foo5(/*i*/1, /*j*/2); +//// foo6(/*k*/1, /*l*/2); + +const start = test.markerByName('c'); +const end = test.markerByName('h'); +const span = { start: start.position, length: end.position - start.position }; + +verify.getInlineHints( + ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'].map(mark => { + return { + text: `${mark}:`, + position: test.markerByName(mark).position, + whitespaceAfter: true + } + }), span, { + includeInlineParameterName: true +}); \ No newline at end of file From a9e007a0b0513fa3c81f80bcf42cd9dbdd807f81 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 29 Dec 2020 23:42:46 +0800 Subject: [PATCH 14/53] Support more hints --- src/compiler/types.ts | 3 ++ src/services/inlineHints.ts | 75 +++++++++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 546007cb87b17..a3fe5c29b2223 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8248,6 +8248,9 @@ namespace ts { readonly includeInlineParameterName?: boolean; readonly includeInlineFunctionParameterType?: boolean; readonly includeInlineVariableType?: boolean; + readonly includeInlinePropertyDeclarationType?: boolean; + readonly includeInlineFunctionLikeReturnType?: boolean; + readonly includeInlineEnumMemberValue?: boolean; } /** Represents a bigint literal value without requiring bigint support */ diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 18fe79f7a3aa4..7eebd1a33129f 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -45,15 +45,34 @@ namespace ts.InlineHints { if (preferences.includeInlineParameterName && (isCallExpression(node) || isNewExpression(node))) { visitCallOrNewExpression(node); } - else if (preferences.includeInlineFunctionParameterType && (isArrowFunction(node) || isFunctionExpression(node))) { - visitFunctionExpressionLike(node); - } else if (preferences.includeInlineVariableType && (isVariableDeclaration(node))) { - visitVariableDeclaration(node); + visitVariableLikeDeclaration(node); + } + else if (preferences.includeInlinePropertyDeclarationType && isPropertyDeclaration(node)) { + visitVariableLikeDeclaration(node); + } + else if (preferences.includeInlineEnumMemberValue && isEnumMember(node)) { + visitEnumMember(node); + } + else { + if (preferences.includeInlineFunctionParameterType && isFunctionExpressionLike(node)) { + visitFunctionExpressionLikeForParameterType(node); + } + if (preferences.includeInlineFunctionLikeReturnType &&isFunctionDeclarationLike(node)) { + visitFunctionDeclarationLikeForReturnType(node); + } } return forEachChild(node, visitor); } + function isFunctionExpressionLike(node: Node): node is ArrowFunction | FunctionExpression { + return isArrowFunction(node) || isFunctionExpression(node); + } + + function isFunctionDeclarationLike(node: Node): node is FunctionDeclaration | ArrowFunction | FunctionExpression | MethodDeclaration { + return isArrowFunction(node) || isFunctionExpression(node) || isFunctionDeclaration(node) || isMethodDeclaration(node); + } + function addNameHints(text: string, position: number) { result.push({ text: `${truncation(text, maxHintsLength)}:`, @@ -70,13 +89,32 @@ namespace ts.InlineHints { }); } - function visitVariableDeclaration(decl: VariableDeclaration) { + function addEnumMemberValueHints(text: string, position: number) { + result.push({ + text: `= ${truncation(text, maxHintsLength)}`, + position, + whitespaceBefore: true, + }); + } + + function visitEnumMember(member: EnumMember) { + if (member.initializer) { + return; + } + + const enumValue = checker.getConstantValue(member); + if (enumValue !== undefined) { + addEnumMemberValueHints(enumValue.toString(), member.end); + } + } + + function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) { if (decl.type || !decl.initializer) { return; } - const initializerType = checker.getTypeAtLocation(decl.initializer); - const typeDisplayString = printTypeInSingleLine(initializerType); + const declarationType = checker.getTypeAtLocation(decl); + const typeDisplayString = printTypeInSingleLine(declarationType); if (typeDisplayString) { addTypeHints(typeDisplayString, decl.name.end); } @@ -105,7 +143,28 @@ namespace ts.InlineHints { } } - function visitFunctionExpressionLike(expr: ArrowFunction | FunctionExpression) { + function visitFunctionDeclarationLikeForReturnType(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { + if (decl.type || !decl.body) { + return; + } + + const type = checker.getTypeAtLocation(decl); + const signatures = checker.getSignaturesOfType(type, SignatureKind.Call); + const signature = firstOrUndefined(signatures); + if (!signature) { + return; + } + + const returnType = checker.getReturnTypeOfSignature(signature); + const typeDisplayString = printTypeInSingleLine(returnType); + if (!typeDisplayString) { + return; + } + + addTypeHints(typeDisplayString, decl.body.pos); + } + + function visitFunctionExpressionLikeForParameterType(expr: ArrowFunction | FunctionExpression) { if (!expr.parameters.length || expr.parameters.every(param => param.type)) { return; } From df62a114b3c1a338cbacb80efece10ddfbf84960 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 30 Dec 2020 13:43:10 +0800 Subject: [PATCH 15/53] Add more options --- src/compiler/types.ts | 3 +++ src/services/inlineHints.ts | 17 ++++++++++++++--- src/services/types.ts | 6 ++++++ .../reference/api/tsserverlibrary.d.ts | 12 ++++++++++++ tests/baselines/reference/api/typescript.d.ts | 12 ++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a3fe5c29b2223..954902e428cf7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8246,8 +8246,11 @@ namespace ts { readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; readonly includeInlineParameterName?: boolean; + readonly includeInlineNonLiteralParameterName?: boolean; + readonly includeInlineDuplicatedParameterName?: boolean; readonly includeInlineFunctionParameterType?: boolean; readonly includeInlineVariableType?: boolean; + readonly includeInlineRequireAssignedVariableType?: boolean; readonly includeInlinePropertyDeclarationType?: boolean; readonly includeInlineFunctionLikeReturnType?: boolean; readonly includeInlineEnumMemberValue?: boolean; diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 7eebd1a33129f..d05c071474276 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -114,6 +114,10 @@ namespace ts.InlineHints { } const declarationType = checker.getTypeAtLocation(decl); + if (!preferences.includeInlineRequireAssignedVariableType || declarationType.symbol && (declarationType.symbol.flags & SymbolFlags.Module)) { + return; + } + const typeDisplayString = printTypeInSingleLine(declarationType); if (typeDisplayString) { addTypeHints(typeDisplayString, decl.name.end); @@ -132,17 +136,24 @@ namespace ts.InlineHints { } for (let i = 0; i < expr.arguments.length; ++i) { + const arg = expr.arguments[i]; + if (!preferences.includeInlineNonLiteralParameterName && !isHintableExpression(arg)) { + continue; + } + const parameterName = checker.getParameterIdentifierNameAtPosition(signature, i); if (parameterName) { - const arg = expr.arguments[i]; - const argumentName = isIdentifier(arg) ? arg.text : undefined; - if (!argumentName || argumentName !== parameterName) { + if (preferences.includeInlineDuplicatedParameterName || !isIdentifier(arg) || arg.text !== parameterName) { addNameHints(unescapeLeadingUnderscores(parameterName), expr.arguments[i].getStart()); } } } } + function isHintableExpression(node: Node) { + return isLiteralExpression(node) || isFunctionExpressionLike(node) || isObjectLiteralExpression(node) || isArrayLiteralExpression(node); + } + function visitFunctionDeclarationLikeForReturnType(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { if (decl.type || !decl.body) { return; diff --git a/src/services/types.ts b/src/services/types.ts index 86b09c9fa1b8c..f0968b63bf4be 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -566,8 +566,14 @@ namespace ts { export interface InlineHintsOptions extends UserPreferences { readonly includeInlineParameterName?: boolean; + readonly includeInlineNonLiteralParameterName?: boolean; + readonly includeDuplicatedParameterName?: boolean; readonly includeInlineFunctionParameterType?: boolean, readonly includeInlineVariableType?: boolean; + readonly includeInlineRequireAssignedVariableType?: boolean; + readonly includeInlinePropertyDeclarationType?: boolean; + readonly includeInlineFunctionLikeReturnType?: boolean; + readonly includeInlineEnumMemberValue?: boolean; } export type SignatureHelpTriggerCharacter = "," | "(" | "<"; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index f6ef11de94044..c03e0d3a5ab49 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3873,8 +3873,14 @@ declare namespace ts { readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; readonly includeInlineParameterName?: boolean; + readonly includeInlineNonLiteralParameterName?: boolean; + readonly includeInlineDuplicatedParameterName?: boolean; readonly includeInlineFunctionParameterType?: boolean; readonly includeInlineVariableType?: boolean; + readonly includeInlineRequireAssignedVariableType?: boolean; + readonly includeInlinePropertyDeclarationType?: boolean; + readonly includeInlineFunctionLikeReturnType?: boolean; + readonly includeInlineEnumMemberValue?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5608,8 +5614,14 @@ declare namespace ts { } interface InlineHintsOptions extends UserPreferences { readonly includeInlineParameterName?: boolean; + readonly includeInlineNonLiteralParameterName?: boolean; + readonly includeDuplicatedParameterName?: boolean; readonly includeInlineFunctionParameterType?: boolean; readonly includeInlineVariableType?: boolean; + readonly includeInlineRequireAssignedVariableType?: boolean; + readonly includeInlinePropertyDeclarationType?: boolean; + readonly includeInlineFunctionLikeReturnType?: boolean; + readonly includeInlineEnumMemberValue?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 48a3578fe79b5..9eafcdd715035 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3873,8 +3873,14 @@ declare namespace ts { readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; readonly includeInlineParameterName?: boolean; + readonly includeInlineNonLiteralParameterName?: boolean; + readonly includeInlineDuplicatedParameterName?: boolean; readonly includeInlineFunctionParameterType?: boolean; readonly includeInlineVariableType?: boolean; + readonly includeInlineRequireAssignedVariableType?: boolean; + readonly includeInlinePropertyDeclarationType?: boolean; + readonly includeInlineFunctionLikeReturnType?: boolean; + readonly includeInlineEnumMemberValue?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5608,8 +5614,14 @@ declare namespace ts { } interface InlineHintsOptions extends UserPreferences { readonly includeInlineParameterName?: boolean; + readonly includeInlineNonLiteralParameterName?: boolean; + readonly includeDuplicatedParameterName?: boolean; readonly includeInlineFunctionParameterType?: boolean; readonly includeInlineVariableType?: boolean; + readonly includeInlineRequireAssignedVariableType?: boolean; + readonly includeInlinePropertyDeclarationType?: boolean; + readonly includeInlineFunctionLikeReturnType?: boolean; + readonly includeInlineEnumMemberValue?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; From fce2619dfdb961f88849c0896df3ceb1e5633a8e Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 30 Dec 2020 13:51:27 +0800 Subject: [PATCH 16/53] Fix logical --- src/services/inlineHints.ts | 2 +- tests/cases/fourslash/fourslash.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index d05c071474276..77ebc895895e4 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -114,7 +114,7 @@ namespace ts.InlineHints { } const declarationType = checker.getTypeAtLocation(decl); - if (!preferences.includeInlineRequireAssignedVariableType || declarationType.symbol && (declarationType.symbol.flags & SymbolFlags.Module)) { + if (!preferences.includeInlineRequireAssignedVariableType && declarationType.symbol && (declarationType.symbol.flags & SymbolFlags.Module)) { return; } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index ce01cd46c15d2..1870f8c424829 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -620,8 +620,14 @@ declare namespace FourSlashInterface { } interface InlineHintsOptions extends UserPreferences { readonly includeInlineParameterName?: boolean; + readonly includeInlineNonLiteralParameterName?: boolean; + readonly includeInlineDuplicatedParameterName?: boolean; readonly includeInlineFunctionParameterType?: boolean; readonly includeInlineVariableType?: boolean; + readonly includeInlineRequireAssignedVariableType?: boolean; + readonly includeInlinePropertyDeclarationType?: boolean; + readonly includeInlineFunctionLikeReturnType?: boolean; + readonly includeInlineEnumMemberValue?: boolean; } interface CompletionsOptions { readonly marker?: ArrayOrSingle; From 679f0664d98b144a152124e7ce8fb40774259ee0 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 30 Dec 2020 14:28:11 +0800 Subject: [PATCH 17/53] Add more cases --- src/compiler/utilitiesPublic.ts | 5 ++++ src/services/inlineHints.ts | 12 ++++++-- .../fourslash/inlineHintsShouldWork13.ts | 4 ++- .../fourslash/inlineHintsShouldWork34.ts | 29 ++++++++++++++++++ .../fourslash/inlineHintsShouldWork35.ts | 29 ++++++++++++++++++ .../fourslash/inlineHintsShouldWork36.ts | 23 ++++++++++++++ .../fourslash/inlineHintsShouldWork37.ts | 18 +++++++++++ .../fourslash/inlineHintsShouldWork38.ts | 16 ++++++++++ .../fourslash/inlineHintsShouldWork39.ts | 10 +++++++ .../fourslash/inlineHintsShouldWork40.ts | 18 +++++++++++ .../fourslash/inlineHintsShouldWork41.ts | 14 +++++++++ .../fourslash/inlineHintsShouldWork42.ts | 14 +++++++++ .../fourslash/inlineHintsShouldWork43.ts | 14 +++++++++ .../fourslash/inlineHintsShouldWork44.ts | 30 +++++++++++++++++++ .../fourslash/inlineHintsShouldWork45.ts | 17 +++++++++++ .../fourslash/inlineHintsShouldWork46.ts | 23 ++++++++++++++ 16 files changed, 273 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/inlineHintsShouldWork34.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork35.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork36.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork37.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork38.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork39.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork40.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork41.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork42.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork43.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork44.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork45.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork46.ts diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 6722e7ad5be1f..37196df209a25 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1204,6 +1204,11 @@ namespace ts { return node && isFunctionLikeDeclarationKind(node.kind); } + /* @internal */ + export function isBooleanLiteral(node: Node): node is BooleanLiteral { + return node.kind === SyntaxKind.TrueKeyword || node.kind === SyntaxKind.FalseKeyword; + } + function isFunctionLikeDeclarationKind(kind: SyntaxKind): boolean { switch (kind) { case SyntaxKind.FunctionDeclaration: diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 77ebc895895e4..e69b3937f2351 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -151,7 +151,7 @@ namespace ts.InlineHints { } function isHintableExpression(node: Node) { - return isLiteralExpression(node) || isFunctionExpressionLike(node) || isObjectLiteralExpression(node) || isArrayLiteralExpression(node); + return isLiteralExpression(node) || isBooleanLiteral(node) || isFunctionExpressionLike(node) || isObjectLiteralExpression(node) || isArrayLiteralExpression(node); } function visitFunctionDeclarationLikeForReturnType(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { @@ -172,7 +172,15 @@ namespace ts.InlineHints { return; } - addTypeHints(typeDisplayString, decl.body.pos); + addTypeHints(typeDisplayString, getTypeAnnotationPosition(decl)); + } + + function getTypeAnnotationPosition(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { + const closeParenToken = findChildOfKind(decl, SyntaxKind.CloseParenToken, file); + if (closeParenToken) { + return closeParenToken.end; + } + return decl.parameters.end; } function visitFunctionExpressionLikeForParameterType(expr: ArrowFunction | FunctionExpression) { diff --git a/tests/cases/fourslash/inlineHintsShouldWork13.ts b/tests/cases/fourslash/inlineHintsShouldWork13.ts index e88e0ffb02e3b..5fbec443f7ad9 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork13.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork13.ts @@ -12,5 +12,7 @@ verify.getInlineHints([ whitespaceAfter: true }, ], undefined, { - includeInlineParameterName: true + includeInlineParameterName: true, + includeInlineNonLiteralParameterName: true, + includeInlineDuplicatedParameterName: false, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork34.ts b/tests/cases/fourslash/inlineHintsShouldWork34.ts new file mode 100644 index 0000000000000..50f6a60f2c099 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork34.ts @@ -0,0 +1,29 @@ +/// + +//// function foo (v: any) {} + +//// foo(/*a*/1); +//// foo(/*b*/''); +//// foo(/*c*/true); +//// foo(/*d*/() => 1); +//// foo(/*e*/function () { return 1 }); +//// foo(/*f*/{}); +//// foo(/*g*/{ a: 1 }); +//// foo(/*h*/[]); +//// foo(/*i*/[1]); + +//// foo(foo); +//// foo((1)); +//// foo(foo(/*j*/1)); + +const markers = test.markers(); + +verify.getInlineHints( + markers.map(m => ({ + text: 'v:', + position: m.position, + whitespaceAfter: true + })) , undefined, { + includeInlineParameterName: true, + includeInlineNonLiteralParameterName: false +}); \ No newline at end of file diff --git a/tests/cases/fourslash/inlineHintsShouldWork35.ts b/tests/cases/fourslash/inlineHintsShouldWork35.ts new file mode 100644 index 0000000000000..55cd02091e714 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork35.ts @@ -0,0 +1,29 @@ +/// + +//// function foo (v: any) {} + +//// foo(/*a*/1); +//// foo(/*b*/''); +//// foo(/*c*/true); +//// foo(/*d*/() => 1); +//// foo(/*e*/function () { return 1 }); +//// foo(/*f*/{}); +//// foo(/*g*/{ a: 1 }); +//// foo(/*h*/[]); +//// foo(/*i*/[1]); + +//// foo(/*j*/foo); +//// foo(/*k*/(1)); +//// foo(/*l*/foo(/*m*/1)); + +const markers = test.markers(); + +verify.getInlineHints( + markers.map(m => ({ + text: 'v:', + position: m.position, + whitespaceAfter: true + })) , undefined, { + includeInlineParameterName: true, + includeInlineNonLiteralParameterName: true +}); \ No newline at end of file diff --git a/tests/cases/fourslash/inlineHintsShouldWork36.ts b/tests/cases/fourslash/inlineHintsShouldWork36.ts new file mode 100644 index 0000000000000..e9fc035365664 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork36.ts @@ -0,0 +1,23 @@ +/// + +//// function foo (a: number, b: number) {} +//// declare const a: 1; +//// foo(/*a*/a, /*b*/2); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + }, +], undefined, { + includeInlineParameterName: true, + includeInlineNonLiteralParameterName: true, + includeInlineDuplicatedParameterName: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork37.ts b/tests/cases/fourslash/inlineHintsShouldWork37.ts new file mode 100644 index 0000000000000..7af7719f8d11f --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork37.ts @@ -0,0 +1,18 @@ +/// + +//// class C { +//// a/*a*/ = 1 +//// b: number = 2 +//// c; +//// } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':number', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlinePropertyDeclarationType: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork38.ts b/tests/cases/fourslash/inlineHintsShouldWork38.ts new file mode 100644 index 0000000000000..da325f19e30aa --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork38.ts @@ -0,0 +1,16 @@ +/// + +//// function foo ()/*a*/ { +//// return 1 +//// } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':number', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineFunctionLikeReturnType: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork39.ts b/tests/cases/fourslash/inlineHintsShouldWork39.ts new file mode 100644 index 0000000000000..38e82c0e02a20 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork39.ts @@ -0,0 +1,10 @@ +/// + +//// function foo (): number { +//// return 1 +//// } + +const markers = test.markers(); +verify.getInlineHints([], undefined, { + includeInlineFunctionLikeReturnType: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork40.ts b/tests/cases/fourslash/inlineHintsShouldWork40.ts new file mode 100644 index 0000000000000..6123a43da28a5 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork40.ts @@ -0,0 +1,18 @@ +/// + +//// class C { +//// foo()/*a*/ { +//// return 1 +//// } +//// } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':number', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineFunctionLikeReturnType: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork41.ts b/tests/cases/fourslash/inlineHintsShouldWork41.ts new file mode 100644 index 0000000000000..822b5d0a01787 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork41.ts @@ -0,0 +1,14 @@ +/// + +//// const a = ()/*a*/ => 1 + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':number', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineFunctionLikeReturnType: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork42.ts b/tests/cases/fourslash/inlineHintsShouldWork42.ts new file mode 100644 index 0000000000000..d920115d02f7e --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork42.ts @@ -0,0 +1,14 @@ +/// + +//// const a = function ()/*a*/ { return 1} + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':number', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineFunctionLikeReturnType: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork43.ts b/tests/cases/fourslash/inlineHintsShouldWork43.ts new file mode 100644 index 0000000000000..4840feb5a57d2 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork43.ts @@ -0,0 +1,14 @@ +/// + +//// const a = b/*a*/ => 1 + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':number', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineFunctionLikeReturnType: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork44.ts b/tests/cases/fourslash/inlineHintsShouldWork44.ts new file mode 100644 index 0000000000000..d406b9475021b --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork44.ts @@ -0,0 +1,30 @@ +/// + +//// enum E { +//// A/*a*/, +//// AA/*b*/, +//// B = 10, +//// BB/*c*/, +//// C = 'C', +//// } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: '= 0', + position: markers[0].position, + whitespaceBefore: true + }, + { + text: '= 1', + position: markers[1].position, + whitespaceBefore: true + }, + { + text: '= 11', + position: markers[2].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineEnumMemberValue: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork45.ts b/tests/cases/fourslash/inlineHintsShouldWork45.ts new file mode 100644 index 0000000000000..8e71ca2f8b0d5 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork45.ts @@ -0,0 +1,17 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: /a.js +//// module.exports.a = 1 + +// @Filename: /b.js +//// const a = require('./a'); + +goTo.file('/b.js') +const markers = test.markers(); +verify.getInlineHints([], undefined, { + includeInlineVariableType: true, + includeInlineRequireAssignedVariableType: false +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork46.ts b/tests/cases/fourslash/inlineHintsShouldWork46.ts new file mode 100644 index 0000000000000..e3c8553094f8c --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork46.ts @@ -0,0 +1,23 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: /a.js +//// module.exports.a = 1 + +// @Filename: /b.js +//// const a/*a*/ = require('./a'); + +goTo.file('/b.js') +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':typeof import("/a")', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineVariableType: true, + includeInlineRequireAssignedVariableType: true +}); From eb4b4ad2ba326593dd29be934e3e57ee1bea3bd3 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 30 Dec 2020 17:32:54 +0800 Subject: [PATCH 18/53] Support call chains --- src/compiler/types.ts | 1 + src/services/inlineHints.ts | 65 ++++++++++++++----- src/services/types.ts | 1 + .../reference/api/tsserverlibrary.d.ts | 2 + tests/baselines/reference/api/typescript.d.ts | 2 + tests/cases/fourslash/fourslash.ts | 1 + .../fourslash/inlineHintsShouldWork26.ts | 2 +- .../fourslash/inlineHintsShouldWork27.ts | 4 +- .../fourslash/inlineHintsShouldWork29.ts | 4 +- .../fourslash/inlineHintsShouldWork30.ts | 2 +- .../fourslash/inlineHintsShouldWork47.ts | 29 +++++++++ .../fourslash/inlineHintsShouldWork48.ts | 17 +++++ .../fourslash/inlineHintsShouldWork49.ts | 10 +++ .../fourslash/inlineHintsShouldWork50.ts | 29 +++++++++ .../fourslash/inlineHintsShouldWork51.ts | 9 +++ 15 files changed, 155 insertions(+), 23 deletions(-) create mode 100644 tests/cases/fourslash/inlineHintsShouldWork47.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork48.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork49.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork50.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork51.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 954902e428cf7..472428234e8e2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8254,6 +8254,7 @@ namespace ts { readonly includeInlinePropertyDeclarationType?: boolean; readonly includeInlineFunctionLikeReturnType?: boolean; readonly includeInlineEnumMemberValue?: boolean; + readonly includeInlineCallChains?: boolean; } /** Represents a bigint literal value without requiring bigint support */ diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index e69b3937f2351..1260e1ce3057e 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -14,9 +14,11 @@ namespace ts.InlineHints { const checker = program.getTypeChecker(); const result: HintInfo[] = []; + const callExpressionHintableCache = new Map(); visitor(file); return result; + function visitor(node: Node): true | undefined | void { if (!node || node.getFullWidth() === 0) { return; @@ -42,10 +44,7 @@ namespace ts.InlineHints { return; } - if (preferences.includeInlineParameterName && (isCallExpression(node) || isNewExpression(node))) { - visitCallOrNewExpression(node); - } - else if (preferences.includeInlineVariableType && (isVariableDeclaration(node))) { + if (preferences.includeInlineVariableType && (isVariableDeclaration(node))) { visitVariableLikeDeclaration(node); } else if (preferences.includeInlinePropertyDeclarationType && isPropertyDeclaration(node)) { @@ -54,11 +53,19 @@ namespace ts.InlineHints { else if (preferences.includeInlineEnumMemberValue && isEnumMember(node)) { visitEnumMember(node); } + else if (isCallExpression(node) || isNewExpression(node)) { + if (preferences.includeInlineParameterName) { + visitCallOrNewExpression(node); + } + if (preferences.includeInlineCallChains && isCallExpression(node)) { + visitCallChains(node); + } + } else { if (preferences.includeInlineFunctionParameterType && isFunctionExpressionLike(node)) { visitFunctionExpressionLikeForParameterType(node); } - if (preferences.includeInlineFunctionLikeReturnType &&isFunctionDeclarationLike(node)) { + if (preferences.includeInlineFunctionLikeReturnType && isFunctionDeclarationLike(node)) { visitFunctionDeclarationLikeForReturnType(node); } } @@ -97,6 +104,42 @@ namespace ts.InlineHints { }); } + function visitCallChains(call: CallExpression) { + if (!shouldCallExpressionHint(call)) { + return; + } + + const candidates: Signature[] = []; + const signature = checker.getResolvedSignature(call, candidates); + if (!signature || !candidates.length) { + return; + } + + const returnType = checker.getReturnTypeOfSignature(signature); + const typeDisplayString = printTypeInSingleLine(returnType); + if (!typeDisplayString) { + return; + } + + addTypeHints(typeDisplayString, call.end); + } + + function shouldCallExpressionHint(call: CallExpression) { + if (!callExpressionHintableCache.has(call)) { + let current = call; + while (true) { + if (!isAccessExpression(current.parent) || !isCallExpression(current.parent.parent)) { + callExpressionHintableCache.set(current, false); + break; + } + + callExpressionHintableCache.set(current, true); + current = current.parent.parent; + } + } + return callExpressionHintableCache.get(call); + } + function visitEnumMember(member: EnumMember) { if (member.initializer) { return; @@ -220,10 +263,6 @@ namespace ts.InlineHints { return undefined; } - if (valueDeclaration.type) { - return printNodeInSingleLine(valueDeclaration.type); - } - const signatureParamType = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration); return printTypeInSingleLine(signatureParamType); } @@ -254,14 +293,6 @@ namespace ts.InlineHints { return displayPartsToString(displayParts); } - function printNodeInSingleLine(node: Node) { - const displayParts = mapToDisplayParts(writer => { - const singleLineWriter = createSignleLineWriter(writer); - writeNodeInSignleLine(node, singleLineWriter); - }); - return displayPartsToString(displayParts); - } - function writeNodeInSignleLine(node: Node, writer: DisplayPartsSymbolWriter) { const options: PrinterOptions = { removeComments: true }; const printer = createPrinter(options); diff --git a/src/services/types.ts b/src/services/types.ts index f0968b63bf4be..7e91ac66f0009 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -574,6 +574,7 @@ namespace ts { readonly includeInlinePropertyDeclarationType?: boolean; readonly includeInlineFunctionLikeReturnType?: boolean; readonly includeInlineEnumMemberValue?: boolean; + readonly includeInlineCallChains?: boolean; } export type SignatureHelpTriggerCharacter = "," | "(" | "<"; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index c03e0d3a5ab49..1c97e9b6c3639 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3881,6 +3881,7 @@ declare namespace ts { readonly includeInlinePropertyDeclarationType?: boolean; readonly includeInlineFunctionLikeReturnType?: boolean; readonly includeInlineEnumMemberValue?: boolean; + readonly includeInlineCallChains?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5622,6 +5623,7 @@ declare namespace ts { readonly includeInlinePropertyDeclarationType?: boolean; readonly includeInlineFunctionLikeReturnType?: boolean; readonly includeInlineEnumMemberValue?: boolean; + readonly includeInlineCallChains?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 9eafcdd715035..7fb59916a0760 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3881,6 +3881,7 @@ declare namespace ts { readonly includeInlinePropertyDeclarationType?: boolean; readonly includeInlineFunctionLikeReturnType?: boolean; readonly includeInlineEnumMemberValue?: boolean; + readonly includeInlineCallChains?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5622,6 +5623,7 @@ declare namespace ts { readonly includeInlinePropertyDeclarationType?: boolean; readonly includeInlineFunctionLikeReturnType?: boolean; readonly includeInlineEnumMemberValue?: boolean; + readonly includeInlineCallChains?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 1870f8c424829..a0ef51b1d90b5 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -628,6 +628,7 @@ declare namespace FourSlashInterface { readonly includeInlinePropertyDeclarationType?: boolean; readonly includeInlineFunctionLikeReturnType?: boolean; readonly includeInlineEnumMemberValue?: boolean; + readonly includeInlineCallChains?: boolean; } interface CompletionsOptions { readonly marker?: ArrayOrSingle; diff --git a/tests/cases/fourslash/inlineHintsShouldWork26.ts b/tests/cases/fourslash/inlineHintsShouldWork26.ts index 5165e0462c89a..7fffbef59a834 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork26.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork26.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { - text: ':Exclude<1 | 2 | 3, 1>', + text: ':2 | 3', position: markers[0].position, whitespaceBefore: true } diff --git a/tests/cases/fourslash/inlineHintsShouldWork27.ts b/tests/cases/fourslash/inlineHintsShouldWork27.ts index e637fd55b7a0d..f40109414f358 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork27.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork27.ts @@ -8,12 +8,12 @@ const markers = test.markers(); verify.getInlineHints([ { - text: ':(c: (d: Exclude<1 | 2 | 3, ...', + text: ':(c: (d: 2 | 3) => void) => ...', position: markers[0].position, whitespaceBefore: true }, { - text: ':Exclude<1 | 2 | 3, 1>', + text: ':2 | 3', position: markers[1].position, whitespaceBefore: true } diff --git a/tests/cases/fourslash/inlineHintsShouldWork29.ts b/tests/cases/fourslash/inlineHintsShouldWork29.ts index 12d0f7d44cad5..8d2f2c0dc508a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork29.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork29.ts @@ -13,7 +13,7 @@ verify.getInlineHints([ whitespaceAfter: true }, { - text: ':(c: (d: Exclude<1 | 2 | 3, ...', + text: ':(c: (d: 2 | 3) => void) => ...', position: markers[1].position, whitespaceBefore: true }, @@ -23,7 +23,7 @@ verify.getInlineHints([ whitespaceAfter: true }, { - text: ':Exclude<1 | 2 | 3, 1>', + text: ':2 | 3', position: markers[3].position, whitespaceBefore: true } diff --git a/tests/cases/fourslash/inlineHintsShouldWork30.ts b/tests/cases/fourslash/inlineHintsShouldWork30.ts index 1d8af95a9e687..46e06521cf42d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork30.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork30.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { - text: ':T', + text: ':number', position: markers[0].position, whitespaceBefore: true } diff --git a/tests/cases/fourslash/inlineHintsShouldWork47.ts b/tests/cases/fourslash/inlineHintsShouldWork47.ts new file mode 100644 index 0000000000000..6c3cd46d3692b --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork47.ts @@ -0,0 +1,29 @@ +/// + +//// const z = [1, 2, 3]; +//// z +//// .map(function (e) { return String(e) })/*a*/ +//// .map(function (e) { return Number(e) })/*b*/ +//// .map(function (e) { return String(e) })/*c*/ +//// .map(function (e) { return Number(e) }); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':string[]', + position: markers[0].position, + whitespaceBefore: true + }, + { + text: ':number[]', + position: markers[1].position, + whitespaceBefore: true + }, + { + text: ':string[]', + position: markers[2].position, + whitespaceBefore: true + } +], undefined, { + includeInlineCallChains: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork48.ts b/tests/cases/fourslash/inlineHintsShouldWork48.ts new file mode 100644 index 0000000000000..2d476f5ebb768 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork48.ts @@ -0,0 +1,17 @@ +/// + +//// const z = [1, 2, 3]; +//// z +//// .map(function (e) { return String(e) })/*a*/ +//// .map(function (e) { return Number(e) }); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':string[]', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineCallChains: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork49.ts b/tests/cases/fourslash/inlineHintsShouldWork49.ts new file mode 100644 index 0000000000000..d5f795028809d --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork49.ts @@ -0,0 +1,10 @@ +/// + +//// const z = [1, 2, 3]; +//// z +//// .map(function (e) { return Number(e) }); + +const markers = test.markers(); +verify.getInlineHints([], undefined, { + includeInlineCallChains: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork50.ts b/tests/cases/fourslash/inlineHintsShouldWork50.ts new file mode 100644 index 0000000000000..95ef3d1734b00 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork50.ts @@ -0,0 +1,29 @@ +/// + +//// const z = [1, 2, 3]; +//// z +//// .map(function (e) { return String(e) })/*a*/ +//// ["map"](function (e) { return Number(e) })/*b*/ +//// .map(function (e) { return String(e) })/*c*/ +//// ["map"](function (e) { return Number(e) }); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':string[]', + position: markers[0].position, + whitespaceBefore: true + }, + { + text: ':number[]', + position: markers[1].position, + whitespaceBefore: true + }, + { + text: ':string[]', + position: markers[2].position, + whitespaceBefore: true + } +], undefined, { + includeInlineCallChains: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork51.ts b/tests/cases/fourslash/inlineHintsShouldWork51.ts new file mode 100644 index 0000000000000..ad4b1949aaae4 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork51.ts @@ -0,0 +1,9 @@ +/// + +//// const z = [1, 2, 3]; +//// (z.map(function (e) { return String(e) })).map(function (e) { return Number(e) }); + +const markers = test.markers(); +verify.getInlineHints([], undefined, { + includeInlineCallChains: true, +}); From 9297051de5f70e4a10a03e1bc6439232013f8bc7 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 30 Dec 2020 17:42:07 +0800 Subject: [PATCH 19/53] Rename options --- src/compiler/types.ts | 20 +++++----- src/services/inlineHints.ts | 20 +++++----- src/services/types.ts | 20 +++++----- .../reference/api/tsserverlibrary.d.ts | 40 +++++++++---------- tests/baselines/reference/api/typescript.d.ts | 40 +++++++++---------- tests/cases/fourslash/fourslash.ts | 20 +++++----- .../cases/fourslash/inlineHintsShouldWork1.ts | 2 +- .../fourslash/inlineHintsShouldWork10.ts | 2 +- .../fourslash/inlineHintsShouldWork11.ts | 2 +- .../fourslash/inlineHintsShouldWork12.ts | 2 +- .../fourslash/inlineHintsShouldWork13.ts | 6 +-- .../fourslash/inlineHintsShouldWork14.ts | 2 +- .../fourslash/inlineHintsShouldWork15.ts | 2 +- .../fourslash/inlineHintsShouldWork16.ts | 2 +- .../fourslash/inlineHintsShouldWork17.ts | 2 +- .../fourslash/inlineHintsShouldWork18.ts | 2 +- .../fourslash/inlineHintsShouldWork19.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork2.ts | 2 +- .../fourslash/inlineHintsShouldWork20.ts | 2 +- .../fourslash/inlineHintsShouldWork21.ts | 2 +- .../fourslash/inlineHintsShouldWork22.ts | 2 +- .../fourslash/inlineHintsShouldWork23.ts | 2 +- .../fourslash/inlineHintsShouldWork24.ts | 2 +- .../fourslash/inlineHintsShouldWork25.ts | 2 +- .../fourslash/inlineHintsShouldWork26.ts | 2 +- .../fourslash/inlineHintsShouldWork27.ts | 2 +- .../fourslash/inlineHintsShouldWork28.ts | 2 +- .../fourslash/inlineHintsShouldWork29.ts | 4 +- .../cases/fourslash/inlineHintsShouldWork3.ts | 2 +- .../fourslash/inlineHintsShouldWork30.ts | 2 +- .../fourslash/inlineHintsShouldWork31.ts | 2 +- .../fourslash/inlineHintsShouldWork32.ts | 2 +- .../fourslash/inlineHintsShouldWork33.ts | 2 +- .../fourslash/inlineHintsShouldWork34.ts | 4 +- .../fourslash/inlineHintsShouldWork35.ts | 4 +- .../fourslash/inlineHintsShouldWork36.ts | 6 +-- .../fourslash/inlineHintsShouldWork37.ts | 2 +- .../fourslash/inlineHintsShouldWork38.ts | 2 +- .../fourslash/inlineHintsShouldWork39.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork4.ts | 2 +- .../fourslash/inlineHintsShouldWork40.ts | 2 +- .../fourslash/inlineHintsShouldWork41.ts | 2 +- .../fourslash/inlineHintsShouldWork42.ts | 2 +- .../fourslash/inlineHintsShouldWork43.ts | 2 +- .../fourslash/inlineHintsShouldWork44.ts | 2 +- .../fourslash/inlineHintsShouldWork45.ts | 4 +- .../fourslash/inlineHintsShouldWork46.ts | 4 +- .../fourslash/inlineHintsShouldWork47.ts | 2 +- .../fourslash/inlineHintsShouldWork48.ts | 2 +- .../fourslash/inlineHintsShouldWork49.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork5.ts | 2 +- .../fourslash/inlineHintsShouldWork50.ts | 2 +- .../fourslash/inlineHintsShouldWork51.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork6.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork7.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork8.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork9.ts | 2 +- 57 files changed, 140 insertions(+), 140 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 472428234e8e2..18c45b8c53ff1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8245,16 +8245,16 @@ namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlineParameterName?: boolean; - readonly includeInlineNonLiteralParameterName?: boolean; - readonly includeInlineDuplicatedParameterName?: boolean; - readonly includeInlineFunctionParameterType?: boolean; - readonly includeInlineVariableType?: boolean; - readonly includeInlineRequireAssignedVariableType?: boolean; - readonly includeInlinePropertyDeclarationType?: boolean; - readonly includeInlineFunctionLikeReturnType?: boolean; - readonly includeInlineEnumMemberValue?: boolean; - readonly includeInlineCallChains?: boolean; + readonly includeInlineParameterNameHints?: boolean; + readonly includeInlineNonLiteralParameterNameHints?: boolean; + readonly includeInlineDuplicatedParameterNameHints?: boolean; + readonly includeInlineFunctionParameterTypeHints?: boolean; + readonly includeInlineVariableTypeHints?: boolean; + readonly includeInlineRequireAssignedVariableTypeHints?: boolean; + readonly includeInlinePropertyDeclarationTypeHints?: boolean; + readonly includeInlineFunctionLikeReturnTypeHints?: boolean; + readonly includeInlineEnumMemberValueHints?: boolean; + readonly includeInlineCallChainsHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 1260e1ce3057e..e43b0860aa0c8 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -44,28 +44,28 @@ namespace ts.InlineHints { return; } - if (preferences.includeInlineVariableType && (isVariableDeclaration(node))) { + if (preferences.includeInlineVariableTypeHints && (isVariableDeclaration(node))) { visitVariableLikeDeclaration(node); } - else if (preferences.includeInlinePropertyDeclarationType && isPropertyDeclaration(node)) { + else if (preferences.includeInlinePropertyDeclarationTypeHints && isPropertyDeclaration(node)) { visitVariableLikeDeclaration(node); } - else if (preferences.includeInlineEnumMemberValue && isEnumMember(node)) { + else if (preferences.includeInlineEnumMemberValueHints && isEnumMember(node)) { visitEnumMember(node); } else if (isCallExpression(node) || isNewExpression(node)) { - if (preferences.includeInlineParameterName) { + if (preferences.includeInlineParameterNameHints) { visitCallOrNewExpression(node); } - if (preferences.includeInlineCallChains && isCallExpression(node)) { + if (preferences.includeInlineCallChainsHints && isCallExpression(node)) { visitCallChains(node); } } else { - if (preferences.includeInlineFunctionParameterType && isFunctionExpressionLike(node)) { + if (preferences.includeInlineFunctionParameterTypeHints && isFunctionExpressionLike(node)) { visitFunctionExpressionLikeForParameterType(node); } - if (preferences.includeInlineFunctionLikeReturnType && isFunctionDeclarationLike(node)) { + if (preferences.includeInlineFunctionLikeReturnTypeHints && isFunctionDeclarationLike(node)) { visitFunctionDeclarationLikeForReturnType(node); } } @@ -157,7 +157,7 @@ namespace ts.InlineHints { } const declarationType = checker.getTypeAtLocation(decl); - if (!preferences.includeInlineRequireAssignedVariableType && declarationType.symbol && (declarationType.symbol.flags & SymbolFlags.Module)) { + if (!preferences.includeInlineRequireAssignedVariableTypeHints && declarationType.symbol && (declarationType.symbol.flags & SymbolFlags.Module)) { return; } @@ -180,13 +180,13 @@ namespace ts.InlineHints { for (let i = 0; i < expr.arguments.length; ++i) { const arg = expr.arguments[i]; - if (!preferences.includeInlineNonLiteralParameterName && !isHintableExpression(arg)) { + if (!preferences.includeInlineNonLiteralParameterNameHints && !isHintableExpression(arg)) { continue; } const parameterName = checker.getParameterIdentifierNameAtPosition(signature, i); if (parameterName) { - if (preferences.includeInlineDuplicatedParameterName || !isIdentifier(arg) || arg.text !== parameterName) { + if (preferences.includeInlineDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { addNameHints(unescapeLeadingUnderscores(parameterName), expr.arguments[i].getStart()); } } diff --git a/src/services/types.ts b/src/services/types.ts index 7e91ac66f0009..e2d9e6cc29346 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -565,16 +565,16 @@ namespace ts { } export interface InlineHintsOptions extends UserPreferences { - readonly includeInlineParameterName?: boolean; - readonly includeInlineNonLiteralParameterName?: boolean; - readonly includeDuplicatedParameterName?: boolean; - readonly includeInlineFunctionParameterType?: boolean, - readonly includeInlineVariableType?: boolean; - readonly includeInlineRequireAssignedVariableType?: boolean; - readonly includeInlinePropertyDeclarationType?: boolean; - readonly includeInlineFunctionLikeReturnType?: boolean; - readonly includeInlineEnumMemberValue?: boolean; - readonly includeInlineCallChains?: boolean; + readonly includeInlineParameterNameHints?: boolean; + readonly includeInlineNonLiteralParameterNameHints?: boolean; + readonly includeDuplicatedParameterNameHints?: boolean; + readonly includeInlineFunctionParameterTypeHints?: boolean, + readonly includeInlineVariableTypeHints?: boolean; + readonly includeInlineRequireAssignedVariableTypeHints?: boolean; + readonly includeInlinePropertyDeclarationTypeHints?: boolean; + readonly includeInlineFunctionLikeReturnTypeHints?: boolean; + readonly includeInlineEnumMemberValueHints?: boolean; + readonly includeInlineCallChainsHints?: boolean; } export type SignatureHelpTriggerCharacter = "," | "(" | "<"; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 1c97e9b6c3639..25f5b7f6bc83d 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3872,16 +3872,16 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlineParameterName?: boolean; - readonly includeInlineNonLiteralParameterName?: boolean; - readonly includeInlineDuplicatedParameterName?: boolean; - readonly includeInlineFunctionParameterType?: boolean; - readonly includeInlineVariableType?: boolean; - readonly includeInlineRequireAssignedVariableType?: boolean; - readonly includeInlinePropertyDeclarationType?: boolean; - readonly includeInlineFunctionLikeReturnType?: boolean; - readonly includeInlineEnumMemberValue?: boolean; - readonly includeInlineCallChains?: boolean; + readonly includeInlineParameterNameHints?: boolean; + readonly includeInlineNonLiteralParameterNameHints?: boolean; + readonly includeInlineDuplicatedParameterNameHints?: boolean; + readonly includeInlineFunctionParameterTypeHints?: boolean; + readonly includeInlineVariableTypeHints?: boolean; + readonly includeInlineRequireAssignedVariableTypeHints?: boolean; + readonly includeInlinePropertyDeclarationTypeHints?: boolean; + readonly includeInlineFunctionLikeReturnTypeHints?: boolean; + readonly includeInlineEnumMemberValueHints?: boolean; + readonly includeInlineCallChainsHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5614,16 +5614,16 @@ declare namespace ts { includeInsertTextCompletions?: boolean; } interface InlineHintsOptions extends UserPreferences { - readonly includeInlineParameterName?: boolean; - readonly includeInlineNonLiteralParameterName?: boolean; - readonly includeDuplicatedParameterName?: boolean; - readonly includeInlineFunctionParameterType?: boolean; - readonly includeInlineVariableType?: boolean; - readonly includeInlineRequireAssignedVariableType?: boolean; - readonly includeInlinePropertyDeclarationType?: boolean; - readonly includeInlineFunctionLikeReturnType?: boolean; - readonly includeInlineEnumMemberValue?: boolean; - readonly includeInlineCallChains?: boolean; + readonly includeInlineParameterNameHints?: boolean; + readonly includeInlineNonLiteralParameterNameHints?: boolean; + readonly includeDuplicatedParameterNameHints?: boolean; + readonly includeInlineFunctionParameterTypeHints?: boolean; + readonly includeInlineVariableTypeHints?: boolean; + readonly includeInlineRequireAssignedVariableTypeHints?: boolean; + readonly includeInlinePropertyDeclarationTypeHints?: boolean; + readonly includeInlineFunctionLikeReturnTypeHints?: boolean; + readonly includeInlineEnumMemberValueHints?: boolean; + readonly includeInlineCallChainsHints?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 7fb59916a0760..8a052714e4c8d 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3872,16 +3872,16 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlineParameterName?: boolean; - readonly includeInlineNonLiteralParameterName?: boolean; - readonly includeInlineDuplicatedParameterName?: boolean; - readonly includeInlineFunctionParameterType?: boolean; - readonly includeInlineVariableType?: boolean; - readonly includeInlineRequireAssignedVariableType?: boolean; - readonly includeInlinePropertyDeclarationType?: boolean; - readonly includeInlineFunctionLikeReturnType?: boolean; - readonly includeInlineEnumMemberValue?: boolean; - readonly includeInlineCallChains?: boolean; + readonly includeInlineParameterNameHints?: boolean; + readonly includeInlineNonLiteralParameterNameHints?: boolean; + readonly includeInlineDuplicatedParameterNameHints?: boolean; + readonly includeInlineFunctionParameterTypeHints?: boolean; + readonly includeInlineVariableTypeHints?: boolean; + readonly includeInlineRequireAssignedVariableTypeHints?: boolean; + readonly includeInlinePropertyDeclarationTypeHints?: boolean; + readonly includeInlineFunctionLikeReturnTypeHints?: boolean; + readonly includeInlineEnumMemberValueHints?: boolean; + readonly includeInlineCallChainsHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5614,16 +5614,16 @@ declare namespace ts { includeInsertTextCompletions?: boolean; } interface InlineHintsOptions extends UserPreferences { - readonly includeInlineParameterName?: boolean; - readonly includeInlineNonLiteralParameterName?: boolean; - readonly includeDuplicatedParameterName?: boolean; - readonly includeInlineFunctionParameterType?: boolean; - readonly includeInlineVariableType?: boolean; - readonly includeInlineRequireAssignedVariableType?: boolean; - readonly includeInlinePropertyDeclarationType?: boolean; - readonly includeInlineFunctionLikeReturnType?: boolean; - readonly includeInlineEnumMemberValue?: boolean; - readonly includeInlineCallChains?: boolean; + readonly includeInlineParameterNameHints?: boolean; + readonly includeInlineNonLiteralParameterNameHints?: boolean; + readonly includeDuplicatedParameterNameHints?: boolean; + readonly includeInlineFunctionParameterTypeHints?: boolean; + readonly includeInlineVariableTypeHints?: boolean; + readonly includeInlineRequireAssignedVariableTypeHints?: boolean; + readonly includeInlinePropertyDeclarationTypeHints?: boolean; + readonly includeInlineFunctionLikeReturnTypeHints?: boolean; + readonly includeInlineEnumMemberValueHints?: boolean; + readonly includeInlineCallChainsHints?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index a0ef51b1d90b5..7c498718578b4 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -619,16 +619,16 @@ declare namespace FourSlashInterface { readonly importModuleSpecifierEnding?: "minimal" | "index" | "js"; } interface InlineHintsOptions extends UserPreferences { - readonly includeInlineParameterName?: boolean; - readonly includeInlineNonLiteralParameterName?: boolean; - readonly includeInlineDuplicatedParameterName?: boolean; - readonly includeInlineFunctionParameterType?: boolean; - readonly includeInlineVariableType?: boolean; - readonly includeInlineRequireAssignedVariableType?: boolean; - readonly includeInlinePropertyDeclarationType?: boolean; - readonly includeInlineFunctionLikeReturnType?: boolean; - readonly includeInlineEnumMemberValue?: boolean; - readonly includeInlineCallChains?: boolean; + readonly includeInlineParameterNameHints?: boolean; + readonly includeInlineNonLiteralParameterNameHints?: boolean; + readonly includeInlineDuplicatedParameterNameHints?: boolean; + readonly includeInlineFunctionParameterTypeHints?: boolean; + readonly includeInlineVariableTypeHints?: boolean; + readonly includeInlineRequireAssignedVariableTypeHints?: boolean; + readonly includeInlinePropertyDeclarationTypeHints?: boolean; + readonly includeInlineFunctionLikeReturnTypeHints?: boolean; + readonly includeInlineEnumMemberValueHints?: boolean; + readonly includeInlineCallChainsHints?: boolean; } interface CompletionsOptions { readonly marker?: ArrayOrSingle; diff --git a/tests/cases/fourslash/inlineHintsShouldWork1.ts b/tests/cases/fourslash/inlineHintsShouldWork1.ts index 2a4fd5e60b85b..66d2a7e69b68b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork1.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork1.ts @@ -16,5 +16,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork10.ts b/tests/cases/fourslash/inlineHintsShouldWork10.ts index 5cbe1a8309604..ab14cd75f6dfc 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork10.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork10.ts @@ -5,5 +5,5 @@ const markers = test.markers(); verify.getInlineHints([], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork11.ts b/tests/cases/fourslash/inlineHintsShouldWork11.ts index f8af60f41d19a..4ed8fe9a06a63 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork11.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork11.ts @@ -20,5 +20,5 @@ verify.getInlineHints([ whitespaceAfter: true }, ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork12.ts b/tests/cases/fourslash/inlineHintsShouldWork12.ts index 2ad65c3e1a7b1..62974f32b073d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork12.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork12.ts @@ -19,5 +19,5 @@ verify.getInlineHints([ whitespaceAfter: true }, ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork13.ts b/tests/cases/fourslash/inlineHintsShouldWork13.ts index 5fbec443f7ad9..5d83e2132cf9e 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork13.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork13.ts @@ -12,7 +12,7 @@ verify.getInlineHints([ whitespaceAfter: true }, ], undefined, { - includeInlineParameterName: true, - includeInlineNonLiteralParameterName: true, - includeInlineDuplicatedParameterName: false, + includeInlineParameterNameHints: true, + includeInlineNonLiteralParameterNameHints: true, + includeInlineDuplicatedParameterNameHints: false, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork14.ts b/tests/cases/fourslash/inlineHintsShouldWork14.ts index 4181305b842a7..9bdba9c34adcd 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork14.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork14.ts @@ -4,5 +4,5 @@ //// foo(1, 2); verify.getInlineHints([], undefined, { - includeInlineParameterName: false + includeInlineParameterNameHints: false }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork15.ts b/tests/cases/fourslash/inlineHintsShouldWork15.ts index 5668f2eaec8ac..07f375cdca1e4 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork15.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork15.ts @@ -10,5 +10,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineVariableType: true + includeInlineVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork16.ts b/tests/cases/fourslash/inlineHintsShouldWork16.ts index 5668f2eaec8ac..07f375cdca1e4 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork16.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork16.ts @@ -10,5 +10,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineVariableType: true + includeInlineVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork17.ts b/tests/cases/fourslash/inlineHintsShouldWork17.ts index 32dfbf4b66363..d10572670e3a7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork17.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork17.ts @@ -10,5 +10,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineVariableType: true + includeInlineVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork18.ts b/tests/cases/fourslash/inlineHintsShouldWork18.ts index dfec616b21c40..8143b2ce13a40 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork18.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork18.ts @@ -11,5 +11,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineVariableType: true + includeInlineVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork19.ts b/tests/cases/fourslash/inlineHintsShouldWork19.ts index e7ebbc99f84e1..3189652d94c69 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork19.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork19.ts @@ -10,5 +10,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineVariableType: true + includeInlineVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork2.ts b/tests/cases/fourslash/inlineHintsShouldWork2.ts index 3f52c17e0153b..aa1ffb330c3f2 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork2.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork2.ts @@ -11,5 +11,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork20.ts b/tests/cases/fourslash/inlineHintsShouldWork20.ts index db6719bfbfcdb..60d852591aefb 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork20.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork20.ts @@ -3,5 +3,5 @@ //// const a = 123; verify.getInlineHints([], undefined, { - includeInlineVariableType: false + includeInlineVariableTypeHints: false }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork21.ts b/tests/cases/fourslash/inlineHintsShouldWork21.ts index 15b92c2096ac3..54e024f674d37 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork21.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork21.ts @@ -3,5 +3,5 @@ //// const a; verify.getInlineHints([], undefined, { - includeInlineVariableType: true + includeInlineVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork22.ts b/tests/cases/fourslash/inlineHintsShouldWork22.ts index 4b26abd6c202d..306b8b8f326cf 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork22.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork22.ts @@ -10,5 +10,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineVariableType: true + includeInlineVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork23.ts b/tests/cases/fourslash/inlineHintsShouldWork23.ts index 7a9536da8d8bf..0edd3049ea65a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork23.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork23.ts @@ -11,5 +11,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork24.ts b/tests/cases/fourslash/inlineHintsShouldWork24.ts index 527b5b17c28ee..97b0840b035fd 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork24.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork24.ts @@ -16,5 +16,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterType: true + includeInlineFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork25.ts b/tests/cases/fourslash/inlineHintsShouldWork25.ts index a75947f8e6eae..962b2fd16c705 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork25.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork25.ts @@ -11,5 +11,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterType: true + includeInlineFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork26.ts b/tests/cases/fourslash/inlineHintsShouldWork26.ts index 7fffbef59a834..2234a44e4060e 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork26.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork26.ts @@ -11,5 +11,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterType: true + includeInlineFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork27.ts b/tests/cases/fourslash/inlineHintsShouldWork27.ts index f40109414f358..57175ca61b00f 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork27.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork27.ts @@ -18,5 +18,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterType: true + includeInlineFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork28.ts b/tests/cases/fourslash/inlineHintsShouldWork28.ts index b04c846cd49c4..3d726d5b1fe2f 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork28.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork28.ts @@ -11,5 +11,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterType: true + includeInlineFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork29.ts b/tests/cases/fourslash/inlineHintsShouldWork29.ts index 8d2f2c0dc508a..dd34ff7d734f1 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork29.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork29.ts @@ -28,6 +28,6 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineParameterName: true, - includeInlineFunctionParameterType: true + includeInlineParameterNameHints: true, + includeInlineFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork3.ts b/tests/cases/fourslash/inlineHintsShouldWork3.ts index 4efe2728d1b13..a307aa7823be1 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork3.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork3.ts @@ -16,5 +16,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork30.ts b/tests/cases/fourslash/inlineHintsShouldWork30.ts index 46e06521cf42d..150bb12dbb3c5 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork30.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork30.ts @@ -11,5 +11,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterType: true + includeInlineFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork31.ts b/tests/cases/fourslash/inlineHintsShouldWork31.ts index 9f015881eb216..4802566490860 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork31.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork31.ts @@ -14,5 +14,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterType: true + includeInlineFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork32.ts b/tests/cases/fourslash/inlineHintsShouldWork32.ts index aca7d443714ed..ad573bf4fa7a2 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork32.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork32.ts @@ -26,5 +26,5 @@ verify.getInlineHints( whitespaceAfter: true } }), span, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }) diff --git a/tests/cases/fourslash/inlineHintsShouldWork33.ts b/tests/cases/fourslash/inlineHintsShouldWork33.ts index 64fdbc4208794..6ac70ec39c936 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork33.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork33.ts @@ -26,5 +26,5 @@ verify.getInlineHints( whitespaceAfter: true } }), span, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); \ No newline at end of file diff --git a/tests/cases/fourslash/inlineHintsShouldWork34.ts b/tests/cases/fourslash/inlineHintsShouldWork34.ts index 50f6a60f2c099..78b3a9b7505a8 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork34.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork34.ts @@ -24,6 +24,6 @@ verify.getInlineHints( position: m.position, whitespaceAfter: true })) , undefined, { - includeInlineParameterName: true, - includeInlineNonLiteralParameterName: false + includeInlineParameterNameHints: true, + includeInlineNonLiteralParameterNameHints: false }); \ No newline at end of file diff --git a/tests/cases/fourslash/inlineHintsShouldWork35.ts b/tests/cases/fourslash/inlineHintsShouldWork35.ts index 55cd02091e714..a5c57ec4fde4a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork35.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork35.ts @@ -24,6 +24,6 @@ verify.getInlineHints( position: m.position, whitespaceAfter: true })) , undefined, { - includeInlineParameterName: true, - includeInlineNonLiteralParameterName: true + includeInlineParameterNameHints: true, + includeInlineNonLiteralParameterNameHints: true }); \ No newline at end of file diff --git a/tests/cases/fourslash/inlineHintsShouldWork36.ts b/tests/cases/fourslash/inlineHintsShouldWork36.ts index e9fc035365664..b6b367e72551a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork36.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork36.ts @@ -17,7 +17,7 @@ verify.getInlineHints([ whitespaceAfter: true }, ], undefined, { - includeInlineParameterName: true, - includeInlineNonLiteralParameterName: true, - includeInlineDuplicatedParameterName: true, + includeInlineParameterNameHints: true, + includeInlineNonLiteralParameterNameHints: true, + includeInlineDuplicatedParameterNameHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork37.ts b/tests/cases/fourslash/inlineHintsShouldWork37.ts index 7af7719f8d11f..c22208099d75b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork37.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork37.ts @@ -14,5 +14,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlinePropertyDeclarationType: true, + includeInlinePropertyDeclarationTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork38.ts b/tests/cases/fourslash/inlineHintsShouldWork38.ts index da325f19e30aa..ad42630a90c32 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork38.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork38.ts @@ -12,5 +12,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnType: true, + includeInlineFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork39.ts b/tests/cases/fourslash/inlineHintsShouldWork39.ts index 38e82c0e02a20..967cf1cd85b17 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork39.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork39.ts @@ -6,5 +6,5 @@ const markers = test.markers(); verify.getInlineHints([], undefined, { - includeInlineFunctionLikeReturnType: true, + includeInlineFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork4.ts b/tests/cases/fourslash/inlineHintsShouldWork4.ts index 1686b08d6e8d3..b7fb591376594 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork4.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork4.ts @@ -25,5 +25,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork40.ts b/tests/cases/fourslash/inlineHintsShouldWork40.ts index 6123a43da28a5..d5a048ff598b7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork40.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork40.ts @@ -14,5 +14,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnType: true, + includeInlineFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork41.ts b/tests/cases/fourslash/inlineHintsShouldWork41.ts index 822b5d0a01787..3346734e6b684 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork41.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork41.ts @@ -10,5 +10,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnType: true, + includeInlineFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork42.ts b/tests/cases/fourslash/inlineHintsShouldWork42.ts index d920115d02f7e..9e93cb642317f 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork42.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork42.ts @@ -10,5 +10,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnType: true, + includeInlineFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork43.ts b/tests/cases/fourslash/inlineHintsShouldWork43.ts index 4840feb5a57d2..6d7a205056dbc 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork43.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork43.ts @@ -10,5 +10,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnType: true, + includeInlineFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork44.ts b/tests/cases/fourslash/inlineHintsShouldWork44.ts index d406b9475021b..96f69702e93e1 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork44.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork44.ts @@ -26,5 +26,5 @@ verify.getInlineHints([ whitespaceBefore: true }, ], undefined, { - includeInlineEnumMemberValue: true, + includeInlineEnumMemberValueHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork45.ts b/tests/cases/fourslash/inlineHintsShouldWork45.ts index 8e71ca2f8b0d5..319e73061c337 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork45.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork45.ts @@ -12,6 +12,6 @@ goTo.file('/b.js') const markers = test.markers(); verify.getInlineHints([], undefined, { - includeInlineVariableType: true, - includeInlineRequireAssignedVariableType: false + includeInlineVariableTypeHints: true, + includeInlineRequireAssignedVariableTypeHints: false }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork46.ts b/tests/cases/fourslash/inlineHintsShouldWork46.ts index e3c8553094f8c..3dbff093f5f6a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork46.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork46.ts @@ -18,6 +18,6 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineVariableType: true, - includeInlineRequireAssignedVariableType: true + includeInlineVariableTypeHints: true, + includeInlineRequireAssignedVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork47.ts b/tests/cases/fourslash/inlineHintsShouldWork47.ts index 6c3cd46d3692b..405b132a35d27 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork47.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork47.ts @@ -25,5 +25,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineCallChains: true, + includeInlineCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork48.ts b/tests/cases/fourslash/inlineHintsShouldWork48.ts index 2d476f5ebb768..f53b9d346f05d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork48.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork48.ts @@ -13,5 +13,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineCallChains: true, + includeInlineCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork49.ts b/tests/cases/fourslash/inlineHintsShouldWork49.ts index d5f795028809d..1a12fd9d62f4a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork49.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork49.ts @@ -6,5 +6,5 @@ const markers = test.markers(); verify.getInlineHints([], undefined, { - includeInlineCallChains: true, + includeInlineCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork5.ts b/tests/cases/fourslash/inlineHintsShouldWork5.ts index 9d4582b541040..5186ccfd33844 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork5.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork5.ts @@ -22,5 +22,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork50.ts b/tests/cases/fourslash/inlineHintsShouldWork50.ts index 95ef3d1734b00..f237a65d245e3 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork50.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork50.ts @@ -25,5 +25,5 @@ verify.getInlineHints([ whitespaceBefore: true } ], undefined, { - includeInlineCallChains: true, + includeInlineCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork51.ts b/tests/cases/fourslash/inlineHintsShouldWork51.ts index ad4b1949aaae4..c5d2bbd21a00f 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork51.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork51.ts @@ -5,5 +5,5 @@ const markers = test.markers(); verify.getInlineHints([], undefined, { - includeInlineCallChains: true, + includeInlineCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork6.ts b/tests/cases/fourslash/inlineHintsShouldWork6.ts index 388e1286f6247..e6b24776269ad 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork6.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork6.ts @@ -12,5 +12,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork7.ts b/tests/cases/fourslash/inlineHintsShouldWork7.ts index 624914c83e89d..9e2092fc3bbab 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork7.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork7.ts @@ -26,5 +26,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork8.ts b/tests/cases/fourslash/inlineHintsShouldWork8.ts index 77fe2067182f9..2419b3048a75e 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork8.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork8.ts @@ -26,5 +26,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork9.ts b/tests/cases/fourslash/inlineHintsShouldWork9.ts index 84ec6d92574cb..d44edfd1904ac 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork9.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork9.ts @@ -33,5 +33,5 @@ verify.getInlineHints([ whitespaceAfter: true } ], undefined, { - includeInlineParameterName: true + includeInlineParameterNameHints: true }); From 467b5cdec7585ea6ab7d075fcf736aaf520161df Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 13 Jan 2021 20:39:56 +0800 Subject: [PATCH 20/53] Match lastest protocol --- src/harness/client.ts | 2 +- src/harness/fourslashImpl.ts | 25 ++++++++++++++-- src/harness/fourslashInterfaceImpl.ts | 2 +- src/server/protocol.ts | 2 +- src/server/scriptInfo.ts | 7 +++++ src/server/session.ts | 2 +- src/services/inlineHints.ts | 30 +++++++++++-------- src/services/types.ts | 2 +- tests/cases/fourslash/fourslash.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork1.ts | 4 +-- .../fourslash/inlineHintsShouldWork11.ts | 4 +-- .../fourslash/inlineHintsShouldWork12.ts | 4 +-- .../fourslash/inlineHintsShouldWork13.ts | 2 +- .../fourslash/inlineHintsShouldWork15.ts | 2 +- .../fourslash/inlineHintsShouldWork16.ts | 2 +- .../fourslash/inlineHintsShouldWork17.ts | 2 +- .../fourslash/inlineHintsShouldWork18.ts | 2 +- .../fourslash/inlineHintsShouldWork19.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork2.ts | 2 +- .../fourslash/inlineHintsShouldWork22.ts | 2 +- .../fourslash/inlineHintsShouldWork23.ts | 2 +- .../fourslash/inlineHintsShouldWork24.ts | 4 +-- .../fourslash/inlineHintsShouldWork25.ts | 2 +- .../fourslash/inlineHintsShouldWork26.ts | 2 +- .../fourslash/inlineHintsShouldWork27.ts | 4 +-- .../fourslash/inlineHintsShouldWork28.ts | 2 +- .../fourslash/inlineHintsShouldWork29.ts | 8 ++--- .../cases/fourslash/inlineHintsShouldWork3.ts | 4 +-- .../fourslash/inlineHintsShouldWork30.ts | 2 +- .../fourslash/inlineHintsShouldWork31.ts | 2 +- .../fourslash/inlineHintsShouldWork32.ts | 2 +- .../fourslash/inlineHintsShouldWork33.ts | 2 +- .../fourslash/inlineHintsShouldWork34.ts | 2 +- .../fourslash/inlineHintsShouldWork35.ts | 2 +- .../fourslash/inlineHintsShouldWork36.ts | 4 +-- .../fourslash/inlineHintsShouldWork37.ts | 2 +- .../fourslash/inlineHintsShouldWork38.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork4.ts | 6 ++-- .../fourslash/inlineHintsShouldWork40.ts | 2 +- .../fourslash/inlineHintsShouldWork41.ts | 2 +- .../fourslash/inlineHintsShouldWork42.ts | 2 +- .../fourslash/inlineHintsShouldWork43.ts | 2 +- .../fourslash/inlineHintsShouldWork44.ts | 6 ++-- .../fourslash/inlineHintsShouldWork46.ts | 2 +- .../fourslash/inlineHintsShouldWork47.ts | 6 ++-- .../fourslash/inlineHintsShouldWork48.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork5.ts | 6 ++-- .../fourslash/inlineHintsShouldWork50.ts | 6 ++-- .../cases/fourslash/inlineHintsShouldWork6.ts | 2 +- .../cases/fourslash/inlineHintsShouldWork7.ts | 6 ++-- .../cases/fourslash/inlineHintsShouldWork8.ts | 6 ++-- .../cases/fourslash/inlineHintsShouldWork9.ts | 8 ++--- 52 files changed, 122 insertions(+), 92 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 3cd6752ffed93..0d498a43c390f 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -644,7 +644,7 @@ namespace ts.server { return response.body!.map(item => ({ // TODO: GH#18217 text: item.text, - position: this.lineOffsetToPosition(file, item.position) + range: this.decodeSpan(item.range, file) })); } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 5815de1d14ab4..8f37891eb8a51 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -827,10 +827,29 @@ namespace FourSlash { public verifyInlineHints(expected: readonly FourSlashInterface.VerifyInlineHintsOptions[], span: ts.TextSpan = { start: 0, length: this.activeFile.content.length }, preference?: ts.InlineHintsOptions) { const hints = this.languageService.provideInlineHints(this.activeFile.fileName, span, preference); assert.equal(hints.length, expected.length, "Number of hints"); - const sortHints = (a: ts.InlineHint, b: ts.InlineHint) => a.position - b.position; - ts.zipWith(hints.sort(sortHints), [...expected].sort(sortHints), (actual, expected) => { + const normalizeVerifyInlineHintsOptions = (rangeOrPosition: FourSlashInterface.VerifyInlineHintsOptions["rangeOrPosition"]) => { + if (typeof rangeOrPosition === "number") { + return { start: rangeOrPosition, length: 0 }; + } + return rangeOrPosition; + }; + const compareTextSpan = (spanA: ts.TextSpan, spanB: ts.TextSpan) => { + if (spanA.start !== spanB.start) { + return spanA.start - spanB.start; + } + return spanA.length - spanB.length; + }; + const compareHintOptions = (a: FourSlashInterface.VerifyInlineHintsOptions, b: FourSlashInterface.VerifyInlineHintsOptions) => { + const spanA = normalizeVerifyInlineHintsOptions(a.rangeOrPosition); + const spanB = normalizeVerifyInlineHintsOptions(b.rangeOrPosition); + return compareTextSpan(spanA, spanB); + }; + const sortHints = (a: ts.InlineHint, b: ts.InlineHint) => { + return compareTextSpan(a.range, b.range); + }; + ts.zipWith(hints.sort(sortHints), [...expected].sort(compareHintOptions), (actual, expected) => { assert.equal(actual.text, expected.text, "Text"); - assert.equal(actual.position, expected.position, "Position"); + assert.deepEqual(actual.range, normalizeVerifyInlineHintsOptions(expected.rangeOrPosition), "RangeOrPosition"); assert.equal(actual.whitespaceBefore, expected.whitespaceBefore, "whitespaceBefore"); assert.equal(actual.whitespaceAfter, expected.whitespaceAfter, "whitespaceAfter"); }); diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index d2b226f6ef129..65e794bd32fef 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1651,7 +1651,7 @@ namespace FourSlashInterface { export interface VerifyInlineHintsOptions { text: string; - position: number + rangeOrPosition: number | ts.TextSpan; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 41df1664d5b05..60002e1477adb 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2492,7 +2492,7 @@ namespace ts.server.protocol { export interface HintItem { text: string; - position: Location; + range: TextSpan; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index 0af6808d892f2..ced45aa2bde2b 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -641,6 +641,13 @@ namespace ts.server { return location; } + textSpanToProtoTextSpan(range: TextSpan): protocol.TextSpan { + return { + start: this.positionToLineOffset(range.start), + end: this.positionToLineOffset(range.start + range.length) + }; + } + public isJavaScript() { return this.scriptKind === ScriptKind.JS || this.scriptKind === ScriptKind.JSX; } diff --git a/src/server/session.ts b/src/server/session.ts index 5825f4893411b..6a28f6167caa6 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1428,7 +1428,7 @@ namespace ts.server { return hints.map(hint => ({ text: hint.text, - position: scriptInfo.positionToLineOffset(hint.position), + range: scriptInfo.textSpanToProtoTextSpan(hint.range), whitespaceBefore: hint.whitespaceBefore, whitespaceAfter: hint.whitespaceAfter })); diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index e43b0860aa0c8..e5d86985408cd 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -2,7 +2,7 @@ namespace ts.InlineHints { interface HintInfo { text: string; - position: number; + range: TextSpan; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -80,26 +80,26 @@ namespace ts.InlineHints { return isArrowFunction(node) || isFunctionExpression(node) || isFunctionDeclaration(node) || isMethodDeclaration(node); } - function addNameHints(text: string, position: number) { + function addNameHints(text: string, range: TextSpan) { result.push({ text: `${truncation(text, maxHintsLength)}:`, - position, + range, whitespaceAfter: true, }); } - function addTypeHints(text: string, position: number) { + function addTypeHints(text: string, range: TextSpan) { result.push({ text: `:${truncation(text, maxHintsLength)}`, - position, + range, whitespaceBefore: true, }); } - function addEnumMemberValueHints(text: string, position: number) { + function addEnumMemberValueHints(text: string, range: TextSpan) { result.push({ text: `= ${truncation(text, maxHintsLength)}`, - position, + range, whitespaceBefore: true, }); } @@ -121,7 +121,7 @@ namespace ts.InlineHints { return; } - addTypeHints(typeDisplayString, call.end); + addTypeHints(typeDisplayString, makeEmptyRange(call.end)); } function shouldCallExpressionHint(call: CallExpression) { @@ -140,6 +140,10 @@ namespace ts.InlineHints { return callExpressionHintableCache.get(call); } + function makeEmptyRange(position: number): TextSpan { + return { start: position, length: 0 }; + } + function visitEnumMember(member: EnumMember) { if (member.initializer) { return; @@ -147,7 +151,7 @@ namespace ts.InlineHints { const enumValue = checker.getConstantValue(member); if (enumValue !== undefined) { - addEnumMemberValueHints(enumValue.toString(), member.end); + addEnumMemberValueHints(enumValue.toString(), makeEmptyRange(member.end)); } } @@ -163,7 +167,7 @@ namespace ts.InlineHints { const typeDisplayString = printTypeInSingleLine(declarationType); if (typeDisplayString) { - addTypeHints(typeDisplayString, decl.name.end); + addTypeHints(typeDisplayString, makeEmptyRange(decl.name.end)); } } @@ -187,7 +191,7 @@ namespace ts.InlineHints { const parameterName = checker.getParameterIdentifierNameAtPosition(signature, i); if (parameterName) { if (preferences.includeInlineDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { - addNameHints(unescapeLeadingUnderscores(parameterName), expr.arguments[i].getStart()); + addNameHints(unescapeLeadingUnderscores(parameterName), makeEmptyRange(expr.arguments[i].getStart())); } } } @@ -215,7 +219,7 @@ namespace ts.InlineHints { return; } - addTypeHints(typeDisplayString, getTypeAnnotationPosition(decl)); + addTypeHints(typeDisplayString, makeEmptyRange(getTypeAnnotationPosition(decl))); } function getTypeAnnotationPosition(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { @@ -253,7 +257,7 @@ namespace ts.InlineHints { continue; } - addTypeHints(typeDisplayString, param.end); + addTypeHints(typeDisplayString, makeEmptyRange(param.end)); } } diff --git a/src/services/types.ts b/src/services/types.ts index e2d9e6cc29346..02903e6697b12 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -702,7 +702,7 @@ namespace ts { export interface InlineHint { text: string; - position: number; + range: TextSpan; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 7c498718578b4..0285224a8537a 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -729,7 +729,7 @@ declare namespace FourSlashInterface { export interface VerifyInlineHintsOptions { text: string; - position: number + rangeOrPosition: number |TextSpan; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/tests/cases/fourslash/inlineHintsShouldWork1.ts b/tests/cases/fourslash/inlineHintsShouldWork1.ts index 66d2a7e69b68b..64a986ee4359d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork1.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork1.ts @@ -7,12 +7,12 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'a:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'b:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork11.ts b/tests/cases/fourslash/inlineHintsShouldWork11.ts index 4ed8fe9a06a63..7a8888f70cd86 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork11.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork11.ts @@ -11,12 +11,12 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'a:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'b:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork12.ts b/tests/cases/fourslash/inlineHintsShouldWork12.ts index 62974f32b073d..da4f1942f7887 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork12.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork12.ts @@ -10,12 +10,12 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'b:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'a:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork13.ts b/tests/cases/fourslash/inlineHintsShouldWork13.ts index 5d83e2132cf9e..f59ca89dd2325 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork13.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork13.ts @@ -8,7 +8,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'b:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork15.ts b/tests/cases/fourslash/inlineHintsShouldWork15.ts index 07f375cdca1e4..5ddf52629f77d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork15.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork15.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':123', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork16.ts b/tests/cases/fourslash/inlineHintsShouldWork16.ts index 07f375cdca1e4..5ddf52629f77d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork16.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork16.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':123', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork17.ts b/tests/cases/fourslash/inlineHintsShouldWork17.ts index d10572670e3a7..c9a6c41709e69 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork17.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork17.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':{ a: number; }', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork18.ts b/tests/cases/fourslash/inlineHintsShouldWork18.ts index 8143b2ce13a40..0160979ba3ae7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork18.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork18.ts @@ -7,7 +7,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':Class', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork19.ts b/tests/cases/fourslash/inlineHintsShouldWork19.ts index 3189652d94c69..1ca6e0e4a7ee7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork19.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork19.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':() => number', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork2.ts b/tests/cases/fourslash/inlineHintsShouldWork2.ts index aa1ffb330c3f2..4e22cf68a0f03 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork2.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork2.ts @@ -7,7 +7,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'a:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork22.ts b/tests/cases/fourslash/inlineHintsShouldWork22.ts index 306b8b8f326cf..eb4a745a9e212 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork22.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork22.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: `:"I'm very very very very ve...`, - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork23.ts b/tests/cases/fourslash/inlineHintsShouldWork23.ts index 0edd3049ea65a..3d6df7ee2a9bd 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork23.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork23.ts @@ -7,7 +7,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'Im_very_very_very_very_very...:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork24.ts b/tests/cases/fourslash/inlineHintsShouldWork24.ts index 97b0840b035fd..f5b8d3e5c6a55 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork24.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork24.ts @@ -7,12 +7,12 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':string', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { text: ':number', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork25.ts b/tests/cases/fourslash/inlineHintsShouldWork25.ts index 962b2fd16c705..9b298e41a5708 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork25.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork25.ts @@ -7,7 +7,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':string', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork26.ts b/tests/cases/fourslash/inlineHintsShouldWork26.ts index 2234a44e4060e..6222b02cb8ada 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork26.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork26.ts @@ -7,7 +7,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':2 | 3', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork27.ts b/tests/cases/fourslash/inlineHintsShouldWork27.ts index 57175ca61b00f..3158a5c27b774 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork27.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork27.ts @@ -9,12 +9,12 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':(c: (d: 2 | 3) => void) => ...', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { text: ':2 | 3', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork28.ts b/tests/cases/fourslash/inlineHintsShouldWork28.ts index 3d726d5b1fe2f..6417e4f958be0 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork28.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork28.ts @@ -7,7 +7,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':string', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork29.ts b/tests/cases/fourslash/inlineHintsShouldWork29.ts index dd34ff7d734f1..775a942472c94 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork29.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork29.ts @@ -9,22 +9,22 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'a:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: ':(c: (d: 2 | 3) => void) => ...', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceBefore: true }, { text: 'c:', - position: markers[2].position, + rangeOrPosition: markers[2].position, whitespaceAfter: true }, { text: ':2 | 3', - position: markers[3].position, + rangeOrPosition: markers[3].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork3.ts b/tests/cases/fourslash/inlineHintsShouldWork3.ts index a307aa7823be1..7376aeb668b27 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork3.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork3.ts @@ -7,12 +7,12 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'a:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'b:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork30.ts b/tests/cases/fourslash/inlineHintsShouldWork30.ts index 150bb12dbb3c5..252bb444cec3b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork30.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork30.ts @@ -7,7 +7,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':number', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork31.ts b/tests/cases/fourslash/inlineHintsShouldWork31.ts index 4802566490860..0a41ae49a70f0 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork31.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork31.ts @@ -10,7 +10,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':{ a: number; b: string; }', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork32.ts b/tests/cases/fourslash/inlineHintsShouldWork32.ts index ad573bf4fa7a2..c01375ec1bac3 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork32.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork32.ts @@ -22,7 +22,7 @@ verify.getInlineHints( ['c', 'd', 'e', 'f', 'g', 'h'].map(mark => { return { text: `${mark}:`, - position: test.markerByName(mark).position, + rangeOrPosition: test.markerByName(mark).position, whitespaceAfter: true } }), span, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork33.ts b/tests/cases/fourslash/inlineHintsShouldWork33.ts index 6ac70ec39c936..d148a7cd8d5e8 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork33.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork33.ts @@ -22,7 +22,7 @@ verify.getInlineHints( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'].map(mark => { return { text: `${mark}:`, - position: test.markerByName(mark).position, + rangeOrPosition: test.markerByName(mark).position, whitespaceAfter: true } }), span, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork34.ts b/tests/cases/fourslash/inlineHintsShouldWork34.ts index 78b3a9b7505a8..e499b3968eb98 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork34.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork34.ts @@ -21,7 +21,7 @@ const markers = test.markers(); verify.getInlineHints( markers.map(m => ({ text: 'v:', - position: m.position, + rangeOrPosition: m.position, whitespaceAfter: true })) , undefined, { includeInlineParameterNameHints: true, diff --git a/tests/cases/fourslash/inlineHintsShouldWork35.ts b/tests/cases/fourslash/inlineHintsShouldWork35.ts index a5c57ec4fde4a..c81f04c71aab0 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork35.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork35.ts @@ -21,7 +21,7 @@ const markers = test.markers(); verify.getInlineHints( markers.map(m => ({ text: 'v:', - position: m.position, + rangeOrPosition: m.position, whitespaceAfter: true })) , undefined, { includeInlineParameterNameHints: true, diff --git a/tests/cases/fourslash/inlineHintsShouldWork36.ts b/tests/cases/fourslash/inlineHintsShouldWork36.ts index b6b367e72551a..cd3ce7a9d95cd 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork36.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork36.ts @@ -8,12 +8,12 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'a:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'b:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork37.ts b/tests/cases/fourslash/inlineHintsShouldWork37.ts index c22208099d75b..ef5bd74c72c76 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork37.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork37.ts @@ -10,7 +10,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':number', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork38.ts b/tests/cases/fourslash/inlineHintsShouldWork38.ts index ad42630a90c32..270858539165b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork38.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork38.ts @@ -8,7 +8,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':number', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork4.ts b/tests/cases/fourslash/inlineHintsShouldWork4.ts index b7fb591376594..06031ceb3cef4 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork4.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork4.ts @@ -11,17 +11,17 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'w:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'a:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true }, { text: 'b:', - position: markers[2].position, + rangeOrPosition: markers[2].position, whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork40.ts b/tests/cases/fourslash/inlineHintsShouldWork40.ts index d5a048ff598b7..b6c891a571703 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork40.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork40.ts @@ -10,7 +10,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':number', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork41.ts b/tests/cases/fourslash/inlineHintsShouldWork41.ts index 3346734e6b684..5b76af18a3b63 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork41.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork41.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':number', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork42.ts b/tests/cases/fourslash/inlineHintsShouldWork42.ts index 9e93cb642317f..657a1a6bf5897 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork42.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork42.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':number', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork43.ts b/tests/cases/fourslash/inlineHintsShouldWork43.ts index 6d7a205056dbc..26626f53df09d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork43.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork43.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':number', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork44.ts b/tests/cases/fourslash/inlineHintsShouldWork44.ts index 96f69702e93e1..1b6fcda680954 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork44.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork44.ts @@ -12,17 +12,17 @@ const markers = test.markers(); verify.getInlineHints([ { text: '= 0', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { text: '= 1', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceBefore: true }, { text: '= 11', - position: markers[2].position, + rangeOrPosition: markers[2].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork46.ts b/tests/cases/fourslash/inlineHintsShouldWork46.ts index 3dbff093f5f6a..a2ef70e880ae8 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork46.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork46.ts @@ -14,7 +14,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':typeof import("/a")', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork47.ts b/tests/cases/fourslash/inlineHintsShouldWork47.ts index 405b132a35d27..ecec242ade7c9 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork47.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork47.ts @@ -11,17 +11,17 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':string[]', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { text: ':number[]', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceBefore: true }, { text: ':string[]', - position: markers[2].position, + rangeOrPosition: markers[2].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork48.ts b/tests/cases/fourslash/inlineHintsShouldWork48.ts index f53b9d346f05d..91ab158f02fec 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork48.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork48.ts @@ -9,7 +9,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':string[]', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork5.ts b/tests/cases/fourslash/inlineHintsShouldWork5.ts index 5186ccfd33844..bc627ae521633 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork5.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork5.ts @@ -8,17 +8,17 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'c:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'a:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true }, { text: 'b:', - position: markers[2].position, + rangeOrPosition: markers[2].position, whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork50.ts b/tests/cases/fourslash/inlineHintsShouldWork50.ts index f237a65d245e3..972231971eaaf 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork50.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork50.ts @@ -11,17 +11,17 @@ const markers = test.markers(); verify.getInlineHints([ { text: ':string[]', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { text: ':number[]', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceBefore: true }, { text: ':string[]', - position: markers[2].position, + rangeOrPosition: markers[2].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork6.ts b/tests/cases/fourslash/inlineHintsShouldWork6.ts index e6b24776269ad..615b6e62145ca 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork6.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork6.ts @@ -8,7 +8,7 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'c:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork7.ts b/tests/cases/fourslash/inlineHintsShouldWork7.ts index 9e2092fc3bbab..fa275f2bcd44a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork7.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork7.ts @@ -12,17 +12,17 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'a:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'b:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true }, { text: 'c:', - position: markers[2].position, + rangeOrPosition: markers[2].position, whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork8.ts b/tests/cases/fourslash/inlineHintsShouldWork8.ts index 2419b3048a75e..c68892a009f9c 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork8.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork8.ts @@ -12,17 +12,17 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'a:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'b:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true }, { text: 'c:', - position: markers[2].position, + rangeOrPosition: markers[2].position, whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork9.ts b/tests/cases/fourslash/inlineHintsShouldWork9.ts index d44edfd1904ac..50a911a028816 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork9.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork9.ts @@ -14,22 +14,22 @@ const markers = test.markers(); verify.getInlineHints([ { text: 'a:', - position: markers[0].position, + rangeOrPosition: markers[0].position, whitespaceAfter: true }, { text: 'b:', - position: markers[1].position, + rangeOrPosition: markers[1].position, whitespaceAfter: true }, { text: 'c:', - position: markers[2].position, + rangeOrPosition: markers[2].position, whitespaceAfter: true }, { text: 'd:', - position: markers[3].position, + rangeOrPosition: markers[3].position, whitespaceAfter: true } ], undefined, { From e5ca31bc30362144c52c1c2512abc553f0c6b869 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 14 Jan 2021 20:57:12 +0800 Subject: [PATCH 21/53] Update protocol changes --- src/harness/client.ts | 7 +++- src/harness/fourslashImpl.ts | 3 ++ src/harness/fourslashInterfaceImpl.ts | 3 ++ src/server/protocol.ts | 3 ++ src/server/session.ts | 3 ++ src/services/inlineHints.ts | 33 ++++++++++++------- src/services/types.ts | 3 ++ tests/cases/fourslash/fourslash.ts | 3 ++ .../cases/fourslash/inlineHintsShouldWork1.ts | 8 +++-- .../fourslash/inlineHintsShouldWork11.ts | 8 +++-- .../fourslash/inlineHintsShouldWork12.ts | 8 +++-- .../fourslash/inlineHintsShouldWork13.ts | 4 ++- .../fourslash/inlineHintsShouldWork15.ts | 10 +++--- .../fourslash/inlineHintsShouldWork16.ts | 8 +++-- .../fourslash/inlineHintsShouldWork17.ts | 8 +++-- .../fourslash/inlineHintsShouldWork18.ts | 10 +++--- .../fourslash/inlineHintsShouldWork19.ts | 8 +++-- .../cases/fourslash/inlineHintsShouldWork2.ts | 4 ++- .../fourslash/inlineHintsShouldWork22.ts | 8 +++-- .../fourslash/inlineHintsShouldWork23.ts | 4 ++- .../fourslash/inlineHintsShouldWork24.ts | 14 +++++--- .../fourslash/inlineHintsShouldWork25.ts | 8 +++-- .../fourslash/inlineHintsShouldWork26.ts | 8 +++-- .../fourslash/inlineHintsShouldWork27.ts | 16 +++++---- .../fourslash/inlineHintsShouldWork28.ts | 8 +++-- .../fourslash/inlineHintsShouldWork29.ts | 16 ++++++--- .../cases/fourslash/inlineHintsShouldWork3.ts | 8 +++-- .../fourslash/inlineHintsShouldWork30.ts | 8 +++-- .../fourslash/inlineHintsShouldWork31.ts | 8 +++-- .../fourslash/inlineHintsShouldWork32.ts | 4 ++- .../fourslash/inlineHintsShouldWork33.ts | 4 ++- .../fourslash/inlineHintsShouldWork34.ts | 4 ++- .../fourslash/inlineHintsShouldWork35.ts | 4 ++- .../fourslash/inlineHintsShouldWork36.ts | 8 +++-- .../fourslash/inlineHintsShouldWork37.ts | 8 +++-- .../fourslash/inlineHintsShouldWork38.ts | 10 +++--- .../cases/fourslash/inlineHintsShouldWork4.ts | 12 +++++-- .../fourslash/inlineHintsShouldWork40.ts | 8 +++-- .../fourslash/inlineHintsShouldWork41.ts | 8 +++-- .../fourslash/inlineHintsShouldWork42.ts | 8 +++-- .../fourslash/inlineHintsShouldWork43.ts | 8 +++-- .../fourslash/inlineHintsShouldWork44.ts | 24 +++++++++----- .../fourslash/inlineHintsShouldWork46.ts | 8 +++-- .../fourslash/inlineHintsShouldWork47.ts | 26 +++++++++------ .../fourslash/inlineHintsShouldWork48.ts | 10 +++--- .../cases/fourslash/inlineHintsShouldWork5.ts | 12 +++++-- .../fourslash/inlineHintsShouldWork50.ts | 26 +++++++++------ .../cases/fourslash/inlineHintsShouldWork6.ts | 4 ++- .../cases/fourslash/inlineHintsShouldWork7.ts | 12 +++++-- .../cases/fourslash/inlineHintsShouldWork8.ts | 12 +++++-- .../cases/fourslash/inlineHintsShouldWork9.ts | 16 ++++++--- 51 files changed, 324 insertions(+), 152 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 0d498a43c390f..1ef9ce8bdd890 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -644,7 +644,12 @@ namespace ts.server { return response.body!.map(item => ({ // TODO: GH#18217 text: item.text, - range: this.decodeSpan(item.range, file) + range: this.decodeSpan(item.range, file), + triggerPosition: this.lineOffsetToPosition(file, item.triggerPosition), + prefix: item.prefix, + postfix: item.postfix, + whitespaceBefore: item.whitespaceBefore, + whitespaceAfter: item.whitespaceAfter })); } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 8f37891eb8a51..40a47da0beaba 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -850,6 +850,9 @@ namespace FourSlash { ts.zipWith(hints.sort(sortHints), [...expected].sort(compareHintOptions), (actual, expected) => { assert.equal(actual.text, expected.text, "Text"); assert.deepEqual(actual.range, normalizeVerifyInlineHintsOptions(expected.rangeOrPosition), "RangeOrPosition"); + assert.equal(actual.triggerPosition, expected.triggerPosition, "TriggerPosition"); + assert.equal(actual.prefix, expected.prefix, "Prefix"); + assert.equal(actual.postfix, expected.postfix, "Postfix"); assert.equal(actual.whitespaceBefore, expected.whitespaceBefore, "whitespaceBefore"); assert.equal(actual.whitespaceAfter, expected.whitespaceAfter, "whitespaceAfter"); }); diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 65e794bd32fef..15c6746651cb4 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1652,6 +1652,9 @@ namespace FourSlashInterface { export interface VerifyInlineHintsOptions { text: string; rangeOrPosition: number | ts.TextSpan; + triggerPosition: number; + prefix?: string; + postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 60002e1477adb..c9a59d83c3aaa 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2493,6 +2493,9 @@ namespace ts.server.protocol { export interface HintItem { text: string; range: TextSpan; + triggerPosition: Location; + prefix?: string; + postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/session.ts b/src/server/session.ts index 6a28f6167caa6..1f2e951173d82 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1429,6 +1429,9 @@ namespace ts.server { return hints.map(hint => ({ text: hint.text, range: scriptInfo.textSpanToProtoTextSpan(hint.range), + triggerPosition: scriptInfo.positionToLineOffset(hint.triggerPosition), + prefix: hint.prefix, + postfix: hint.postfix, whitespaceBefore: hint.whitespaceBefore, whitespaceAfter: hint.whitespaceAfter })); diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index e5d86985408cd..f7cba7fccdd35 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -3,6 +3,9 @@ namespace ts.InlineHints { interface HintInfo { text: string; range: TextSpan; + triggerPosition: number; + prefix?: string; + postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -80,26 +83,32 @@ namespace ts.InlineHints { return isArrowFunction(node) || isFunctionExpression(node) || isFunctionDeclaration(node) || isMethodDeclaration(node); } - function addNameHints(text: string, range: TextSpan) { + function addNameHints(node: Node, text: string, range: TextSpan) { result.push({ - text: `${truncation(text, maxHintsLength)}:`, + text: truncation(text, maxHintsLength), range, + triggerPosition: node.getStart(), + postfix: ":", whitespaceAfter: true, }); } - function addTypeHints(text: string, range: TextSpan) { + function addTypeHints(node: Node, text: string, range: TextSpan) { result.push({ - text: `:${truncation(text, maxHintsLength)}`, + text: truncation(text, maxHintsLength), range, + triggerPosition: node.getStart(), + prefix: ":", whitespaceBefore: true, }); } - function addEnumMemberValueHints(text: string, range: TextSpan) { + function addEnumMemberValueHints(node: Node, text: string, range: TextSpan) { result.push({ - text: `= ${truncation(text, maxHintsLength)}`, + text: truncation(text, maxHintsLength), range, + triggerPosition: node.getStart(), + prefix: "= ", whitespaceBefore: true, }); } @@ -121,7 +130,7 @@ namespace ts.InlineHints { return; } - addTypeHints(typeDisplayString, makeEmptyRange(call.end)); + addTypeHints(call, typeDisplayString, makeEmptyRange(call.end)); } function shouldCallExpressionHint(call: CallExpression) { @@ -151,7 +160,7 @@ namespace ts.InlineHints { const enumValue = checker.getConstantValue(member); if (enumValue !== undefined) { - addEnumMemberValueHints(enumValue.toString(), makeEmptyRange(member.end)); + addEnumMemberValueHints(member, enumValue.toString(), makeEmptyRange(member.end)); } } @@ -167,7 +176,7 @@ namespace ts.InlineHints { const typeDisplayString = printTypeInSingleLine(declarationType); if (typeDisplayString) { - addTypeHints(typeDisplayString, makeEmptyRange(decl.name.end)); + addTypeHints(decl.name, typeDisplayString, makeEmptyRange(decl.name.end)); } } @@ -191,7 +200,7 @@ namespace ts.InlineHints { const parameterName = checker.getParameterIdentifierNameAtPosition(signature, i); if (parameterName) { if (preferences.includeInlineDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { - addNameHints(unescapeLeadingUnderscores(parameterName), makeEmptyRange(expr.arguments[i].getStart())); + addNameHints(arg, unescapeLeadingUnderscores(parameterName), makeEmptyRange(expr.arguments[i].getStart())); } } } @@ -219,7 +228,7 @@ namespace ts.InlineHints { return; } - addTypeHints(typeDisplayString, makeEmptyRange(getTypeAnnotationPosition(decl))); + addTypeHints(decl, typeDisplayString, makeEmptyRange(getTypeAnnotationPosition(decl))); } function getTypeAnnotationPosition(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { @@ -257,7 +266,7 @@ namespace ts.InlineHints { continue; } - addTypeHints(typeDisplayString, makeEmptyRange(param.end)); + addTypeHints(param, typeDisplayString, makeEmptyRange(param.end)); } } diff --git a/src/services/types.ts b/src/services/types.ts index 02903e6697b12..3366370e5600d 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -703,6 +703,9 @@ namespace ts { export interface InlineHint { text: string; range: TextSpan; + triggerPosition: number; + prefix?: string; + postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 0285224a8537a..94d3c85e08405 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -730,6 +730,9 @@ declare namespace FourSlashInterface { export interface VerifyInlineHintsOptions { text: string; rangeOrPosition: number |TextSpan; + triggerPosition: number; + prefix?: string; + postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/tests/cases/fourslash/inlineHintsShouldWork1.ts b/tests/cases/fourslash/inlineHintsShouldWork1.ts index 64a986ee4359d..fcadbd86158a4 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork1.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork1.ts @@ -6,13 +6,17 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a:', + text: 'a', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'b:', + text: 'b', rangeOrPosition: markers[1].position, + triggerPosition: markers[1].position, + postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork11.ts b/tests/cases/fourslash/inlineHintsShouldWork11.ts index 7a8888f70cd86..a9e06fa491ee0 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork11.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork11.ts @@ -10,13 +10,17 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a:', + text: 'a', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'b:', + text: 'b', rangeOrPosition: markers[1].position, + triggerPosition: markers[1].position, + postfix: ':', whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork12.ts b/tests/cases/fourslash/inlineHintsShouldWork12.ts index da4f1942f7887..4b868d0f11289 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork12.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork12.ts @@ -9,13 +9,17 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'b:', + text: 'b', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'a:', + text: 'a', rangeOrPosition: markers[1].position, + triggerPosition: markers[1].position, + postfix: ':', whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork13.ts b/tests/cases/fourslash/inlineHintsShouldWork13.ts index f59ca89dd2325..c8b016f0b6150 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork13.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork13.ts @@ -7,8 +7,10 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'b:', + text: 'b', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork15.ts b/tests/cases/fourslash/inlineHintsShouldWork15.ts index 5ddf52629f77d..cf1ce98697803 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork15.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork15.ts @@ -1,13 +1,15 @@ /// -//// const a/*a*/ = 123; +//// const /*a*/a/*b*/ = 123; const markers = test.markers(); verify.getInlineHints([ { - text: ':123', - rangeOrPosition: markers[0].position, - whitespaceBefore: true + text: '123', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + whitespaceBefore: true, + prefix: ':' }, ], undefined, { includeInlineVariableTypeHints: true diff --git a/tests/cases/fourslash/inlineHintsShouldWork16.ts b/tests/cases/fourslash/inlineHintsShouldWork16.ts index 5ddf52629f77d..6626553b2fb13 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork16.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork16.ts @@ -1,12 +1,14 @@ /// -//// const a/*a*/ = 123; +//// const /*a*/a/*b*/ = 123; const markers = test.markers(); verify.getInlineHints([ { - text: ':123', - rangeOrPosition: markers[0].position, + text: '123', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork17.ts b/tests/cases/fourslash/inlineHintsShouldWork17.ts index c9a6c41709e69..899dbc812a154 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork17.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork17.ts @@ -1,12 +1,14 @@ /// -//// const a/*a*/ = { a: 123 }; +//// const /*a*/a/*b*/ = { a: 123 }; const markers = test.markers(); verify.getInlineHints([ { - text: ':{ a: number; }', - rangeOrPosition: markers[0].position, + text: '{ a: number; }', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork18.ts b/tests/cases/fourslash/inlineHintsShouldWork18.ts index 0160979ba3ae7..ce44e62cb168a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork18.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork18.ts @@ -1,14 +1,16 @@ /// //// class Class {} -//// const a/*a*/ = new Class(); +//// const /*a*/a/*b*/ = new Class(); const markers = test.markers(); verify.getInlineHints([ { - text: ':Class', - rangeOrPosition: markers[0].position, - whitespaceBefore: true + text: 'Class', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + whitespaceBefore: true, + prefix: ':' }, ], undefined, { includeInlineVariableTypeHints: true diff --git a/tests/cases/fourslash/inlineHintsShouldWork19.ts b/tests/cases/fourslash/inlineHintsShouldWork19.ts index 1ca6e0e4a7ee7..3409c7b40d878 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork19.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork19.ts @@ -1,12 +1,14 @@ /// -//// const a/*a*/ = () => 123; +//// const /*a*/a/*b*/ = () => 123; const markers = test.markers(); verify.getInlineHints([ { - text: ':() => number', - rangeOrPosition: markers[0].position, + text: '() => number', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork2.ts b/tests/cases/fourslash/inlineHintsShouldWork2.ts index 4e22cf68a0f03..e7ddcca050feb 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork2.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork2.ts @@ -6,8 +6,10 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a:', + text: 'a', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork22.ts b/tests/cases/fourslash/inlineHintsShouldWork22.ts index eb4a745a9e212..497d465760542 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork22.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork22.ts @@ -1,12 +1,14 @@ /// -//// const a/*a*/ = "I'm very very very very very very very very very long"; +//// const /*a*/a/*b*/ = "I'm very very very very very very very very very long"; const markers = test.markers(); verify.getInlineHints([ { - text: `:"I'm very very very very ve...`, - rangeOrPosition: markers[0].position, + text: `"I'm very very very very ve...`, + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork23.ts b/tests/cases/fourslash/inlineHintsShouldWork23.ts index 3d6df7ee2a9bd..bb9b7abe6c126 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork23.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork23.ts @@ -6,8 +6,10 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'Im_very_very_very_very_very...:', + text: 'Im_very_very_very_very_very...', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork24.ts b/tests/cases/fourslash/inlineHintsShouldWork24.ts index f5b8d3e5c6a55..72ec8f21dc69f 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork24.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork24.ts @@ -1,18 +1,22 @@ /// //// type F = (a: string, b: number) => void -//// const f: F = (a/*a*/, b/*b*/) => { } +//// const f: F = (/*a*/a/*b*/, /*c*/b/*d*/) => { } const markers = test.markers(); verify.getInlineHints([ { - text: ':string', - rangeOrPosition: markers[0].position, + text: 'string', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, { - text: ':number', - rangeOrPosition: markers[1].position, + text: 'number', + triggerPosition: markers[2].position, + rangeOrPosition: markers[3].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork25.ts b/tests/cases/fourslash/inlineHintsShouldWork25.ts index 9b298e41a5708..05ff2c56cd5d7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork25.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork25.ts @@ -1,13 +1,15 @@ /// //// function foo (cb: (a: string) => void) {} -//// foo((a/*a*/) => { }) +//// foo((/*a*/a/*b*/) => { }) const markers = test.markers(); verify.getInlineHints([ { - text: ':string', - rangeOrPosition: markers[0].position, + text: 'string', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork26.ts b/tests/cases/fourslash/inlineHintsShouldWork26.ts index 6222b02cb8ada..d7b6d60e4ffe9 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork26.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork26.ts @@ -1,13 +1,15 @@ /// //// function foo (cb: (a: Exclude<1 | 2 | 3, 1>) => void) {} -//// foo((a/*a*/) => { }) +//// foo((/*a*/a/*b*/) => { }) const markers = test.markers(); verify.getInlineHints([ { - text: ':2 | 3', - rangeOrPosition: markers[0].position, + text: '2 | 3', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork27.ts b/tests/cases/fourslash/inlineHintsShouldWork27.ts index 3158a5c27b774..fd1905dc4217b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork27.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork27.ts @@ -1,20 +1,24 @@ /// //// function foo (a: (b: (c: (d: Exclude<1 | 2 | 3, 1>) => void) => void) => void) {} -//// foo(a/*a*/ => { -//// a(d/*b*/ => {}) +//// foo(/*a*/a/*b*/ => { +//// a(/*c*/d/*d*/ => {}) //// }) const markers = test.markers(); verify.getInlineHints([ { - text: ':(c: (d: 2 | 3) => void) => ...', - rangeOrPosition: markers[0].position, + text: '(c: (d: 2 | 3) => void) => ...', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, { - text: ':2 | 3', - rangeOrPosition: markers[1].position, + text: '2 | 3', + triggerPosition: markers[2].position, + rangeOrPosition: markers[3].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork28.ts b/tests/cases/fourslash/inlineHintsShouldWork28.ts index 6417e4f958be0..aef19f4a2b903 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork28.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork28.ts @@ -1,13 +1,15 @@ /// //// type F = (a: string, b: number) => void -//// const f: F = (a/*a*/, b: number) => { } +//// const f: F = (/*a*/a/*b*/, b: number) => { } const markers = test.markers(); verify.getInlineHints([ { - text: ':string', - rangeOrPosition: markers[0].position, + text: 'string', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork29.ts b/tests/cases/fourslash/inlineHintsShouldWork29.ts index 775a942472c94..7c32d380e747b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork29.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork29.ts @@ -8,23 +8,31 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a:', + text: 'a', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: ':(c: (d: 2 | 3) => void) => ...', + text: '(c: (d: 2 | 3) => void) => ...', + triggerPosition: markers[0].position, rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, { - text: 'c:', + text: 'c', + triggerPosition: markers[2].position, rangeOrPosition: markers[2].position, + postfix: ':', whitespaceAfter: true }, { - text: ':2 | 3', + text: '2 | 3', + triggerPosition: markers[2].position, rangeOrPosition: markers[3].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork3.ts b/tests/cases/fourslash/inlineHintsShouldWork3.ts index 7376aeb668b27..c46d38593729d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork3.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork3.ts @@ -6,13 +6,17 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a:', + text: 'a', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'b:', + text: 'b', rangeOrPosition: markers[1].position, + triggerPosition: markers[1].position, + postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork30.ts b/tests/cases/fourslash/inlineHintsShouldWork30.ts index 252bb444cec3b..cb655b3db776c 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork30.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork30.ts @@ -1,13 +1,15 @@ /// //// function f(v: T, a: (v: T) => void) {} -//// f(1, a/*a*/ => { }) +//// f(1, /*a*/a/*b*/ => { }) const markers = test.markers(); verify.getInlineHints([ { - text: ':number', - rangeOrPosition: markers[0].position, + text: 'number', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork31.ts b/tests/cases/fourslash/inlineHintsShouldWork31.ts index 0a41ae49a70f0..7620a83bf2759 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork31.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork31.ts @@ -4,13 +4,15 @@ //// a: number //// b: string //// }) => void -//// const f: F = (a/*a*/) => { } +//// const f: F = (/*a*/a/*b*/) => { } const markers = test.markers(); verify.getInlineHints([ { - text: ':{ a: number; b: string; }', - rangeOrPosition: markers[0].position, + text: '{ a: number; b: string; }', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork32.ts b/tests/cases/fourslash/inlineHintsShouldWork32.ts index c01375ec1bac3..09cdec11d604d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork32.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork32.ts @@ -21,8 +21,10 @@ const span = { start: start.position, length: end.position - start.position }; verify.getInlineHints( ['c', 'd', 'e', 'f', 'g', 'h'].map(mark => { return { - text: `${mark}:`, + text: mark, + triggerPosition: test.markerByName(mark).position, rangeOrPosition: test.markerByName(mark).position, + postfix: ':', whitespaceAfter: true } }), span, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork33.ts b/tests/cases/fourslash/inlineHintsShouldWork33.ts index d148a7cd8d5e8..a17a5aded342d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork33.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork33.ts @@ -21,8 +21,10 @@ const span = { start: start.position, length: end.position - start.position }; verify.getInlineHints( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'].map(mark => { return { - text: `${mark}:`, + text: mark, + triggerPosition: test.markerByName(mark).position, rangeOrPosition: test.markerByName(mark).position, + postfix: ':', whitespaceAfter: true } }), span, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork34.ts b/tests/cases/fourslash/inlineHintsShouldWork34.ts index e499b3968eb98..ac2717ddd9448 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork34.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork34.ts @@ -20,8 +20,10 @@ const markers = test.markers(); verify.getInlineHints( markers.map(m => ({ - text: 'v:', + text: 'v', + triggerPosition: m.position, rangeOrPosition: m.position, + postfix: ':', whitespaceAfter: true })) , undefined, { includeInlineParameterNameHints: true, diff --git a/tests/cases/fourslash/inlineHintsShouldWork35.ts b/tests/cases/fourslash/inlineHintsShouldWork35.ts index c81f04c71aab0..f3da66ff8a605 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork35.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork35.ts @@ -20,8 +20,10 @@ const markers = test.markers(); verify.getInlineHints( markers.map(m => ({ - text: 'v:', + text: 'v', + triggerPosition: m.position, rangeOrPosition: m.position, + postfix: ':', whitespaceAfter: true })) , undefined, { includeInlineParameterNameHints: true, diff --git a/tests/cases/fourslash/inlineHintsShouldWork36.ts b/tests/cases/fourslash/inlineHintsShouldWork36.ts index cd3ce7a9d95cd..3fed90feb773a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork36.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork36.ts @@ -7,13 +7,17 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a:', + text: 'a', + triggerPosition: markers[0].position, rangeOrPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'b:', + text: 'b', + triggerPosition: markers[1].position, rangeOrPosition: markers[1].position, + postfix: ':', whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork37.ts b/tests/cases/fourslash/inlineHintsShouldWork37.ts index ef5bd74c72c76..90455a2e30b1b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork37.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork37.ts @@ -1,7 +1,7 @@ /// //// class C { -//// a/*a*/ = 1 +//// /*a*/a/*b*/ = 1 //// b: number = 2 //// c; //// } @@ -9,8 +9,10 @@ const markers = test.markers(); verify.getInlineHints([ { - text: ':number', - rangeOrPosition: markers[0].position, + text: 'number', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork38.ts b/tests/cases/fourslash/inlineHintsShouldWork38.ts index 270858539165b..0950bd2494a0c 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork38.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork38.ts @@ -1,15 +1,17 @@ /// -//// function foo ()/*a*/ { +//// /*a*/function foo ()/*b*/ { //// return 1 //// } const markers = test.markers(); verify.getInlineHints([ { - text: ':number', - rangeOrPosition: markers[0].position, - whitespaceBefore: true + text: 'number', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', + whitespaceBefore: true, }, ], undefined, { includeInlineFunctionLikeReturnTypeHints: true, diff --git a/tests/cases/fourslash/inlineHintsShouldWork4.ts b/tests/cases/fourslash/inlineHintsShouldWork4.ts index 06031ceb3cef4..9d91db8891445 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork4.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork4.ts @@ -10,18 +10,24 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'w:', + text: 'w', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'a:', + text: 'a', rangeOrPosition: markers[1].position, + triggerPosition: markers[1].position, + postfix: ':', whitespaceAfter: true }, { - text: 'b:', + text: 'b', rangeOrPosition: markers[2].position, + triggerPosition: markers[2].position, + postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork40.ts b/tests/cases/fourslash/inlineHintsShouldWork40.ts index b6c891a571703..5708200071a30 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork40.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork40.ts @@ -1,7 +1,7 @@ /// //// class C { -//// foo()/*a*/ { +//// /*a*/foo()/*b*/ { //// return 1 //// } //// } @@ -9,8 +9,10 @@ const markers = test.markers(); verify.getInlineHints([ { - text: ':number', - rangeOrPosition: markers[0].position, + text: 'number', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork41.ts b/tests/cases/fourslash/inlineHintsShouldWork41.ts index 5b76af18a3b63..f631481689046 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork41.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork41.ts @@ -1,12 +1,14 @@ /// -//// const a = ()/*a*/ => 1 +//// const a = /*a*/()/*b*/ => 1 const markers = test.markers(); verify.getInlineHints([ { - text: ':number', - rangeOrPosition: markers[0].position, + text: 'number', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork42.ts b/tests/cases/fourslash/inlineHintsShouldWork42.ts index 657a1a6bf5897..23e81f9e1d2df 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork42.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork42.ts @@ -1,12 +1,14 @@ /// -//// const a = function ()/*a*/ { return 1} +//// const a = /*a*/function ()/*b*/ { return 1} const markers = test.markers(); verify.getInlineHints([ { - text: ':number', - rangeOrPosition: markers[0].position, + text: 'number', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork43.ts b/tests/cases/fourslash/inlineHintsShouldWork43.ts index 26626f53df09d..cc5b53bf8010d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork43.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork43.ts @@ -1,12 +1,14 @@ /// -//// const a = b/*a*/ => 1 +//// const a = /*a*/b/*b*/ => 1 const markers = test.markers(); verify.getInlineHints([ { - text: ':number', - rangeOrPosition: markers[0].position, + text: 'number', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork44.ts b/tests/cases/fourslash/inlineHintsShouldWork44.ts index 1b6fcda680954..03a5d2b95bd10 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork44.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork44.ts @@ -1,28 +1,34 @@ /// //// enum E { -//// A/*a*/, -//// AA/*b*/, +//// /*a*/A/*b*/, +//// /*c*/AA/*d*/, //// B = 10, -//// BB/*c*/, +//// /*e*/BB/*f*/, //// C = 'C', //// } const markers = test.markers(); verify.getInlineHints([ { - text: '= 0', - rangeOrPosition: markers[0].position, + text: '0', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: '= ', whitespaceBefore: true }, { - text: '= 1', - rangeOrPosition: markers[1].position, + text: '1', + triggerPosition: markers[2].position, + rangeOrPosition: markers[3].position, + prefix: '= ', whitespaceBefore: true }, { - text: '= 11', - rangeOrPosition: markers[2].position, + text: '11', + triggerPosition: markers[4].position, + rangeOrPosition: markers[5].position, + prefix: '= ', whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork46.ts b/tests/cases/fourslash/inlineHintsShouldWork46.ts index a2ef70e880ae8..dc9de4f50ac20 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork46.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork46.ts @@ -7,14 +7,16 @@ //// module.exports.a = 1 // @Filename: /b.js -//// const a/*a*/ = require('./a'); +//// const /*a*/a/*b*/ = require('./a'); goTo.file('/b.js') const markers = test.markers(); verify.getInlineHints([ { - text: ':typeof import("/a")', - rangeOrPosition: markers[0].position, + text: 'typeof import("/a")', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork47.ts b/tests/cases/fourslash/inlineHintsShouldWork47.ts index ecec242ade7c9..409487270413d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork47.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork47.ts @@ -1,27 +1,33 @@ /// //// const z = [1, 2, 3]; -//// z -//// .map(function (e) { return String(e) })/*a*/ -//// .map(function (e) { return Number(e) })/*b*/ -//// .map(function (e) { return String(e) })/*c*/ +//// /*a*/z +//// .map(function (e) { return String(e) })/*b*/ +//// .map(function (e) { return Number(e) })/*c*/ +//// .map(function (e) { return String(e) })/*d*/ //// .map(function (e) { return Number(e) }); const markers = test.markers(); verify.getInlineHints([ { - text: ':string[]', - rangeOrPosition: markers[0].position, + text: 'string[]', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, { - text: ':number[]', - rangeOrPosition: markers[1].position, + text: 'number[]', + triggerPosition: markers[0].position, + rangeOrPosition: markers[2].position, + prefix: ':', whitespaceBefore: true }, { - text: ':string[]', - rangeOrPosition: markers[2].position, + text: 'string[]', + triggerPosition: markers[0].position, + rangeOrPosition: markers[3].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork48.ts b/tests/cases/fourslash/inlineHintsShouldWork48.ts index 91ab158f02fec..c00d9d84ee3ba 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork48.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork48.ts @@ -1,15 +1,17 @@ /// //// const z = [1, 2, 3]; -//// z -//// .map(function (e) { return String(e) })/*a*/ +//// /*a*/z +//// .map(function (e) { return String(e) })/*b*/ //// .map(function (e) { return Number(e) }); const markers = test.markers(); verify.getInlineHints([ { - text: ':string[]', - rangeOrPosition: markers[0].position, + text: 'string[]', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork5.ts b/tests/cases/fourslash/inlineHintsShouldWork5.ts index bc627ae521633..2a655c725cd5d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork5.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork5.ts @@ -7,18 +7,24 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'c:', + text: 'c', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'a:', + text: 'a', rangeOrPosition: markers[1].position, + triggerPosition: markers[1].position, + postfix: ':', whitespaceAfter: true }, { - text: 'b:', + text: 'b', rangeOrPosition: markers[2].position, + triggerPosition: markers[2].position, + postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork50.ts b/tests/cases/fourslash/inlineHintsShouldWork50.ts index 972231971eaaf..e70722a790d3c 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork50.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork50.ts @@ -1,27 +1,33 @@ /// //// const z = [1, 2, 3]; -//// z -//// .map(function (e) { return String(e) })/*a*/ -//// ["map"](function (e) { return Number(e) })/*b*/ -//// .map(function (e) { return String(e) })/*c*/ +//// /*a*/z +//// .map(function (e) { return String(e) })/*b*/ +//// ["map"](function (e) { return Number(e) })/*c*/ +//// .map(function (e) { return String(e) })/*d*/ //// ["map"](function (e) { return Number(e) }); const markers = test.markers(); verify.getInlineHints([ { - text: ':string[]', - rangeOrPosition: markers[0].position, + text: 'string[]', + triggerPosition: markers[0].position, + rangeOrPosition: markers[1].position, + prefix: ':', whitespaceBefore: true }, { - text: ':number[]', - rangeOrPosition: markers[1].position, + text: 'number[]', + triggerPosition: markers[0].position, + rangeOrPosition: markers[2].position, + prefix: ':', whitespaceBefore: true }, { - text: ':string[]', - rangeOrPosition: markers[2].position, + text: 'string[]', + triggerPosition: markers[0].position, + rangeOrPosition: markers[3].position, + prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork6.ts b/tests/cases/fourslash/inlineHintsShouldWork6.ts index 615b6e62145ca..bbc39658c94ae 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork6.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork6.ts @@ -7,8 +7,10 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'c:', + text: 'c', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork7.ts b/tests/cases/fourslash/inlineHintsShouldWork7.ts index fa275f2bcd44a..a052a7470dfc7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork7.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork7.ts @@ -11,18 +11,24 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a:', + text: 'a', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'b:', + text: 'b', rangeOrPosition: markers[1].position, + triggerPosition: markers[1].position, + postfix: ':', whitespaceAfter: true }, { - text: 'c:', + text: 'c', rangeOrPosition: markers[2].position, + triggerPosition: markers[2].position, + postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork8.ts b/tests/cases/fourslash/inlineHintsShouldWork8.ts index c68892a009f9c..a4408eb3fb08e 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork8.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork8.ts @@ -11,18 +11,24 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a:', + text: 'a', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'b:', + text: 'b', rangeOrPosition: markers[1].position, + triggerPosition: markers[1].position, + postfix: ':', whitespaceAfter: true }, { - text: 'c:', + text: 'c', rangeOrPosition: markers[2].position, + triggerPosition: markers[2].position, + postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork9.ts b/tests/cases/fourslash/inlineHintsShouldWork9.ts index 50a911a028816..f0f96eb6c5c3b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork9.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork9.ts @@ -13,23 +13,31 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a:', + text: 'a', rangeOrPosition: markers[0].position, + triggerPosition: markers[0].position, + postfix: ':', whitespaceAfter: true }, { - text: 'b:', + text: 'b', rangeOrPosition: markers[1].position, + triggerPosition: markers[1].position, + postfix: ':', whitespaceAfter: true }, { - text: 'c:', + text: 'c', rangeOrPosition: markers[2].position, + triggerPosition: markers[2].position, + postfix: ':', whitespaceAfter: true }, { - text: 'd:', + text: 'd', rangeOrPosition: markers[3].position, + triggerPosition: markers[3].position, + postfix: ':', whitespaceAfter: true } ], undefined, { From 37a70896337ddd6dd5360d20e7001ed2338a2595 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 17 Jan 2021 00:11:46 +0800 Subject: [PATCH 22/53] Support context value and hover message --- src/server/protocol.ts | 2 ++ src/server/session.ts | 2 ++ src/services/inlineHints.ts | 5 +++++ src/services/types.ts | 2 ++ 4 files changed, 11 insertions(+) diff --git a/src/server/protocol.ts b/src/server/protocol.ts index c9a59d83c3aaa..fcdf3adb6aced 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2496,6 +2496,8 @@ namespace ts.server.protocol { triggerPosition: Location; prefix?: string; postfix?: string; + contextValue?: string; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/session.ts b/src/server/session.ts index 1f2e951173d82..58c64136946b8 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1432,6 +1432,8 @@ namespace ts.server { triggerPosition: scriptInfo.positionToLineOffset(hint.triggerPosition), prefix: hint.prefix, postfix: hint.postfix, + contextValue: hint.contextValue, + hoverMessage: hint.hoverMessage, whitespaceBefore: hint.whitespaceBefore, whitespaceAfter: hint.whitespaceAfter })); diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index f7cba7fccdd35..c538fb04be265 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -6,6 +6,8 @@ namespace ts.InlineHints { triggerPosition: number; prefix?: string; postfix?: string; + contextValue?: string; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -89,6 +91,7 @@ namespace ts.InlineHints { range, triggerPosition: node.getStart(), postfix: ":", + hoverMessage: text, whitespaceAfter: true, }); } @@ -99,6 +102,7 @@ namespace ts.InlineHints { range, triggerPosition: node.getStart(), prefix: ":", + hoverMessage: text, whitespaceBefore: true, }); } @@ -109,6 +113,7 @@ namespace ts.InlineHints { range, triggerPosition: node.getStart(), prefix: "= ", + hoverMessage: text, whitespaceBefore: true, }); } diff --git a/src/services/types.ts b/src/services/types.ts index 3366370e5600d..6be7f3300570a 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -706,6 +706,8 @@ namespace ts { triggerPosition: number; prefix?: string; postfix?: string; + contextValue?: string; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } From 2ccfc985f67e919014320211ebe86bbbe809e043 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 21 Jan 2021 16:02:19 +0800 Subject: [PATCH 23/53] Revert "Support context value and hover message" This reverts commit 37a70896337ddd6dd5360d20e7001ed2338a2595. --- src/server/protocol.ts | 2 -- src/server/session.ts | 2 -- src/services/inlineHints.ts | 5 ----- src/services/types.ts | 2 -- 4 files changed, 11 deletions(-) diff --git a/src/server/protocol.ts b/src/server/protocol.ts index fcdf3adb6aced..c9a59d83c3aaa 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2496,8 +2496,6 @@ namespace ts.server.protocol { triggerPosition: Location; prefix?: string; postfix?: string; - contextValue?: string; - hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/session.ts b/src/server/session.ts index 58c64136946b8..1f2e951173d82 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1432,8 +1432,6 @@ namespace ts.server { triggerPosition: scriptInfo.positionToLineOffset(hint.triggerPosition), prefix: hint.prefix, postfix: hint.postfix, - contextValue: hint.contextValue, - hoverMessage: hint.hoverMessage, whitespaceBefore: hint.whitespaceBefore, whitespaceAfter: hint.whitespaceAfter })); diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index c538fb04be265..f7cba7fccdd35 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -6,8 +6,6 @@ namespace ts.InlineHints { triggerPosition: number; prefix?: string; postfix?: string; - contextValue?: string; - hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -91,7 +89,6 @@ namespace ts.InlineHints { range, triggerPosition: node.getStart(), postfix: ":", - hoverMessage: text, whitespaceAfter: true, }); } @@ -102,7 +99,6 @@ namespace ts.InlineHints { range, triggerPosition: node.getStart(), prefix: ":", - hoverMessage: text, whitespaceBefore: true, }); } @@ -113,7 +109,6 @@ namespace ts.InlineHints { range, triggerPosition: node.getStart(), prefix: "= ", - hoverMessage: text, whitespaceBefore: true, }); } diff --git a/src/services/types.ts b/src/services/types.ts index 6be7f3300570a..3366370e5600d 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -706,8 +706,6 @@ namespace ts { triggerPosition: number; prefix?: string; postfix?: string; - contextValue?: string; - hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } From 0e5f223015ae3285566435afc8cf3779103faf2b Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 21 Jan 2021 16:03:06 +0800 Subject: [PATCH 24/53] Revert "Update protocol changes" This reverts commit e5ca31bc30362144c52c1c2512abc553f0c6b869. --- src/harness/client.ts | 7 +--- src/harness/fourslashImpl.ts | 3 -- src/harness/fourslashInterfaceImpl.ts | 3 -- src/server/protocol.ts | 3 -- src/server/session.ts | 3 -- src/services/inlineHints.ts | 33 +++++++------------ src/services/types.ts | 3 -- tests/cases/fourslash/fourslash.ts | 3 -- .../cases/fourslash/inlineHintsShouldWork1.ts | 8 ++--- .../fourslash/inlineHintsShouldWork11.ts | 8 ++--- .../fourslash/inlineHintsShouldWork12.ts | 8 ++--- .../fourslash/inlineHintsShouldWork13.ts | 4 +-- .../fourslash/inlineHintsShouldWork15.ts | 10 +++--- .../fourslash/inlineHintsShouldWork16.ts | 8 ++--- .../fourslash/inlineHintsShouldWork17.ts | 8 ++--- .../fourslash/inlineHintsShouldWork18.ts | 10 +++--- .../fourslash/inlineHintsShouldWork19.ts | 8 ++--- .../cases/fourslash/inlineHintsShouldWork2.ts | 4 +-- .../fourslash/inlineHintsShouldWork22.ts | 8 ++--- .../fourslash/inlineHintsShouldWork23.ts | 4 +-- .../fourslash/inlineHintsShouldWork24.ts | 14 +++----- .../fourslash/inlineHintsShouldWork25.ts | 8 ++--- .../fourslash/inlineHintsShouldWork26.ts | 8 ++--- .../fourslash/inlineHintsShouldWork27.ts | 16 ++++----- .../fourslash/inlineHintsShouldWork28.ts | 8 ++--- .../fourslash/inlineHintsShouldWork29.ts | 16 +++------ .../cases/fourslash/inlineHintsShouldWork3.ts | 8 ++--- .../fourslash/inlineHintsShouldWork30.ts | 8 ++--- .../fourslash/inlineHintsShouldWork31.ts | 8 ++--- .../fourslash/inlineHintsShouldWork32.ts | 4 +-- .../fourslash/inlineHintsShouldWork33.ts | 4 +-- .../fourslash/inlineHintsShouldWork34.ts | 4 +-- .../fourslash/inlineHintsShouldWork35.ts | 4 +-- .../fourslash/inlineHintsShouldWork36.ts | 8 ++--- .../fourslash/inlineHintsShouldWork37.ts | 8 ++--- .../fourslash/inlineHintsShouldWork38.ts | 10 +++--- .../cases/fourslash/inlineHintsShouldWork4.ts | 12 ++----- .../fourslash/inlineHintsShouldWork40.ts | 8 ++--- .../fourslash/inlineHintsShouldWork41.ts | 8 ++--- .../fourslash/inlineHintsShouldWork42.ts | 8 ++--- .../fourslash/inlineHintsShouldWork43.ts | 8 ++--- .../fourslash/inlineHintsShouldWork44.ts | 24 +++++--------- .../fourslash/inlineHintsShouldWork46.ts | 8 ++--- .../fourslash/inlineHintsShouldWork47.ts | 26 ++++++--------- .../fourslash/inlineHintsShouldWork48.ts | 10 +++--- .../cases/fourslash/inlineHintsShouldWork5.ts | 12 ++----- .../fourslash/inlineHintsShouldWork50.ts | 26 ++++++--------- .../cases/fourslash/inlineHintsShouldWork6.ts | 4 +-- .../cases/fourslash/inlineHintsShouldWork7.ts | 12 ++----- .../cases/fourslash/inlineHintsShouldWork8.ts | 12 ++----- .../cases/fourslash/inlineHintsShouldWork9.ts | 16 +++------ 51 files changed, 152 insertions(+), 324 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 1ef9ce8bdd890..0d498a43c390f 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -644,12 +644,7 @@ namespace ts.server { return response.body!.map(item => ({ // TODO: GH#18217 text: item.text, - range: this.decodeSpan(item.range, file), - triggerPosition: this.lineOffsetToPosition(file, item.triggerPosition), - prefix: item.prefix, - postfix: item.postfix, - whitespaceBefore: item.whitespaceBefore, - whitespaceAfter: item.whitespaceAfter + range: this.decodeSpan(item.range, file) })); } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 40a47da0beaba..8f37891eb8a51 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -850,9 +850,6 @@ namespace FourSlash { ts.zipWith(hints.sort(sortHints), [...expected].sort(compareHintOptions), (actual, expected) => { assert.equal(actual.text, expected.text, "Text"); assert.deepEqual(actual.range, normalizeVerifyInlineHintsOptions(expected.rangeOrPosition), "RangeOrPosition"); - assert.equal(actual.triggerPosition, expected.triggerPosition, "TriggerPosition"); - assert.equal(actual.prefix, expected.prefix, "Prefix"); - assert.equal(actual.postfix, expected.postfix, "Postfix"); assert.equal(actual.whitespaceBefore, expected.whitespaceBefore, "whitespaceBefore"); assert.equal(actual.whitespaceAfter, expected.whitespaceAfter, "whitespaceAfter"); }); diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 15c6746651cb4..65e794bd32fef 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1652,9 +1652,6 @@ namespace FourSlashInterface { export interface VerifyInlineHintsOptions { text: string; rangeOrPosition: number | ts.TextSpan; - triggerPosition: number; - prefix?: string; - postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index c9a59d83c3aaa..60002e1477adb 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2493,9 +2493,6 @@ namespace ts.server.protocol { export interface HintItem { text: string; range: TextSpan; - triggerPosition: Location; - prefix?: string; - postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/session.ts b/src/server/session.ts index 1f2e951173d82..6a28f6167caa6 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1429,9 +1429,6 @@ namespace ts.server { return hints.map(hint => ({ text: hint.text, range: scriptInfo.textSpanToProtoTextSpan(hint.range), - triggerPosition: scriptInfo.positionToLineOffset(hint.triggerPosition), - prefix: hint.prefix, - postfix: hint.postfix, whitespaceBefore: hint.whitespaceBefore, whitespaceAfter: hint.whitespaceAfter })); diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index f7cba7fccdd35..e5d86985408cd 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -3,9 +3,6 @@ namespace ts.InlineHints { interface HintInfo { text: string; range: TextSpan; - triggerPosition: number; - prefix?: string; - postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -83,32 +80,26 @@ namespace ts.InlineHints { return isArrowFunction(node) || isFunctionExpression(node) || isFunctionDeclaration(node) || isMethodDeclaration(node); } - function addNameHints(node: Node, text: string, range: TextSpan) { + function addNameHints(text: string, range: TextSpan) { result.push({ - text: truncation(text, maxHintsLength), + text: `${truncation(text, maxHintsLength)}:`, range, - triggerPosition: node.getStart(), - postfix: ":", whitespaceAfter: true, }); } - function addTypeHints(node: Node, text: string, range: TextSpan) { + function addTypeHints(text: string, range: TextSpan) { result.push({ - text: truncation(text, maxHintsLength), + text: `:${truncation(text, maxHintsLength)}`, range, - triggerPosition: node.getStart(), - prefix: ":", whitespaceBefore: true, }); } - function addEnumMemberValueHints(node: Node, text: string, range: TextSpan) { + function addEnumMemberValueHints(text: string, range: TextSpan) { result.push({ - text: truncation(text, maxHintsLength), + text: `= ${truncation(text, maxHintsLength)}`, range, - triggerPosition: node.getStart(), - prefix: "= ", whitespaceBefore: true, }); } @@ -130,7 +121,7 @@ namespace ts.InlineHints { return; } - addTypeHints(call, typeDisplayString, makeEmptyRange(call.end)); + addTypeHints(typeDisplayString, makeEmptyRange(call.end)); } function shouldCallExpressionHint(call: CallExpression) { @@ -160,7 +151,7 @@ namespace ts.InlineHints { const enumValue = checker.getConstantValue(member); if (enumValue !== undefined) { - addEnumMemberValueHints(member, enumValue.toString(), makeEmptyRange(member.end)); + addEnumMemberValueHints(enumValue.toString(), makeEmptyRange(member.end)); } } @@ -176,7 +167,7 @@ namespace ts.InlineHints { const typeDisplayString = printTypeInSingleLine(declarationType); if (typeDisplayString) { - addTypeHints(decl.name, typeDisplayString, makeEmptyRange(decl.name.end)); + addTypeHints(typeDisplayString, makeEmptyRange(decl.name.end)); } } @@ -200,7 +191,7 @@ namespace ts.InlineHints { const parameterName = checker.getParameterIdentifierNameAtPosition(signature, i); if (parameterName) { if (preferences.includeInlineDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { - addNameHints(arg, unescapeLeadingUnderscores(parameterName), makeEmptyRange(expr.arguments[i].getStart())); + addNameHints(unescapeLeadingUnderscores(parameterName), makeEmptyRange(expr.arguments[i].getStart())); } } } @@ -228,7 +219,7 @@ namespace ts.InlineHints { return; } - addTypeHints(decl, typeDisplayString, makeEmptyRange(getTypeAnnotationPosition(decl))); + addTypeHints(typeDisplayString, makeEmptyRange(getTypeAnnotationPosition(decl))); } function getTypeAnnotationPosition(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { @@ -266,7 +257,7 @@ namespace ts.InlineHints { continue; } - addTypeHints(param, typeDisplayString, makeEmptyRange(param.end)); + addTypeHints(typeDisplayString, makeEmptyRange(param.end)); } } diff --git a/src/services/types.ts b/src/services/types.ts index 3366370e5600d..02903e6697b12 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -703,9 +703,6 @@ namespace ts { export interface InlineHint { text: string; range: TextSpan; - triggerPosition: number; - prefix?: string; - postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 94d3c85e08405..0285224a8537a 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -730,9 +730,6 @@ declare namespace FourSlashInterface { export interface VerifyInlineHintsOptions { text: string; rangeOrPosition: number |TextSpan; - triggerPosition: number; - prefix?: string; - postfix?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/tests/cases/fourslash/inlineHintsShouldWork1.ts b/tests/cases/fourslash/inlineHintsShouldWork1.ts index fcadbd86158a4..64a986ee4359d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork1.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork1.ts @@ -6,17 +6,13 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a', + text: 'a:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'b', + text: 'b:', rangeOrPosition: markers[1].position, - triggerPosition: markers[1].position, - postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork11.ts b/tests/cases/fourslash/inlineHintsShouldWork11.ts index a9e06fa491ee0..7a8888f70cd86 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork11.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork11.ts @@ -10,17 +10,13 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a', + text: 'a:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'b', + text: 'b:', rangeOrPosition: markers[1].position, - triggerPosition: markers[1].position, - postfix: ':', whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork12.ts b/tests/cases/fourslash/inlineHintsShouldWork12.ts index 4b868d0f11289..da4f1942f7887 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork12.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork12.ts @@ -9,17 +9,13 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'b', + text: 'b:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'a', + text: 'a:', rangeOrPosition: markers[1].position, - triggerPosition: markers[1].position, - postfix: ':', whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork13.ts b/tests/cases/fourslash/inlineHintsShouldWork13.ts index c8b016f0b6150..f59ca89dd2325 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork13.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork13.ts @@ -7,10 +7,8 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'b', + text: 'b:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork15.ts b/tests/cases/fourslash/inlineHintsShouldWork15.ts index cf1ce98697803..5ddf52629f77d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork15.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork15.ts @@ -1,15 +1,13 @@ /// -//// const /*a*/a/*b*/ = 123; +//// const a/*a*/ = 123; const markers = test.markers(); verify.getInlineHints([ { - text: '123', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - whitespaceBefore: true, - prefix: ':' + text: ':123', + rangeOrPosition: markers[0].position, + whitespaceBefore: true }, ], undefined, { includeInlineVariableTypeHints: true diff --git a/tests/cases/fourslash/inlineHintsShouldWork16.ts b/tests/cases/fourslash/inlineHintsShouldWork16.ts index 6626553b2fb13..5ddf52629f77d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork16.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork16.ts @@ -1,14 +1,12 @@ /// -//// const /*a*/a/*b*/ = 123; +//// const a/*a*/ = 123; const markers = test.markers(); verify.getInlineHints([ { - text: '123', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':123', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork17.ts b/tests/cases/fourslash/inlineHintsShouldWork17.ts index 899dbc812a154..c9a6c41709e69 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork17.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork17.ts @@ -1,14 +1,12 @@ /// -//// const /*a*/a/*b*/ = { a: 123 }; +//// const a/*a*/ = { a: 123 }; const markers = test.markers(); verify.getInlineHints([ { - text: '{ a: number; }', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':{ a: number; }', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork18.ts b/tests/cases/fourslash/inlineHintsShouldWork18.ts index ce44e62cb168a..0160979ba3ae7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork18.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork18.ts @@ -1,16 +1,14 @@ /// //// class Class {} -//// const /*a*/a/*b*/ = new Class(); +//// const a/*a*/ = new Class(); const markers = test.markers(); verify.getInlineHints([ { - text: 'Class', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - whitespaceBefore: true, - prefix: ':' + text: ':Class', + rangeOrPosition: markers[0].position, + whitespaceBefore: true }, ], undefined, { includeInlineVariableTypeHints: true diff --git a/tests/cases/fourslash/inlineHintsShouldWork19.ts b/tests/cases/fourslash/inlineHintsShouldWork19.ts index 3409c7b40d878..1ca6e0e4a7ee7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork19.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork19.ts @@ -1,14 +1,12 @@ /// -//// const /*a*/a/*b*/ = () => 123; +//// const a/*a*/ = () => 123; const markers = test.markers(); verify.getInlineHints([ { - text: '() => number', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':() => number', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork2.ts b/tests/cases/fourslash/inlineHintsShouldWork2.ts index e7ddcca050feb..4e22cf68a0f03 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork2.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork2.ts @@ -6,10 +6,8 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a', + text: 'a:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork22.ts b/tests/cases/fourslash/inlineHintsShouldWork22.ts index 497d465760542..eb4a745a9e212 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork22.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork22.ts @@ -1,14 +1,12 @@ /// -//// const /*a*/a/*b*/ = "I'm very very very very very very very very very long"; +//// const a/*a*/ = "I'm very very very very very very very very very long"; const markers = test.markers(); verify.getInlineHints([ { - text: `"I'm very very very very ve...`, - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: `:"I'm very very very very ve...`, + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork23.ts b/tests/cases/fourslash/inlineHintsShouldWork23.ts index bb9b7abe6c126..3d6df7ee2a9bd 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork23.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork23.ts @@ -6,10 +6,8 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'Im_very_very_very_very_very...', + text: 'Im_very_very_very_very_very...:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork24.ts b/tests/cases/fourslash/inlineHintsShouldWork24.ts index 72ec8f21dc69f..f5b8d3e5c6a55 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork24.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork24.ts @@ -1,22 +1,18 @@ /// //// type F = (a: string, b: number) => void -//// const f: F = (/*a*/a/*b*/, /*c*/b/*d*/) => { } +//// const f: F = (a/*a*/, b/*b*/) => { } const markers = test.markers(); verify.getInlineHints([ { - text: 'string', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':string', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { - text: 'number', - triggerPosition: markers[2].position, - rangeOrPosition: markers[3].position, - prefix: ':', + text: ':number', + rangeOrPosition: markers[1].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork25.ts b/tests/cases/fourslash/inlineHintsShouldWork25.ts index 05ff2c56cd5d7..9b298e41a5708 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork25.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork25.ts @@ -1,15 +1,13 @@ /// //// function foo (cb: (a: string) => void) {} -//// foo((/*a*/a/*b*/) => { }) +//// foo((a/*a*/) => { }) const markers = test.markers(); verify.getInlineHints([ { - text: 'string', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':string', + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork26.ts b/tests/cases/fourslash/inlineHintsShouldWork26.ts index d7b6d60e4ffe9..6222b02cb8ada 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork26.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork26.ts @@ -1,15 +1,13 @@ /// //// function foo (cb: (a: Exclude<1 | 2 | 3, 1>) => void) {} -//// foo((/*a*/a/*b*/) => { }) +//// foo((a/*a*/) => { }) const markers = test.markers(); verify.getInlineHints([ { - text: '2 | 3', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':2 | 3', + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork27.ts b/tests/cases/fourslash/inlineHintsShouldWork27.ts index fd1905dc4217b..3158a5c27b774 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork27.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork27.ts @@ -1,24 +1,20 @@ /// //// function foo (a: (b: (c: (d: Exclude<1 | 2 | 3, 1>) => void) => void) => void) {} -//// foo(/*a*/a/*b*/ => { -//// a(/*c*/d/*d*/ => {}) +//// foo(a/*a*/ => { +//// a(d/*b*/ => {}) //// }) const markers = test.markers(); verify.getInlineHints([ { - text: '(c: (d: 2 | 3) => void) => ...', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':(c: (d: 2 | 3) => void) => ...', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { - text: '2 | 3', - triggerPosition: markers[2].position, - rangeOrPosition: markers[3].position, - prefix: ':', + text: ':2 | 3', + rangeOrPosition: markers[1].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork28.ts b/tests/cases/fourslash/inlineHintsShouldWork28.ts index aef19f4a2b903..6417e4f958be0 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork28.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork28.ts @@ -1,15 +1,13 @@ /// //// type F = (a: string, b: number) => void -//// const f: F = (/*a*/a/*b*/, b: number) => { } +//// const f: F = (a/*a*/, b: number) => { } const markers = test.markers(); verify.getInlineHints([ { - text: 'string', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':string', + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork29.ts b/tests/cases/fourslash/inlineHintsShouldWork29.ts index 7c32d380e747b..775a942472c94 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork29.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork29.ts @@ -8,31 +8,23 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a', + text: 'a:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: '(c: (d: 2 | 3) => void) => ...', - triggerPosition: markers[0].position, + text: ':(c: (d: 2 | 3) => void) => ...', rangeOrPosition: markers[1].position, - prefix: ':', whitespaceBefore: true }, { - text: 'c', - triggerPosition: markers[2].position, + text: 'c:', rangeOrPosition: markers[2].position, - postfix: ':', whitespaceAfter: true }, { - text: '2 | 3', - triggerPosition: markers[2].position, + text: ':2 | 3', rangeOrPosition: markers[3].position, - prefix: ':', whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork3.ts b/tests/cases/fourslash/inlineHintsShouldWork3.ts index c46d38593729d..7376aeb668b27 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork3.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork3.ts @@ -6,17 +6,13 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a', + text: 'a:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'b', + text: 'b:', rangeOrPosition: markers[1].position, - triggerPosition: markers[1].position, - postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork30.ts b/tests/cases/fourslash/inlineHintsShouldWork30.ts index cb655b3db776c..252bb444cec3b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork30.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork30.ts @@ -1,15 +1,13 @@ /// //// function f(v: T, a: (v: T) => void) {} -//// f(1, /*a*/a/*b*/ => { }) +//// f(1, a/*a*/ => { }) const markers = test.markers(); verify.getInlineHints([ { - text: 'number', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':number', + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork31.ts b/tests/cases/fourslash/inlineHintsShouldWork31.ts index 7620a83bf2759..0a41ae49a70f0 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork31.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork31.ts @@ -4,15 +4,13 @@ //// a: number //// b: string //// }) => void -//// const f: F = (/*a*/a/*b*/) => { } +//// const f: F = (a/*a*/) => { } const markers = test.markers(); verify.getInlineHints([ { - text: '{ a: number; b: string; }', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':{ a: number; b: string; }', + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork32.ts b/tests/cases/fourslash/inlineHintsShouldWork32.ts index 09cdec11d604d..c01375ec1bac3 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork32.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork32.ts @@ -21,10 +21,8 @@ const span = { start: start.position, length: end.position - start.position }; verify.getInlineHints( ['c', 'd', 'e', 'f', 'g', 'h'].map(mark => { return { - text: mark, - triggerPosition: test.markerByName(mark).position, + text: `${mark}:`, rangeOrPosition: test.markerByName(mark).position, - postfix: ':', whitespaceAfter: true } }), span, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork33.ts b/tests/cases/fourslash/inlineHintsShouldWork33.ts index a17a5aded342d..d148a7cd8d5e8 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork33.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork33.ts @@ -21,10 +21,8 @@ const span = { start: start.position, length: end.position - start.position }; verify.getInlineHints( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'].map(mark => { return { - text: mark, - triggerPosition: test.markerByName(mark).position, + text: `${mark}:`, rangeOrPosition: test.markerByName(mark).position, - postfix: ':', whitespaceAfter: true } }), span, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork34.ts b/tests/cases/fourslash/inlineHintsShouldWork34.ts index ac2717ddd9448..e499b3968eb98 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork34.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork34.ts @@ -20,10 +20,8 @@ const markers = test.markers(); verify.getInlineHints( markers.map(m => ({ - text: 'v', - triggerPosition: m.position, + text: 'v:', rangeOrPosition: m.position, - postfix: ':', whitespaceAfter: true })) , undefined, { includeInlineParameterNameHints: true, diff --git a/tests/cases/fourslash/inlineHintsShouldWork35.ts b/tests/cases/fourslash/inlineHintsShouldWork35.ts index f3da66ff8a605..c81f04c71aab0 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork35.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork35.ts @@ -20,10 +20,8 @@ const markers = test.markers(); verify.getInlineHints( markers.map(m => ({ - text: 'v', - triggerPosition: m.position, + text: 'v:', rangeOrPosition: m.position, - postfix: ':', whitespaceAfter: true })) , undefined, { includeInlineParameterNameHints: true, diff --git a/tests/cases/fourslash/inlineHintsShouldWork36.ts b/tests/cases/fourslash/inlineHintsShouldWork36.ts index 3fed90feb773a..cd3ce7a9d95cd 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork36.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork36.ts @@ -7,17 +7,13 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a', - triggerPosition: markers[0].position, + text: 'a:', rangeOrPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'b', - triggerPosition: markers[1].position, + text: 'b:', rangeOrPosition: markers[1].position, - postfix: ':', whitespaceAfter: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork37.ts b/tests/cases/fourslash/inlineHintsShouldWork37.ts index 90455a2e30b1b..ef5bd74c72c76 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork37.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork37.ts @@ -1,7 +1,7 @@ /// //// class C { -//// /*a*/a/*b*/ = 1 +//// a/*a*/ = 1 //// b: number = 2 //// c; //// } @@ -9,10 +9,8 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'number', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':number', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork38.ts b/tests/cases/fourslash/inlineHintsShouldWork38.ts index 0950bd2494a0c..270858539165b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork38.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork38.ts @@ -1,17 +1,15 @@ /// -//// /*a*/function foo ()/*b*/ { +//// function foo ()/*a*/ { //// return 1 //// } const markers = test.markers(); verify.getInlineHints([ { - text: 'number', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', - whitespaceBefore: true, + text: ':number', + rangeOrPosition: markers[0].position, + whitespaceBefore: true }, ], undefined, { includeInlineFunctionLikeReturnTypeHints: true, diff --git a/tests/cases/fourslash/inlineHintsShouldWork4.ts b/tests/cases/fourslash/inlineHintsShouldWork4.ts index 9d91db8891445..06031ceb3cef4 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork4.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork4.ts @@ -10,24 +10,18 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'w', + text: 'w:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'a', + text: 'a:', rangeOrPosition: markers[1].position, - triggerPosition: markers[1].position, - postfix: ':', whitespaceAfter: true }, { - text: 'b', + text: 'b:', rangeOrPosition: markers[2].position, - triggerPosition: markers[2].position, - postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork40.ts b/tests/cases/fourslash/inlineHintsShouldWork40.ts index 5708200071a30..b6c891a571703 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork40.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork40.ts @@ -1,7 +1,7 @@ /// //// class C { -//// /*a*/foo()/*b*/ { +//// foo()/*a*/ { //// return 1 //// } //// } @@ -9,10 +9,8 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'number', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':number', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork41.ts b/tests/cases/fourslash/inlineHintsShouldWork41.ts index f631481689046..5b76af18a3b63 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork41.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork41.ts @@ -1,14 +1,12 @@ /// -//// const a = /*a*/()/*b*/ => 1 +//// const a = ()/*a*/ => 1 const markers = test.markers(); verify.getInlineHints([ { - text: 'number', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':number', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork42.ts b/tests/cases/fourslash/inlineHintsShouldWork42.ts index 23e81f9e1d2df..657a1a6bf5897 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork42.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork42.ts @@ -1,14 +1,12 @@ /// -//// const a = /*a*/function ()/*b*/ { return 1} +//// const a = function ()/*a*/ { return 1} const markers = test.markers(); verify.getInlineHints([ { - text: 'number', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':number', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork43.ts b/tests/cases/fourslash/inlineHintsShouldWork43.ts index cc5b53bf8010d..26626f53df09d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork43.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork43.ts @@ -1,14 +1,12 @@ /// -//// const a = /*a*/b/*b*/ => 1 +//// const a = b/*a*/ => 1 const markers = test.markers(); verify.getInlineHints([ { - text: 'number', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':number', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork44.ts b/tests/cases/fourslash/inlineHintsShouldWork44.ts index 03a5d2b95bd10..1b6fcda680954 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork44.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork44.ts @@ -1,34 +1,28 @@ /// //// enum E { -//// /*a*/A/*b*/, -//// /*c*/AA/*d*/, +//// A/*a*/, +//// AA/*b*/, //// B = 10, -//// /*e*/BB/*f*/, +//// BB/*c*/, //// C = 'C', //// } const markers = test.markers(); verify.getInlineHints([ { - text: '0', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: '= ', + text: '= 0', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { - text: '1', - triggerPosition: markers[2].position, - rangeOrPosition: markers[3].position, - prefix: '= ', + text: '= 1', + rangeOrPosition: markers[1].position, whitespaceBefore: true }, { - text: '11', - triggerPosition: markers[4].position, - rangeOrPosition: markers[5].position, - prefix: '= ', + text: '= 11', + rangeOrPosition: markers[2].position, whitespaceBefore: true }, ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork46.ts b/tests/cases/fourslash/inlineHintsShouldWork46.ts index dc9de4f50ac20..a2ef70e880ae8 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork46.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork46.ts @@ -7,16 +7,14 @@ //// module.exports.a = 1 // @Filename: /b.js -//// const /*a*/a/*b*/ = require('./a'); +//// const a/*a*/ = require('./a'); goTo.file('/b.js') const markers = test.markers(); verify.getInlineHints([ { - text: 'typeof import("/a")', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':typeof import("/a")', + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork47.ts b/tests/cases/fourslash/inlineHintsShouldWork47.ts index 409487270413d..ecec242ade7c9 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork47.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork47.ts @@ -1,33 +1,27 @@ /// //// const z = [1, 2, 3]; -//// /*a*/z -//// .map(function (e) { return String(e) })/*b*/ -//// .map(function (e) { return Number(e) })/*c*/ -//// .map(function (e) { return String(e) })/*d*/ +//// z +//// .map(function (e) { return String(e) })/*a*/ +//// .map(function (e) { return Number(e) })/*b*/ +//// .map(function (e) { return String(e) })/*c*/ //// .map(function (e) { return Number(e) }); const markers = test.markers(); verify.getInlineHints([ { - text: 'string[]', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':string[]', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { - text: 'number[]', - triggerPosition: markers[0].position, - rangeOrPosition: markers[2].position, - prefix: ':', + text: ':number[]', + rangeOrPosition: markers[1].position, whitespaceBefore: true }, { - text: 'string[]', - triggerPosition: markers[0].position, - rangeOrPosition: markers[3].position, - prefix: ':', + text: ':string[]', + rangeOrPosition: markers[2].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork48.ts b/tests/cases/fourslash/inlineHintsShouldWork48.ts index c00d9d84ee3ba..91ab158f02fec 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork48.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork48.ts @@ -1,17 +1,15 @@ /// //// const z = [1, 2, 3]; -//// /*a*/z -//// .map(function (e) { return String(e) })/*b*/ +//// z +//// .map(function (e) { return String(e) })/*a*/ //// .map(function (e) { return Number(e) }); const markers = test.markers(); verify.getInlineHints([ { - text: 'string[]', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':string[]', + rangeOrPosition: markers[0].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork5.ts b/tests/cases/fourslash/inlineHintsShouldWork5.ts index 2a655c725cd5d..bc627ae521633 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork5.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork5.ts @@ -7,24 +7,18 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'c', + text: 'c:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'a', + text: 'a:', rangeOrPosition: markers[1].position, - triggerPosition: markers[1].position, - postfix: ':', whitespaceAfter: true }, { - text: 'b', + text: 'b:', rangeOrPosition: markers[2].position, - triggerPosition: markers[2].position, - postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork50.ts b/tests/cases/fourslash/inlineHintsShouldWork50.ts index e70722a790d3c..972231971eaaf 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork50.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork50.ts @@ -1,33 +1,27 @@ /// //// const z = [1, 2, 3]; -//// /*a*/z -//// .map(function (e) { return String(e) })/*b*/ -//// ["map"](function (e) { return Number(e) })/*c*/ -//// .map(function (e) { return String(e) })/*d*/ +//// z +//// .map(function (e) { return String(e) })/*a*/ +//// ["map"](function (e) { return Number(e) })/*b*/ +//// .map(function (e) { return String(e) })/*c*/ //// ["map"](function (e) { return Number(e) }); const markers = test.markers(); verify.getInlineHints([ { - text: 'string[]', - triggerPosition: markers[0].position, - rangeOrPosition: markers[1].position, - prefix: ':', + text: ':string[]', + rangeOrPosition: markers[0].position, whitespaceBefore: true }, { - text: 'number[]', - triggerPosition: markers[0].position, - rangeOrPosition: markers[2].position, - prefix: ':', + text: ':number[]', + rangeOrPosition: markers[1].position, whitespaceBefore: true }, { - text: 'string[]', - triggerPosition: markers[0].position, - rangeOrPosition: markers[3].position, - prefix: ':', + text: ':string[]', + rangeOrPosition: markers[2].position, whitespaceBefore: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork6.ts b/tests/cases/fourslash/inlineHintsShouldWork6.ts index bbc39658c94ae..615b6e62145ca 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork6.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork6.ts @@ -7,10 +7,8 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'c', + text: 'c:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork7.ts b/tests/cases/fourslash/inlineHintsShouldWork7.ts index a052a7470dfc7..fa275f2bcd44a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork7.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork7.ts @@ -11,24 +11,18 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a', + text: 'a:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'b', + text: 'b:', rangeOrPosition: markers[1].position, - triggerPosition: markers[1].position, - postfix: ':', whitespaceAfter: true }, { - text: 'c', + text: 'c:', rangeOrPosition: markers[2].position, - triggerPosition: markers[2].position, - postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork8.ts b/tests/cases/fourslash/inlineHintsShouldWork8.ts index a4408eb3fb08e..c68892a009f9c 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork8.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork8.ts @@ -11,24 +11,18 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a', + text: 'a:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'b', + text: 'b:', rangeOrPosition: markers[1].position, - triggerPosition: markers[1].position, - postfix: ':', whitespaceAfter: true }, { - text: 'c', + text: 'c:', rangeOrPosition: markers[2].position, - triggerPosition: markers[2].position, - postfix: ':', whitespaceAfter: true } ], undefined, { diff --git a/tests/cases/fourslash/inlineHintsShouldWork9.ts b/tests/cases/fourslash/inlineHintsShouldWork9.ts index f0f96eb6c5c3b..50a911a028816 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork9.ts +++ b/tests/cases/fourslash/inlineHintsShouldWork9.ts @@ -13,31 +13,23 @@ const markers = test.markers(); verify.getInlineHints([ { - text: 'a', + text: 'a:', rangeOrPosition: markers[0].position, - triggerPosition: markers[0].position, - postfix: ':', whitespaceAfter: true }, { - text: 'b', + text: 'b:', rangeOrPosition: markers[1].position, - triggerPosition: markers[1].position, - postfix: ':', whitespaceAfter: true }, { - text: 'c', + text: 'c:', rangeOrPosition: markers[2].position, - triggerPosition: markers[2].position, - postfix: ':', whitespaceAfter: true }, { - text: 'd', + text: 'd:', rangeOrPosition: markers[3].position, - triggerPosition: markers[3].position, - postfix: ':', whitespaceAfter: true } ], undefined, { From 7197d0dc200c87f0d49e41b6201b481e612f4a76 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 21 Jan 2021 16:41:24 +0800 Subject: [PATCH 25/53] Add hover message --- src/harness/client.ts | 5 ++++- src/harness/fourslashImpl.ts | 2 ++ src/harness/fourslashInterfaceImpl.ts | 1 + src/server/protocol.ts | 1 + src/server/session.ts | 1 + src/services/inlineHints.ts | 10 ++-------- src/services/types.ts | 1 + tests/cases/fourslash/fourslash.ts | 1 + 8 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 0d498a43c390f..05df0bdfb7448 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -644,7 +644,10 @@ namespace ts.server { return response.body!.map(item => ({ // TODO: GH#18217 text: item.text, - range: this.decodeSpan(item.range, file) + range: this.decodeSpan(item.range, file), + hoverMessage: item.hoverMessage, + whitespaceBefore: item.whitespaceBefore, + whitespaceAfter: item.whitespaceAfter })); } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 8f37891eb8a51..380706bd48bef 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -1,3 +1,4 @@ + namespace FourSlash { import ArrayOrSingle = FourSlashInterface.ArrayOrSingle; @@ -850,6 +851,7 @@ namespace FourSlash { ts.zipWith(hints.sort(sortHints), [...expected].sort(compareHintOptions), (actual, expected) => { assert.equal(actual.text, expected.text, "Text"); assert.deepEqual(actual.range, normalizeVerifyInlineHintsOptions(expected.rangeOrPosition), "RangeOrPosition"); + assert.equal(actual.hoverMessage, expected.hoverMessage, "hoverMessage"); assert.equal(actual.whitespaceBefore, expected.whitespaceBefore, "whitespaceBefore"); assert.equal(actual.whitespaceAfter, expected.whitespaceAfter, "whitespaceAfter"); }); diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 65e794bd32fef..803678ec1d8fa 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1652,6 +1652,7 @@ namespace FourSlashInterface { export interface VerifyInlineHintsOptions { text: string; rangeOrPosition: number | ts.TextSpan; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 60002e1477adb..8ae4d17a9b181 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2493,6 +2493,7 @@ namespace ts.server.protocol { export interface HintItem { text: string; range: TextSpan; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/session.ts b/src/server/session.ts index 6a28f6167caa6..934c331406185 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1429,6 +1429,7 @@ namespace ts.server { return hints.map(hint => ({ text: hint.text, range: scriptInfo.textSpanToProtoTextSpan(hint.range), + hoverMessage: hint.hoverMessage, whitespaceBefore: hint.whitespaceBefore, whitespaceAfter: hint.whitespaceAfter })); diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index e5d86985408cd..2946f2d2ad7f4 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -1,19 +1,13 @@ /* @internal */ namespace ts.InlineHints { - interface HintInfo { - text: string; - range: TextSpan; - whitespaceBefore?: boolean; - whitespaceAfter?: boolean; - } const maxHintsLength = 30; - export function provideInlineHints(context: InlineHintsContext): HintInfo[] { + export function provideInlineHints(context: InlineHintsContext): InlineHint[] { const { file, program, span, cancellationToken, preferences } = context; const checker = program.getTypeChecker(); - const result: HintInfo[] = []; + const result: InlineHint[] = []; const callExpressionHintableCache = new Map(); visitor(file); diff --git a/src/services/types.ts b/src/services/types.ts index 02903e6697b12..f8b06670f4a20 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -703,6 +703,7 @@ namespace ts { export interface InlineHint { text: string; range: TextSpan; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 0285224a8537a..b6441f16ccc56 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -730,6 +730,7 @@ declare namespace FourSlashInterface { export interface VerifyInlineHintsOptions { text: string; rangeOrPosition: number |TextSpan; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } From e785943ef1cbb496fb28a995e44618d5bb631fe6 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 21 Jan 2021 17:18:46 +0800 Subject: [PATCH 26/53] Accept baseline --- tests/baselines/reference/api/tsserverlibrary.d.ts | 7 +++++-- tests/baselines/reference/api/typescript.d.ts | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 25f5b7f6bc83d..861b92a1055d2 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5732,7 +5732,8 @@ declare namespace ts { } interface InlineHint { text: string; - position: number; + range: TextSpan; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -8427,7 +8428,8 @@ declare namespace ts.server.protocol { } interface HintItem { text: string; - position: Location; + range: TextSpan; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -9252,6 +9254,7 @@ declare namespace ts.server { */ lineOffsetToPosition(line: number, offset: number): number; positionToLineOffset(position: number): protocol.Location; + textSpanToProtoTextSpan(range: TextSpan): protocol.TextSpan; isJavaScript(): boolean; } } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 8a052714e4c8d..a5742e12069cb 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5732,7 +5732,8 @@ declare namespace ts { } interface InlineHint { text: string; - position: number; + range: TextSpan; + hoverMessage?: string; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } From 637c7f8124aa5b20d48de4dc918ab7065f83dcde Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Thu, 4 Feb 2021 11:15:43 +0800 Subject: [PATCH 27/53] Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser --- src/services/inlineHints.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 2946f2d2ad7f4..3cd8e988f1dda 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -166,7 +166,8 @@ namespace ts.InlineHints { } function visitCallOrNewExpression(expr: CallExpression | NewExpression) { - if (!expr.arguments || !expr.arguments.length) { + const args = expr.arguments; + if (!args || !args.length) { return; } @@ -176,8 +177,8 @@ namespace ts.InlineHints { return; } - for (let i = 0; i < expr.arguments.length; ++i) { - const arg = expr.arguments[i]; + for (let i = 0; i < args.length; ++i) { + const arg = args[i]; if (!preferences.includeInlineNonLiteralParameterNameHints && !isHintableExpression(arg)) { continue; } @@ -185,7 +186,7 @@ namespace ts.InlineHints { const parameterName = checker.getParameterIdentifierNameAtPosition(signature, i); if (parameterName) { if (preferences.includeInlineDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { - addNameHints(unescapeLeadingUnderscores(parameterName), makeEmptyRange(expr.arguments[i].getStart())); + addNameHints(unescapeLeadingUnderscores(parameterName), makeEmptyRange(args[i].getStart())); } } } @@ -297,4 +298,4 @@ namespace ts.InlineHints { printer.writeNode(EmitHint.Unspecified, node, /*sourceFile*/ file, writer); } } -} \ No newline at end of file +} From b3c3e7e1b136205721bf4365942a31abb3722e6c Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Thu, 4 Feb 2021 11:16:01 +0800 Subject: [PATCH 28/53] Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser --- src/services/inlineHints.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 3cd8e988f1dda..46221bd18fca2 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -18,7 +18,8 @@ namespace ts.InlineHints { return; } - switch(node.kind) { + switch (node.kind) { + case SyntaxKind.ModuleDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: From a374417ab8fe39e629248cf99256a963c3b311c3 Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Thu, 4 Feb 2021 17:12:00 +0800 Subject: [PATCH 29/53] Cache across the program --- src/compiler/types.ts | 1 + src/services/inlineHints.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b583a0f2e0292..2774981ef156c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3886,6 +3886,7 @@ namespace ts { * This implementation handles file exists to be true if file is source of project reference redirect when program is created using useSourceOfProjectReferenceRedirect */ /*@internal*/ fileExists(fileName: string): boolean; + /*@internal*/ inlineHintsCallExpressionHintableCache?: ESMap } /*@internal*/ diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 46221bd18fca2..e54d777d3d3e7 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -8,7 +8,7 @@ namespace ts.InlineHints { const checker = program.getTypeChecker(); const result: InlineHint[] = []; - const callExpressionHintableCache = new Map(); + const callExpressionHintableCache = program.inlineHintsCallExpressionHintableCache ??= new Map(); visitor(file); return result; From 5767d7e7c96bfcfe649de27a5c117d10b6d896f5 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 7 May 2021 14:01:39 +0800 Subject: [PATCH 30/53] Fix possible undefined --- src/services/inlineHints.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index e54d777d3d3e7..4191050297a94 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -263,7 +263,7 @@ namespace ts.InlineHints { return undefined; } - const signatureParamType = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration); + const signatureParamType = checker.getTypeOfSymbolAtLocation(symbol, valueDeclaration); return printTypeInSingleLine(signatureParamType); } From d7d72d65c480b14c166aeac6d0a6046eab43e421 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 3 Jun 2021 13:29:40 +0800 Subject: [PATCH 31/53] Update protocol changes --- src/compiler/types.ts | 22 ++--- src/harness/client.ts | 12 +-- src/harness/fourslashImpl.ts | 32 ++----- src/harness/fourslashInterfaceImpl.ts | 10 +-- src/harness/harnessLanguageService.ts | 4 +- src/server/protocol.ts | 26 +++--- src/server/session.ts | 12 +-- .../{inlineHints.ts => inlayHints.ts} | 59 +++++++------ src/services/services.ts | 10 +-- src/services/shims.ts | 8 +- src/services/tsconfig.json | 2 +- src/services/types.ts | 38 +++++---- src/testRunner/unittests/tsserver/session.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 84 +++++++++++-------- tests/baselines/reference/api/typescript.d.ts | 57 +++++++------ tests/cases/fourslash/fourslash.ts | 39 +++++---- ...houldWork1.ts => inlayHintsShouldWork1.ts} | 10 ++- ...uldWork10.ts => inlayHintsShouldWork10.ts} | 4 +- ...uldWork11.ts => inlayHintsShouldWork11.ts} | 10 ++- ...uldWork12.ts => inlayHintsShouldWork12.ts} | 10 ++- .../cases/fourslash/inlayHintsShouldWork13.ts | 19 +++++ ...uldWork14.ts => inlayHintsShouldWork14.ts} | 4 +- ...uldWork15.ts => inlayHintsShouldWork15.ts} | 7 +- ...uldWork16.ts => inlayHintsShouldWork16.ts} | 7 +- ...uldWork17.ts => inlayHintsShouldWork17.ts} | 7 +- ...uldWork18.ts => inlayHintsShouldWork18.ts} | 7 +- ...uldWork19.ts => inlayHintsShouldWork19.ts} | 7 +- ...houldWork2.ts => inlayHintsShouldWork2.ts} | 7 +- .../cases/fourslash/inlayHintsShouldWork20.ts | 7 ++ .../cases/fourslash/inlayHintsShouldWork21.ts | 7 ++ ...uldWork22.ts => inlayHintsShouldWork22.ts} | 7 +- ...uldWork23.ts => inlayHintsShouldWork23.ts} | 7 +- ...uldWork24.ts => inlayHintsShouldWork24.ts} | 10 ++- ...uldWork25.ts => inlayHintsShouldWork25.ts} | 7 +- ...uldWork26.ts => inlayHintsShouldWork26.ts} | 7 +- ...uldWork27.ts => inlayHintsShouldWork27.ts} | 10 ++- ...uldWork28.ts => inlayHintsShouldWork28.ts} | 7 +- ...uldWork29.ts => inlayHintsShouldWork29.ts} | 18 ++-- ...houldWork3.ts => inlayHintsShouldWork3.ts} | 10 ++- ...uldWork30.ts => inlayHintsShouldWork30.ts} | 7 +- ...uldWork31.ts => inlayHintsShouldWork31.ts} | 7 +- ...uldWork32.ts => inlayHintsShouldWork32.ts} | 7 +- ...uldWork33.ts => inlayHintsShouldWork33.ts} | 7 +- ...uldWork34.ts => inlayHintsShouldWork34.ts} | 9 +- ...uldWork35.ts => inlayHintsShouldWork35.ts} | 9 +- .../cases/fourslash/inlayHintsShouldWork36.ts | 25 ++++++ ...uldWork37.ts => inlayHintsShouldWork37.ts} | 7 +- ...uldWork38.ts => inlayHintsShouldWork38.ts} | 7 +- ...uldWork39.ts => inlayHintsShouldWork39.ts} | 4 +- ...houldWork4.ts => inlayHintsShouldWork4.ts} | 13 +-- ...uldWork40.ts => inlayHintsShouldWork40.ts} | 7 +- ...uldWork41.ts => inlayHintsShouldWork41.ts} | 7 +- ...uldWork42.ts => inlayHintsShouldWork42.ts} | 7 +- ...uldWork43.ts => inlayHintsShouldWork43.ts} | 7 +- ...uldWork44.ts => inlayHintsShouldWork44.ts} | 13 +-- ...uldWork45.ts => inlayHintsShouldWork45.ts} | 6 +- ...uldWork46.ts => inlayHintsShouldWork46.ts} | 9 +- ...uldWork47.ts => inlayHintsShouldWork47.ts} | 13 +-- ...uldWork48.ts => inlayHintsShouldWork48.ts} | 7 +- ...uldWork49.ts => inlayHintsShouldWork49.ts} | 4 +- ...houldWork5.ts => inlayHintsShouldWork5.ts} | 13 +-- ...uldWork50.ts => inlayHintsShouldWork50.ts} | 13 +-- ...uldWork51.ts => inlayHintsShouldWork51.ts} | 4 +- ...houldWork6.ts => inlayHintsShouldWork6.ts} | 7 +- ...houldWork7.ts => inlayHintsShouldWork7.ts} | 13 +-- ...houldWork8.ts => inlayHintsShouldWork8.ts} | 13 +-- ...houldWork9.ts => inlayHintsShouldWork9.ts} | 16 ++-- .../fourslash/inlineHintsShouldWork13.ts | 18 ---- .../fourslash/inlineHintsShouldWork20.ts | 7 -- .../fourslash/inlineHintsShouldWork21.ts | 7 -- .../fourslash/inlineHintsShouldWork36.ts | 23 ----- 71 files changed, 507 insertions(+), 422 deletions(-) rename src/services/{inlineHints.ts => inlayHints.ts} (79%) rename tests/cases/fourslash/{inlineHintsShouldWork1.ts => inlayHintsShouldWork1.ts} (53%) rename tests/cases/fourslash/{inlineHintsShouldWork10.ts => inlayHintsShouldWork10.ts} (59%) rename tests/cases/fourslash/{inlineHintsShouldWork11.ts => inlayHintsShouldWork11.ts} (58%) rename tests/cases/fourslash/{inlineHintsShouldWork12.ts => inlayHintsShouldWork12.ts} (57%) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork13.ts rename tests/cases/fourslash/{inlineHintsShouldWork14.ts => inlayHintsShouldWork14.ts} (53%) rename tests/cases/fourslash/{inlineHintsShouldWork15.ts => inlayHintsShouldWork15.ts} (54%) rename tests/cases/fourslash/{inlineHintsShouldWork16.ts => inlayHintsShouldWork16.ts} (54%) rename tests/cases/fourslash/{inlineHintsShouldWork17.ts => inlayHintsShouldWork17.ts} (56%) rename tests/cases/fourslash/{inlineHintsShouldWork18.ts => inlayHintsShouldWork18.ts} (57%) rename tests/cases/fourslash/{inlineHintsShouldWork19.ts => inlayHintsShouldWork19.ts} (56%) rename tests/cases/fourslash/{inlineHintsShouldWork2.ts => inlayHintsShouldWork2.ts} (58%) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork20.ts create mode 100644 tests/cases/fourslash/inlayHintsShouldWork21.ts rename tests/cases/fourslash/{inlineHintsShouldWork22.ts => inlayHintsShouldWork22.ts} (62%) rename tests/cases/fourslash/{inlineHintsShouldWork23.ts => inlayHintsShouldWork23.ts} (63%) rename tests/cases/fourslash/{inlineHintsShouldWork24.ts => inlayHintsShouldWork24.ts} (56%) rename tests/cases/fourslash/{inlineHintsShouldWork25.ts => inlayHintsShouldWork25.ts} (58%) rename tests/cases/fourslash/{inlineHintsShouldWork26.ts => inlayHintsShouldWork26.ts} (60%) rename tests/cases/fourslash/{inlineHintsShouldWork27.ts => inlayHintsShouldWork27.ts} (61%) rename tests/cases/fourslash/{inlineHintsShouldWork28.ts => inlayHintsShouldWork28.ts} (60%) rename tests/cases/fourslash/{inlineHintsShouldWork29.ts => inlayHintsShouldWork29.ts} (53%) rename tests/cases/fourslash/{inlineHintsShouldWork3.ts => inlayHintsShouldWork3.ts} (54%) rename tests/cases/fourslash/{inlineHintsShouldWork30.ts => inlayHintsShouldWork30.ts} (58%) rename tests/cases/fourslash/{inlineHintsShouldWork31.ts => inlayHintsShouldWork31.ts} (63%) rename tests/cases/fourslash/{inlineHintsShouldWork32.ts => inlayHintsShouldWork32.ts} (82%) rename tests/cases/fourslash/{inlineHintsShouldWork33.ts => inlayHintsShouldWork33.ts} (80%) rename tests/cases/fourslash/{inlineHintsShouldWork34.ts => inlayHintsShouldWork34.ts} (68%) rename tests/cases/fourslash/{inlineHintsShouldWork35.ts => inlayHintsShouldWork35.ts} (68%) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork36.ts rename tests/cases/fourslash/{inlineHintsShouldWork37.ts => inlayHintsShouldWork37.ts} (58%) rename tests/cases/fourslash/{inlineHintsShouldWork38.ts => inlayHintsShouldWork38.ts} (56%) rename tests/cases/fourslash/{inlineHintsShouldWork39.ts => inlayHintsShouldWork39.ts} (56%) rename tests/cases/fourslash/{inlineHintsShouldWork4.ts => inlayHintsShouldWork4.ts} (59%) rename tests/cases/fourslash/{inlineHintsShouldWork40.ts => inlayHintsShouldWork40.ts} (58%) rename tests/cases/fourslash/{inlineHintsShouldWork41.ts => inlayHintsShouldWork41.ts} (53%) rename tests/cases/fourslash/{inlineHintsShouldWork42.ts => inlayHintsShouldWork42.ts} (55%) rename tests/cases/fourslash/{inlineHintsShouldWork43.ts => inlayHintsShouldWork43.ts} (53%) rename tests/cases/fourslash/{inlineHintsShouldWork44.ts => inlayHintsShouldWork44.ts} (54%) rename tests/cases/fourslash/{inlineHintsShouldWork45.ts => inlayHintsShouldWork45.ts} (59%) rename tests/cases/fourslash/{inlineHintsShouldWork46.ts => inlayHintsShouldWork46.ts} (60%) rename tests/cases/fourslash/{inlineHintsShouldWork47.ts => inlayHintsShouldWork47.ts} (63%) rename tests/cases/fourslash/{inlineHintsShouldWork48.ts => inlayHintsShouldWork48.ts} (65%) rename tests/cases/fourslash/{inlineHintsShouldWork49.ts => inlayHintsShouldWork49.ts} (64%) rename tests/cases/fourslash/{inlineHintsShouldWork5.ts => inlayHintsShouldWork5.ts} (54%) rename tests/cases/fourslash/{inlineHintsShouldWork50.ts => inlayHintsShouldWork50.ts} (63%) rename tests/cases/fourslash/{inlineHintsShouldWork51.ts => inlayHintsShouldWork51.ts} (68%) rename tests/cases/fourslash/{inlineHintsShouldWork6.ts => inlayHintsShouldWork6.ts} (61%) rename tests/cases/fourslash/{inlineHintsShouldWork7.ts => inlayHintsShouldWork7.ts} (57%) rename tests/cases/fourslash/{inlineHintsShouldWork8.ts => inlayHintsShouldWork8.ts} (58%) rename tests/cases/fourslash/{inlineHintsShouldWork9.ts => inlayHintsShouldWork9.ts} (56%) delete mode 100644 tests/cases/fourslash/inlineHintsShouldWork13.ts delete mode 100644 tests/cases/fourslash/inlineHintsShouldWork20.ts delete mode 100644 tests/cases/fourslash/inlineHintsShouldWork21.ts delete mode 100644 tests/cases/fourslash/inlineHintsShouldWork36.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index aa7e27c436885..db611266ac249 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3939,7 +3939,7 @@ namespace ts { * This implementation handles file exists to be true if file is source of project reference redirect when program is created using useSourceOfProjectReferenceRedirect */ /*@internal*/ fileExists(fileName: string): boolean; - /*@internal*/ inlineHintsCallExpressionHintableCache?: ESMap + /*@internal*/ inlayHintsCallExpressionHintableCache?: ESMap } /*@internal*/ @@ -8414,16 +8414,16 @@ namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlineParameterNameHints?: boolean; - readonly includeInlineNonLiteralParameterNameHints?: boolean; - readonly includeInlineDuplicatedParameterNameHints?: boolean; - readonly includeInlineFunctionParameterTypeHints?: boolean; - readonly includeInlineVariableTypeHints?: boolean; - readonly includeInlineRequireAssignedVariableTypeHints?: boolean; - readonly includeInlinePropertyDeclarationTypeHints?: boolean; - readonly includeInlineFunctionLikeReturnTypeHints?: boolean; - readonly includeInlineEnumMemberValueHints?: boolean; - readonly includeInlineCallChainsHints?: boolean; + readonly includeInlayParameterNameHints?: boolean; + readonly includeInlayNonLiteralParameterNameHints?: boolean; + readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayFunctionParameterTypeHints?: boolean; + readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayRequireAssignedVariableTypeHints?: boolean; + readonly includeInlayPropertyDeclarationTypeHints?: boolean; + readonly includeInlayFunctionLikeReturnTypeHints?: boolean; + readonly includeInlayEnumMemberValueHints?: boolean; + readonly includeInlayCallChainsHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ diff --git a/src/harness/client.ts b/src/harness/client.ts index 2195ef98ebc64..e555ed759500c 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -646,17 +646,17 @@ namespace ts.server { applyCodeActionCommand = notImplemented; - provideInlineHints(file: string, span: TextSpan): InlineHint[] { + provideInlayHints(file: string, span: TextSpan): InlayHint[] { const { start, length } = span; - const args: protocol.ProvideInlineHintsRequestArgs = { file, start, length }; + const args: protocol.ProvideInlayHintsRequestArgs = { file, start, length }; - const request = this.processRequest(CommandNames.ProvideInlineHints, args); - const response = this.processResponse(request); + const request = this.processRequest(CommandNames.ProvideInlayHints, args); + const response = this.processResponse(request); return response.body!.map(item => ({ // TODO: GH#18217 text: item.text, - range: this.decodeSpan(item.range, file), - hoverMessage: item.hoverMessage, + position: this.lineOffsetToPosition(file, item.position), + kind: item.kind as InlayHintKind | undefined, whitespaceBefore: item.whitespaceBefore, whitespaceAfter: item.whitespaceAfter })); diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 5576b16e7e568..a666546b0feec 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -837,33 +837,17 @@ namespace FourSlash { }); } - public verifyInlineHints(expected: readonly FourSlashInterface.VerifyInlineHintsOptions[], span: ts.TextSpan = { start: 0, length: this.activeFile.content.length }, preference?: ts.InlineHintsOptions) { - const hints = this.languageService.provideInlineHints(this.activeFile.fileName, span, preference); + public verifyInlayHints(expected: readonly FourSlashInterface.VerifyInlayHintsOptions[], span: ts.TextSpan = { start: 0, length: this.activeFile.content.length }, preference?: ts.InlayHintsOptions) { + const hints = this.languageService.provideInlayHints(this.activeFile.fileName, span, preference); assert.equal(hints.length, expected.length, "Number of hints"); - const normalizeVerifyInlineHintsOptions = (rangeOrPosition: FourSlashInterface.VerifyInlineHintsOptions["rangeOrPosition"]) => { - if (typeof rangeOrPosition === "number") { - return { start: rangeOrPosition, length: 0 }; - } - return rangeOrPosition; - }; - const compareTextSpan = (spanA: ts.TextSpan, spanB: ts.TextSpan) => { - if (spanA.start !== spanB.start) { - return spanA.start - spanB.start; - } - return spanA.length - spanB.length; - }; - const compareHintOptions = (a: FourSlashInterface.VerifyInlineHintsOptions, b: FourSlashInterface.VerifyInlineHintsOptions) => { - const spanA = normalizeVerifyInlineHintsOptions(a.rangeOrPosition); - const spanB = normalizeVerifyInlineHintsOptions(b.rangeOrPosition); - return compareTextSpan(spanA, spanB); - }; - const sortHints = (a: ts.InlineHint, b: ts.InlineHint) => { - return compareTextSpan(a.range, b.range); + + const sortHints = (a: ts.InlayHint, b: ts.InlayHint) => { + return a.position - b.position; }; - ts.zipWith(hints.sort(sortHints), [...expected].sort(compareHintOptions), (actual, expected) => { + ts.zipWith(hints.sort(sortHints), [...expected].sort(sortHints), (actual, expected) => { assert.equal(actual.text, expected.text, "Text"); - assert.deepEqual(actual.range, normalizeVerifyInlineHintsOptions(expected.rangeOrPosition), "RangeOrPosition"); - assert.equal(actual.hoverMessage, expected.hoverMessage, "hoverMessage"); + assert.deepEqual(actual.position, expected.position, "Position"); + assert.equal(actual.kind, expected.kind, "Kind"); assert.equal(actual.whitespaceBefore, expected.whitespaceBefore, "whitespaceBefore"); assert.equal(actual.whitespaceAfter, expected.whitespaceAfter, "whitespaceAfter"); }); diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index f8f7995787a10..48036e989eb29 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -247,8 +247,8 @@ namespace FourSlashInterface { } } - public getInlineHints(expected: readonly VerifyInlineHintsOptions[], span: ts.TextSpan, preference?: ts.InlineHintsOptions) { - this.state.verifyInlineHints(expected, span, preference); + public getInlayHints(expected: readonly VerifyInlayHintsOptions[], span: ts.TextSpan, preference?: ts.InlayHintsOptions) { + this.state.verifyInlayHints(expected, span, preference); } public quickInfoIs(expectedText: string, expectedDocumentation?: string) { @@ -1663,10 +1663,10 @@ namespace FourSlashInterface { readonly containerKind?: ts.ScriptElementKind; } - export interface VerifyInlineHintsOptions { + export interface VerifyInlayHintsOptions { text: string; - rangeOrPosition: number | ts.TextSpan; - hoverMessage?: string; + position: number; + kind?: ts.InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 99e70ba238e7b..a9f8b2befe2d1 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -599,8 +599,8 @@ namespace Harness.LanguageService { provideCallHierarchyOutgoingCalls(fileName: string, position: number) { return unwrapJSONCallResult(this.shim.provideCallHierarchyOutgoingCalls(fileName, position)); } - provideInlineHints(fileName: string, span: ts.TextSpan, preference: ts.InlineHintsOptions) { - return unwrapJSONCallResult(this.shim.provideInlineHints(fileName, span, preference)); + provideInlayHints(fileName: string, span: ts.TextSpan, preference: ts.InlayHintsOptions) { + return unwrapJSONCallResult(this.shim.provideInlayHints(fileName, span, preference)); } getEmitOutput(fileName: string): ts.EmitOutput { return unwrapJSONCallResult(this.shim.getEmitOutput(fileName)); diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 4cf13727696aa..aa832dcf027b4 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -154,7 +154,7 @@ namespace ts.server.protocol { PrepareCallHierarchy = "prepareCallHierarchy", ProvideCallHierarchyIncomingCalls = "provideCallHierarchyIncomingCalls", ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls", - ProvideInlineHints = "provideInlineHints" + ProvideInlayHints = "provideInlayHints" // NOTE: If updating this, be sure to also update `allCommandNames` in `testRunner/unittests/tsserver/session.ts`. } @@ -2550,7 +2550,13 @@ namespace ts.server.protocol { body?: SignatureHelpItems; } - export interface ProvideInlineHintsRequestArgs extends FileRequestArgs { + export const enum InlayHintKind { + Other = 0, + Type = 1, + Parameter = 2, + } + + export interface ProvideInlayHintsRequestArgs extends FileRequestArgs { /** * Start position of the span. */ @@ -2561,21 +2567,21 @@ namespace ts.server.protocol { length: number; } - export interface ProvideInlineHintsRequest extends Request { - command: CommandTypes.ProvideInlineHints; - arguments: ProvideInlineHintsRequestArgs; + export interface ProvideInlayHintsRequest extends Request { + command: CommandTypes.ProvideInlayHints; + arguments: ProvideInlayHintsRequestArgs; } - export interface HintItem { + export interface InlayHintItem { text: string; - range: TextSpan; - hoverMessage?: string; + position: Location; + kind?: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } - export interface ProvideInlineHintsResponse extends Response { - body?: HintItem[]; + export interface ProvideInlayHintsResponse extends Response { + body?: InlayHintItem[]; } /** diff --git a/src/server/session.ts b/src/server/session.ts index d80aa45130bd8..7ae71ca5b9f10 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1449,15 +1449,15 @@ namespace ts.server { }); } - private provideInlineHints(args: protocol.ProvideInlineHintsRequestArgs) { + private provideInlayHints(args: protocol.ProvideInlayHintsRequestArgs) { const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args); const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; - const hints = languageService.provideInlineHints(file, args, this.getPreferences(file)); + const hints = languageService.provideInlayHints(file, args, this.getPreferences(file)); return hints.map(hint => ({ text: hint.text, - range: scriptInfo.textSpanToProtoTextSpan(hint.range), - hoverMessage: hint.hoverMessage, + range: scriptInfo.positionToLineOffset(hint.position), + kind: hint.kind, whitespaceBefore: hint.whitespaceBefore, whitespaceAfter: hint.whitespaceAfter })); @@ -2976,8 +2976,8 @@ namespace ts.server { [CommandNames.UncommentSelectionFull]: (request: protocol.UncommentSelectionRequest) => { return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.ProvideInlineHints]: (request: protocol.ProvideInlineHintsRequest) => { - return this.requiredResponse(this.provideInlineHints(request.arguments)); + [CommandNames.ProvideInlayHints]: (request: protocol.ProvideInlayHintsRequest) => { + return this.requiredResponse(this.provideInlayHints(request.arguments)); } })); diff --git a/src/services/inlineHints.ts b/src/services/inlayHints.ts similarity index 79% rename from src/services/inlineHints.ts rename to src/services/inlayHints.ts index 4191050297a94..701b9b6e4d2af 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlayHints.ts @@ -1,14 +1,14 @@ /* @internal */ -namespace ts.InlineHints { +namespace ts.InlayHints { const maxHintsLength = 30; - export function provideInlineHints(context: InlineHintsContext): InlineHint[] { + export function provideInlayHints(context: InlayHintsContext): InlayHint[] { const { file, program, span, cancellationToken, preferences } = context; const checker = program.getTypeChecker(); - const result: InlineHint[] = []; - const callExpressionHintableCache = program.inlineHintsCallExpressionHintableCache ??= new Map(); + const result: InlayHint[] = []; + const callExpressionHintableCache = program.inlayHintsCallExpressionHintableCache ??= new Map(); visitor(file); return result; @@ -39,28 +39,28 @@ namespace ts.InlineHints { return; } - if (preferences.includeInlineVariableTypeHints && (isVariableDeclaration(node))) { + if (preferences.includeInlayVariableTypeHints && (isVariableDeclaration(node))) { visitVariableLikeDeclaration(node); } - else if (preferences.includeInlinePropertyDeclarationTypeHints && isPropertyDeclaration(node)) { + else if (preferences.includeInlayPropertyDeclarationTypeHints && isPropertyDeclaration(node)) { visitVariableLikeDeclaration(node); } - else if (preferences.includeInlineEnumMemberValueHints && isEnumMember(node)) { + else if (preferences.includeInlayEnumMemberValueHints && isEnumMember(node)) { visitEnumMember(node); } else if (isCallExpression(node) || isNewExpression(node)) { - if (preferences.includeInlineParameterNameHints) { + if (preferences.includeInlayParameterNameHints) { visitCallOrNewExpression(node); } - if (preferences.includeInlineCallChainsHints && isCallExpression(node)) { + if (preferences.includeInlayCallChainsHints && isCallExpression(node)) { visitCallChains(node); } } else { - if (preferences.includeInlineFunctionParameterTypeHints && isFunctionExpressionLike(node)) { + if (preferences.includeInlayFunctionParameterTypeHints && isFunctionExpressionLike(node)) { visitFunctionExpressionLikeForParameterType(node); } - if (preferences.includeInlineFunctionLikeReturnTypeHints && isFunctionDeclarationLike(node)) { + if (preferences.includeInlayFunctionLikeReturnTypeHints && isFunctionDeclarationLike(node)) { visitFunctionDeclarationLikeForReturnType(node); } } @@ -75,26 +75,29 @@ namespace ts.InlineHints { return isArrowFunction(node) || isFunctionExpression(node) || isFunctionDeclaration(node) || isMethodDeclaration(node); } - function addNameHints(text: string, range: TextSpan) { + function addParameterHints(text: string, position: number) { result.push({ text: `${truncation(text, maxHintsLength)}:`, - range, + position, + kind: InlayHintKind.Parameter, whitespaceAfter: true, }); } - function addTypeHints(text: string, range: TextSpan) { + function addTypeHints(text: string, position: number) { result.push({ text: `:${truncation(text, maxHintsLength)}`, - range, + position, + kind: InlayHintKind.Type, whitespaceBefore: true, }); } - function addEnumMemberValueHints(text: string, range: TextSpan) { + function addEnumMemberValueHints(text: string, position: number) { result.push({ text: `= ${truncation(text, maxHintsLength)}`, - range, + position, + kind: InlayHintKind.Other, whitespaceBefore: true, }); } @@ -116,7 +119,7 @@ namespace ts.InlineHints { return; } - addTypeHints(typeDisplayString, makeEmptyRange(call.end)); + addTypeHints(typeDisplayString, call.end); } function shouldCallExpressionHint(call: CallExpression) { @@ -135,10 +138,6 @@ namespace ts.InlineHints { return callExpressionHintableCache.get(call); } - function makeEmptyRange(position: number): TextSpan { - return { start: position, length: 0 }; - } - function visitEnumMember(member: EnumMember) { if (member.initializer) { return; @@ -146,7 +145,7 @@ namespace ts.InlineHints { const enumValue = checker.getConstantValue(member); if (enumValue !== undefined) { - addEnumMemberValueHints(enumValue.toString(), makeEmptyRange(member.end)); + addEnumMemberValueHints(enumValue.toString(), member.end); } } @@ -156,13 +155,13 @@ namespace ts.InlineHints { } const declarationType = checker.getTypeAtLocation(decl); - if (!preferences.includeInlineRequireAssignedVariableTypeHints && declarationType.symbol && (declarationType.symbol.flags & SymbolFlags.Module)) { + if (!preferences.includeInlayRequireAssignedVariableTypeHints && declarationType.symbol && (declarationType.symbol.flags & SymbolFlags.Module)) { return; } const typeDisplayString = printTypeInSingleLine(declarationType); if (typeDisplayString) { - addTypeHints(typeDisplayString, makeEmptyRange(decl.name.end)); + addTypeHints(typeDisplayString, decl.name.end); } } @@ -180,14 +179,14 @@ namespace ts.InlineHints { for (let i = 0; i < args.length; ++i) { const arg = args[i]; - if (!preferences.includeInlineNonLiteralParameterNameHints && !isHintableExpression(arg)) { + if (!preferences.includeInlayNonLiteralParameterNameHints && !isHintableExpression(arg)) { continue; } const parameterName = checker.getParameterIdentifierNameAtPosition(signature, i); if (parameterName) { - if (preferences.includeInlineDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { - addNameHints(unescapeLeadingUnderscores(parameterName), makeEmptyRange(args[i].getStart())); + if (preferences.includeInlayDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { + addParameterHints(unescapeLeadingUnderscores(parameterName), args[i].getStart()); } } } @@ -215,7 +214,7 @@ namespace ts.InlineHints { return; } - addTypeHints(typeDisplayString, makeEmptyRange(getTypeAnnotationPosition(decl))); + addTypeHints(typeDisplayString, getTypeAnnotationPosition(decl)); } function getTypeAnnotationPosition(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { @@ -253,7 +252,7 @@ namespace ts.InlineHints { continue; } - addTypeHints(typeDisplayString, makeEmptyRange(param.end)); + addTypeHints(typeDisplayString, param.end); } } diff --git a/src/services/services.ts b/src/services/services.ts index 49a5918be6375..bb2152de5786b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1184,7 +1184,7 @@ namespace ts { "prepareCallHierarchy", "provideCallHierarchyIncomingCalls", "provideCallHierarchyOutgoingCalls", - "provideInlineHints" + "provideInlayHints" ]; const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [ @@ -2514,7 +2514,7 @@ namespace ts { }; } - function getInlineHintsContext(file: SourceFile, span: TextSpan, preferences: UserPreferences): InlineHintsContext { + function getInlayHintsContext(file: SourceFile, span: TextSpan, preferences: UserPreferences): InlayHintsContext { return { file, program: getProgram()!, @@ -2579,10 +2579,10 @@ namespace ts { return declaration ? CallHierarchy.getOutgoingCalls(program, declaration) : []; } - function provideInlineHints(fileName: string, span: TextSpan, preferences: InlineHintsOptions = emptyOptions): InlineHint[] { + function provideInlayHints(fileName: string, span: TextSpan, preferences: InlayHintsOptions = emptyOptions): InlayHint[] { synchronizeHostData(); const sourceFile = getValidSourceFile(fileName); - return InlineHints.provideInlineHints(getInlineHintsContext(sourceFile, span, preferences)); + return InlayHints.provideInlayHints(getInlayHintsContext(sourceFile, span, preferences)); } const ls: LanguageService = { @@ -2650,7 +2650,7 @@ namespace ts { toggleMultilineComment, commentSelection, uncommentSelection, - provideInlineHints, + provideInlayHints, }; switch (languageServiceMode) { diff --git a/src/services/shims.ts b/src/services/shims.ts index 5c2626a52c4a5..4ceaaf2cde7fe 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -280,7 +280,7 @@ namespace ts { prepareCallHierarchy(fileName: string, position: number): string; provideCallHierarchyIncomingCalls(fileName: string, position: number): string; provideCallHierarchyOutgoingCalls(fileName: string, position: number): string; - provideInlineHints(fileName: string, span: TextSpan, preference: InlineHintsOptions | undefined): string; + provideInlayHints(fileName: string, span: TextSpan, preference: InlayHintsOptions | undefined): string; getEmitOutput(fileName: string): string; getEmitOutputObject(fileName: string): EmitOutput; @@ -1067,10 +1067,10 @@ namespace ts { ); } - public provideInlineHints(fileName: string, span: TextSpan, preference: InlineHintsOptions | undefined): string { + public provideInlayHints(fileName: string, span: TextSpan, preference: InlayHintsOptions | undefined): string { return this.forwardJSONCall( - `provideInlineHints('${fileName}', '${JSON.stringify(span)}', ${JSON.stringify(preference)})`, - () => this.languageService.provideInlineHints(fileName, span, preference) + `provideInlayHints('${fileName}', '${JSON.stringify(span)}', ${JSON.stringify(preference)})`, + () => this.languageService.provideInlayHints(fileName, span, preference) ); } diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 5c114f39f334c..ba72007a40e2d 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -33,7 +33,7 @@ "rename.ts", "smartSelection.ts", "signatureHelp.ts", - "inlineHints.ts", + "inlayHints.ts", "sourcemaps.ts", "suggestionDiagnostics.ts", "symbolDisplay.ts", diff --git a/src/services/types.ts b/src/services/types.ts index 8ac38188d3bca..34f03affcef1a 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -487,7 +487,7 @@ namespace ts { provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideInlineHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlineHint[] + provideInlayHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlayHint[] getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; @@ -572,17 +572,17 @@ namespace ts { includeInsertTextCompletions?: boolean; } - export interface InlineHintsOptions extends UserPreferences { - readonly includeInlineParameterNameHints?: boolean; - readonly includeInlineNonLiteralParameterNameHints?: boolean; - readonly includeDuplicatedParameterNameHints?: boolean; - readonly includeInlineFunctionParameterTypeHints?: boolean, - readonly includeInlineVariableTypeHints?: boolean; - readonly includeInlineRequireAssignedVariableTypeHints?: boolean; - readonly includeInlinePropertyDeclarationTypeHints?: boolean; - readonly includeInlineFunctionLikeReturnTypeHints?: boolean; - readonly includeInlineEnumMemberValueHints?: boolean; - readonly includeInlineCallChainsHints?: boolean; + export interface InlayHintsOptions extends UserPreferences { + readonly includeInlayParameterNameHints?: boolean; + readonly includeInlayNonLiteralParameterNameHints?: boolean; + readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayFunctionParameterTypeHints?: boolean, + readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayRequireAssignedVariableTypeHints?: boolean; + readonly includeInlayPropertyDeclarationTypeHints?: boolean; + readonly includeInlayFunctionLikeReturnTypeHints?: boolean; + readonly includeInlayEnumMemberValueHints?: boolean; + readonly includeInlayCallChainsHints?: boolean; } export type SignatureHelpTriggerCharacter = "," | "(" | "<"; @@ -708,10 +708,16 @@ namespace ts { fromSpans: TextSpan[]; } - export interface InlineHint { + export const enum InlayHintKind { + Other = 0, + Type = 1, + Parameter = 2, + } + + export interface InlayHint { text: string; - range: TextSpan; - hoverMessage?: string; + position: number; + kind?: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -1580,7 +1586,7 @@ namespace ts { kind?: string; } - export interface InlineHintsContext { + export interface InlayHintsContext { file: SourceFile; program: Program; cancellationToken: CancellationToken; diff --git a/src/testRunner/unittests/tsserver/session.ts b/src/testRunner/unittests/tsserver/session.ts index 476474bacff66..46105841c2fb0 100644 --- a/src/testRunner/unittests/tsserver/session.ts +++ b/src/testRunner/unittests/tsserver/session.ts @@ -278,7 +278,7 @@ namespace ts.server { CommandNames.ToggleMultilineComment, CommandNames.CommentSelection, CommandNames.UncommentSelection, - CommandNames.ProvideInlineHints + CommandNames.ProvideInlayHints ]; it("should not throw when commands are executed with invalid arguments", () => { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index a1ad9e125b9e6..1098ccc73739e 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3927,16 +3927,16 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlineParameterNameHints?: boolean; - readonly includeInlineNonLiteralParameterNameHints?: boolean; - readonly includeInlineDuplicatedParameterNameHints?: boolean; - readonly includeInlineFunctionParameterTypeHints?: boolean; - readonly includeInlineVariableTypeHints?: boolean; - readonly includeInlineRequireAssignedVariableTypeHints?: boolean; - readonly includeInlinePropertyDeclarationTypeHints?: boolean; - readonly includeInlineFunctionLikeReturnTypeHints?: boolean; - readonly includeInlineEnumMemberValueHints?: boolean; - readonly includeInlineCallChainsHints?: boolean; + readonly includeInlayParameterNameHints?: boolean; + readonly includeInlayNonLiteralParameterNameHints?: boolean; + readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayFunctionParameterTypeHints?: boolean; + readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayRequireAssignedVariableTypeHints?: boolean; + readonly includeInlayPropertyDeclarationTypeHints?: boolean; + readonly includeInlayFunctionLikeReturnTypeHints?: boolean; + readonly includeInlayEnumMemberValueHints?: boolean; + readonly includeInlayCallChainsHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5648,7 +5648,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideInlineHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlineHint[]; + provideInlayHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlayHint[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -5710,17 +5710,17 @@ declare namespace ts { /** @deprecated Use includeCompletionsWithInsertText */ includeInsertTextCompletions?: boolean; } - interface InlineHintsOptions extends UserPreferences { - readonly includeInlineParameterNameHints?: boolean; - readonly includeInlineNonLiteralParameterNameHints?: boolean; - readonly includeDuplicatedParameterNameHints?: boolean; - readonly includeInlineFunctionParameterTypeHints?: boolean; - readonly includeInlineVariableTypeHints?: boolean; - readonly includeInlineRequireAssignedVariableTypeHints?: boolean; - readonly includeInlinePropertyDeclarationTypeHints?: boolean; - readonly includeInlineFunctionLikeReturnTypeHints?: boolean; - readonly includeInlineEnumMemberValueHints?: boolean; - readonly includeInlineCallChainsHints?: boolean; + interface InlayHintsOptions extends UserPreferences { + readonly includeInlayParameterNameHints?: boolean; + readonly includeInlayNonLiteralParameterNameHints?: boolean; + readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayFunctionParameterTypeHints?: boolean; + readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayRequireAssignedVariableTypeHints?: boolean; + readonly includeInlayPropertyDeclarationTypeHints?: boolean; + readonly includeInlayFunctionLikeReturnTypeHints?: boolean; + readonly includeInlayEnumMemberValueHints?: boolean; + readonly includeInlayCallChainsHints?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; @@ -5827,10 +5827,15 @@ declare namespace ts { to: CallHierarchyItem; fromSpans: TextSpan[]; } - interface InlineHint { + enum InlayHintKind { + Other = 0, + Type = 1, + Parameter = 2 + } + interface InlayHint { text: string; - range: TextSpan; - hoverMessage?: string; + position: number; + kind?: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -6499,7 +6504,7 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24, bigintLiteral = 25 } - interface InlineHintsContext { + interface InlayHintsContext { file: SourceFile; program: Program; cancellationToken: CancellationToken; @@ -6799,7 +6804,7 @@ declare namespace ts.server.protocol { PrepareCallHierarchy = "prepareCallHierarchy", ProvideCallHierarchyIncomingCalls = "provideCallHierarchyIncomingCalls", ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls", - ProvideInlineHints = "provideInlineHints" + ProvideInlayHints = "provideInlayHints" } /** * A TypeScript Server message @@ -8671,7 +8676,12 @@ declare namespace ts.server.protocol { interface SignatureHelpResponse extends Response { body?: SignatureHelpItems; } - interface ProvideInlineHintsRequestArgs extends FileRequestArgs { + enum InlayHintKind { + Other = 0, + Type = 1, + Parameter = 2 + } + interface ProvideInlayHintsRequestArgs extends FileRequestArgs { /** * Start position of the span. */ @@ -8681,19 +8691,19 @@ declare namespace ts.server.protocol { */ length: number; } - interface ProvideInlineHintsRequest extends Request { - command: CommandTypes.ProvideInlineHints; - arguments: ProvideInlineHintsRequestArgs; + interface ProvideInlayHintsRequest extends Request { + command: CommandTypes.ProvideInlayHints; + arguments: ProvideInlayHintsRequestArgs; } - interface HintItem { + interface InlayHintItem { text: string; - range: TextSpan; - hoverMessage?: string; + position: Location; + kind?: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } - interface ProvideInlineHintsResponse extends Response { - body?: HintItem[]; + interface ProvideInlayHintsResponse extends Response { + body?: InlayHintItem[]; } /** * Synchronous request for semantic diagnostics of one file. @@ -10325,7 +10335,7 @@ declare namespace ts.server { private getSuggestionDiagnosticsSync; private getJsxClosingTag; private getDocumentHighlights; - private provideInlineHints; + private provideInlayHints; private setCompilerOptionsForInferredProjects; private getProjectInfo; private getProjectInfoWorker; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 81bd888ad291f..4280d9216eb35 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3927,16 +3927,16 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlineParameterNameHints?: boolean; - readonly includeInlineNonLiteralParameterNameHints?: boolean; - readonly includeInlineDuplicatedParameterNameHints?: boolean; - readonly includeInlineFunctionParameterTypeHints?: boolean; - readonly includeInlineVariableTypeHints?: boolean; - readonly includeInlineRequireAssignedVariableTypeHints?: boolean; - readonly includeInlinePropertyDeclarationTypeHints?: boolean; - readonly includeInlineFunctionLikeReturnTypeHints?: boolean; - readonly includeInlineEnumMemberValueHints?: boolean; - readonly includeInlineCallChainsHints?: boolean; + readonly includeInlayParameterNameHints?: boolean; + readonly includeInlayNonLiteralParameterNameHints?: boolean; + readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayFunctionParameterTypeHints?: boolean; + readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayRequireAssignedVariableTypeHints?: boolean; + readonly includeInlayPropertyDeclarationTypeHints?: boolean; + readonly includeInlayFunctionLikeReturnTypeHints?: boolean; + readonly includeInlayEnumMemberValueHints?: boolean; + readonly includeInlayCallChainsHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5648,7 +5648,7 @@ declare namespace ts { prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; - provideInlineHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlineHint[]; + provideInlayHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlayHint[]; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; @@ -5710,17 +5710,17 @@ declare namespace ts { /** @deprecated Use includeCompletionsWithInsertText */ includeInsertTextCompletions?: boolean; } - interface InlineHintsOptions extends UserPreferences { - readonly includeInlineParameterNameHints?: boolean; - readonly includeInlineNonLiteralParameterNameHints?: boolean; - readonly includeDuplicatedParameterNameHints?: boolean; - readonly includeInlineFunctionParameterTypeHints?: boolean; - readonly includeInlineVariableTypeHints?: boolean; - readonly includeInlineRequireAssignedVariableTypeHints?: boolean; - readonly includeInlinePropertyDeclarationTypeHints?: boolean; - readonly includeInlineFunctionLikeReturnTypeHints?: boolean; - readonly includeInlineEnumMemberValueHints?: boolean; - readonly includeInlineCallChainsHints?: boolean; + interface InlayHintsOptions extends UserPreferences { + readonly includeInlayParameterNameHints?: boolean; + readonly includeInlayNonLiteralParameterNameHints?: boolean; + readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayFunctionParameterTypeHints?: boolean; + readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayRequireAssignedVariableTypeHints?: boolean; + readonly includeInlayPropertyDeclarationTypeHints?: boolean; + readonly includeInlayFunctionLikeReturnTypeHints?: boolean; + readonly includeInlayEnumMemberValueHints?: boolean; + readonly includeInlayCallChainsHints?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; @@ -5827,10 +5827,15 @@ declare namespace ts { to: CallHierarchyItem; fromSpans: TextSpan[]; } - interface InlineHint { + enum InlayHintKind { + Other = 0, + Type = 1, + Parameter = 2 + } + interface InlayHint { text: string; - range: TextSpan; - hoverMessage?: string; + position: number; + kind?: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -6499,7 +6504,7 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24, bigintLiteral = 25 } - interface InlineHintsContext { + interface InlayHintsContext { file: SourceFile; program: Program; cancellationToken: CancellationToken; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 1062bc03282b7..922336b0304a2 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -66,6 +66,12 @@ declare module ts { Smart = 2, } + const enum InlayHintKind { + Other = 0, + Type = 1, + Parameter = 2, + } + enum SemicolonPreference { Ignore = "ignore", Insert = "insert", @@ -393,10 +399,10 @@ declare namespace FourSlashInterface { start: number; length: number; }, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: { name: string, text?: string }[] | undefined): void; - getInlineHints(expected: readonly VerifyInlineHintsOptions[], textSpan?: { + getInlayHints(expected: readonly VerifyInlayHintsOptions[], textSpan?: { start: number; length: number; - }, preference?: InlineHintsOptions); + }, preference?: InlayHintsOptions); getSyntacticDiagnostics(expected: ReadonlyArray): void; getSemanticDiagnostics(expected: ReadonlyArray): void; getSuggestionDiagnostics(expected: ReadonlyArray): void; @@ -632,17 +638,17 @@ declare namespace FourSlashInterface { readonly importModuleSpecifierPreference?: "shortest" | "project-relative" | "relative" | "non-relative"; readonly importModuleSpecifierEnding?: "minimal" | "index" | "js"; } - interface InlineHintsOptions extends UserPreferences { - readonly includeInlineParameterNameHints?: boolean; - readonly includeInlineNonLiteralParameterNameHints?: boolean; - readonly includeInlineDuplicatedParameterNameHints?: boolean; - readonly includeInlineFunctionParameterTypeHints?: boolean; - readonly includeInlineVariableTypeHints?: boolean; - readonly includeInlineRequireAssignedVariableTypeHints?: boolean; - readonly includeInlinePropertyDeclarationTypeHints?: boolean; - readonly includeInlineFunctionLikeReturnTypeHints?: boolean; - readonly includeInlineEnumMemberValueHints?: boolean; - readonly includeInlineCallChainsHints?: boolean; + interface InlayHintsOptions extends UserPreferences { + readonly includeInlayParameterNameHints?: boolean; + readonly includeInlayNonLiteralParameterNameHints?: boolean; + readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayFunctionParameterTypeHints?: boolean; + readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayRequireAssignedVariableTypeHints?: boolean; + readonly includeInlayPropertyDeclarationTypeHints?: boolean; + readonly includeInlayFunctionLikeReturnTypeHints?: boolean; + readonly includeInlayEnumMemberValueHints?: boolean; + readonly includeInlayCallChainsHints?: boolean; } interface CompletionsOptions { readonly marker?: ArrayOrSingle; @@ -746,15 +752,14 @@ declare namespace FourSlashInterface { readonly commands?: ReadonlyArray<{}>; } - export interface VerifyInlineHintsOptions { + export interface VerifyInlayHintsOptions { text: string; - rangeOrPosition: number |TextSpan; - hoverMessage?: string; + position: number; + kind?: VerifyInlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } - interface VerifyNavigateToOptions { readonly pattern: string; readonly fileName?: string; diff --git a/tests/cases/fourslash/inlineHintsShouldWork1.ts b/tests/cases/fourslash/inlayHintsShouldWork1.ts similarity index 53% rename from tests/cases/fourslash/inlineHintsShouldWork1.ts rename to tests/cases/fourslash/inlayHintsShouldWork1.ts index 64a986ee4359d..4fb894f68538d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork1.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork1.ts @@ -4,17 +4,19 @@ //// foo(/*a*/1, /*b*/2); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'a:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'b:', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork10.ts b/tests/cases/fourslash/inlayHintsShouldWork10.ts similarity index 59% rename from tests/cases/fourslash/inlineHintsShouldWork10.ts rename to tests/cases/fourslash/inlayHintsShouldWork10.ts index ab14cd75f6dfc..3086b41ca0066 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork10.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork10.ts @@ -4,6 +4,6 @@ //// unknownCall(); const markers = test.markers(); -verify.getInlineHints([], undefined, { - includeInlineParameterNameHints: true +verify.getInlayHints([], undefined, { + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork11.ts b/tests/cases/fourslash/inlayHintsShouldWork11.ts similarity index 58% rename from tests/cases/fourslash/inlineHintsShouldWork11.ts rename to tests/cases/fourslash/inlayHintsShouldWork11.ts index 7a8888f70cd86..3188f5d007d86 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork11.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork11.ts @@ -8,17 +8,19 @@ //// foo(/*a*/1)(/*b*/2); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'a:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'b:', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork12.ts b/tests/cases/fourslash/inlayHintsShouldWork12.ts similarity index 57% rename from tests/cases/fourslash/inlineHintsShouldWork12.ts rename to tests/cases/fourslash/inlayHintsShouldWork12.ts index da4f1942f7887..8e55b5f3e0d27 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork12.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork12.ts @@ -7,17 +7,19 @@ //// foo(/*b*/(c: number) => c + 1); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'b:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'a:', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork13.ts b/tests/cases/fourslash/inlayHintsShouldWork13.ts new file mode 100644 index 0000000000000..0c86169491226 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork13.ts @@ -0,0 +1,19 @@ +/// + +//// function foo (a: number, b: number) {} +//// declare const a: 1; +//// foo(a, /*b*/2); + +const markers = test.markers(); +verify.getInlayHints([ + { + text: 'b:', + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, +], undefined, { + includeInlayParameterNameHints: true, + includeInlayNonLiteralParameterNameHints: true, + includeInlayDuplicatedParameterNameHints: false, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork14.ts b/tests/cases/fourslash/inlayHintsShouldWork14.ts similarity index 53% rename from tests/cases/fourslash/inlineHintsShouldWork14.ts rename to tests/cases/fourslash/inlayHintsShouldWork14.ts index 9bdba9c34adcd..69703855d53ad 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork14.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork14.ts @@ -3,6 +3,6 @@ //// function foo (a: number, b: number) {} //// foo(1, 2); -verify.getInlineHints([], undefined, { - includeInlineParameterNameHints: false +verify.getInlayHints([], undefined, { + includeInlayParameterNameHints: false }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork15.ts b/tests/cases/fourslash/inlayHintsShouldWork15.ts similarity index 54% rename from tests/cases/fourslash/inlineHintsShouldWork15.ts rename to tests/cases/fourslash/inlayHintsShouldWork15.ts index 5ddf52629f77d..c295c8e1eaf36 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork15.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork15.ts @@ -3,12 +3,13 @@ //// const a/*a*/ = 123; const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':123', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineVariableTypeHints: true + includeInlayVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork16.ts b/tests/cases/fourslash/inlayHintsShouldWork16.ts similarity index 54% rename from tests/cases/fourslash/inlineHintsShouldWork16.ts rename to tests/cases/fourslash/inlayHintsShouldWork16.ts index 5ddf52629f77d..c295c8e1eaf36 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork16.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork16.ts @@ -3,12 +3,13 @@ //// const a/*a*/ = 123; const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':123', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineVariableTypeHints: true + includeInlayVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork17.ts b/tests/cases/fourslash/inlayHintsShouldWork17.ts similarity index 56% rename from tests/cases/fourslash/inlineHintsShouldWork17.ts rename to tests/cases/fourslash/inlayHintsShouldWork17.ts index c9a6c41709e69..4d3165b901190 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork17.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork17.ts @@ -3,12 +3,13 @@ //// const a/*a*/ = { a: 123 }; const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':{ a: number; }', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineVariableTypeHints: true + includeInlayVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork18.ts b/tests/cases/fourslash/inlayHintsShouldWork18.ts similarity index 57% rename from tests/cases/fourslash/inlineHintsShouldWork18.ts rename to tests/cases/fourslash/inlayHintsShouldWork18.ts index 0160979ba3ae7..fa84a7369d309 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork18.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork18.ts @@ -4,12 +4,13 @@ //// const a/*a*/ = new Class(); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':Class', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineVariableTypeHints: true + includeInlayVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork19.ts b/tests/cases/fourslash/inlayHintsShouldWork19.ts similarity index 56% rename from tests/cases/fourslash/inlineHintsShouldWork19.ts rename to tests/cases/fourslash/inlayHintsShouldWork19.ts index 1ca6e0e4a7ee7..ef2e72a7f1147 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork19.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork19.ts @@ -3,12 +3,13 @@ //// const a/*a*/ = () => 123; const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':() => number', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineVariableTypeHints: true + includeInlayVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork2.ts b/tests/cases/fourslash/inlayHintsShouldWork2.ts similarity index 58% rename from tests/cases/fourslash/inlineHintsShouldWork2.ts rename to tests/cases/fourslash/inlayHintsShouldWork2.ts index 4e22cf68a0f03..7cfbaf8abd655 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork2.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork2.ts @@ -4,12 +4,13 @@ //// foo(/*a*/1, { c: 1}); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'a:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork20.ts b/tests/cases/fourslash/inlayHintsShouldWork20.ts new file mode 100644 index 0000000000000..4510a740a79f0 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork20.ts @@ -0,0 +1,7 @@ +/// + +//// const a = 123; + +verify.getInlayHints([], undefined, { + includeInlayVariableTypeHints: false +}); diff --git a/tests/cases/fourslash/inlayHintsShouldWork21.ts b/tests/cases/fourslash/inlayHintsShouldWork21.ts new file mode 100644 index 0000000000000..7a63f903f3410 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork21.ts @@ -0,0 +1,7 @@ +/// + +//// const a; + +verify.getInlayHints([], undefined, { + includeInlayVariableTypeHints: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork22.ts b/tests/cases/fourslash/inlayHintsShouldWork22.ts similarity index 62% rename from tests/cases/fourslash/inlineHintsShouldWork22.ts rename to tests/cases/fourslash/inlayHintsShouldWork22.ts index eb4a745a9e212..a6df150349d2b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork22.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork22.ts @@ -3,12 +3,13 @@ //// const a/*a*/ = "I'm very very very very very very very very very long"; const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: `:"I'm very very very very ve...`, - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineVariableTypeHints: true + includeInlayVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork23.ts b/tests/cases/fourslash/inlayHintsShouldWork23.ts similarity index 63% rename from tests/cases/fourslash/inlineHintsShouldWork23.ts rename to tests/cases/fourslash/inlayHintsShouldWork23.ts index 3d6df7ee2a9bd..657a9d1bcad4b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork23.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork23.ts @@ -4,12 +4,13 @@ //// foo(/*a*/1); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'Im_very_very_very_very_very...:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork24.ts b/tests/cases/fourslash/inlayHintsShouldWork24.ts similarity index 56% rename from tests/cases/fourslash/inlineHintsShouldWork24.ts rename to tests/cases/fourslash/inlayHintsShouldWork24.ts index f5b8d3e5c6a55..7403df51f87aa 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork24.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork24.ts @@ -4,17 +4,19 @@ //// const f: F = (a/*a*/, b/*b*/) => { } const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':string', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, { text: ':number', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterTypeHints: true + includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork25.ts b/tests/cases/fourslash/inlayHintsShouldWork25.ts similarity index 58% rename from tests/cases/fourslash/inlineHintsShouldWork25.ts rename to tests/cases/fourslash/inlayHintsShouldWork25.ts index 9b298e41a5708..0fe69a4be64f0 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork25.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork25.ts @@ -4,12 +4,13 @@ //// foo((a/*a*/) => { }) const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':string', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterTypeHints: true + includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork26.ts b/tests/cases/fourslash/inlayHintsShouldWork26.ts similarity index 60% rename from tests/cases/fourslash/inlineHintsShouldWork26.ts rename to tests/cases/fourslash/inlayHintsShouldWork26.ts index 6222b02cb8ada..64c22bab33f3c 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork26.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork26.ts @@ -4,12 +4,13 @@ //// foo((a/*a*/) => { }) const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':2 | 3', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterTypeHints: true + includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork27.ts b/tests/cases/fourslash/inlayHintsShouldWork27.ts similarity index 61% rename from tests/cases/fourslash/inlineHintsShouldWork27.ts rename to tests/cases/fourslash/inlayHintsShouldWork27.ts index 3158a5c27b774..04369b4a92f11 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork27.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork27.ts @@ -6,17 +6,19 @@ //// }) const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':(c: (d: 2 | 3) => void) => ...', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, { text: ':2 | 3', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterTypeHints: true + includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork28.ts b/tests/cases/fourslash/inlayHintsShouldWork28.ts similarity index 60% rename from tests/cases/fourslash/inlineHintsShouldWork28.ts rename to tests/cases/fourslash/inlayHintsShouldWork28.ts index 6417e4f958be0..2e20836171e4a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork28.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork28.ts @@ -4,12 +4,13 @@ //// const f: F = (a/*a*/, b: number) => { } const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':string', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterTypeHints: true + includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork29.ts b/tests/cases/fourslash/inlayHintsShouldWork29.ts similarity index 53% rename from tests/cases/fourslash/inlineHintsShouldWork29.ts rename to tests/cases/fourslash/inlayHintsShouldWork29.ts index 775a942472c94..3dbf7fb8c75a0 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork29.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork29.ts @@ -6,28 +6,32 @@ //// }) const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'a:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: ':(c: (d: 2 | 3) => void) => ...', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, { text: 'c:', - rangeOrPosition: markers[2].position, + position: markers[2].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: ':2 | 3', - rangeOrPosition: markers[3].position, + position: markers[3].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineParameterNameHints: true, - includeInlineFunctionParameterTypeHints: true + includeInlayParameterNameHints: true, + includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork3.ts b/tests/cases/fourslash/inlayHintsShouldWork3.ts similarity index 54% rename from tests/cases/fourslash/inlineHintsShouldWork3.ts rename to tests/cases/fourslash/inlayHintsShouldWork3.ts index 7376aeb668b27..34fec2d053228 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork3.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork3.ts @@ -4,17 +4,19 @@ //// foo(/*a*/1, /*b*/1, 1, 1); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'a:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'b:', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork30.ts b/tests/cases/fourslash/inlayHintsShouldWork30.ts similarity index 58% rename from tests/cases/fourslash/inlineHintsShouldWork30.ts rename to tests/cases/fourslash/inlayHintsShouldWork30.ts index 252bb444cec3b..96d244b85bef7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork30.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork30.ts @@ -4,12 +4,13 @@ //// f(1, a/*a*/ => { }) const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':number', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterTypeHints: true + includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork31.ts b/tests/cases/fourslash/inlayHintsShouldWork31.ts similarity index 63% rename from tests/cases/fourslash/inlineHintsShouldWork31.ts rename to tests/cases/fourslash/inlayHintsShouldWork31.ts index 0a41ae49a70f0..ed178ead22d19 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork31.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork31.ts @@ -7,12 +7,13 @@ //// const f: F = (a/*a*/) => { } const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':{ a: number; b: string; }', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineFunctionParameterTypeHints: true + includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork32.ts b/tests/cases/fourslash/inlayHintsShouldWork32.ts similarity index 82% rename from tests/cases/fourslash/inlineHintsShouldWork32.ts rename to tests/cases/fourslash/inlayHintsShouldWork32.ts index c01375ec1bac3..0dc42ab47bd52 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork32.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork32.ts @@ -18,13 +18,14 @@ const start = test.markerByName('c'); const end = test.markerByName('h'); const span = { start: start.position, length: end.position - start.position }; -verify.getInlineHints( +verify.getInlayHints( ['c', 'd', 'e', 'f', 'g', 'h'].map(mark => { return { text: `${mark}:`, - rangeOrPosition: test.markerByName(mark).position, + position: test.markerByName(mark).position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } }), span, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }) diff --git a/tests/cases/fourslash/inlineHintsShouldWork33.ts b/tests/cases/fourslash/inlayHintsShouldWork33.ts similarity index 80% rename from tests/cases/fourslash/inlineHintsShouldWork33.ts rename to tests/cases/fourslash/inlayHintsShouldWork33.ts index d148a7cd8d5e8..1fc93d9b736f4 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork33.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork33.ts @@ -18,13 +18,14 @@ const start = test.markerByName('c'); const end = test.markerByName('h'); const span = { start: start.position, length: end.position - start.position }; -verify.getInlineHints( +verify.getInlayHints( ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'].map(mark => { return { text: `${mark}:`, - rangeOrPosition: test.markerByName(mark).position, + position: test.markerByName(mark).position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } }), span, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); \ No newline at end of file diff --git a/tests/cases/fourslash/inlineHintsShouldWork34.ts b/tests/cases/fourslash/inlayHintsShouldWork34.ts similarity index 68% rename from tests/cases/fourslash/inlineHintsShouldWork34.ts rename to tests/cases/fourslash/inlayHintsShouldWork34.ts index e499b3968eb98..ec345460889f7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork34.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork34.ts @@ -18,12 +18,13 @@ const markers = test.markers(); -verify.getInlineHints( +verify.getInlayHints( markers.map(m => ({ text: 'v:', - rangeOrPosition: m.position, + position: m.position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true })) , undefined, { - includeInlineParameterNameHints: true, - includeInlineNonLiteralParameterNameHints: false + includeInlayParameterNameHints: true, + includeInlayNonLiteralParameterNameHints: false }); \ No newline at end of file diff --git a/tests/cases/fourslash/inlineHintsShouldWork35.ts b/tests/cases/fourslash/inlayHintsShouldWork35.ts similarity index 68% rename from tests/cases/fourslash/inlineHintsShouldWork35.ts rename to tests/cases/fourslash/inlayHintsShouldWork35.ts index c81f04c71aab0..346a294feba94 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork35.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork35.ts @@ -18,12 +18,13 @@ const markers = test.markers(); -verify.getInlineHints( +verify.getInlayHints( markers.map(m => ({ text: 'v:', - rangeOrPosition: m.position, + position: m.position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true })) , undefined, { - includeInlineParameterNameHints: true, - includeInlineNonLiteralParameterNameHints: true + includeInlayParameterNameHints: true, + includeInlayNonLiteralParameterNameHints: true }); \ No newline at end of file diff --git a/tests/cases/fourslash/inlayHintsShouldWork36.ts b/tests/cases/fourslash/inlayHintsShouldWork36.ts new file mode 100644 index 0000000000000..feb63a5570237 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork36.ts @@ -0,0 +1,25 @@ +/// + +//// function foo (a: number, b: number) {} +//// declare const a: 1; +//// foo(/*a*/a, /*b*/2); + +const markers = test.markers(); +verify.getInlayHints([ + { + text: 'a:', + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, +], undefined, { + includeInlayParameterNameHints: true, + includeInlayNonLiteralParameterNameHints: true, + includeInlayDuplicatedParameterNameHints: true, +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork37.ts b/tests/cases/fourslash/inlayHintsShouldWork37.ts similarity index 58% rename from tests/cases/fourslash/inlineHintsShouldWork37.ts rename to tests/cases/fourslash/inlayHintsShouldWork37.ts index ef5bd74c72c76..9a541ddb146b4 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork37.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork37.ts @@ -7,12 +7,13 @@ //// } const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':number', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlinePropertyDeclarationTypeHints: true, + includeInlayPropertyDeclarationTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork38.ts b/tests/cases/fourslash/inlayHintsShouldWork38.ts similarity index 56% rename from tests/cases/fourslash/inlineHintsShouldWork38.ts rename to tests/cases/fourslash/inlayHintsShouldWork38.ts index 270858539165b..b2ad912844218 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork38.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork38.ts @@ -5,12 +5,13 @@ //// } const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':number', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnTypeHints: true, + includeInlayFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork39.ts b/tests/cases/fourslash/inlayHintsShouldWork39.ts similarity index 56% rename from tests/cases/fourslash/inlineHintsShouldWork39.ts rename to tests/cases/fourslash/inlayHintsShouldWork39.ts index 967cf1cd85b17..6649246eee7e7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork39.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork39.ts @@ -5,6 +5,6 @@ //// } const markers = test.markers(); -verify.getInlineHints([], undefined, { - includeInlineFunctionLikeReturnTypeHints: true, +verify.getInlayHints([], undefined, { + includeInlayFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork4.ts b/tests/cases/fourslash/inlayHintsShouldWork4.ts similarity index 59% rename from tests/cases/fourslash/inlineHintsShouldWork4.ts rename to tests/cases/fourslash/inlayHintsShouldWork4.ts index 06031ceb3cef4..7515747fc74d7 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork4.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork4.ts @@ -8,22 +8,25 @@ //// foo(/*b*/1, /*c*/2) const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'w:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'a:', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'b:', - rangeOrPosition: markers[2].position, + position: markers[2].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork40.ts b/tests/cases/fourslash/inlayHintsShouldWork40.ts similarity index 58% rename from tests/cases/fourslash/inlineHintsShouldWork40.ts rename to tests/cases/fourslash/inlayHintsShouldWork40.ts index b6c891a571703..139ea7cc88750 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork40.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork40.ts @@ -7,12 +7,13 @@ //// } const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':number', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnTypeHints: true, + includeInlayFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork41.ts b/tests/cases/fourslash/inlayHintsShouldWork41.ts similarity index 53% rename from tests/cases/fourslash/inlineHintsShouldWork41.ts rename to tests/cases/fourslash/inlayHintsShouldWork41.ts index 5b76af18a3b63..974f864b46cc2 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork41.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork41.ts @@ -3,12 +3,13 @@ //// const a = ()/*a*/ => 1 const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':number', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnTypeHints: true, + includeInlayFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork42.ts b/tests/cases/fourslash/inlayHintsShouldWork42.ts similarity index 55% rename from tests/cases/fourslash/inlineHintsShouldWork42.ts rename to tests/cases/fourslash/inlayHintsShouldWork42.ts index 657a1a6bf5897..8913e92985e7b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork42.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork42.ts @@ -3,12 +3,13 @@ //// const a = function ()/*a*/ { return 1} const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':number', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnTypeHints: true, + includeInlayFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork43.ts b/tests/cases/fourslash/inlayHintsShouldWork43.ts similarity index 53% rename from tests/cases/fourslash/inlineHintsShouldWork43.ts rename to tests/cases/fourslash/inlayHintsShouldWork43.ts index 26626f53df09d..32e8289042511 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork43.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork43.ts @@ -3,12 +3,13 @@ //// const a = b/*a*/ => 1 const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':number', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, ], undefined, { - includeInlineFunctionLikeReturnTypeHints: true, + includeInlayFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork44.ts b/tests/cases/fourslash/inlayHintsShouldWork44.ts similarity index 54% rename from tests/cases/fourslash/inlineHintsShouldWork44.ts rename to tests/cases/fourslash/inlayHintsShouldWork44.ts index 1b6fcda680954..fd60c972236a3 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork44.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork44.ts @@ -9,22 +9,25 @@ //// } const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: '= 0', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Other, whitespaceBefore: true }, { text: '= 1', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Other, whitespaceBefore: true }, { text: '= 11', - rangeOrPosition: markers[2].position, + position: markers[2].position, + kind: ts.InlayHintKind.Other, whitespaceBefore: true }, ], undefined, { - includeInlineEnumMemberValueHints: true, + includeInlayEnumMemberValueHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork45.ts b/tests/cases/fourslash/inlayHintsShouldWork45.ts similarity index 59% rename from tests/cases/fourslash/inlineHintsShouldWork45.ts rename to tests/cases/fourslash/inlayHintsShouldWork45.ts index 319e73061c337..4ba7399d46076 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork45.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork45.ts @@ -11,7 +11,7 @@ goTo.file('/b.js') const markers = test.markers(); -verify.getInlineHints([], undefined, { - includeInlineVariableTypeHints: true, - includeInlineRequireAssignedVariableTypeHints: false +verify.getInlayHints([], undefined, { + includeInlayVariableTypeHints: true, + includeInlayRequireAssignedVariableTypeHints: false }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork46.ts b/tests/cases/fourslash/inlayHintsShouldWork46.ts similarity index 60% rename from tests/cases/fourslash/inlineHintsShouldWork46.ts rename to tests/cases/fourslash/inlayHintsShouldWork46.ts index a2ef70e880ae8..dd6ba4317b591 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork46.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork46.ts @@ -11,13 +11,14 @@ goTo.file('/b.js') const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':typeof import("/a")', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineVariableTypeHints: true, - includeInlineRequireAssignedVariableTypeHints: true + includeInlayVariableTypeHints: true, + includeInlayRequireAssignedVariableTypeHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork47.ts b/tests/cases/fourslash/inlayHintsShouldWork47.ts similarity index 63% rename from tests/cases/fourslash/inlineHintsShouldWork47.ts rename to tests/cases/fourslash/inlayHintsShouldWork47.ts index ecec242ade7c9..14a333bc3997d 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork47.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork47.ts @@ -8,22 +8,25 @@ //// .map(function (e) { return Number(e) }); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':string[]', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, { text: ':number[]', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, { text: ':string[]', - rangeOrPosition: markers[2].position, + position: markers[2].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineCallChainsHints: true, + includeInlayCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork48.ts b/tests/cases/fourslash/inlayHintsShouldWork48.ts similarity index 65% rename from tests/cases/fourslash/inlineHintsShouldWork48.ts rename to tests/cases/fourslash/inlayHintsShouldWork48.ts index 91ab158f02fec..5a2a729915c3a 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork48.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork48.ts @@ -6,12 +6,13 @@ //// .map(function (e) { return Number(e) }); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':string[]', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineCallChainsHints: true, + includeInlayCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork49.ts b/tests/cases/fourslash/inlayHintsShouldWork49.ts similarity index 64% rename from tests/cases/fourslash/inlineHintsShouldWork49.ts rename to tests/cases/fourslash/inlayHintsShouldWork49.ts index 1a12fd9d62f4a..84bcea95d3efd 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork49.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork49.ts @@ -5,6 +5,6 @@ //// .map(function (e) { return Number(e) }); const markers = test.markers(); -verify.getInlineHints([], undefined, { - includeInlineCallChainsHints: true, +verify.getInlayHints([], undefined, { + includeInlayCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork5.ts b/tests/cases/fourslash/inlayHintsShouldWork5.ts similarity index 54% rename from tests/cases/fourslash/inlineHintsShouldWork5.ts rename to tests/cases/fourslash/inlayHintsShouldWork5.ts index bc627ae521633..0885237ff14e3 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork5.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork5.ts @@ -5,22 +5,25 @@ //// foo(/*a*/1, /*b*/2, /*c*/3) const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'c:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'a:', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'b:', - rangeOrPosition: markers[2].position, + position: markers[2].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork50.ts b/tests/cases/fourslash/inlayHintsShouldWork50.ts similarity index 63% rename from tests/cases/fourslash/inlineHintsShouldWork50.ts rename to tests/cases/fourslash/inlayHintsShouldWork50.ts index 972231971eaaf..e0a6c7836f2fe 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork50.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork50.ts @@ -8,22 +8,25 @@ //// ["map"](function (e) { return Number(e) }); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: ':string[]', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, { text: ':number[]', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true }, { text: ':string[]', - rangeOrPosition: markers[2].position, + position: markers[2].position, + kind: ts.InlayHintKind.Type, whitespaceBefore: true } ], undefined, { - includeInlineCallChainsHints: true, + includeInlayCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork51.ts b/tests/cases/fourslash/inlayHintsShouldWork51.ts similarity index 68% rename from tests/cases/fourslash/inlineHintsShouldWork51.ts rename to tests/cases/fourslash/inlayHintsShouldWork51.ts index c5d2bbd21a00f..114fe5c5f508b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork51.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork51.ts @@ -4,6 +4,6 @@ //// (z.map(function (e) { return String(e) })).map(function (e) { return Number(e) }); const markers = test.markers(); -verify.getInlineHints([], undefined, { - includeInlineCallChainsHints: true, +verify.getInlayHints([], undefined, { + includeInlayCallChainsHints: true, }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork6.ts b/tests/cases/fourslash/inlayHintsShouldWork6.ts similarity index 61% rename from tests/cases/fourslash/inlineHintsShouldWork6.ts rename to tests/cases/fourslash/inlayHintsShouldWork6.ts index 615b6e62145ca..30a2eec1fbb53 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork6.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork6.ts @@ -5,12 +5,13 @@ //// foo(/*a*/1, 2, 3) const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'c:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork7.ts b/tests/cases/fourslash/inlayHintsShouldWork7.ts similarity index 57% rename from tests/cases/fourslash/inlineHintsShouldWork7.ts rename to tests/cases/fourslash/inlayHintsShouldWork7.ts index fa275f2bcd44a..1ded5cb9fc934 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork7.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork7.ts @@ -9,22 +9,25 @@ //// call(/*b*/1, /*c*/2); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'a:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'b:', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'c:', - rangeOrPosition: markers[2].position, + position: markers[2].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork8.ts b/tests/cases/fourslash/inlayHintsShouldWork8.ts similarity index 58% rename from tests/cases/fourslash/inlineHintsShouldWork8.ts rename to tests/cases/fourslash/inlayHintsShouldWork8.ts index c68892a009f9c..1c44c6062c60b 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork8.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork8.ts @@ -9,22 +9,25 @@ //// new Class(/*b*/1, /*c*/2) const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'a:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'b:', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'c:', - rangeOrPosition: markers[2].position, + position: markers[2].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork9.ts b/tests/cases/fourslash/inlayHintsShouldWork9.ts similarity index 56% rename from tests/cases/fourslash/inlineHintsShouldWork9.ts rename to tests/cases/fourslash/inlayHintsShouldWork9.ts index 50a911a028816..552ff9d02de20 100644 --- a/tests/cases/fourslash/inlineHintsShouldWork9.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork9.ts @@ -11,27 +11,31 @@ //// new call(/*d*/1); const markers = test.markers(); -verify.getInlineHints([ +verify.getInlayHints([ { text: 'a:', - rangeOrPosition: markers[0].position, + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'b:', - rangeOrPosition: markers[1].position, + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'c:', - rangeOrPosition: markers[2].position, + position: markers[2].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { text: 'd:', - rangeOrPosition: markers[3].position, + position: markers[3].position, + kind: ts.InlayHintKind.Parameter, whitespaceAfter: true } ], undefined, { - includeInlineParameterNameHints: true + includeInlayParameterNameHints: true }); diff --git a/tests/cases/fourslash/inlineHintsShouldWork13.ts b/tests/cases/fourslash/inlineHintsShouldWork13.ts deleted file mode 100644 index f59ca89dd2325..0000000000000 --- a/tests/cases/fourslash/inlineHintsShouldWork13.ts +++ /dev/null @@ -1,18 +0,0 @@ -/// - -//// function foo (a: number, b: number) {} -//// declare const a: 1; -//// foo(a, /*b*/2); - -const markers = test.markers(); -verify.getInlineHints([ - { - text: 'b:', - rangeOrPosition: markers[0].position, - whitespaceAfter: true - }, -], undefined, { - includeInlineParameterNameHints: true, - includeInlineNonLiteralParameterNameHints: true, - includeInlineDuplicatedParameterNameHints: false, -}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork20.ts b/tests/cases/fourslash/inlineHintsShouldWork20.ts deleted file mode 100644 index 60d852591aefb..0000000000000 --- a/tests/cases/fourslash/inlineHintsShouldWork20.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// - -//// const a = 123; - -verify.getInlineHints([], undefined, { - includeInlineVariableTypeHints: false -}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork21.ts b/tests/cases/fourslash/inlineHintsShouldWork21.ts deleted file mode 100644 index 54e024f674d37..0000000000000 --- a/tests/cases/fourslash/inlineHintsShouldWork21.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// - -//// const a; - -verify.getInlineHints([], undefined, { - includeInlineVariableTypeHints: true -}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork36.ts b/tests/cases/fourslash/inlineHintsShouldWork36.ts deleted file mode 100644 index cd3ce7a9d95cd..0000000000000 --- a/tests/cases/fourslash/inlineHintsShouldWork36.ts +++ /dev/null @@ -1,23 +0,0 @@ -/// - -//// function foo (a: number, b: number) {} -//// declare const a: 1; -//// foo(/*a*/a, /*b*/2); - -const markers = test.markers(); -verify.getInlineHints([ - { - text: 'a:', - rangeOrPosition: markers[0].position, - whitespaceAfter: true - }, - { - text: 'b:', - rangeOrPosition: markers[1].position, - whitespaceAfter: true - }, -], undefined, { - includeInlineParameterNameHints: true, - includeInlineNonLiteralParameterNameHints: true, - includeInlineDuplicatedParameterNameHints: true, -}); From 9306d7210e480c0830cb0c0d5e947ab5383dade4 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 3 Jun 2021 14:02:11 +0800 Subject: [PATCH 32/53] Fix missing property --- src/server/session.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/session.ts b/src/server/session.ts index 7ae71ca5b9f10..150628e2c9468 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1456,7 +1456,7 @@ namespace ts.server { return hints.map(hint => ({ text: hint.text, - range: scriptInfo.positionToLineOffset(hint.position), + position: scriptInfo.positionToLineOffset(hint.position), kind: hint.kind, whitespaceBefore: hint.whitespaceBefore, whitespaceAfter: hint.whitespaceAfter From 2750c6b8e097cb0b5999256ec102908ca0d40ff7 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 4 Jun 2021 11:35:10 +0800 Subject: [PATCH 33/53] Make lint happy --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cd4df8553bddd..12d44f457817a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30351,7 +30351,7 @@ namespace ts { const restType = getTypeOfSymbol(restParameter); if (isTupleType(restType)) { - const associatedNames = ((restType).target).labeledElementDeclarations; + const associatedNames = ((restType as TypeReference).target as TupleType).labeledElementDeclarations; const index = pos - paramCount; return associatedNames ? getTupleElementLabel(associatedNames[index]) : undefined; } From 009096268bbfb0db1dd7a83e7f199a3d8b7da7e3 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 10 Jun 2021 11:56:52 +0800 Subject: [PATCH 34/53] Avoid call chain hints --- src/compiler/types.ts | 2 - src/services/inlayHints.ts | 42 +------------------ src/services/types.ts | 1 - .../reference/api/tsserverlibrary.d.ts | 2 - tests/baselines/reference/api/typescript.d.ts | 2 - tests/cases/fourslash/fourslash.ts | 1 - .../cases/fourslash/inlayHintsShouldWork47.ts | 32 -------------- .../cases/fourslash/inlayHintsShouldWork48.ts | 18 -------- .../cases/fourslash/inlayHintsShouldWork49.ts | 10 ----- .../cases/fourslash/inlayHintsShouldWork50.ts | 32 -------------- .../cases/fourslash/inlayHintsShouldWork51.ts | 9 ---- 11 files changed, 1 insertion(+), 150 deletions(-) delete mode 100644 tests/cases/fourslash/inlayHintsShouldWork47.ts delete mode 100644 tests/cases/fourslash/inlayHintsShouldWork48.ts delete mode 100644 tests/cases/fourslash/inlayHintsShouldWork49.ts delete mode 100644 tests/cases/fourslash/inlayHintsShouldWork50.ts delete mode 100644 tests/cases/fourslash/inlayHintsShouldWork51.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 92dd8979a6719..bc124f2751071 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3967,7 +3967,6 @@ namespace ts { * This implementation handles file exists to be true if file is source of project reference redirect when program is created using useSourceOfProjectReferenceRedirect */ /*@internal*/ fileExists(fileName: string): boolean; - /*@internal*/ inlayHintsCallExpressionHintableCache?: ESMap } /*@internal*/ @@ -8473,7 +8472,6 @@ namespace ts { readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; - readonly includeInlayCallChainsHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 701b9b6e4d2af..0ad3dd62b8e5a 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -8,7 +8,6 @@ namespace ts.InlayHints { const checker = program.getTypeChecker(); const result: InlayHint[] = []; - const callExpressionHintableCache = program.inlayHintsCallExpressionHintableCache ??= new Map(); visitor(file); return result; @@ -48,13 +47,10 @@ namespace ts.InlayHints { else if (preferences.includeInlayEnumMemberValueHints && isEnumMember(node)) { visitEnumMember(node); } - else if (isCallExpression(node) || isNewExpression(node)) { + else if (preferences.includeInlayParameterNameHints && isCallExpression(node) || isNewExpression(node)) { if (preferences.includeInlayParameterNameHints) { visitCallOrNewExpression(node); } - if (preferences.includeInlayCallChainsHints && isCallExpression(node)) { - visitCallChains(node); - } } else { if (preferences.includeInlayFunctionParameterTypeHints && isFunctionExpressionLike(node)) { @@ -102,42 +98,6 @@ namespace ts.InlayHints { }); } - function visitCallChains(call: CallExpression) { - if (!shouldCallExpressionHint(call)) { - return; - } - - const candidates: Signature[] = []; - const signature = checker.getResolvedSignature(call, candidates); - if (!signature || !candidates.length) { - return; - } - - const returnType = checker.getReturnTypeOfSignature(signature); - const typeDisplayString = printTypeInSingleLine(returnType); - if (!typeDisplayString) { - return; - } - - addTypeHints(typeDisplayString, call.end); - } - - function shouldCallExpressionHint(call: CallExpression) { - if (!callExpressionHintableCache.has(call)) { - let current = call; - while (true) { - if (!isAccessExpression(current.parent) || !isCallExpression(current.parent.parent)) { - callExpressionHintableCache.set(current, false); - break; - } - - callExpressionHintableCache.set(current, true); - current = current.parent.parent; - } - } - return callExpressionHintableCache.get(call); - } - function visitEnumMember(member: EnumMember) { if (member.initializer) { return; diff --git a/src/services/types.ts b/src/services/types.ts index 34f03affcef1a..1398fe0b2bfe8 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -582,7 +582,6 @@ namespace ts { readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; - readonly includeInlayCallChainsHints?: boolean; } export type SignatureHelpTriggerCharacter = "," | "(" | "<"; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 091cdf6308883..1b38fb36568f2 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3965,7 +3965,6 @@ declare namespace ts { readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; - readonly includeInlayCallChainsHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5754,7 +5753,6 @@ declare namespace ts { readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; - readonly includeInlayCallChainsHints?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 07adf59ae0d75..750b6e4ddc449 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3965,7 +3965,6 @@ declare namespace ts { readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; - readonly includeInlayCallChainsHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -5754,7 +5753,6 @@ declare namespace ts { readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; - readonly includeInlayCallChainsHints?: boolean; } type SignatureHelpTriggerCharacter = "," | "(" | "<"; type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index f62b3e589e720..542ad100278b6 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -650,7 +650,6 @@ declare namespace FourSlashInterface { readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; - readonly includeInlayCallChainsHints?: boolean; } interface CompletionsOptions { readonly marker?: ArrayOrSingle; diff --git a/tests/cases/fourslash/inlayHintsShouldWork47.ts b/tests/cases/fourslash/inlayHintsShouldWork47.ts deleted file mode 100644 index 14a333bc3997d..0000000000000 --- a/tests/cases/fourslash/inlayHintsShouldWork47.ts +++ /dev/null @@ -1,32 +0,0 @@ -/// - -//// const z = [1, 2, 3]; -//// z -//// .map(function (e) { return String(e) })/*a*/ -//// .map(function (e) { return Number(e) })/*b*/ -//// .map(function (e) { return String(e) })/*c*/ -//// .map(function (e) { return Number(e) }); - -const markers = test.markers(); -verify.getInlayHints([ - { - text: ':string[]', - position: markers[0].position, - kind: ts.InlayHintKind.Type, - whitespaceBefore: true - }, - { - text: ':number[]', - position: markers[1].position, - kind: ts.InlayHintKind.Type, - whitespaceBefore: true - }, - { - text: ':string[]', - position: markers[2].position, - kind: ts.InlayHintKind.Type, - whitespaceBefore: true - } -], undefined, { - includeInlayCallChainsHints: true, -}); diff --git a/tests/cases/fourslash/inlayHintsShouldWork48.ts b/tests/cases/fourslash/inlayHintsShouldWork48.ts deleted file mode 100644 index 5a2a729915c3a..0000000000000 --- a/tests/cases/fourslash/inlayHintsShouldWork48.ts +++ /dev/null @@ -1,18 +0,0 @@ -/// - -//// const z = [1, 2, 3]; -//// z -//// .map(function (e) { return String(e) })/*a*/ -//// .map(function (e) { return Number(e) }); - -const markers = test.markers(); -verify.getInlayHints([ - { - text: ':string[]', - position: markers[0].position, - kind: ts.InlayHintKind.Type, - whitespaceBefore: true - } -], undefined, { - includeInlayCallChainsHints: true, -}); diff --git a/tests/cases/fourslash/inlayHintsShouldWork49.ts b/tests/cases/fourslash/inlayHintsShouldWork49.ts deleted file mode 100644 index 84bcea95d3efd..0000000000000 --- a/tests/cases/fourslash/inlayHintsShouldWork49.ts +++ /dev/null @@ -1,10 +0,0 @@ -/// - -//// const z = [1, 2, 3]; -//// z -//// .map(function (e) { return Number(e) }); - -const markers = test.markers(); -verify.getInlayHints([], undefined, { - includeInlayCallChainsHints: true, -}); diff --git a/tests/cases/fourslash/inlayHintsShouldWork50.ts b/tests/cases/fourslash/inlayHintsShouldWork50.ts deleted file mode 100644 index e0a6c7836f2fe..0000000000000 --- a/tests/cases/fourslash/inlayHintsShouldWork50.ts +++ /dev/null @@ -1,32 +0,0 @@ -/// - -//// const z = [1, 2, 3]; -//// z -//// .map(function (e) { return String(e) })/*a*/ -//// ["map"](function (e) { return Number(e) })/*b*/ -//// .map(function (e) { return String(e) })/*c*/ -//// ["map"](function (e) { return Number(e) }); - -const markers = test.markers(); -verify.getInlayHints([ - { - text: ':string[]', - position: markers[0].position, - kind: ts.InlayHintKind.Type, - whitespaceBefore: true - }, - { - text: ':number[]', - position: markers[1].position, - kind: ts.InlayHintKind.Type, - whitespaceBefore: true - }, - { - text: ':string[]', - position: markers[2].position, - kind: ts.InlayHintKind.Type, - whitespaceBefore: true - } -], undefined, { - includeInlayCallChainsHints: true, -}); diff --git a/tests/cases/fourslash/inlayHintsShouldWork51.ts b/tests/cases/fourslash/inlayHintsShouldWork51.ts deleted file mode 100644 index 114fe5c5f508b..0000000000000 --- a/tests/cases/fourslash/inlayHintsShouldWork51.ts +++ /dev/null @@ -1,9 +0,0 @@ -/// - -//// const z = [1, 2, 3]; -//// (z.map(function (e) { return String(e) })).map(function (e) { return Number(e) }); - -const markers = test.markers(); -verify.getInlayHints([], undefined, { - includeInlayCallChainsHints: true, -}); From f771afc99fa16a69c4e980abccc4cb98dd4d186c Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 10 Jun 2021 11:58:45 +0800 Subject: [PATCH 35/53] I'm bad --- src/services/inlayHints.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 0ad3dd62b8e5a..96ffff0133f60 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -47,10 +47,8 @@ namespace ts.InlayHints { else if (preferences.includeInlayEnumMemberValueHints && isEnumMember(node)) { visitEnumMember(node); } - else if (preferences.includeInlayParameterNameHints && isCallExpression(node) || isNewExpression(node)) { - if (preferences.includeInlayParameterNameHints) { - visitCallOrNewExpression(node); - } + else if (preferences.includeInlayParameterNameHints && (isCallExpression(node) || isNewExpression(node))) { + visitCallOrNewExpression(node); } else { if (preferences.includeInlayFunctionParameterTypeHints && isFunctionExpressionLike(node)) { From 67dcbb0fd0cd06691b3d672fcd2f6cc957df8474 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 10 Jun 2021 12:06:09 +0800 Subject: [PATCH 36/53] Add whitespace before type --- src/services/inlayHints.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork15.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork16.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork17.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork18.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork19.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork22.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork24.ts | 4 ++-- tests/cases/fourslash/inlayHintsShouldWork25.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork26.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork27.ts | 4 ++-- tests/cases/fourslash/inlayHintsShouldWork28.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork29.ts | 4 ++-- tests/cases/fourslash/inlayHintsShouldWork30.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork31.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork37.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork38.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork40.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork41.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork42.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork43.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork46.ts | 2 +- 22 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 96ffff0133f60..e268112e0bafc 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -80,7 +80,7 @@ namespace ts.InlayHints { function addTypeHints(text: string, position: number) { result.push({ - text: `:${truncation(text, maxHintsLength)}`, + text: `: ${truncation(text, maxHintsLength)}`, position, kind: InlayHintKind.Type, whitespaceBefore: true, diff --git a/tests/cases/fourslash/inlayHintsShouldWork15.ts b/tests/cases/fourslash/inlayHintsShouldWork15.ts index c295c8e1eaf36..544838b43c73b 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork15.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork15.ts @@ -5,7 +5,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':123', + text: ': 123', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork16.ts b/tests/cases/fourslash/inlayHintsShouldWork16.ts index c295c8e1eaf36..544838b43c73b 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork16.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork16.ts @@ -5,7 +5,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':123', + text: ': 123', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork17.ts b/tests/cases/fourslash/inlayHintsShouldWork17.ts index 4d3165b901190..70ea5e0d5eb5d 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork17.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork17.ts @@ -5,7 +5,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':{ a: number; }', + text: ': { a: number; }', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork18.ts b/tests/cases/fourslash/inlayHintsShouldWork18.ts index fa84a7369d309..e33033549f0dc 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork18.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork18.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':Class', + text: ': Class', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork19.ts b/tests/cases/fourslash/inlayHintsShouldWork19.ts index ef2e72a7f1147..8d21f16cda77e 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork19.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork19.ts @@ -5,7 +5,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':() => number', + text: ': () => number', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork22.ts b/tests/cases/fourslash/inlayHintsShouldWork22.ts index a6df150349d2b..91fa9eb02c3a5 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork22.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork22.ts @@ -5,7 +5,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: `:"I'm very very very very ve...`, + text: `: "I'm very very very very ve...`, position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork24.ts b/tests/cases/fourslash/inlayHintsShouldWork24.ts index 7403df51f87aa..9e38e7cf75ffd 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork24.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork24.ts @@ -6,13 +6,13 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':string', + text: ': string', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true }, { - text: ':number', + text: ': number', position: markers[1].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork25.ts b/tests/cases/fourslash/inlayHintsShouldWork25.ts index 0fe69a4be64f0..9bb52811c3412 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork25.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork25.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':string', + text: ': string', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork26.ts b/tests/cases/fourslash/inlayHintsShouldWork26.ts index 64c22bab33f3c..e02d1b2792890 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork26.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork26.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':2 | 3', + text: ': 2 | 3', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork27.ts b/tests/cases/fourslash/inlayHintsShouldWork27.ts index 04369b4a92f11..77d966f549740 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork27.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork27.ts @@ -8,13 +8,13 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':(c: (d: 2 | 3) => void) => ...', + text: ': (c: (d: 2 | 3) => void) => ...', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true }, { - text: ':2 | 3', + text: ': 2 | 3', position: markers[1].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork28.ts b/tests/cases/fourslash/inlayHintsShouldWork28.ts index 2e20836171e4a..9ceca69c2d501 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork28.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork28.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':string', + text: ': string', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork29.ts b/tests/cases/fourslash/inlayHintsShouldWork29.ts index 3dbf7fb8c75a0..8a8e384d65799 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork29.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork29.ts @@ -14,7 +14,7 @@ verify.getInlayHints([ whitespaceAfter: true }, { - text: ':(c: (d: 2 | 3) => void) => ...', + text: ': (c: (d: 2 | 3) => void) => ...', position: markers[1].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true @@ -26,7 +26,7 @@ verify.getInlayHints([ whitespaceAfter: true }, { - text: ':2 | 3', + text: ': 2 | 3', position: markers[3].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork30.ts b/tests/cases/fourslash/inlayHintsShouldWork30.ts index 96d244b85bef7..2c44c86cfeb36 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork30.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork30.ts @@ -6,7 +6,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':number', + text: ': number', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork31.ts b/tests/cases/fourslash/inlayHintsShouldWork31.ts index ed178ead22d19..d6c2c41e45385 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork31.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork31.ts @@ -9,7 +9,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':{ a: number; b: string; }', + text: ': { a: number; b: string; }', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork37.ts b/tests/cases/fourslash/inlayHintsShouldWork37.ts index 9a541ddb146b4..878d92df3bd7b 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork37.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork37.ts @@ -9,7 +9,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':number', + text: ': number', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork38.ts b/tests/cases/fourslash/inlayHintsShouldWork38.ts index b2ad912844218..e43d6cedb673a 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork38.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork38.ts @@ -7,7 +7,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':number', + text: ': number', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork40.ts b/tests/cases/fourslash/inlayHintsShouldWork40.ts index 139ea7cc88750..4016b38f4924d 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork40.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork40.ts @@ -9,7 +9,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':number', + text: ': number', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork41.ts b/tests/cases/fourslash/inlayHintsShouldWork41.ts index 974f864b46cc2..ddd5ba22d8924 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork41.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork41.ts @@ -5,7 +5,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':number', + text: ': number', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork42.ts b/tests/cases/fourslash/inlayHintsShouldWork42.ts index 8913e92985e7b..4fbd4b8fd6ff8 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork42.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork42.ts @@ -5,7 +5,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':number', + text: ': number', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork43.ts b/tests/cases/fourslash/inlayHintsShouldWork43.ts index 32e8289042511..157f55f0736eb 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork43.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork43.ts @@ -5,7 +5,7 @@ const markers = test.markers(); verify.getInlayHints([ { - text: ':number', + text: ': number', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork46.ts b/tests/cases/fourslash/inlayHintsShouldWork46.ts index dd6ba4317b591..938399ebd16be 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork46.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork46.ts @@ -13,7 +13,7 @@ goTo.file('/b.js') const markers = test.markers(); verify.getInlayHints([ { - text: ':typeof import("/a")', + text: ': typeof import("/a")', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true From 957756cb884505235aa7a592c6a0b2f1521454b0 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 10 Jun 2021 12:14:13 +0800 Subject: [PATCH 37/53] Add more tests --- .../cases/fourslash/inlayHintsShouldWork47.ts | 33 +++++++++++++++++++ .../cases/fourslash/inlayHintsShouldWork48.ts | 16 +++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork47.ts create mode 100644 tests/cases/fourslash/inlayHintsShouldWork48.ts diff --git a/tests/cases/fourslash/inlayHintsShouldWork47.ts b/tests/cases/fourslash/inlayHintsShouldWork47.ts new file mode 100644 index 0000000000000..e6d8c570d7d4c --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork47.ts @@ -0,0 +1,33 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: /a.js +//// var x +//// x.foo(1, 2); + +//// /** +//// * @type {{foo: (a: number, b: number) => void}} +//// */ +//// var y +//// y.foo(/*a*/1, /*b*/2) + +goTo.file('/a.js') +const markers = test.markers(); +verify.getInlayHints([ + { + text: 'a:', + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + } +], undefined, { + includeInlayParameterNameHints: true +}); diff --git a/tests/cases/fourslash/inlayHintsShouldWork48.ts b/tests/cases/fourslash/inlayHintsShouldWork48.ts new file mode 100644 index 0000000000000..5c7a09fa1f27f --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork48.ts @@ -0,0 +1,16 @@ +/// + +//// declare function foo(t: T): T +//// const x/*a*/ = foo(1) + +const markers = test.markers(); +verify.getInlayHints([ + { + text: `: 1`, + position: markers[0].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, +], undefined, { + includeInlayVariableTypeHints: true +}); From db4135bc90de547a30698da60099263147491fe8 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 10 Jun 2021 15:40:54 +0800 Subject: [PATCH 38/53] Should care about jsdoc --- src/services/inlayHints.ts | 12 ++++++++---- tests/cases/fourslash/inlayHintsShouldWork49.ts | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork49.ts diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index e268112e0bafc..699447627dff7 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -108,7 +108,8 @@ namespace ts.InlayHints { } function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) { - if (decl.type || !decl.initializer) { + const effectiveTypeAnnotation = getEffectiveTypeAnnotationNode(decl); + if (effectiveTypeAnnotation || !decl.initializer) { return; } @@ -155,7 +156,8 @@ namespace ts.InlayHints { } function visitFunctionDeclarationLikeForReturnType(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { - if (decl.type || !decl.body) { + const effectiveTypeAnnotation = getEffectiveReturnTypeNode(decl); + if (effectiveTypeAnnotation || !decl.body) { return; } @@ -184,7 +186,7 @@ namespace ts.InlayHints { } function visitFunctionExpressionLikeForParameterType(expr: ArrowFunction | FunctionExpression) { - if (!expr.parameters.length || expr.parameters.every(param => param.type)) { + if (!expr.parameters.length || expr.parameters.every(param => !!getEffectiveTypeAnnotationNode(param))) { return; } @@ -201,7 +203,9 @@ namespace ts.InlayHints { for (let i = 0; i < expr.parameters.length && i < signature.parameters.length; ++i) { const param = expr.parameters[i]; - if (param.type) { + const effectiveTypeAnnotation = getEffectiveTypeAnnotationNode(param); + + if (effectiveTypeAnnotation) { continue; } diff --git a/tests/cases/fourslash/inlayHintsShouldWork49.ts b/tests/cases/fourslash/inlayHintsShouldWork49.ts new file mode 100644 index 0000000000000..004ebac42d475 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork49.ts @@ -0,0 +1,17 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: /a.js +//// /** +//// * @type {string} +//// */ +//// var x = "" + + +goTo.file('/a.js') +const markers = test.markers(); +verify.getInlayHints([], undefined, { + includeInlayParameterNameHints: true +}); From b74af7ca7f1c8ccbfd8bad6846f53046ed5797e9 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 10 Jun 2021 18:08:28 +0800 Subject: [PATCH 39/53] Support complex rest parameter --- src/compiler/checker.ts | 13 +++-- src/compiler/types.ts | 2 +- src/services/inlayHints.ts | 13 ++--- .../cases/fourslash/inlayHintsShouldWork3.ts | 2 +- .../cases/fourslash/inlayHintsShouldWork50.ts | 49 +++++++++++++++++++ 5 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork50.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 12d44f457817a..c7c8e5074aefd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30337,11 +30337,11 @@ namespace ts { return restParameter.escapedName; } - function getParameterIdentifierNameAtPosition(signature: Signature, pos: number): __String | undefined { + function getParameterIdentifierNameAtPosition(signature: Signature, pos: number): [__String, boolean] | undefined { const paramCount = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0); if (pos < paramCount) { const param = signature.parameters[pos]; - return isParameterDeclarationWithIdentifierName(param) ? param.escapedName : undefined; + return isParameterDeclarationWithIdentifierName(param) ? [param.escapedName, false] : undefined; } const restParameter = signature.parameters[paramCount] || unknownSymbol; @@ -30353,11 +30353,16 @@ namespace ts { if (isTupleType(restType)) { const associatedNames = ((restType as TypeReference).target as TupleType).labeledElementDeclarations; const index = pos - paramCount; - return associatedNames ? getTupleElementLabel(associatedNames[index]) : undefined; + const associatedName = associatedNames?.[index]; + const isRestTupleElement = !!associatedName?.dotDotDotToken; + return associatedName ? [ + getTupleElementLabel(associatedName), + isRestTupleElement + ] : undefined; } if (pos === paramCount) { - return restParameter.escapedName; + return [restParameter.escapedName, true]; } return undefined; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bc124f2751071..d9ae01cfbf28d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4100,7 +4100,7 @@ namespace ts { * Returns `any` if the index is not valid. */ /* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type; - /* @internal */ getParameterIdentifierNameAtPosition(signature: Signature, parameterIndex: number): __String | undefined; + /* @internal */ getParameterIdentifierNameAtPosition(signature: Signature, parameterIndex: number): [__String, boolean] | undefined; getNullableType(type: Type, flags: TypeFlags): Type; getNonNullableType(type: Type): Type; /* @internal */ getNonOptionalType(type: Type): Type; diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 699447627dff7..c0e3e00b73900 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -69,9 +69,9 @@ namespace ts.InlayHints { return isArrowFunction(node) || isFunctionExpression(node) || isFunctionDeclaration(node) || isMethodDeclaration(node); } - function addParameterHints(text: string, position: number) { + function addParameterHints(text: string, position: number, isFirstVariadicArgument: boolean) { result.push({ - text: `${truncation(text, maxHintsLength)}:`, + text: `${isFirstVariadicArgument ? "..." : ""}${truncation(text, maxHintsLength)}:`, position, kind: InlayHintKind.Parameter, whitespaceAfter: true, @@ -142,10 +142,11 @@ namespace ts.InlayHints { continue; } - const parameterName = checker.getParameterIdentifierNameAtPosition(signature, i); - if (parameterName) { - if (preferences.includeInlayDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { - addParameterHints(unescapeLeadingUnderscores(parameterName), args[i].getStart()); + const identifierNameInfo = checker.getParameterIdentifierNameAtPosition(signature, i); + if (identifierNameInfo) { + const [parameterName, isFirstVariadicArgument] = identifierNameInfo; + if (isFirstVariadicArgument || preferences.includeInlayDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { + addParameterHints(unescapeLeadingUnderscores(parameterName), args[i].getStart(), isFirstVariadicArgument); } } } diff --git a/tests/cases/fourslash/inlayHintsShouldWork3.ts b/tests/cases/fourslash/inlayHintsShouldWork3.ts index 34fec2d053228..7387ec9d33b79 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork3.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork3.ts @@ -12,7 +12,7 @@ verify.getInlayHints([ whitespaceAfter: true }, { - text: 'b:', + text: '...b:', position: markers[1].position, kind: ts.InlayHintKind.Parameter, whitespaceAfter: true diff --git a/tests/cases/fourslash/inlayHintsShouldWork50.ts b/tests/cases/fourslash/inlayHintsShouldWork50.ts new file mode 100644 index 0000000000000..94258c549a0c4 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork50.ts @@ -0,0 +1,49 @@ +/// + +//// type T = [a: string, b: boolean, ...c: number[]] +//// declare function foo(f: number, ...args: T):void +//// declare function foo1(f1: number, ...args: string[]): void +//// foo(/*f*/1, /*a*/'', /*b*/false, /*c*/1, 2) +//// foo1(/*f1*/1, /*args*/"", "") + +const markers = test.markers(); +verify.getInlayHints([ + { + text: 'f:', + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: 'a:', + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[2].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: '...c:', + position: markers[3].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: 'f1:', + position: markers[4].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: '...args:', + position: markers[5].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, +], undefined, { + includeInlayParameterNameHints: true +}); From 388cc6decd741236db9d9a393f52c16b4e162f1d Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 14 Jun 2021 17:34:04 +0800 Subject: [PATCH 40/53] Avoid module symbol hints --- src/compiler/types.ts | 1 - src/services/inlayHints.ts | 14 +++++- src/services/types.ts | 1 - .../reference/api/tsserverlibrary.d.ts | 2 - tests/baselines/reference/api/typescript.d.ts | 2 - tests/cases/fourslash/fourslash.ts | 1 - .../cases/fourslash/inlayHintsShouldWork45.ts | 1 - .../cases/fourslash/inlayHintsShouldWork46.ts | 17 +++++-- .../cases/fourslash/inlayHintsShouldWork51.ts | 46 +++++++++++++++++++ 9 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork51.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d9ae01cfbf28d..68d680852d02f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8468,7 +8468,6 @@ namespace ts { readonly includeInlayDuplicatedParameterNameHints?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayRequireAssignedVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index c0e3e00b73900..2fedaa886ef66 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -107,6 +107,10 @@ namespace ts.InlayHints { } } + function isModuleReferenceType(type: Type) { + return type.symbol && (type.symbol.flags & SymbolFlags.Module); + } + function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) { const effectiveTypeAnnotation = getEffectiveTypeAnnotationNode(decl); if (effectiveTypeAnnotation || !decl.initializer) { @@ -114,7 +118,7 @@ namespace ts.InlayHints { } const declarationType = checker.getTypeAtLocation(decl); - if (!preferences.includeInlayRequireAssignedVariableTypeHints && declarationType.symbol && (declarationType.symbol.flags & SymbolFlags.Module)) { + if (isModuleReferenceType(declarationType)) { return; } @@ -170,6 +174,10 @@ namespace ts.InlayHints { } const returnType = checker.getReturnTypeOfSignature(signature); + if (isModuleReferenceType(returnType)) { + return; + } + const typeDisplayString = printTypeInSingleLine(returnType); if (!typeDisplayString) { return; @@ -226,6 +234,10 @@ namespace ts.InlayHints { } const signatureParamType = checker.getTypeOfSymbolAtLocation(symbol, valueDeclaration); + if (isModuleReferenceType(signatureParamType)) { + return undefined; + } + return printTypeInSingleLine(signatureParamType); } diff --git a/src/services/types.ts b/src/services/types.ts index 1398fe0b2bfe8..4316be58d46ef 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -578,7 +578,6 @@ namespace ts { readonly includeInlayDuplicatedParameterNameHints?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean, readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayRequireAssignedVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 1b38fb36568f2..256f9eadafc37 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3961,7 +3961,6 @@ declare namespace ts { readonly includeInlayDuplicatedParameterNameHints?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayRequireAssignedVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; @@ -5749,7 +5748,6 @@ declare namespace ts { readonly includeInlayDuplicatedParameterNameHints?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayRequireAssignedVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 750b6e4ddc449..08d68516633f4 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3961,7 +3961,6 @@ declare namespace ts { readonly includeInlayDuplicatedParameterNameHints?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayRequireAssignedVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; @@ -5749,7 +5748,6 @@ declare namespace ts { readonly includeInlayDuplicatedParameterNameHints?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayRequireAssignedVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 542ad100278b6..1d7d4ab877d66 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -646,7 +646,6 @@ declare namespace FourSlashInterface { readonly includeInlayDuplicatedParameterNameHints?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayRequireAssignedVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/tests/cases/fourslash/inlayHintsShouldWork45.ts b/tests/cases/fourslash/inlayHintsShouldWork45.ts index 4ba7399d46076..586f46fc905ff 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork45.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork45.ts @@ -13,5 +13,4 @@ goTo.file('/b.js') const markers = test.markers(); verify.getInlayHints([], undefined, { includeInlayVariableTypeHints: true, - includeInlayRequireAssignedVariableTypeHints: false }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork46.ts b/tests/cases/fourslash/inlayHintsShouldWork46.ts index 938399ebd16be..3fac222fd2467 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork46.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork46.ts @@ -7,18 +7,27 @@ //// module.exports.a = 1 // @Filename: /b.js -//// const a/*a*/ = require('./a'); +//// function foo () { return require('./a'); } +//// function bar ()/*a*/ { return require('./a').a; } +//// const c = foo() +//// const d/*b*/ = bar() goTo.file('/b.js') const markers = test.markers(); verify.getInlayHints([ { - text: ': typeof import("/a")', + text: ': number', position: markers[0].position, kind: ts.InlayHintKind.Type, whitespaceBefore: true - } + }, + { + text: ': number', + position: markers[1].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, ], undefined, { includeInlayVariableTypeHints: true, - includeInlayRequireAssignedVariableTypeHints: true + includeInlayFunctionLikeReturnTypeHints: true }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork51.ts b/tests/cases/fourslash/inlayHintsShouldWork51.ts new file mode 100644 index 0000000000000..2e9f44ccc59d4 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork51.ts @@ -0,0 +1,46 @@ +/// + +// @Filename: /a.ts +//// export interface Foo { a: string } + +// @Filename: /b.ts +//// async function foo ()/*a*/ { +//// return {} as any as import('./a').Foo +//// } +//// function bar ()/*b*/ { return import('./a') } +//// async function main ()/*c*/ { +//// const a/*d*/ = await foo() +//// const b = await bar() +//// } + +goTo.file('/b.ts') +const markers = test.markers(); +verify.getInlayHints([ + { + text: ': Promise', + position: markers[0].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, + { + text: ': Promise', + position: markers[1].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, + { + text: ': Promise', + position: markers[2].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, + { + text: ': Foo', + position: markers[3].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + } +], undefined, { + includeInlayVariableTypeHints: true, + includeInlayFunctionLikeReturnTypeHints: true +}); From f5695a1eb6e1d71e61a8c9d8204cfd2986d44922 Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 14 Jun 2021 18:23:56 +0800 Subject: [PATCH 41/53] Care about leading comments --- src/services/inlayHints.ts | 19 +++++- .../cases/fourslash/inlayHintsShouldWork52.ts | 66 +++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork52.ts diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 2fedaa886ef66..393535332c662 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -5,6 +5,7 @@ namespace ts.InlayHints { export function provideInlayHints(context: InlayHintsContext): InlayHint[] { const { file, program, span, cancellationToken, preferences } = context; + const sourceFileText = file.text; const checker = program.getTypeChecker(); const result: InlayHint[] = []; @@ -149,13 +150,27 @@ namespace ts.InlayHints { const identifierNameInfo = checker.getParameterIdentifierNameAtPosition(signature, i); if (identifierNameInfo) { const [parameterName, isFirstVariadicArgument] = identifierNameInfo; - if (isFirstVariadicArgument || preferences.includeInlayDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName) { - addParameterHints(unescapeLeadingUnderscores(parameterName), args[i].getStart(), isFirstVariadicArgument); + const isParameterNameNotSameAsArgument = preferences.includeInlayDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName; + if (!isParameterNameNotSameAsArgument && !isFirstVariadicArgument) { + continue; } + + const name = unescapeLeadingUnderscores(parameterName); + const commentRanges = getLeadingCommentRanges(sourceFileText, arg.pos); + if (leadingCommentsHasParameterName(commentRanges, name)) { + continue; + } + + addParameterHints(name, args[i].getStart(), isFirstVariadicArgument); } } } + function leadingCommentsHasParameterName(commentRanges: CommentRange[] | undefined, name: string) { + if (!commentRanges?.length) return false; + return commentRanges.some(range => stringContains(sourceFileText.substring(range.pos, range.end), name)); + } + function isHintableExpression(node: Node) { return isLiteralExpression(node) || isBooleanLiteral(node) || isFunctionExpressionLike(node) || isObjectLiteralExpression(node) || isArrayLiteralExpression(node); } diff --git a/tests/cases/fourslash/inlayHintsShouldWork52.ts b/tests/cases/fourslash/inlayHintsShouldWork52.ts new file mode 100644 index 0000000000000..5c875c45680c3 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork52.ts @@ -0,0 +1,66 @@ +/// + +//// function foo (aParameter: number, bParameter: number, cParameter: number)/*f*/ { } + +//// foo( +//// /** aParameter */ +//// 1, +//// // bParameter +//// 2, +//// /* cParameter */ +//// 3 +//// ) + +//// foo( +//// /** multiple comments */ +//// /** aParameter */ +//// 1, +//// /** bParameter */ +//// /** multiple comments */ +//// 2, +//// // cParameter +//// /** multiple comments */ +//// 3 +//// ) + +//// foo( +//// /** wrong name */ +//// /*a*/1, +//// /*b*/2, +//// /** multiple */ +//// /** wrong */ +//// /** name */ +//// /*c*/3 +//// ) + + +const markers = test.markers(); +verify.getInlayHints([ + { + text: ': void', + position: markers[0].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, + { + text: 'aParameter:', + position: markers[1].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: 'bParameter:', + position: markers[2].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: 'cParameter:', + position: markers[3].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + } +], undefined, { + includeInlayParameterNameHints: true, + includeInlayFunctionLikeReturnTypeHints: true +}); From 633680308b36ba65cd5d5c3f501499ca8b129c5d Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 15 Jun 2021 12:22:42 +0800 Subject: [PATCH 42/53] Fix CR issues --- src/services/inlayHints.ts | 34 ++++++------------- .../cases/fourslash/inlayHintsShouldWork33.ts | 2 +- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 393535332c662..699460d71d336 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -13,13 +13,12 @@ namespace ts.InlayHints { visitor(file); return result; - function visitor(node: Node): true | undefined | void { + function visitor(node: Node): true | undefined { if (!node || node.getFullWidth() === 0) { return; } switch (node.kind) { - case SyntaxKind.ModuleDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: @@ -29,10 +28,10 @@ namespace ts.InlayHints { case SyntaxKind.MethodDeclaration: case SyntaxKind.ArrowFunction: cancellationToken.throwIfCancellationRequested(); + } - if (!textSpanIntersectsWith(span, node.pos, node.getFullWidth())) { - return; - } + if (!textSpanIntersectsWith(span, node.pos, node.getFullWidth())) { + return; } if (isTypeNode(node)) { @@ -263,29 +262,16 @@ namespace ts.InlayHints { return text; } - function createSignleLineWriter(writer: DisplayPartsSymbolWriter): DisplayPartsSymbolWriter { - return { - ...writer, - writeLine: () => writer.writeSpace(" ") - }; - } - function printTypeInSingleLine(type: Type) { const flags = NodeBuilderFlags.IgnoreErrors | TypeFormatFlags.AllowUniqueESSymbolType | TypeFormatFlags.UseAliasDefinedOutsideCurrentScope; - const displayParts = mapToDisplayParts(writer => { - const singleLineWriter = createSignleLineWriter(writer); - const typeNode = checker.typeToTypeNode(type, /*enclosingDeclaration*/ undefined, flags, singleLineWriter); - Debug.assertIsDefined(typeNode, "should always get typenode"); - - writeNodeInSignleLine(typeNode, singleLineWriter); - }); - return displayPartsToString(displayParts); - } - - function writeNodeInSignleLine(node: Node, writer: DisplayPartsSymbolWriter) { const options: PrinterOptions = { removeComments: true }; const printer = createPrinter(options); - printer.writeNode(EmitHint.Unspecified, node, /*sourceFile*/ file, writer); + + return usingSingleLineStringWriter(writer => { + const typeNode = checker.typeToTypeNode(type, /*enclosingDeclaration*/ undefined, flags, writer); + Debug.assertIsDefined(typeNode, "should always get typenode"); + printer.writeNode(EmitHint.Unspecified, typeNode, /*sourceFile*/ file, writer); + }); } } } diff --git a/tests/cases/fourslash/inlayHintsShouldWork33.ts b/tests/cases/fourslash/inlayHintsShouldWork33.ts index 1fc93d9b736f4..9cdb1b06ce121 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork33.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork33.ts @@ -19,7 +19,7 @@ const end = test.markerByName('h'); const span = { start: start.position, length: end.position - start.position }; verify.getInlayHints( - ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'].map(mark => { + ['c', 'd', 'e', 'f', 'g', 'h'].map(mark => { return { text: `${mark}:`, position: test.markerByName(mark).position, From 09cdf3721e7c8e9af176a25f37e45d56e856dea7 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 15 Jun 2021 12:23:26 +0800 Subject: [PATCH 43/53] Avoid changes --- src/testRunner/parallel/worker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testRunner/parallel/worker.ts b/src/testRunner/parallel/worker.ts index 5d457d0ecdea0..21570ab3e1e62 100644 --- a/src/testRunner/parallel/worker.ts +++ b/src/testRunner/parallel/worker.ts @@ -223,7 +223,7 @@ namespace Harness.Parallel.Worker { }) .on("end", () => { hookUncaughtExceptions(); - (runner as any).dispose(); + runner.dispose(); }) .run(() => { fn({ task, errors, passes, passing: passes.length, duration: +new Date() - start }); From 71bae5e5e2491195c97cef6bb28ba7f31aff6a84 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 15 Jun 2021 14:33:25 +0800 Subject: [PATCH 44/53] Simplify comments contains --- src/services/inlayHints.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 699460d71d336..933e3a2d79a32 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -155,8 +155,7 @@ namespace ts.InlayHints { } const name = unescapeLeadingUnderscores(parameterName); - const commentRanges = getLeadingCommentRanges(sourceFileText, arg.pos); - if (leadingCommentsHasParameterName(commentRanges, name)) { + if (leadingCommentsContainsParameterName(arg, name)) { continue; } @@ -165,9 +164,15 @@ namespace ts.InlayHints { } } - function leadingCommentsHasParameterName(commentRanges: CommentRange[] | undefined, name: string) { - if (!commentRanges?.length) return false; - return commentRanges.some(range => stringContains(sourceFileText.substring(range.pos, range.end), name)); + function leadingCommentsContainsParameterName(node: Node, name: string) { + const fullStart = node.getFullStart(); + const start = node.getStart(); + if (start === fullStart) { + return false; + } + + // leading comments contains parameter name + return stringContains(sourceFileText.substring(fullStart, start), name); } function isHintableExpression(node: Node) { From cba4dc30314e37b2e8d60db7fabeb3096733800f Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 18 Jun 2021 13:56:57 +0800 Subject: [PATCH 45/53] Fix CR issues --- src/compiler/checker.ts | 2 +- src/compiler/types.ts | 2 +- src/harness/client.ts | 6 ++-- src/harness/fourslashImpl.ts | 2 +- src/server/scriptInfo.ts | 7 ----- src/server/session.ts | 5 +--- src/services/inlayHints.ts | 21 ++++++++++---- .../cases/fourslash/inlayHintsShouldWork43.ts | 3 +- .../cases/fourslash/inlayHintsShouldWork52.ts | 28 +++++++++++++------ .../cases/fourslash/inlayHintsShouldWork53.ts | 16 +++++++++++ 10 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork53.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c7c8e5074aefd..614a97bc5f4e3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30337,7 +30337,7 @@ namespace ts { return restParameter.escapedName; } - function getParameterIdentifierNameAtPosition(signature: Signature, pos: number): [__String, boolean] | undefined { + function getParameterIdentifierNameAtPosition(signature: Signature, pos: number): [parameterName: __String, isRestParameter: boolean] | undefined { const paramCount = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0); if (pos < paramCount) { const param = signature.parameters[pos]; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 68d680852d02f..a684f7cfa9bc8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4100,7 +4100,7 @@ namespace ts { * Returns `any` if the index is not valid. */ /* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type; - /* @internal */ getParameterIdentifierNameAtPosition(signature: Signature, parameterIndex: number): [__String, boolean] | undefined; + /* @internal */ getParameterIdentifierNameAtPosition(signature: Signature, parameterIndex: number): [parameterName: __String, isRestParameter: boolean] | undefined; getNullableType(type: Type, flags: TypeFlags): Type; getNonNullableType(type: Type): Type; /* @internal */ getNonOptionalType(type: Type): Type; diff --git a/src/harness/client.ts b/src/harness/client.ts index 78e31819275b4..8fa69826565ee 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -654,11 +654,9 @@ namespace ts.server { const response = this.processResponse(request); return response.body!.map(item => ({ // TODO: GH#18217 - text: item.text, - position: this.lineOffsetToPosition(file, item.position), + ...item, kind: item.kind as InlayHintKind | undefined, - whitespaceBefore: item.whitespaceBefore, - whitespaceAfter: item.whitespaceAfter + position: this.lineOffsetToPosition(file, item.position), })); } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 51f97266617da..af75c48f0bae0 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -846,7 +846,7 @@ namespace FourSlash { }; ts.zipWith(hints.sort(sortHints), [...expected].sort(sortHints), (actual, expected) => { assert.equal(actual.text, expected.text, "Text"); - assert.deepEqual(actual.position, expected.position, "Position"); + assert.equal(actual.position, expected.position, "Position"); assert.equal(actual.kind, expected.kind, "Kind"); assert.equal(actual.whitespaceBefore, expected.whitespaceBefore, "whitespaceBefore"); assert.equal(actual.whitespaceAfter, expected.whitespaceAfter, "whitespaceAfter"); diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index 81a947900131e..a26fcc6748932 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -651,13 +651,6 @@ namespace ts.server { return location; } - textSpanToProtoTextSpan(range: TextSpan): protocol.TextSpan { - return { - start: this.positionToLineOffset(range.start), - end: this.positionToLineOffset(range.start + range.length) - }; - } - public isJavaScript() { return this.scriptKind === ScriptKind.JS || this.scriptKind === ScriptKind.JSX; } diff --git a/src/server/session.ts b/src/server/session.ts index 1ecb06d94ee44..28c46c5c8a049 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1455,11 +1455,8 @@ namespace ts.server { const hints = languageService.provideInlayHints(file, args, this.getPreferences(file)); return hints.map(hint => ({ - text: hint.text, + ...hint, position: scriptInfo.positionToLineOffset(hint.position), - kind: hint.kind, - whitespaceBefore: hint.whitespaceBefore, - whitespaceAfter: hint.whitespaceAfter })); } diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 933e3a2d79a32..1b98e57269e36 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -3,6 +3,10 @@ namespace ts.InlayHints { const maxHintsLength = 30; + const leadingParameterNameCommentRegexFactory = (name: string) => { + return new RegExp(`^\\s?/\\*\\*?\\s?${name}\\s?\\*\\/\\s?$`); + }; + export function provideInlayHints(context: InlayHintsContext): InlayHint[] { const { file, program, span, cancellationToken, preferences } = context; const sourceFileText = file.text; @@ -38,7 +42,7 @@ namespace ts.InlayHints { return; } - if (preferences.includeInlayVariableTypeHints && (isVariableDeclaration(node))) { + if (preferences.includeInlayVariableTypeHints && isVariableDeclaration(node)) { visitVariableLikeDeclaration(node); } else if (preferences.includeInlayPropertyDeclarationTypeHints && isPropertyDeclaration(node)) { @@ -165,14 +169,13 @@ namespace ts.InlayHints { } function leadingCommentsContainsParameterName(node: Node, name: string) { - const fullStart = node.getFullStart(); - const start = node.getStart(); - if (start === fullStart) { + const ranges = getLeadingCommentRanges(sourceFileText, node.pos); + if (!ranges?.length) { return false; } - // leading comments contains parameter name - return stringContains(sourceFileText.substring(fullStart, start), name); + const regex = leadingParameterNameCommentRegexFactory(name); + return some(ranges, range => regex.test(sourceFileText.substring(range.pos, range.end))); } function isHintableExpression(node: Node) { @@ -180,6 +183,12 @@ namespace ts.InlayHints { } function visitFunctionDeclarationLikeForReturnType(decl: ArrowFunction | FunctionExpression | MethodDeclaration | FunctionDeclaration) { + if (isArrowFunction(decl)) { + if (!findChildOfKind(decl, SyntaxKind.OpenParenToken, file)) { + return; + } + } + const effectiveTypeAnnotation = getEffectiveReturnTypeNode(decl); if (effectiveTypeAnnotation || !decl.body) { return; diff --git a/tests/cases/fourslash/inlayHintsShouldWork43.ts b/tests/cases/fourslash/inlayHintsShouldWork43.ts index 157f55f0736eb..f89ea44a2646e 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork43.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork43.ts @@ -1,6 +1,7 @@ /// -//// const a = b/*a*/ => 1 +//// const a = (b)/*a*/ => 1 +//// const aa = b => 1 const markers = test.markers(); verify.getInlayHints([ diff --git a/tests/cases/fourslash/inlayHintsShouldWork52.ts b/tests/cases/fourslash/inlayHintsShouldWork52.ts index 5c875c45680c3..87d93f391a416 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork52.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork52.ts @@ -6,7 +6,7 @@ //// /** aParameter */ //// 1, //// // bParameter -//// 2, +//// /*a*/2, //// /* cParameter */ //// 3 //// ) @@ -20,17 +20,17 @@ //// 2, //// // cParameter //// /** multiple comments */ -//// 3 +//// /*b*/3 //// ) //// foo( //// /** wrong name */ -//// /*a*/1, -//// /*b*/2, +//// /*c*/1, +//// /*d*/2, //// /** multiple */ //// /** wrong */ //// /** name */ -//// /*c*/3 +//// /*e*/3 //// ) @@ -43,22 +43,34 @@ verify.getInlayHints([ whitespaceBefore: true }, { - text: 'aParameter:', + text: 'bParameter:', position: markers[1].position, kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { - text: 'bParameter:', + text: 'cParameter:', position: markers[2].position, kind: ts.InlayHintKind.Parameter, whitespaceAfter: true }, { - text: 'cParameter:', + text: 'aParameter:', position: markers[3].position, kind: ts.InlayHintKind.Parameter, whitespaceAfter: true + }, + { + text: 'bParameter:', + position: markers[4].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + }, + { + text: 'cParameter:', + position: markers[5].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true } ], undefined, { includeInlayParameterNameHints: true, diff --git a/tests/cases/fourslash/inlayHintsShouldWork53.ts b/tests/cases/fourslash/inlayHintsShouldWork53.ts new file mode 100644 index 0000000000000..71e40cd775159 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork53.ts @@ -0,0 +1,16 @@ +/// + +//// const fn = (x: any) => { } +//// fn(/* nobody knows exactly what this param is */ /*a*/42); + +const markers = test.markers(); +verify.getInlayHints([ + { + text: 'x:', + position: markers[0].position, + kind: ts.InlayHintKind.Parameter, + whitespaceAfter: true + } +], undefined, { + includeInlayParameterNameHints: true +}); From 0e8cdb649ee3fa36d00fbc0be2ffe691fdbdddfe Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 18 Jun 2021 16:14:19 +0800 Subject: [PATCH 46/53] Accept baseline --- tests/baselines/reference/api/tsserverlibrary.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 256f9eadafc37..a6b04389a1e01 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -9592,7 +9592,6 @@ declare namespace ts.server { */ lineOffsetToPosition(line: number, offset: number): number; positionToLineOffset(position: number): protocol.Location; - textSpanToProtoTextSpan(range: TextSpan): protocol.TextSpan; isJavaScript(): boolean; } } From e8fef30f2ca5600efe00c4d4d2d3edbd0b0eaa25 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 19 Jun 2021 00:42:59 +0800 Subject: [PATCH 47/53] Check parameter name before create regex --- src/services/inlayHints.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 1b98e57269e36..f050d8cd49390 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -10,6 +10,7 @@ namespace ts.InlayHints { export function provideInlayHints(context: InlayHintsContext): InlayHint[] { const { file, program, span, cancellationToken, preferences } = context; const sourceFileText = file.text; + const compilerOptions = program.getCompilerOptions(); const checker = program.getTypeChecker(); const result: InlayHint[] = []; @@ -169,6 +170,10 @@ namespace ts.InlayHints { } function leadingCommentsContainsParameterName(node: Node, name: string) { + if (!isIdentifierText(name, compilerOptions.target, getLanguageVariant(file.scriptKind))) { + return false; + } + const ranges = getLeadingCommentRanges(sourceFileText, node.pos); if (!ranges?.length) { return false; From d8dc8f193cd3dba4ebcab5bda03629c2ff54e937 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Jun 2021 01:52:30 +0800 Subject: [PATCH 48/53] Rename option --- src/compiler/types.ts | 5 ++--- src/services/inlayHints.ts | 14 +++++++++++--- src/services/types.ts | 5 ++--- tests/baselines/reference/api/tsserverlibrary.d.ts | 10 ++++------ tests/baselines/reference/api/typescript.d.ts | 10 ++++------ tests/cases/fourslash/fourslash.ts | 5 ++--- tests/cases/fourslash/inlayHintsShouldWork1.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork10.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork11.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork12.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork13.ts | 5 ++--- tests/cases/fourslash/inlayHintsShouldWork14.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork2.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork23.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork29.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork3.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork32.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork33.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork34.ts | 3 +-- tests/cases/fourslash/inlayHintsShouldWork35.ts | 3 +-- tests/cases/fourslash/inlayHintsShouldWork36.ts | 5 ++--- tests/cases/fourslash/inlayHintsShouldWork4.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork47.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork49.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork5.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork50.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork52.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork53.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork6.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork7.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork8.ts | 2 +- tests/cases/fourslash/inlayHintsShouldWork9.ts | 2 +- 32 files changed, 53 insertions(+), 56 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index faddb8749977e..e2b57070ace70 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8479,9 +8479,8 @@ namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlayParameterNameHints?: boolean; - readonly includeInlayNonLiteralParameterNameHints?: boolean; - readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; + readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index f050d8cd49390..59dd6f74e1eef 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -7,6 +7,14 @@ namespace ts.InlayHints { return new RegExp(`^\\s?/\\*\\*?\\s?${name}\\s?\\*\\/\\s?$`); }; + function shouldShowParameterNameHints(preferences: UserPreferences) { + return preferences.includeInlayParameterNameHints === "literals" || preferences.includeInlayParameterNameHints === "all"; + } + + function shouldShowLiteralParameterNameHintsOnly(preferences: UserPreferences) { + return preferences.includeInlayParameterNameHints === "literals"; + } + export function provideInlayHints(context: InlayHintsContext): InlayHint[] { const { file, program, span, cancellationToken, preferences } = context; const sourceFileText = file.text; @@ -52,7 +60,7 @@ namespace ts.InlayHints { else if (preferences.includeInlayEnumMemberValueHints && isEnumMember(node)) { visitEnumMember(node); } - else if (preferences.includeInlayParameterNameHints && (isCallExpression(node) || isNewExpression(node))) { + else if (shouldShowParameterNameHints(preferences) && (isCallExpression(node) || isNewExpression(node))) { visitCallOrNewExpression(node); } else { @@ -147,14 +155,14 @@ namespace ts.InlayHints { for (let i = 0; i < args.length; ++i) { const arg = args[i]; - if (!preferences.includeInlayNonLiteralParameterNameHints && !isHintableExpression(arg)) { + if (shouldShowLiteralParameterNameHintsOnly(preferences) && !isHintableExpression(arg)) { continue; } const identifierNameInfo = checker.getParameterIdentifierNameAtPosition(signature, i); if (identifierNameInfo) { const [parameterName, isFirstVariadicArgument] = identifierNameInfo; - const isParameterNameNotSameAsArgument = preferences.includeInlayDuplicatedParameterNameHints || !isIdentifier(arg) || arg.text !== parameterName; + const isParameterNameNotSameAsArgument = preferences.includeInlayParameterNameHintsWhenArgumentMatchesName || !isIdentifier(arg) || arg.text !== parameterName; if (!isParameterNameNotSameAsArgument && !isFirstVariadicArgument) { continue; } diff --git a/src/services/types.ts b/src/services/types.ts index 4316be58d46ef..8e2e7a26989a6 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -573,9 +573,8 @@ namespace ts { } export interface InlayHintsOptions extends UserPreferences { - readonly includeInlayParameterNameHints?: boolean; - readonly includeInlayNonLiteralParameterNameHints?: boolean; - readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; + readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean, readonly includeInlayVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 97cf4aa507c6f..d3890da7f6a07 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3957,9 +3957,8 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlayParameterNameHints?: boolean; - readonly includeInlayNonLiteralParameterNameHints?: boolean; - readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; + readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; @@ -5746,9 +5745,8 @@ declare namespace ts { includeInsertTextCompletions?: boolean; } interface InlayHintsOptions extends UserPreferences { - readonly includeInlayParameterNameHints?: boolean; - readonly includeInlayNonLiteralParameterNameHints?: boolean; - readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; + readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 3549d41ff8b4a..a9515c56bb6c3 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3957,9 +3957,8 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlayParameterNameHints?: boolean; - readonly includeInlayNonLiteralParameterNameHints?: boolean; - readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; + readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; @@ -5746,9 +5745,8 @@ declare namespace ts { includeInsertTextCompletions?: boolean; } interface InlayHintsOptions extends UserPreferences { - readonly includeInlayParameterNameHints?: boolean; - readonly includeInlayNonLiteralParameterNameHints?: boolean; - readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; + readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 1f925d7241898..fecb77330f5b7 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -644,9 +644,8 @@ declare namespace FourSlashInterface { readonly importModuleSpecifierEnding?: "minimal" | "index" | "js"; } interface InlayHintsOptions extends UserPreferences { - readonly includeInlayParameterNameHints?: boolean; - readonly includeInlayNonLiteralParameterNameHints?: boolean; - readonly includeInlayDuplicatedParameterNameHints?: boolean; + readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; + readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; diff --git a/tests/cases/fourslash/inlayHintsShouldWork1.ts b/tests/cases/fourslash/inlayHintsShouldWork1.ts index 4fb894f68538d..418a82e97a42d 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork1.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork1.ts @@ -18,5 +18,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork10.ts b/tests/cases/fourslash/inlayHintsShouldWork10.ts index 3086b41ca0066..8ec5ec099f345 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork10.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork10.ts @@ -5,5 +5,5 @@ const markers = test.markers(); verify.getInlayHints([], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork11.ts b/tests/cases/fourslash/inlayHintsShouldWork11.ts index 3188f5d007d86..55e08a0ea26f6 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork11.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork11.ts @@ -22,5 +22,5 @@ verify.getInlayHints([ whitespaceAfter: true }, ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork12.ts b/tests/cases/fourslash/inlayHintsShouldWork12.ts index 8e55b5f3e0d27..8414ca08c97e0 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork12.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork12.ts @@ -21,5 +21,5 @@ verify.getInlayHints([ whitespaceAfter: true }, ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork13.ts b/tests/cases/fourslash/inlayHintsShouldWork13.ts index 0c86169491226..ffcf223637ee0 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork13.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork13.ts @@ -13,7 +13,6 @@ verify.getInlayHints([ whitespaceAfter: true }, ], undefined, { - includeInlayParameterNameHints: true, - includeInlayNonLiteralParameterNameHints: true, - includeInlayDuplicatedParameterNameHints: false, + includeInlayParameterNameHints: "all", + includeInlayParameterNameHintsWhenArgumentMatchesName: false, }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork14.ts b/tests/cases/fourslash/inlayHintsShouldWork14.ts index 69703855d53ad..675d50d1c10f2 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork14.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork14.ts @@ -4,5 +4,5 @@ //// foo(1, 2); verify.getInlayHints([], undefined, { - includeInlayParameterNameHints: false + includeInlayParameterNameHints: "none" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork2.ts b/tests/cases/fourslash/inlayHintsShouldWork2.ts index 7cfbaf8abd655..ed95b8fc04c71 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork2.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork2.ts @@ -12,5 +12,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork23.ts b/tests/cases/fourslash/inlayHintsShouldWork23.ts index 657a9d1bcad4b..07de14a89c6e7 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork23.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork23.ts @@ -12,5 +12,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork29.ts b/tests/cases/fourslash/inlayHintsShouldWork29.ts index 8a8e384d65799..f371e2c552633 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork29.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork29.ts @@ -32,6 +32,6 @@ verify.getInlayHints([ whitespaceBefore: true } ], undefined, { - includeInlayParameterNameHints: true, + includeInlayParameterNameHints: "literals", includeInlayFunctionParameterTypeHints: true }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork3.ts b/tests/cases/fourslash/inlayHintsShouldWork3.ts index 7387ec9d33b79..f728d0657946b 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork3.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork3.ts @@ -18,5 +18,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork32.ts b/tests/cases/fourslash/inlayHintsShouldWork32.ts index 0dc42ab47bd52..19e6461a53e16 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork32.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork32.ts @@ -27,5 +27,5 @@ verify.getInlayHints( whitespaceAfter: true } }), span, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }) diff --git a/tests/cases/fourslash/inlayHintsShouldWork33.ts b/tests/cases/fourslash/inlayHintsShouldWork33.ts index 9cdb1b06ce121..3a418920d538e 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork33.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork33.ts @@ -27,5 +27,5 @@ verify.getInlayHints( whitespaceAfter: true } }), span, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); \ No newline at end of file diff --git a/tests/cases/fourslash/inlayHintsShouldWork34.ts b/tests/cases/fourslash/inlayHintsShouldWork34.ts index ec345460889f7..042a48e2a7efc 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork34.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork34.ts @@ -25,6 +25,5 @@ verify.getInlayHints( kind: ts.InlayHintKind.Parameter, whitespaceAfter: true })) , undefined, { - includeInlayParameterNameHints: true, - includeInlayNonLiteralParameterNameHints: false + includeInlayParameterNameHints: "literals" }); \ No newline at end of file diff --git a/tests/cases/fourslash/inlayHintsShouldWork35.ts b/tests/cases/fourslash/inlayHintsShouldWork35.ts index 346a294feba94..ce33995dd1da2 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork35.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork35.ts @@ -25,6 +25,5 @@ verify.getInlayHints( kind: ts.InlayHintKind.Parameter, whitespaceAfter: true })) , undefined, { - includeInlayParameterNameHints: true, - includeInlayNonLiteralParameterNameHints: true + includeInlayParameterNameHints: "all" }); \ No newline at end of file diff --git a/tests/cases/fourslash/inlayHintsShouldWork36.ts b/tests/cases/fourslash/inlayHintsShouldWork36.ts index feb63a5570237..afb9c14845d24 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork36.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork36.ts @@ -19,7 +19,6 @@ verify.getInlayHints([ whitespaceAfter: true }, ], undefined, { - includeInlayParameterNameHints: true, - includeInlayNonLiteralParameterNameHints: true, - includeInlayDuplicatedParameterNameHints: true, + includeInlayParameterNameHints: "all", + includeInlayParameterNameHintsWhenArgumentMatchesName: true, }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork4.ts b/tests/cases/fourslash/inlayHintsShouldWork4.ts index 7515747fc74d7..3753c9f19981a 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork4.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork4.ts @@ -28,5 +28,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork47.ts b/tests/cases/fourslash/inlayHintsShouldWork47.ts index e6d8c570d7d4c..e06704d28b20d 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork47.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork47.ts @@ -29,5 +29,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork49.ts b/tests/cases/fourslash/inlayHintsShouldWork49.ts index 004ebac42d475..8402469eaaf46 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork49.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork49.ts @@ -13,5 +13,5 @@ goTo.file('/a.js') const markers = test.markers(); verify.getInlayHints([], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork5.ts b/tests/cases/fourslash/inlayHintsShouldWork5.ts index 0885237ff14e3..32550023c84d5 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork5.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork5.ts @@ -25,5 +25,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork50.ts b/tests/cases/fourslash/inlayHintsShouldWork50.ts index 94258c549a0c4..a722dec40f785 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork50.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork50.ts @@ -45,5 +45,5 @@ verify.getInlayHints([ whitespaceAfter: true }, ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork52.ts b/tests/cases/fourslash/inlayHintsShouldWork52.ts index 87d93f391a416..9c603ceb9b6b0 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork52.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork52.ts @@ -73,6 +73,6 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true, + includeInlayParameterNameHints: "literals", includeInlayFunctionLikeReturnTypeHints: true }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork53.ts b/tests/cases/fourslash/inlayHintsShouldWork53.ts index 71e40cd775159..657a8fb7db805 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork53.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork53.ts @@ -12,5 +12,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork6.ts b/tests/cases/fourslash/inlayHintsShouldWork6.ts index 30a2eec1fbb53..fe94167b22a12 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork6.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork6.ts @@ -13,5 +13,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork7.ts b/tests/cases/fourslash/inlayHintsShouldWork7.ts index 1ded5cb9fc934..1505c7b5446e1 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork7.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork7.ts @@ -29,5 +29,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork8.ts b/tests/cases/fourslash/inlayHintsShouldWork8.ts index 1c44c6062c60b..a774e6443b13d 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork8.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork8.ts @@ -29,5 +29,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork9.ts b/tests/cases/fourslash/inlayHintsShouldWork9.ts index 552ff9d02de20..435da15cbcdcb 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork9.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork9.ts @@ -37,5 +37,5 @@ verify.getInlayHints([ whitespaceAfter: true } ], undefined, { - includeInlayParameterNameHints: true + includeInlayParameterNameHints: "literals" }); From 52c9d5c0bfe2d010c2f3fa85569c3ff29dd10eac Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Jun 2021 01:54:14 +0800 Subject: [PATCH 49/53] Avoid makers --- tests/cases/fourslash/inlayHintsShouldWork10.ts | 1 - tests/cases/fourslash/inlayHintsShouldWork39.ts | 1 - tests/cases/fourslash/inlayHintsShouldWork45.ts | 1 - tests/cases/fourslash/inlayHintsShouldWork49.ts | 1 - 4 files changed, 4 deletions(-) diff --git a/tests/cases/fourslash/inlayHintsShouldWork10.ts b/tests/cases/fourslash/inlayHintsShouldWork10.ts index 8ec5ec099f345..650c3d801bc4b 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork10.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork10.ts @@ -3,7 +3,6 @@ //// declare const unknownCall: any; //// unknownCall(); -const markers = test.markers(); verify.getInlayHints([], undefined, { includeInlayParameterNameHints: "literals" }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork39.ts b/tests/cases/fourslash/inlayHintsShouldWork39.ts index 6649246eee7e7..3096ae2aaf983 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork39.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork39.ts @@ -4,7 +4,6 @@ //// return 1 //// } -const markers = test.markers(); verify.getInlayHints([], undefined, { includeInlayFunctionLikeReturnTypeHints: true, }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork45.ts b/tests/cases/fourslash/inlayHintsShouldWork45.ts index 586f46fc905ff..6c84520fe2f48 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork45.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork45.ts @@ -10,7 +10,6 @@ //// const a = require('./a'); goTo.file('/b.js') -const markers = test.markers(); verify.getInlayHints([], undefined, { includeInlayVariableTypeHints: true, }); diff --git a/tests/cases/fourslash/inlayHintsShouldWork49.ts b/tests/cases/fourslash/inlayHintsShouldWork49.ts index 8402469eaaf46..e3b6e1d668dd5 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork49.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork49.ts @@ -11,7 +11,6 @@ goTo.file('/a.js') -const markers = test.markers(); verify.getInlayHints([], undefined, { includeInlayParameterNameHints: "literals" }); From 7ce7a44196e42b3750d36b1c681715eb88d82dab Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Jun 2021 01:57:57 +0800 Subject: [PATCH 50/53] Skip parens for argument --- src/services/inlayHints.ts | 5 +++-- tests/cases/fourslash/inlayHintsShouldWork34.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 59dd6f74e1eef..c54e69752ab1f 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -154,7 +154,8 @@ namespace ts.InlayHints { } for (let i = 0; i < args.length; ++i) { - const arg = args[i]; + const originalArg = args[i]; + const arg = skipParentheses(originalArg); if (shouldShowLiteralParameterNameHintsOnly(preferences) && !isHintableExpression(arg)) { continue; } @@ -172,7 +173,7 @@ namespace ts.InlayHints { continue; } - addParameterHints(name, args[i].getStart(), isFirstVariadicArgument); + addParameterHints(name, originalArg.getStart(), isFirstVariadicArgument); } } } diff --git a/tests/cases/fourslash/inlayHintsShouldWork34.ts b/tests/cases/fourslash/inlayHintsShouldWork34.ts index 042a48e2a7efc..6c5f87a78340f 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork34.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork34.ts @@ -13,8 +13,8 @@ //// foo(/*i*/[1]); //// foo(foo); -//// foo((1)); -//// foo(foo(/*j*/1)); +//// foo(/*j*/(1)); +//// foo(foo(/*k*/1)); const markers = test.markers(); From 24e1a4af8a12114a45cd862aacbe047bd83ec281 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 25 Jun 2021 03:18:10 +0800 Subject: [PATCH 51/53] Fix CR issues --- src/compiler/types.ts | 7 ------ src/harness/client.ts | 6 ++--- src/server/protocol.ts | 14 +++++------ src/server/session.ts | 4 ++-- src/services/inlayHints.ts | 4 ++-- src/services/types.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 23 +++++++------------ tests/baselines/reference/api/typescript.d.ts | 9 +------- 8 files changed, 24 insertions(+), 45 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e2b57070ace70..6acfbd2f895f5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8479,13 +8479,6 @@ namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; - readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; - readonly includeInlayFunctionParameterTypeHints?: boolean; - readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayPropertyDeclarationTypeHints?: boolean; - readonly includeInlayFunctionLikeReturnTypeHints?: boolean; - readonly includeInlayEnumMemberValueHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ diff --git a/src/harness/client.ts b/src/harness/client.ts index ede9c3741ff1f..c72cfe681a725 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -646,10 +646,10 @@ namespace ts.server { provideInlayHints(file: string, span: TextSpan): InlayHint[] { const { start, length } = span; - const args: protocol.ProvideInlayHintsRequestArgs = { file, start, length }; + const args: protocol.InlayHintsRequestArgs = { file, start, length }; - const request = this.processRequest(CommandNames.ProvideInlayHints, args); - const response = this.processResponse(request); + const request = this.processRequest(CommandNames.ProvideInlayHints, args); + const response = this.processResponse(request); return response.body!.map(item => ({ // TODO: GH#18217 ...item, diff --git a/src/server/protocol.ts b/src/server/protocol.ts index aa832dcf027b4..350e0f5e22ae6 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2551,12 +2551,12 @@ namespace ts.server.protocol { } export const enum InlayHintKind { - Other = 0, - Type = 1, - Parameter = 2, + Type = "Type", + Parameter = "Parameter", + Enum = "Enum", } - export interface ProvideInlayHintsRequestArgs extends FileRequestArgs { + export interface InlayHintsRequestArgs extends FileRequestArgs { /** * Start position of the span. */ @@ -2567,9 +2567,9 @@ namespace ts.server.protocol { length: number; } - export interface ProvideInlayHintsRequest extends Request { + export interface InlayHintsRequest extends Request { command: CommandTypes.ProvideInlayHints; - arguments: ProvideInlayHintsRequestArgs; + arguments: InlayHintsRequestArgs; } export interface InlayHintItem { @@ -2580,7 +2580,7 @@ namespace ts.server.protocol { whitespaceAfter?: boolean; } - export interface ProvideInlayHintsResponse extends Response { + export interface InlayHintsResponse extends Response { body?: InlayHintItem[]; } diff --git a/src/server/session.ts b/src/server/session.ts index 28c46c5c8a049..241ae9647219f 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1449,7 +1449,7 @@ namespace ts.server { }); } - private provideInlayHints(args: protocol.ProvideInlayHintsRequestArgs) { + private provideInlayHints(args: protocol.InlayHintsRequestArgs) { const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args); const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; const hints = languageService.provideInlayHints(file, args, this.getPreferences(file)); @@ -2973,7 +2973,7 @@ namespace ts.server { [CommandNames.UncommentSelectionFull]: (request: protocol.UncommentSelectionRequest) => { return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.ProvideInlayHints]: (request: protocol.ProvideInlayHintsRequest) => { + [CommandNames.ProvideInlayHints]: (request: protocol.InlayHintsRequest) => { return this.requiredResponse(this.provideInlayHints(request.arguments)); } })); diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index c54e69752ab1f..b41934e65e15a 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -7,11 +7,11 @@ namespace ts.InlayHints { return new RegExp(`^\\s?/\\*\\*?\\s?${name}\\s?\\*\\/\\s?$`); }; - function shouldShowParameterNameHints(preferences: UserPreferences) { + function shouldShowParameterNameHints(preferences: InlayHintsOptions) { return preferences.includeInlayParameterNameHints === "literals" || preferences.includeInlayParameterNameHints === "all"; } - function shouldShowLiteralParameterNameHintsOnly(preferences: UserPreferences) { + function shouldShowLiteralParameterNameHintsOnly(preferences: InlayHintsOptions) { return preferences.includeInlayParameterNameHints === "literals"; } diff --git a/src/services/types.ts b/src/services/types.ts index 8e2e7a26989a6..4597c01dcf7ef 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -1589,6 +1589,6 @@ namespace ts { cancellationToken: CancellationToken; host: LanguageServiceHost; span: TextSpan; - preferences: UserPreferences; + preferences: InlayHintsOptions; } } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index d3890da7f6a07..74090b84559b7 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3957,13 +3957,6 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; - readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; - readonly includeInlayFunctionParameterTypeHints?: boolean; - readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayPropertyDeclarationTypeHints?: boolean; - readonly includeInlayFunctionLikeReturnTypeHints?: boolean; - readonly includeInlayEnumMemberValueHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -6541,7 +6534,7 @@ declare namespace ts { cancellationToken: CancellationToken; host: LanguageServiceHost; span: TextSpan; - preferences: UserPreferences; + preferences: InlayHintsOptions; } } declare namespace ts { @@ -8708,11 +8701,11 @@ declare namespace ts.server.protocol { body?: SignatureHelpItems; } enum InlayHintKind { - Other = 0, - Type = 1, - Parameter = 2 + Type = "Type", + Parameter = "Parameter", + Enum = "Enum" } - interface ProvideInlayHintsRequestArgs extends FileRequestArgs { + interface InlayHintsRequestArgs extends FileRequestArgs { /** * Start position of the span. */ @@ -8722,9 +8715,9 @@ declare namespace ts.server.protocol { */ length: number; } - interface ProvideInlayHintsRequest extends Request { + interface InlayHintsRequest extends Request { command: CommandTypes.ProvideInlayHints; - arguments: ProvideInlayHintsRequestArgs; + arguments: InlayHintsRequestArgs; } interface InlayHintItem { text: string; @@ -8733,7 +8726,7 @@ declare namespace ts.server.protocol { whitespaceBefore?: boolean; whitespaceAfter?: boolean; } - interface ProvideInlayHintsResponse extends Response { + interface InlayHintsResponse extends Response { body?: InlayHintItem[]; } /** diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index a9515c56bb6c3..f74d9fc6b70e5 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3957,13 +3957,6 @@ declare namespace ts { readonly providePrefixAndSuffixTextForRename?: boolean; readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; - readonly includeInlayParameterNameHints?: "none" | "literals" | "all"; - readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; - readonly includeInlayFunctionParameterTypeHints?: boolean; - readonly includeInlayVariableTypeHints?: boolean; - readonly includeInlayPropertyDeclarationTypeHints?: boolean; - readonly includeInlayFunctionLikeReturnTypeHints?: boolean; - readonly includeInlayEnumMemberValueHints?: boolean; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -6541,7 +6534,7 @@ declare namespace ts { cancellationToken: CancellationToken; host: LanguageServiceHost; span: TextSpan; - preferences: UserPreferences; + preferences: InlayHintsOptions; } } declare namespace ts { From 6b279e73ee322dec1bbf94a940e200e032950104 Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Fri, 25 Jun 2021 11:59:17 +0800 Subject: [PATCH 52/53] Fix enums --- src/services/inlayHints.ts | 2 +- src/services/types.ts | 6 +++--- tests/cases/fourslash/fourslash.ts | 6 +++--- tests/cases/fourslash/inlayHintsShouldWork44.ts | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index b41934e65e15a..d01574941a33a 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -104,7 +104,7 @@ namespace ts.InlayHints { result.push({ text: `= ${truncation(text, maxHintsLength)}`, position, - kind: InlayHintKind.Other, + kind: InlayHintKind.Enum, whitespaceBefore: true, }); } diff --git a/src/services/types.ts b/src/services/types.ts index 4597c01dcf7ef..50945159cc37d 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -706,9 +706,9 @@ namespace ts { } export const enum InlayHintKind { - Other = 0, - Type = 1, - Parameter = 2, + Type = "Type", + Parameter = "Parameter", + Enum = "Enum", } export interface InlayHint { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index fecb77330f5b7..fe874e74d6252 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -67,9 +67,9 @@ declare module ts { } const enum InlayHintKind { - Other = 0, - Type = 1, - Parameter = 2, + Type = "Type", + Parameter = "Parameter", + Enum = "Enum", } enum SemicolonPreference { diff --git a/tests/cases/fourslash/inlayHintsShouldWork44.ts b/tests/cases/fourslash/inlayHintsShouldWork44.ts index fd60c972236a3..fb890330ddef5 100644 --- a/tests/cases/fourslash/inlayHintsShouldWork44.ts +++ b/tests/cases/fourslash/inlayHintsShouldWork44.ts @@ -13,19 +13,19 @@ verify.getInlayHints([ { text: '= 0', position: markers[0].position, - kind: ts.InlayHintKind.Other, + kind: ts.InlayHintKind.Enum, whitespaceBefore: true }, { text: '= 1', position: markers[1].position, - kind: ts.InlayHintKind.Other, + kind: ts.InlayHintKind.Enum, whitespaceBefore: true }, { text: '= 11', position: markers[2].position, - kind: ts.InlayHintKind.Other, + kind: ts.InlayHintKind.Enum, whitespaceBefore: true }, ], undefined, { From 8e9a8d8715f4c2b3961494cb5e3f3669ef363bd2 Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Fri, 25 Jun 2021 12:00:36 +0800 Subject: [PATCH 53/53] Accept baseline --- tests/baselines/reference/api/tsserverlibrary.d.ts | 6 +++--- tests/baselines/reference/api/typescript.d.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 74090b84559b7..bf708e8422769 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5852,9 +5852,9 @@ declare namespace ts { fromSpans: TextSpan[]; } enum InlayHintKind { - Other = 0, - Type = 1, - Parameter = 2 + Type = "Type", + Parameter = "Parameter", + Enum = "Enum" } interface InlayHint { text: string; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index f74d9fc6b70e5..80dadec513b62 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5852,9 +5852,9 @@ declare namespace ts { fromSpans: TextSpan[]; } enum InlayHintKind { - Other = 0, - Type = 1, - Parameter = 2 + Type = "Type", + Parameter = "Parameter", + Enum = "Enum" } interface InlayHint { text: string;