mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
fix: omit inlay hints for setters (#45228)
This commit is contained in:
parent
975aabe788
commit
39c653cd83
@ -67,13 +67,17 @@ namespace ts.InlayHints {
|
||||
if (preferences.includeInlayFunctionParameterTypeHints && isFunctionExpressionLike(node)) {
|
||||
visitFunctionExpressionLikeForParameterType(node);
|
||||
}
|
||||
if (preferences.includeInlayFunctionLikeReturnTypeHints && isFunctionLikeDeclaration(node)) {
|
||||
if (preferences.includeInlayFunctionLikeReturnTypeHints && isSignatureSupportingReturnAnnotation(node)) {
|
||||
visitFunctionDeclarationLikeForReturnType(node);
|
||||
}
|
||||
}
|
||||
return forEachChild(node, visitor);
|
||||
}
|
||||
|
||||
function isSignatureSupportingReturnAnnotation(node: Node): node is FunctionDeclaration | ArrowFunction | FunctionExpression | MethodDeclaration | GetAccessorDeclaration {
|
||||
return isArrowFunction(node) || isFunctionExpression(node) || isFunctionDeclaration(node) || isMethodDeclaration(node) || isGetAccessorDeclaration(node);
|
||||
}
|
||||
|
||||
function isFunctionExpressionLike(node: Node): node is ArrowFunction | FunctionExpression {
|
||||
return isArrowFunction(node) || isFunctionExpression(node);
|
||||
}
|
||||
@ -206,7 +210,7 @@ namespace ts.InlayHints {
|
||||
return isLiteralExpression(node) || isBooleanLiteral(node) || isFunctionExpressionLike(node) || isObjectLiteralExpression(node) || isArrayLiteralExpression(node);
|
||||
}
|
||||
|
||||
function visitFunctionDeclarationLikeForReturnType(decl: FunctionLikeDeclaration) {
|
||||
function visitFunctionDeclarationLikeForReturnType(decl: FunctionDeclaration | ArrowFunction | FunctionExpression | MethodDeclaration | GetAccessorDeclaration) {
|
||||
if (isArrowFunction(decl)) {
|
||||
if (!findChildOfKind(decl, SyntaxKind.OpenParenToken, file)) {
|
||||
return;
|
||||
@ -236,7 +240,7 @@ namespace ts.InlayHints {
|
||||
addTypeHints(typeDisplayString, getTypeAnnotationPosition(decl));
|
||||
}
|
||||
|
||||
function getTypeAnnotationPosition(decl: FunctionLikeDeclaration) {
|
||||
function getTypeAnnotationPosition(decl: FunctionDeclaration | ArrowFunction | FunctionExpression | MethodDeclaration | GetAccessorDeclaration) {
|
||||
const closeParenToken = findChildOfKind(decl, SyntaxKind.CloseParenToken, file);
|
||||
if (closeParenToken) {
|
||||
return closeParenToken.end;
|
||||
|
||||
@ -1,22 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////class Foo {
|
||||
//// get foo()/*a*/ { return 1; }
|
||||
//// set foo(value: number)/*b*/ {}
|
||||
//// get foo()/**/ { return 1; }
|
||||
////}
|
||||
|
||||
const [a, b] = test.markers();
|
||||
const [marker] = test.markers();
|
||||
|
||||
verify.getInlayHints([
|
||||
{
|
||||
text: ': number',
|
||||
position: a.position,
|
||||
kind: ts.InlayHintKind.Type,
|
||||
whitespaceBefore: true
|
||||
},
|
||||
{
|
||||
text: ': void',
|
||||
position: b.position,
|
||||
position: marker.position,
|
||||
kind: ts.InlayHintKind.Type,
|
||||
whitespaceBefore: true
|
||||
},
|
||||
|
||||
9
tests/cases/fourslash/inlayHintsShouldWork61.ts
Normal file
9
tests/cases/fourslash/inlayHintsShouldWork61.ts
Normal file
@ -0,0 +1,9 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////class Foo {
|
||||
//// set foo(value: number)/**/ {}
|
||||
////}
|
||||
|
||||
verify.getInlayHints([], undefined, {
|
||||
includeInlayFunctionLikeReturnTypeHints: true
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user