Change refactoring name and description

This commit is contained in:
Nathan Shively-Sanders 2017-09-26 08:58:18 -07:00
parent 8996d11096
commit 13b37a4825
15 changed files with 61 additions and 36 deletions

View File

@ -3704,8 +3704,12 @@
"category": "Message",
"code": 95004
},
"Convert to Typescript type": {
"Annotate with type from JSDoc": {
"category": "Message",
"code": 95005
},
"Annotate with return type from JSDoc": {
"category": "Message",
"code": 95006
}
}

View File

@ -1,10 +1,16 @@
/* @internal */
namespace ts.refactor.convertJSDocToTypes {
const actionName = "convert";
const actionName = "annotate";
const convertJSDocToTypes: Refactor = {
name: "Convert to Typescript type",
description: Diagnostics.Convert_to_Typescript_type.message,
const annotateTypeFromJSDoc: Refactor = {
name: "Annotate with type from JSDoc",
description: Diagnostics.Annotate_with_type_from_JSDoc.message,
getEditsForAction,
getAvailableActions
};
const annotateReturnTypeFromJSDoc: Refactor = {
name: "Annotate with return type from JSDoc",
description: Diagnostics.Annotate_with_return_type_from_JSDoc.message,
getEditsForAction,
getAvailableActions
};
@ -16,7 +22,8 @@ namespace ts.refactor.convertJSDocToTypes {
| PropertySignature
| PropertyDeclaration;
registerRefactor(convertJSDocToTypes);
registerRefactor(annotateTypeFromJSDoc);
registerRefactor(annotateReturnTypeFromJSDoc);
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
if (isInJavaScriptFile(context.file)) {
@ -25,19 +32,22 @@ namespace ts.refactor.convertJSDocToTypes {
const node = getTokenAtPosition(context.file, context.startPosition, /*includeJsDocComment*/ false);
const decl = findAncestor(node, isTypedNode);
if (decl && (getJSDocType(decl) || getJSDocReturnType(decl)) && !decl.type) {
return [
{
name: convertJSDocToTypes.name,
description: convertJSDocToTypes.description,
if (decl && !decl.type) {
const annotate = getJSDocType(decl) ? annotateTypeFromJSDoc :
getJSDocReturnType(decl) ? annotateReturnTypeFromJSDoc :
undefined;
if (annotate) {
return [{
name: annotate.name,
description: annotate.description,
actions: [
{
description: convertJSDocToTypes.description,
name: actionName
}
description: annotate.description,
name: actionName
}
]
}
];
}];
}
}
}

View File

@ -7,4 +7,4 @@
verify.applicableRefactorAvailableAtMarker('1');
verify.fileAfterApplyingRefactorAtMarker('1',
`/** @type {number} */
var x: number;`, 'Convert to Typescript type', 'convert');
var x: number;`, 'Annotate with type from JSDoc', 'annotate');

View File

@ -12,4 +12,4 @@ verify.fileAfterApplyingRefactorAtMarker('1',
* @param {?} x
* @returns {number}
*/
var f = (x): number => x`, 'Convert to Typescript type', 'convert');
var f = (x): number => x`, 'Annotate with return type from JSDoc', 'annotate');

View File

@ -12,4 +12,4 @@ verify.fileAfterApplyingRefactorAtMarker('2',
* @param {?} x
* @returns {number}
*/
var f = (x: any) => x`, 'Convert to Typescript type', 'convert');
var f = (x: any) => x`, 'Annotate with type from JSDoc', 'annotate');

View File

@ -18,4 +18,4 @@ verify.fileAfterApplyingRefactorAtMarker('1',
*/
m(x): any[] {
}
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with return type from JSDoc', 'annotate');

View File

@ -8,4 +8,4 @@ verify.fileAfterApplyingRefactorAtMarker('1',
`class C {
/** @return {number} */
get c(): number { return 12; }
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with return type from JSDoc', 'annotate');

View File

@ -0,0 +1,11 @@
/// <reference path='fourslash.ts' />
/////** @return {number} */
////function f() {
//// /*1*/return 12;
////}
verify.applicableRefactorAvailableAtMarker('1');
verify.fileAfterApplyingRefactorAtMarker('1',
`/** @return {number} */
function f(): number {
return 12;
}`, 'Annotate with return type from JSDoc', 'annotate');

View File

@ -19,7 +19,7 @@ verify.fileAfterApplyingRefactorAtMarker('1',
* @param {*} beta - I have no idea how this got here
*/
function f(x: number, y, z: string, alpha, beta) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');
verify.applicableRefactorAvailableAtMarker('2');
verify.fileAfterApplyingRefactorAtMarker('2',
@ -34,7 +34,7 @@ function f(x: number, y: {
a: string;
b: Date;
}, z: string, alpha, beta) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');
verify.not.applicableRefactorAvailableAtMarker('3');
verify.not.applicableRefactorAvailableAtMarker('4');
@ -51,4 +51,4 @@ function f(x: number, y: {
a: string;
b: Date;
}, z: string, alpha, beta: any) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');

View File

@ -24,7 +24,7 @@ verify.fileAfterApplyingRefactorAtMarker('1',
* @param {number!} delta
*/
function f(x: any, y, z, alpha, beta, gamma, delta) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');
verify.applicableRefactorAvailableAtMarker('2');
verify.fileAfterApplyingRefactorAtMarker('2',
@ -38,7 +38,7 @@ verify.fileAfterApplyingRefactorAtMarker('2',
* @param {number!} delta
*/
function f(x: any, y: any, z, alpha, beta, gamma, delta) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');
verify.applicableRefactorAvailableAtMarker('3');
verify.fileAfterApplyingRefactorAtMarker('3',
@ -52,7 +52,7 @@ verify.fileAfterApplyingRefactorAtMarker('3',
* @param {number!} delta
*/
function f(x: any, y: any, z: number | undefined, alpha, beta, gamma, delta) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');
verify.applicableRefactorAvailableAtMarker('4');
verify.fileAfterApplyingRefactorAtMarker('4',
`/**
@ -65,7 +65,7 @@ verify.fileAfterApplyingRefactorAtMarker('4',
* @param {number!} delta
*/
function f(x: any, y: any, z: number | undefined, alpha: number[], beta, gamma, delta) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');
verify.applicableRefactorAvailableAtMarker('5');
verify.fileAfterApplyingRefactorAtMarker('5',
@ -81,7 +81,7 @@ verify.fileAfterApplyingRefactorAtMarker('5',
function f(x: any, y: any, z: number | undefined, alpha: number[], beta: (this: {
a: string;
}, arg1: string, arg2: number) => boolean, gamma, delta) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');
verify.applicableRefactorAvailableAtMarker('6');
verify.fileAfterApplyingRefactorAtMarker('6',
`/**
@ -96,7 +96,7 @@ verify.fileAfterApplyingRefactorAtMarker('6',
function f(x: any, y: any, z: number | undefined, alpha: number[], beta: (this: {
a: string;
}, arg1: string, arg2: number) => boolean, gamma: number | null, delta) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');
verify.applicableRefactorAvailableAtMarker('7');
verify.fileAfterApplyingRefactorAtMarker('7',
@ -112,4 +112,4 @@ verify.fileAfterApplyingRefactorAtMarker('7',
function f(x: any, y: any, z: number | undefined, alpha: number[], beta: (this: {
a: string;
}, arg1: string, arg2: number) => boolean, gamma: number | null, delta: number) {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');

View File

@ -12,4 +12,4 @@ verify.fileAfterApplyingRefactorAtMarker('1',
/** @type {number | null} */
/** @type {number | null} */
p: number | null = null;
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');

View File

@ -12,4 +12,4 @@ verify.fileAfterApplyingRefactorAtMarker('1',
/** @type {number | null} */
/** @type {number | null} */
p: number | null;
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with type from JSDoc', 'annotate');

View File

@ -14,4 +14,4 @@ verify.fileAfterApplyingRefactorAtMarker('1',
* @returns {number}
*/
function f(x): number {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with return type from JSDoc', 'annotate');

View File

@ -14,4 +14,4 @@ verify.fileAfterApplyingRefactorAtMarker('1',
* @returns {number}
*/
var f = function(x): number {
}`, 'Convert to Typescript type', 'convert');
}`, 'Annotate with return type from JSDoc', 'annotate');

View File

@ -12,4 +12,4 @@ verify.fileAfterApplyingRefactorAtMarker('1',
* @param {?} x
* @returns {number}
*/
var f = (x: any) => x`, 'Convert to Typescript type', 'convert');
var f = (x: any) => x`, 'Annotate with type from JSDoc', 'annotate');