Skip to content

Commit

Permalink
GH-1431: let webflux index elements create document symbols on-demand
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlippert committed Feb 20, 2025
1 parent 6f66310 commit 812102a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.requestmapping;

import org.eclipse.lsp4j.Range;

public class WebfluxHandlerMethodIndexElement extends RequestMappingIndexElement {

private final String handlerClass;
private final String handlerMethod;

public WebfluxHandlerMethodIndexElement(String handlerClass, String handlerMethod, String path, String[] httpMethods, String[] contentTypes, String[] acceptTypes) {
super(path, httpMethods, contentTypes, acceptTypes);
public WebfluxHandlerMethodIndexElement(String handlerClass, String handlerMethod, String path, String[] httpMethods, String[] contentTypes, String[] acceptTypes,
Range range, String symbolLabel) {
super(path, httpMethods, contentTypes, acceptTypes, range, symbolLabel);

this.handlerClass = handlerClass;
this.handlerMethod = handlerMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,18 @@ protected static void extractMappingSymbol(MethodInvocation node, TextDocument d
try {

Location location = new Location(doc.getUri(), doc.toRange(methodNameStart, node.getLength() - (methodNameStart - invocationStart)));
WebfluxHandlerMethodIndexElement handler = extractHandlerInformation(node, path, httpMethods, contentTypes, acceptTypes);
WebfluxRouteElementRangesIndexElement elements = extractElementsInformation(pathElements, httpMethods, contentTypes, acceptTypes);

if (handler != null) indexElementsCollector.add(handler);
if (elements != null) indexElementsCollector.add(elements);

WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, path, getElementStrings(httpMethods),
getElementStrings(contentTypes), getElementStrings(acceptTypes));

context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));

WebfluxHandlerMethodIndexElement handler = extractHandlerInformation(node, path, httpMethods, contentTypes, acceptTypes, location.getRange(), symbol.getName());
WebfluxRouteElementRangesIndexElement elements = extractElementsInformation(pathElements, httpMethods, contentTypes, acceptTypes);

if (handler != null) indexElementsCollector.add(handler);
if (elements != null) indexElementsCollector.add(elements);

} catch (BadLocationException e) {
log.error("bad location while extracting mapping symbol for " + doc.getUri(), e);
}
Expand Down Expand Up @@ -319,7 +320,7 @@ private static void extractNestedValue(ASTNode node, Collection<WebfluxRouteElem
}

private static WebfluxHandlerMethodIndexElement extractHandlerInformation(MethodInvocation node, String path, WebfluxRouteElement[] httpMethods,
WebfluxRouteElement[] contentTypes, WebfluxRouteElement[] acceptTypes) {
WebfluxRouteElement[] contentTypes, WebfluxRouteElement[] acceptTypes, Range range, String symbolLabel) {

List<?> arguments = node.arguments();

Expand All @@ -336,7 +337,8 @@ private static WebfluxHandlerMethodIndexElement extractHandlerInformation(Method
String handlerMethod = methodBinding.getMethodDeclaration().toString();
if (handlerMethod != null) handlerMethod = handlerMethod.trim();

return new WebfluxHandlerMethodIndexElement(handlerClass, handlerMethod, path, getElementStrings(httpMethods), getElementStrings(contentTypes), getElementStrings(acceptTypes));
return new WebfluxHandlerMethodIndexElement(handlerClass, handlerMethod, path, getElementStrings(httpMethods), getElementStrings(contentTypes),
getElementStrings(acceptTypes), range, symbolLabel);
}
}
}
Expand Down

0 comments on commit 812102a

Please sign in to comment.