mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-13 22:53:33 -05:00
Provide jsdoc type code fixes for all variable-like decls
This includes 3 SyntaxKinds I missed earlier: Parameter, PropertyDeclaration and PropertyAssignment.
This commit is contained in:
@@ -8,11 +8,16 @@ namespace ts.codefix {
|
||||
function getActionsForJSDocTypes(context: CodeFixContext): CodeAction[] | undefined {
|
||||
const sourceFile = context.sourceFile;
|
||||
const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
|
||||
const decl = ts.findAncestor(node, n => n.kind === SyntaxKind.VariableDeclaration);
|
||||
const decl = ts.findAncestor(node,
|
||||
n => n.kind === SyntaxKind.VariableDeclaration ||
|
||||
n.kind === SyntaxKind.Parameter ||
|
||||
n.kind === SyntaxKind.PropertyDeclaration ||
|
||||
n.kind === SyntaxKind.PropertyAssignment);
|
||||
if (!decl) return;
|
||||
const checker = context.program.getTypeChecker();
|
||||
|
||||
const jsdocType = (decl as VariableDeclaration).type;
|
||||
if (!jsdocType) return;
|
||||
const original = getTextOfNode(jsdocType);
|
||||
const type = checker.getTypeFromTypeNode(jsdocType);
|
||||
const actions = [createAction(jsdocType, sourceFile.fileName, original, checker.typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.NoTruncation))];
|
||||
|
||||
Reference in New Issue
Block a user