From 0a80f1f1815f158e10f1edbea7bc7f5ee16d362e Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Fri, 27 Sep 2019 14:01:50 +0200 Subject: [PATCH] re-enable live request mapping symbols on new live hovers v2 mechanism --- .../LiveAppURLSymbolProvider.java | 68 ++++++++++--------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/LiveAppURLSymbolProvider.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/LiveAppURLSymbolProvider.java index a98954da6..654f40631 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/LiveAppURLSymbolProvider.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/LiveAppURLSymbolProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017, 2018 Pivotal, Inc. + * Copyright (c) 2017, 2019 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 @@ -13,9 +13,15 @@ package org.springframework.ide.vscode.boot.java.requestmapping; import java.util.ArrayList; import java.util.List; +import org.eclipse.lsp4j.Location; +import org.eclipse.lsp4j.Position; +import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.SymbolInformation; +import org.eclipse.lsp4j.SymbolKind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.ide.vscode.boot.java.livehover.v2.LiveRequestMapping; +import org.springframework.ide.vscode.boot.java.livehover.v2.SpringProcessLiveData; import org.springframework.ide.vscode.boot.java.livehover.v2.SpringProcessLiveDataProvider; /** @@ -34,36 +40,36 @@ public class LiveAppURLSymbolProvider { public List getSymbols(String query) { List result = new ArrayList<>(); -// try { -// SpringBootApp[] runningApps = runningAppProvider.getAllRunningSpringApps().toArray(new SpringBootApp[0]); -// for (SpringBootApp app : runningApps) { -// try { -// String urlScheme = app.getUrlScheme(); -// String host = app.getHost(); -// String port = app.getPort(); -// String contextPath = app.getContextPath(); -// for (LiveRequestMapping rm : app.getRequestMappings()) { -// String[] paths = rm.getSplitPath(); -// if (paths==null || paths.length==0) { -// //Technically, this means the path 'predicate' is unconstrained, meaning any path matches. -// //So this is not quite the same as the case where path=""... but... -// //It is better for us to show one link where any path is allowed, versus showing no links where any link is allowed. -// //So we'll pretend this is the same as path="" as that gives a working link. -// paths = new String[] {""}; -// } -// for (String path : paths) { -// String url = UrlUtil.createUrl(urlScheme, host, port, path, contextPath); -// result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1))))); -// } -// } -// } -// catch (Exception e) { -// log.error("", e); -// } -// } -// } catch (Exception e) { -// log.error("", e); -// } + try { + SpringProcessLiveData[] liveData = liveDataProvider.getLatestLiveData(); + for (SpringProcessLiveData live : liveData) { + try { + String urlScheme = live.getUrlScheme(); + String host = live.getHost(); + String port = live.getPort(); + String contextPath = live.getContextPath(); + for (LiveRequestMapping rm : live.getRequestMappings()) { + String[] paths = rm.getSplitPath(); + if (paths==null || paths.length==0) { + //Technically, this means the path 'predicate' is unconstrained, meaning any path matches. + //So this is not quite the same as the case where path=""... but... + //It is better for us to show one link where any path is allowed, versus showing no links where any link is allowed. + //So we'll pretend this is the same as path="" as that gives a working link. + paths = new String[] {""}; + } + for (String path : paths) { + String url = UrlUtil.createUrl(urlScheme, host, port, path, contextPath); + result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1))))); + } + } + } + catch (Exception e) { + log.error("", e); + } + } + } catch (Exception e) { + log.error("", e); + } return result; }