mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Codefix for Array.<number> -> Array<number>
This commit is contained in:
@@ -7,13 +7,14 @@ namespace ts.codefix {
|
||||
|
||||
function getActionsForJSDocTypes(context: CodeFixContext): CodeAction[] | undefined {
|
||||
const sourceFile = context.sourceFile;
|
||||
|
||||
const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
|
||||
if (node.kind !== SyntaxKind.VariableDeclaration) return;
|
||||
const decl = ts.findAncestor(node, n => n.kind === SyntaxKind.VariableDeclaration);
|
||||
if (!decl) return;
|
||||
const jsdocType = (decl as VariableDeclaration).type;
|
||||
|
||||
// TODO: Only if get(jsdoctype) !== jsdoctype
|
||||
|
||||
const trk = textChanges.ChangeTracker.fromCodeFixContext(context);
|
||||
const jsdocType = (node as VariableDeclaration).type;
|
||||
// TODO: Only if get(jsdoctype) !== jsdoctype
|
||||
trk.replaceNode(sourceFile, jsdocType, getTypeFromJSDocType(jsdocType));
|
||||
return [{
|
||||
// TODO: This seems like the LEAST SAFE way to get the new text
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var x: [|...number|] = 12;
|
||||
//// var x: [|......number[][]|] = 12;
|
||||
|
||||
verify.rangeAfterCodeFix("number[]");
|
||||
verify.rangeAfterCodeFix("number[][][][]");
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var x: [|Array.<number>|] = 12;
|
||||
|
||||
verify.rangeAfterCodeFix("Array<number>");
|
||||
Reference in New Issue
Block a user