PT #160151830: Accept range within quickfix range

This commit is contained in:
BoykoAlex
2018-11-22 20:17:53 -05:00
parent f358431b00
commit a41025c23e
2 changed files with 24 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ import org.eclipse.lsp4j.CodeActionContext;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Range;
import org.springframework.ide.vscode.commons.util.text.DocumentUtil;
import com.google.common.collect.ImmutableList;
@@ -59,7 +60,7 @@ public class Quickfix<T> {
}
public boolean appliesTo(Range range, CodeActionContext context) {
return range.equals(this.range) && appliesToContext(context);
return appliesToContext(context) && DocumentUtil.containsRange(this.range, range);
}
private boolean appliesToContext(CodeActionContext context) {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016-2017 Pivotal, Inc.
* Copyright (c) 2016, 2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,8 @@
package org.springframework.ide.vscode.commons.util.text;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.springframework.ide.vscode.commons.util.Assert;
import org.springframework.ide.vscode.commons.util.BadLocationException;
@@ -45,5 +47,24 @@ public class DocumentUtil {
throw new IllegalStateException("Bug!", e);
}
}
/**
* Compares two LSP4J positions
* @param p1
* @param p2
* @return integer number which is 0 if equals, <0 if p1 comes before p2 and >0 otherwise
*/
public static int compare(Position p1, Position p2) {
int res = p1.getLine() - p2.getLine();
if (res == 0) {
res = p1.getCharacter() - p2.getCharacter();
}
return res;
}
public static boolean containsRange(Range outer, Range inner) {
return compare(outer.getStart(), inner.getStart()) <= 0
&& compare(outer.getEnd(), inner.getEnd()) >= 0;
}
}