Fix bug when there are multiple overlapping diagnostics with quickfix
This commit is contained in:
@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.commons.languageserver.quickfix;
|
||||
|
||||
import org.eclipse.lsp4j.CodeActionContext;
|
||||
import org.eclipse.lsp4j.Command;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -33,12 +34,15 @@ public class Quickfix<T> {
|
||||
private final String CODE_ACTION_CMD_ID;
|
||||
|
||||
private final Range range;
|
||||
private final String diagMsg;
|
||||
private final QuickfixData<T> data;
|
||||
|
||||
public Quickfix(String CODE_ACTION_CMD_ID, Range range, QuickfixData<T> data) {
|
||||
|
||||
public Quickfix(String CODE_ACTION_CMD_ID, Diagnostic diag, QuickfixData<T> data) {
|
||||
super();
|
||||
this.CODE_ACTION_CMD_ID = CODE_ACTION_CMD_ID;
|
||||
this.range = range;
|
||||
this.range = diag.getRange();
|
||||
this.diagMsg = diag.getMessage();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@@ -55,6 +59,17 @@ public class Quickfix<T> {
|
||||
}
|
||||
|
||||
public boolean appliesTo(Range range, CodeActionContext context) {
|
||||
return range.equals(this.range);
|
||||
return range.equals(this.range) && appliesToContext(context);
|
||||
}
|
||||
|
||||
private boolean appliesToContext(CodeActionContext context) {
|
||||
if (context!=null) {
|
||||
return context.getDiagnostics().stream().anyMatch(diag -> {
|
||||
boolean okay = this.diagMsg == null || this.diagMsg.equals(diag.getMessage());
|
||||
System.out.println(okay + " <- "+diag);
|
||||
return okay;
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ public abstract class SimpleLanguageServer implements LanguageServer, LanguageCl
|
||||
List<QuickfixData<?>> fixes = problem.getQuickfixes();
|
||||
if (CollectionUtil.hasElements(fixes)) {
|
||||
for (QuickfixData<?> fix : fixes) {
|
||||
quickfixes.add(new Quickfix<>(CODE_ACTION_COMMAND_ID, rng, fix));
|
||||
quickfixes.add(new Quickfix<>(CODE_ACTION_COMMAND_ID, d, fix));
|
||||
}
|
||||
}
|
||||
diagnostics.add(d);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package org.springframework.ide.vscode.concourse;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.ide.vscode.languageserver.testharness.TestAsserts.assertContains;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -121,11 +122,9 @@ public class ConcourseEditorTest {
|
||||
"config|[platform, run] are required"
|
||||
);
|
||||
|
||||
CodeAction quickfix = editor.assertCodeAction(problems.get(0));
|
||||
//TODO: fix https://www.pivotaltracker.com/story/show/151460687 and uncomment code below
|
||||
// assertEquals(null, quickfix);
|
||||
assertTrue(editor.getCodeActions(problems.get(0)).isEmpty());
|
||||
|
||||
quickfix = editor.assertCodeAction(problems.get(1));
|
||||
CodeAction quickfix = editor.assertCodeAction(problems.get(1));
|
||||
assertEquals("Add properties: [platform, run]", quickfix.getLabel());
|
||||
quickfix.perform();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user