Simplify boot java hover providers api.

Remove unused and pointless CompletableFuture wrappers.
This commit is contained in:
Kris De Volder
2017-11-20 10:40:42 -08:00
parent ac3b0efa46
commit b4b4512ccd
8 changed files with 23 additions and 25 deletions

View File

@@ -77,7 +77,7 @@ public class AutowiredHoverProvider implements HoverProvider {
}
@Override
public CompletableFuture<Hover> provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
if (runningApps.length > 0) {
@@ -110,8 +110,7 @@ public class AutowiredHoverProvider implements HoverProvider {
}
}
if (hasInterestingApp && hasAutowiring) {
return CompletableFuture
.completedFuture(new Hover(ImmutableList.of(Either.forLeft(hover.toString()))));
return new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
}
}
}

View File

@@ -44,7 +44,7 @@ import com.google.common.collect.ImmutableList;
public class ConditionalsLiveHoverProvider implements HoverProvider {
@Override
public CompletableFuture<Hover> provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
return provideHover(annotation, doc, runningApps);
}
@@ -85,7 +85,7 @@ public class ConditionalsLiveHoverProvider implements HoverProvider {
return Optional.empty();
}
private CompletableFuture<Hover> provideHover(Annotation annotation, TextDocument doc,
private Hover provideHover(Annotation annotation, TextDocument doc,
SpringBootApp[] runningApps) {
try {
@@ -102,7 +102,7 @@ public class ConditionalsLiveHoverProvider implements HoverProvider {
hover.setContents(hoverContent);
hover.setRange(hoverRange);
return CompletableFuture.completedFuture(hover);
return hover;
} catch (Exception e) {
Log.log(e);
}

View File

@@ -70,9 +70,9 @@ public class BootJavaHoverProvider implements HoverHandler {
TextDocument doc = documents.get(params).copy();
try {
int offset = doc.toOffset(params.getPosition());
CompletableFuture<Hover> hoverResult = provideHover(doc, offset);
Hover hoverResult = provideHover(doc, offset);
if (hoverResult != null) {
return hoverResult;
return CompletableFuture.completedFuture(hoverResult);
}
}
catch (Exception e) {
@@ -155,7 +155,7 @@ public class BootJavaHoverProvider implements HoverHandler {
}
}
private CompletableFuture<Hover> provideHover(TextDocument document, int offset) throws Exception {
private Hover provideHover(TextDocument document, int offset) throws Exception {
IJavaProject project = getProject(document).orElse(null);
if (project!=null) {
CompilationUnit cu = server.getCompilationUnitCache().getCompilationUnit(document);
@@ -167,7 +167,7 @@ public class BootJavaHoverProvider implements HoverHandler {
return null;
}
private CompletableFuture<Hover> provideHoverForAnnotation(ASTNode node, int offset, TextDocument doc, IJavaProject project) {
private Hover provideHoverForAnnotation(ASTNode node, int offset, TextDocument doc, IJavaProject project) {
Annotation annotation = null;
while (node != null && !(node instanceof Annotation)) {
@@ -200,13 +200,13 @@ public class BootJavaHoverProvider implements HoverHandler {
return null;
}
private CompletableFuture<Hover> actuatorWarning(IJavaProject project) {
private Hover actuatorWarning(IJavaProject project) {
String hoverText =
"**No live hover information available**.\n"+
"\n" +
"Live hover providers use various `spring-boot-actuator` endpoints to retrieve information. "+
"Consider adding `spring-boot-actuator` as a dependency to your project `"+project.getElementName()+"`";
return CompletableFuture.completedFuture(new Hover(ImmutableList.of(Either.forLeft(hoverText))));
return new Hover(ImmutableList.of(Either.forLeft(hoverText)));
}
private boolean hasActuatorDependency(IJavaProject project) {

View File

@@ -27,7 +27,7 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
*/
public interface HoverProvider {
CompletableFuture<Hover> provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps);
Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps);
Collection<Range> getLiveHoverHints(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps);
}

View File

@@ -58,7 +58,7 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
}
@Override
public CompletableFuture<Hover> provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
if (runningApps.length > 0) {
@@ -87,8 +87,7 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
}
}
if (hasInterestingApp) {
return CompletableFuture
.completedFuture(new Hover(ImmutableList.of(Either.forLeft(hover.toString()))));
return new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
}
}
}

View File

@@ -43,7 +43,7 @@ import com.google.common.collect.ImmutableSet;
public class ActiveProfilesProvider implements HoverProvider {
@Override
public CompletableFuture<Hover> provideHover(
public Hover provideHover(
ASTNode node,
Annotation annotation,
ITypeBinding type,
@@ -67,9 +67,9 @@ public class ActiveProfilesProvider implements HoverProvider {
markdown.append("\n");
}
}
return CompletableFuture.completedFuture(new Hover(
return new Hover(
ImmutableList.of(Either.forLeft(markdown.toString()))
));
);
}
return null;
}

View File

@@ -49,7 +49,7 @@ import reactor.util.function.Tuples;
public class RequestMappingHoverProvider implements HoverProvider {
@Override
public CompletableFuture<Hover> provideHover(ASTNode node, Annotation annotation,
public Hover provideHover(ASTNode node, Annotation annotation,
ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
return provideHover(annotation, doc, runningApps);
}
@@ -72,7 +72,7 @@ public class RequestMappingHoverProvider implements HoverProvider {
return null;
}
private CompletableFuture<Hover> provideHover(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) {
private Hover provideHover(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) {
try {
List<Either<String, MarkedString>> hoverContent = new ArrayList<>();
@@ -89,7 +89,7 @@ public class RequestMappingHoverProvider implements HoverProvider {
hover.setContents(hoverContent);
hover.setRange(hoverRange);
return CompletableFuture.completedFuture(hover);
return hover;
} catch (Exception e) {
Log.log(e);
}

View File

@@ -37,7 +37,7 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
public class ValueHoverProvider implements HoverProvider {
@Override
public CompletableFuture<Hover> provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
try {
@@ -67,7 +67,7 @@ public class ValueHoverProvider implements HoverProvider {
return null;
}
private CompletableFuture<Hover> provideHover(String value, int offset, int nodeStartOffset, TextDocument doc, SpringBootApp[] runningApps) {
private Hover provideHover(String value, int offset, int nodeStartOffset, TextDocument doc, SpringBootApp[] runningApps) {
try {
LocalRange range = getPropertyRange(value, offset);
@@ -104,7 +104,7 @@ public class ValueHoverProvider implements HoverProvider {
hover.setContents(hoverContent);
hover.setRange(hoverRange);
return CompletableFuture.completedFuture(hover);
return hover;
}
}
}