use of org.eclipse.lsp4j.Range in project sts4 by spring-projects.
the class WebfluxPathFinder method visit.
@Override
public boolean visit(MethodInvocation node) {
boolean visitChildren = true;
if (node != this.root) {
IMethodBinding methodBinding = node.resolveMethodBinding();
try {
if (WebfluxUtils.REQUEST_PREDICATES_TYPE.equals(methodBinding.getDeclaringClass().getBinaryName())) {
String name = methodBinding.getName();
if (name != null && WebfluxUtils.REQUEST_PREDICATE_ALL_PATH_METHODS.contains(name)) {
StringLiteral stringLiteral = WebfluxUtils.extractStringLiteralArgument(node);
if (stringLiteral != null) {
Range range = doc.toRange(stringLiteral.getStartPosition(), stringLiteral.getLength());
path.add(new WebfluxRouteElement(stringLiteral.getLiteralValue(), range));
}
}
}
} catch (BadLocationException e) {
// ignore
}
if (WebfluxUtils.isRouteMethodInvocation(methodBinding)) {
visitChildren = false;
}
}
return visitChildren;
}
use of org.eclipse.lsp4j.Range in project sts4 by spring-projects.
the class WebfluxRouterSymbolProvider method extractContentTypes.
private WebfluxRouteElement[] extractContentTypes(MethodInvocation routerInvocation, TextDocument doc) {
WebfluxContentTypeFinder contentTypeFinder = new WebfluxContentTypeFinder(doc);
List<?> arguments = routerInvocation.arguments();
for (Object argument : arguments) {
if (argument != null && argument instanceof ASTNode) {
((ASTNode) argument).accept(contentTypeFinder);
}
}
final List<WebfluxRouteElement> contentTypes = contentTypeFinder.getContentTypes();
extractNestedValue(routerInvocation, contentTypes, (methodInvocation) -> {
IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
String methodName = methodBinding.getName();
try {
if (WebfluxUtils.REQUEST_PREDICATE_CONTENT_TYPE_METHOD.equals(methodName)) {
SimpleName nameArgument = WebfluxUtils.extractSimpleNameArgument(methodInvocation);
if (nameArgument != null && nameArgument.getFullyQualifiedName() != null) {
Range range = doc.toRange(nameArgument.getStartPosition(), nameArgument.getLength());
return new WebfluxRouteElement(nameArgument.getFullyQualifiedName().toString(), range);
}
}
} catch (BadLocationException e) {
// ignore
}
return null;
});
return (WebfluxRouteElement[]) contentTypes.toArray(new WebfluxRouteElement[contentTypes.size()]);
}
use of org.eclipse.lsp4j.Range in project sts4 by spring-projects.
the class ActiveProfilesProvider method getLiveHoverHints.
@Override
public Collection<Range> getLiveHoverHints(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) {
if (runningApps.length > 0) {
Builder<Range> ranges = ImmutableList.builder();
nameRange(doc, annotation).ifPresent(ranges::add);
Set<String> allActiveProfiles = getAllActiveProfiles(runningApps);
annotation.accept(new ASTVisitor() {
@Override
public boolean visit(StringLiteral node) {
String value = ASTUtils.getLiteralValue(node);
if (value != null && allActiveProfiles.contains(value)) {
rangeOf(doc, node).ifPresent(ranges::add);
}
return true;
}
});
return ranges.build();
}
return ImmutableList.of();
}
use of org.eclipse.lsp4j.Range in project sts4 by spring-projects.
the class WebfluxContentTypeFinder method visit.
@Override
public boolean visit(MethodInvocation node) {
IMethodBinding methodBinding = node.resolveMethodBinding();
try {
if (WebfluxUtils.REQUEST_PREDICATES_TYPE.equals(methodBinding.getDeclaringClass().getBinaryName())) {
String name = methodBinding.getName();
if (name != null && WebfluxUtils.REQUEST_PREDICATE_CONTENT_TYPE_METHOD.equals(name)) {
SimpleName nameArgument = WebfluxUtils.extractSimpleNameArgument(node);
if (nameArgument != null && nameArgument.getFullyQualifiedName() != null) {
Range range = doc.toRange(nameArgument.getStartPosition(), nameArgument.getLength());
contentTypes.add(new WebfluxRouteElement(nameArgument.getFullyQualifiedName().toString(), range));
}
}
}
} catch (BadLocationException e) {
// ignore
}
return !WebfluxUtils.isRouteMethodInvocation(methodBinding);
}
use of org.eclipse.lsp4j.Range in project sts4 by spring-projects.
the class SimpleLanguageServer method validateWith.
/**
* Convenience method. Subclasses can call this to use a {@link IReconcileEngine} ported
* from old STS codebase to validate a given {@link TextDocument} and publish Diagnostics.
*/
public void validateWith(TextDocumentIdentifier docId, IReconcileEngine engine) {
CompletableFuture<Void> reconcileSession = this.busyReconcile = new CompletableFuture<Void>();
// Log.debug("Reconciling BUSY");
SimpleTextDocumentService documents = getTextDocumentService();
int requestedVersion = documents.getDocument(docId.getUri()).getVersion();
// Avoid running in the same thread as lsp4j as it can result
// in long "hangs" for slow reconcile providers
Mono.fromRunnable(() -> {
TextDocument doc = documents.getDocument(docId.getUri()).copy();
if (requestedVersion != doc.getVersion()) {
// Do not bother reconciling if document contents is already stale.
return;
}
if (testListener != null) {
testListener.reconcileStarted(docId.getUri(), doc.getVersion());
}
IProblemCollector problems = new IProblemCollector() {
private LinkedHashSet<Diagnostic> diagnostics = new LinkedHashSet<>();
private List<Quickfix> quickfixes = new ArrayList<>();
@Override
public void endCollecting() {
documents.setQuickfixes(docId, quickfixes);
documents.publishDiagnostics(docId, diagnostics);
}
@Override
public void beginCollecting() {
diagnostics.clear();
}
@Override
public void checkPointCollecting() {
// publish what has been collected so far
documents.publishDiagnostics(docId, diagnostics);
}
@Override
public void accept(ReconcileProblem problem) {
try {
DiagnosticSeverity severity = getDiagnosticSeverity(problem);
if (severity != null) {
Diagnostic d = new Diagnostic();
d.setCode(problem.getCode());
d.setMessage(problem.getMessage());
Range rng = doc.toRange(problem.getOffset(), problem.getLength());
d.setRange(rng);
d.setSeverity(severity);
List<QuickfixData<?>> fixes = problem.getQuickfixes();
if (CollectionUtil.hasElements(fixes)) {
for (QuickfixData<?> fix : fixes) {
quickfixes.add(new Quickfix<>(CODE_ACTION_COMMAND_ID, d, fix));
}
}
diagnostics.add(d);
}
} catch (BadLocationException e) {
Log.warn("Invalid reconcile problem ignored", e);
}
}
};
// try {
// Thread.sleep(2000);
// } catch (InterruptedException e) {
// }
engine.reconcile(doc, problems);
}).onErrorResume(error -> {
Log.log(error);
return Mono.empty();
}).doFinally(ignore -> {
reconcileSession.complete(null);
// Log.debug("Reconciler DONE : "+this.busyReconcile.isDone());
}).subscribeOn(RECONCILER_SCHEDULER).subscribe();
}
Aggregations