@@ -25,32 +25,35 @@ class RefactorFeature implements CodeActionContributor {
25
25
public function createCodeActions (params : CodeActionParams ): Array <CodeAction > {
26
26
var actions : Array <CodeAction > = [];
27
27
if (params .context .only != null ) {
28
- if (params .context .only .contains (Refactor )) {}
29
- if (params .context .only .contains (RefactorExtract )) {
30
- actions = actions .concat (extractRefactors (params ));
31
- }
32
- if (params .context .only .contains (RefactorRewrite )) {}
33
- // if (params.context.only.contains(RefactorMove)) {} // upcoming LSP 3.18.0
34
- if (params .context .only .contains (RefactorInline )) {}
28
+ actions = actions .concat (extractRefactors (params , i -> {
29
+ if (i == null ) {
30
+ return false ;
31
+ }
32
+ return params .context .only .contains (i .codeActionKind );
33
+ }));
35
34
} else {
36
- actions = actions .concat (extractRefactors (params ));
35
+ actions = actions .concat (extractRefactors (params , i -> true ));
37
36
}
38
37
39
38
return actions ;
40
39
}
41
40
42
- function extractRefactors (params : CodeActionParams ): Array <CodeAction > {
41
+ function extractRefactors (params : CodeActionParams , filterType : FilterRefactorModuleCB ): Array <CodeAction > {
43
42
var actions : Array <CodeAction > = [];
44
43
final canRefactorContext = refactorCache .makeCanRefactorContext (context .documents .getHaxe (params .textDocument .uri ), params .range );
45
44
if (canRefactorContext == null ) {
46
45
return actions ;
47
46
}
48
- var refactorInfo : Array <Null <RefactorInfo >> = [
47
+ var allRefactorInfos : Array <Null <RefactorInfo >> = [
49
48
getRefactorInfo (ExtractInterface ),
50
49
getRefactorInfo (ExtractMethod ),
51
50
getRefactorInfo (ExtractType ),
52
- getRefactorInfo (ExtractConstructorParams ),
51
+ getRefactorInfo (ExtractConstructorParamsAsVars ),
52
+ getRefactorInfo (ExtractConstructorParamsAsFinals ),
53
+ getRefactorInfo (RewriteVarsToFinals ),
54
+ getRefactorInfo (RewriteFinalsToVars ),
53
55
];
56
+ final refactorInfo = allRefactorInfos .filter (filterType );
54
57
refactorCache .updateSingleFileCache (canRefactorContext .what .fileName );
55
58
for (refactor in refactorInfo ) {
56
59
if (refactor == null ) {
@@ -62,7 +65,6 @@ class RefactorFeature implements CodeActionContributor {
62
65
actions .push (makeEmptyCodeAction (title , refactor .codeActionKind , params , refactor .type ));
63
66
}
64
67
}
65
-
66
68
return actions ;
67
69
}
68
70
@@ -94,13 +96,37 @@ class RefactorFeature implements CodeActionContributor {
94
96
title : " extractType" ,
95
97
prefix : " [ExtractType]"
96
98
}
97
- case ExtractConstructorParams :
99
+ case ExtractConstructorParamsAsVars :
100
+ return {
101
+ refactorType : RefactorExtractConstructorParams (false ),
102
+ type : type ,
103
+ codeActionKind : RefactorExtract ,
104
+ title : " extractConstructorParamsAsVars" ,
105
+ prefix : " [ExtractConstructorParams as Vars]"
106
+ }
107
+ case ExtractConstructorParamsAsFinals :
98
108
return {
99
- refactorType : RefactorExtractConstructorParams ,
109
+ refactorType : RefactorExtractConstructorParams ( true ) ,
100
110
type : type ,
101
111
codeActionKind : RefactorExtract ,
102
- title : " extractConstructorParams" ,
103
- prefix : " [ExtractConstructorParams]"
112
+ title : " extractConstructorParamsAsFinals" ,
113
+ prefix : " [ExtractConstructorParams as Finals]"
114
+ }
115
+ case RewriteVarsToFinals :
116
+ return {
117
+ refactorType : RefactorRewriteVarsToFinals (true ),
118
+ type : type ,
119
+ codeActionKind : RefactorRewrite ,
120
+ title : " refactorRewriteVarsToFinals" ,
121
+ prefix : " [RefactorRewriteVarsToFinals]"
122
+ }
123
+ case RewriteFinalsToVars :
124
+ return {
125
+ refactorType : RefactorRewriteVarsToFinals (false ),
126
+ type : type ,
127
+ codeActionKind : RefactorRewrite ,
128
+ title : " refactorRewriteFinalsToVars" ,
129
+ prefix : " [RefactorRewriteFinalsToVars]"
104
130
}
105
131
}
106
132
}
@@ -115,7 +141,6 @@ class RefactorFeature implements CodeActionContributor {
115
141
116
142
public function createCodeActionEdits (context : Context , type : CodeActionResolveType , action : CodeAction , params : CodeActionParams ): Promise <WorkspaceEdit > {
117
143
var endProgress = context .startProgress (" Performing Refactor Operation…" );
118
-
119
144
var actions : Array <CodeAction > = [];
120
145
final editList : EditList = new EditList ();
121
146
final refactorContext = refactorCache .makeRefactorContext (context .documents .getHaxe (params .textDocument .uri ), params .range , editList );
@@ -127,7 +152,6 @@ class RefactorFeature implements CodeActionContributor {
127
152
return Promise .reject (" failed to make refactor context" );
128
153
}
129
154
final onResolve : (? result : Null <Dynamic >, ? debugInfo : Null <String >) -> Void = context .startTimer (" refactor/" + info .title );
130
- refactorCache .updateFileCache ();
131
155
return Refactoring .doRefactor (info .refactorType , refactorContext ).then ((result : RefactorResult ) -> {
132
156
var promise = switch (result ) {
133
157
case NoChange :
@@ -166,3 +190,5 @@ typedef RefactorInfo = {
166
190
var title : String ;
167
191
var prefix : String ;
168
192
}
193
+
194
+ typedef FilterRefactorModuleCB = (info : Null <RefactorInfo >) -> Bool ;
0 commit comments