File tree Expand file tree Collapse file tree 8 files changed +34
-80
lines changed Expand file tree Collapse file tree 8 files changed +34
-80
lines changed Original file line number Diff line number Diff line change 3897
3897
"category" : " Message" ,
3898
3898
"code" : 95002
3899
3899
},
3900
- "Extract symbol" : {
3901
- "category" : " Message" ,
3902
- "code" : 95003
3903
- },
3904
3900
"Extract to {0} in {1}" : {
3905
3901
"category" : " Message" ,
3906
3902
"code" : 95004
Original file line number Diff line number Diff line change 1
1
/* @internal */
2
2
namespace ts {
3
3
export interface Refactor {
4
- /** An unique code associated with each refactor */
5
- name : string ;
6
-
7
- /** Description of the refactor to display in the UI of the editor */
8
- description : string ;
9
-
10
4
/** Compute the associated code actions */
11
5
getEditsForAction ( context : RefactorContext , actionName : string ) : RefactorEditInfo | undefined ;
12
6
@@ -27,8 +21,9 @@ namespace ts {
27
21
// e.g. nonSuggestableRefactors[refactorCode] -> the refactor you want
28
22
const refactors : Map < Refactor > = createMap < Refactor > ( ) ;
29
23
30
- export function registerRefactor ( refactor : Refactor ) {
31
- refactors . set ( refactor . name , refactor ) ;
24
+ /** @param name An unique code associated with each refactor. Does not have to be human-readable. */
25
+ export function registerRefactor ( name : string , refactor : Refactor ) {
26
+ refactors . set ( name , refactor ) ;
32
27
}
33
28
34
29
export function getApplicableRefactors ( context : RefactorContext ) : ApplicableRefactorInfo [ ] {
Original file line number Diff line number Diff line change 1
1
/* @internal */
2
2
namespace ts . refactor . annotateWithTypeFromJSDoc {
3
+ const refactorName = "Annotate with type from JSDoc" ;
3
4
const actionName = "annotate" ;
5
+ const description = Diagnostics . Annotate_with_type_from_JSDoc . message ;
6
+ registerRefactor ( refactorName , { getEditsForAction, getAvailableActions } ) ;
4
7
5
- const annotateTypeFromJSDoc : Refactor = {
6
- name : "Annotate with type from JSDoc" ,
7
- description : Diagnostics . Annotate_with_type_from_JSDoc . message ,
8
- getEditsForAction,
9
- getAvailableActions
10
- } ;
11
8
type DeclarationWithType =
12
9
| FunctionLikeDeclaration
13
10
| VariableDeclaration
14
11
| ParameterDeclaration
15
12
| PropertySignature
16
13
| PropertyDeclaration ;
17
14
18
- registerRefactor ( annotateTypeFromJSDoc ) ;
19
-
20
15
function getAvailableActions ( context : RefactorContext ) : ApplicableRefactorInfo [ ] | undefined {
21
16
if ( isInJavaScriptFile ( context . file ) ) {
22
17
return undefined ;
@@ -25,11 +20,11 @@ namespace ts.refactor.annotateWithTypeFromJSDoc {
25
20
const node = getTokenAtPosition ( context . file , context . startPosition , /*includeJsDocComment*/ false ) ;
26
21
if ( hasUsableJSDoc ( findAncestor ( node , isDeclarationWithType ) ) ) {
27
22
return [ {
28
- name : annotateTypeFromJSDoc . name ,
29
- description : annotateTypeFromJSDoc . description ,
23
+ name : refactorName ,
24
+ description,
30
25
actions : [
31
26
{
32
- description : annotateTypeFromJSDoc . description ,
27
+ description,
33
28
name : actionName
34
29
}
35
30
]
Original file line number Diff line number Diff line change 1
1
/* @internal */
2
2
3
3
namespace ts . refactor . convertFunctionToES6Class {
4
+ const refactorName = "Convert to ES2015 class" ;
4
5
const actionName = "convert" ;
5
-
6
- const convertFunctionToES6Class : Refactor = {
7
- name : "Convert to ES2015 class" ,
8
- description : Diagnostics . Convert_function_to_an_ES2015_class . message ,
9
- getEditsForAction,
10
- getAvailableActions
11
- } ;
12
-
13
- registerRefactor ( convertFunctionToES6Class ) ;
6
+ const description = Diagnostics . Convert_function_to_an_ES2015_class . message ;
7
+ registerRefactor ( refactorName , { getEditsForAction, getAvailableActions } ) ;
14
8
15
9
function getAvailableActions ( context : RefactorContext ) : ApplicableRefactorInfo [ ] | undefined {
16
10
if ( ! isInJavaScriptFile ( context . file ) ) {
@@ -29,11 +23,11 @@ namespace ts.refactor.convertFunctionToES6Class {
29
23
if ( ( symbol . flags & SymbolFlags . Function ) && symbol . members && ( symbol . members . size > 0 ) ) {
30
24
return [
31
25
{
32
- name : convertFunctionToES6Class . name ,
33
- description : convertFunctionToES6Class . description ,
26
+ name : refactorName ,
27
+ description,
34
28
actions : [
35
29
{
36
- description : convertFunctionToES6Class . description ,
30
+ description,
37
31
name : actionName
38
32
}
39
33
]
Original file line number Diff line number Diff line change 1
1
/* @internal */
2
2
namespace ts . refactor {
3
3
const actionName = "Convert to ES6 module" ;
4
-
5
- const convertToEs6Module : Refactor = {
6
- name : actionName ,
7
- description : getLocaleSpecificMessage ( Diagnostics . Convert_to_ES6_module ) ,
8
- getEditsForAction,
9
- getAvailableActions,
10
- } ;
11
-
12
- registerRefactor ( convertToEs6Module ) ;
4
+ const description = getLocaleSpecificMessage ( Diagnostics . Convert_to_ES6_module ) ;
5
+ registerRefactor ( actionName , { getEditsForAction, getAvailableActions } ) ;
13
6
14
7
function getAvailableActions ( context : RefactorContext ) : ApplicableRefactorInfo [ ] | undefined {
15
8
const { file, startPosition } = context ;
@@ -20,11 +13,11 @@ namespace ts.refactor {
20
13
const node = getTokenAtPosition ( file , startPosition , /*includeJsDocComment*/ false ) ;
21
14
return ! isAtTriggerLocation ( file , node ) ? undefined : [
22
15
{
23
- name : convertToEs6Module . name ,
24
- description : convertToEs6Module . description ,
16
+ name : actionName ,
17
+ description,
25
18
actions : [
26
19
{
27
- description : convertToEs6Module . description ,
20
+ description,
28
21
name : actionName ,
29
22
} ,
30
23
] ,
Original file line number Diff line number Diff line change 3
3
4
4
/* @internal */
5
5
namespace ts . refactor . extractSymbol {
6
- const extractSymbol : Refactor = {
7
- name : "Extract Symbol" ,
8
- description : getLocaleSpecificMessage ( Diagnostics . Extract_symbol ) ,
9
- getAvailableActions,
10
- getEditsForAction,
11
- } ;
12
-
13
- registerRefactor ( extractSymbol ) ;
6
+ const refactorName = "Extract Symbol" ;
7
+ registerRefactor ( refactorName , { getAvailableActions, getEditsForAction } ) ;
14
8
15
9
/**
16
10
* Compute the associated code actions
@@ -77,15 +71,15 @@ namespace ts.refactor.extractSymbol {
77
71
78
72
if ( functionActions . length ) {
79
73
infos . push ( {
80
- name : extractSymbol . name ,
74
+ name : refactorName ,
81
75
description : getLocaleSpecificMessage ( Diagnostics . Extract_function ) ,
82
76
actions : functionActions
83
77
} ) ;
84
78
}
85
79
86
80
if ( constantActions . length ) {
87
81
infos . push ( {
88
- name : extractSymbol . name ,
82
+ name : refactorName ,
89
83
description : getLocaleSpecificMessage ( Diagnostics . Extract_constant ) ,
90
84
actions : constantActions
91
85
} ) ;
Original file line number Diff line number Diff line change 1
1
/* @internal */
2
2
namespace ts . refactor . installTypesForPackage {
3
+ const refactorName = "Install missing types package" ;
3
4
const actionName = "install" ;
4
-
5
- const installTypesForPackage : Refactor = {
6
- name : "Install missing types package" ,
7
- description : "Install missing types package" ,
8
- getEditsForAction,
9
- getAvailableActions,
10
- } ;
11
-
12
- registerRefactor ( installTypesForPackage ) ;
5
+ const description = "Install missing types package" ;
6
+ registerRefactor ( refactorName , { getEditsForAction, getAvailableActions } ) ;
13
7
14
8
function getAvailableActions ( context : RefactorContext ) : ApplicableRefactorInfo [ ] | undefined {
15
9
if ( getStrictOptionValue ( context . program . getCompilerOptions ( ) , "noImplicitAny" ) ) {
@@ -20,8 +14,8 @@ namespace ts.refactor.installTypesForPackage {
20
14
const action = getAction ( context ) ;
21
15
return action && [
22
16
{
23
- name : installTypesForPackage . name ,
24
- description : installTypesForPackage . description ,
17
+ name : refactorName ,
18
+ description,
25
19
actions : [
26
20
{
27
21
description : action . description ,
Original file line number Diff line number Diff line change 1
1
/* @internal */
2
2
namespace ts . refactor . installTypesForPackage {
3
3
const actionName = "Convert to default import" ;
4
-
5
- const useDefaultImport : Refactor = {
6
- name : actionName ,
7
- description : getLocaleSpecificMessage ( Diagnostics . Convert_to_default_import ) ,
8
- getEditsForAction,
9
- getAvailableActions,
10
- } ;
11
-
12
- registerRefactor ( useDefaultImport ) ;
4
+ const description = getLocaleSpecificMessage ( Diagnostics . Convert_to_default_import ) ;
5
+ registerRefactor ( actionName , { getEditsForAction, getAvailableActions } ) ;
13
6
14
7
function getAvailableActions ( context : RefactorContext ) : ApplicableRefactorInfo [ ] | undefined {
15
8
const { file, startPosition, program } = context ;
@@ -31,11 +24,11 @@ namespace ts.refactor.installTypesForPackage {
31
24
32
25
return [
33
26
{
34
- name : useDefaultImport . name ,
35
- description : useDefaultImport . description ,
27
+ name : actionName ,
28
+ description,
36
29
actions : [
37
30
{
38
- description : useDefaultImport . description ,
31
+ description,
39
32
name : actionName ,
40
33
} ,
41
34
] ,
You can’t perform that action at this time.
0 commit comments