46
46
import org .eclipse .jdt .ls .core .internal .corrections .QuickFixProcessor ;
47
47
import org .eclipse .jdt .ls .core .internal .corrections .RefactorProcessor ;
48
48
import org .eclipse .jdt .ls .core .internal .corrections .proposals .ChangeCorrectionProposal ;
49
+ import org .eclipse .jdt .ls .core .internal .corrections .proposals .NewAnnotationMemberProposal ;
50
+ import org .eclipse .jdt .ls .core .internal .corrections .proposals .NewCUProposal ;
51
+ import org .eclipse .jdt .ls .core .internal .corrections .proposals .NewMethodCorrectionProposal ;
52
+ import org .eclipse .jdt .ls .core .internal .corrections .proposals .NewVariableCorrectionProposal ;
49
53
import org .eclipse .jdt .ls .core .internal .preferences .PreferenceManager ;
50
54
import org .eclipse .jdt .ls .core .internal .preferences .Preferences ;
51
55
import org .eclipse .jdt .ls .core .internal .text .correction .AssignToVariableAssistCommandProposal ;
@@ -198,7 +202,7 @@ public List<Either<Command, CodeAction>> getCodeActionCommands(CodeActionParams
198
202
}
199
203
try {
200
204
for (ChangeCorrectionProposal proposal : proposals ) {
201
- Optional <Either <Command , CodeAction >> codeActionFromProposal = getCodeActionFromProposal (proposal , params .getContext ());
205
+ Optional <Either <Command , CodeAction >> codeActionFromProposal = getCodeActionFromProposal (params . getTextDocument (). getUri (), proposal , params .getContext ());
202
206
if (codeActionFromProposal .isPresent () && !codeActions .contains (codeActionFromProposal .get ())) {
203
207
codeActions .add (codeActionFromProposal .get ());
204
208
}
@@ -256,7 +260,7 @@ private void populateDataFields(List<Either<Command, CodeAction>> codeActions) {
256
260
}
257
261
}
258
262
259
- private Optional <Either <Command , CodeAction >> getCodeActionFromProposal (ChangeCorrectionProposal proposal , CodeActionContext context ) throws CoreException {
263
+ private Optional <Either <Command , CodeAction >> getCodeActionFromProposal (String uri , ChangeCorrectionProposal proposal , CodeActionContext context ) throws CoreException {
260
264
String name = proposal .getName ();
261
265
262
266
Command command = null ;
@@ -281,6 +285,18 @@ private Optional<Either<Command, CodeAction>> getCodeActionFromProposal(ChangeCo
281
285
CodeAction codeAction = new CodeAction (name );
282
286
codeAction .setKind (proposal .getKind ());
283
287
if (command == null ) { // lazy resolve the edit.
288
+ if (!preferenceManager .getPreferences ().isValidateAllOpenBuffersOnChanges ()) {
289
+ if (proposal instanceof NewCUProposal
290
+ || proposal instanceof NewMethodCorrectionProposal
291
+ || proposal instanceof NewAnnotationMemberProposal
292
+ || proposal instanceof NewVariableCorrectionProposal
293
+ ) {
294
+ codeAction .setCommand (new Command ("refresh Diagnostics" , "java.project.refreshDiagnostics" , Arrays .asList (
295
+ uri , "thisFile" , false , true
296
+ )));
297
+ }
298
+ }
299
+
284
300
// The relevance is in descending order while CodeActionComparator sorts in ascending order
285
301
codeAction .setData (new CodeActionData (proposal , -proposal .getRelevance ()));
286
302
} else {
0 commit comments