early work to provide quick navigation to running apps via live request mappings

This commit is contained in:
Martin Lippert
2017-10-19 16:26:21 +02:00
parent 05c6749628
commit e27aece3f8
3 changed files with 87 additions and 5 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.ide.vscode.boot.java.handlers.HoverProvider;
import org.springframework.ide.vscode.boot.java.handlers.ReferenceProvider;
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.boot.java.handlers.SymbolProvider;
import org.springframework.ide.vscode.boot.java.requestmapping.LiveAppURLSymbolProvider;
import org.springframework.ide.vscode.boot.java.requestmapping.RequestMappingHoverProvider;
import org.springframework.ide.vscode.boot.java.requestmapping.RequestMappingSymbolProvider;
import org.springframework.ide.vscode.boot.java.scope.ScopeCompletionProcessor;
@@ -48,7 +49,6 @@ import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndexProvider;
import org.springframework.ide.vscode.commons.languageserver.HighlightParams;
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
import org.springframework.ide.vscode.commons.languageserver.completion.VscodeCompletionEngineAdapter;
import org.springframework.ide.vscode.commons.languageserver.java.CompositeJavaProjectFinder;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
import org.springframework.ide.vscode.commons.languageserver.reconcile.IReconcileEngine;
@@ -126,7 +126,7 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
});
documents.onDocumentSymbol(new BootJavaDocumentSymbolHandler(indexer));
workspaceService.onWorkspaceSymbol(new BootJavaWorkspaceSymbolHandler(indexer));
workspaceService.onWorkspaceSymbol(new BootJavaWorkspaceSymbolHandler(indexer, new LiveAppURLSymbolProvider(serverParams.runningAppProvider)));
BootJavaCodeLensEngine codeLensHandler = createCodeLensEngine(this, javaProjectFinder);
documents.onCodeLens(codeLensHandler::createCodeLenses);

View File

@@ -14,6 +14,7 @@ import java.util.List;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.springframework.ide.vscode.boot.java.requestmapping.LiveAppURLSymbolProvider;
import org.springframework.ide.vscode.boot.java.utils.SpringIndexer;
import org.springframework.ide.vscode.commons.languageserver.util.WorkspaceSymbolHandler;
@@ -22,15 +23,22 @@ import org.springframework.ide.vscode.commons.languageserver.util.WorkspaceSymbo
*/
public class BootJavaWorkspaceSymbolHandler implements WorkspaceSymbolHandler {
private SpringIndexer indexer;
private final SpringIndexer indexer;
private final LiveAppURLSymbolProvider liveAppSymbolProvider;
public BootJavaWorkspaceSymbolHandler(SpringIndexer indexer) {
public BootJavaWorkspaceSymbolHandler(SpringIndexer indexer, LiveAppURLSymbolProvider liveAppSymbolProvider) {
this.indexer = indexer;
this.liveAppSymbolProvider = liveAppSymbolProvider;
}
@Override
public List<? extends SymbolInformation> handle(WorkspaceSymbolParams params) {
return indexer.getAllSymbols(params.getQuery());
if (params.getQuery() != null && params.getQuery().startsWith("//")) {
return liveAppSymbolProvider.getSymbols(params.getQuery());
}
else {
return indexer.getAllSymbols(params.getQuery());
}
}
}

View File

@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2017 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.requestmapping;
import java.util.ArrayList;
import java.util.Iterator;
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.json.JSONObject;
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServer;
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.util.Log;
/**
* @author Martin Lippert
*/
public class LiveAppURLSymbolProvider {
private final RunningAppProvider runningAppProvider;
public LiveAppURLSymbolProvider(RunningAppProvider runningAppProvider) {
this.runningAppProvider = runningAppProvider;
}
public List<? extends SymbolInformation> getSymbols(String query) {
System.out.println(query);
List<SymbolInformation> result = new ArrayList<>();
try {
SpringBootApp[] runningApps = runningAppProvider.getAllRunningSpringApps().stream()
.filter((app) -> !app.containsSystemProperty(BootJavaLanguageServer.LANGUAGE_SERVER_PROCESS_PROPERTY))
.toArray(SpringBootApp[]::new);
for (SpringBootApp app : runningApps) {
try {
String mappings = app.getRequestMappings();
JSONObject requestMappings = new JSONObject(mappings);
Iterator<String> keys = requestMappings.keys();
while (keys.hasNext()) {
String key = keys.next();
String path = UrlUtil.extractPath(key);
if (path != null) {
String url = UrlUtil.createUrl(app.getHost(), app.getPort(), path);
result.add(new SymbolInformation(url, SymbolKind.File, new Location(url, new Range(new Position(0, 0), new Position(0, 1)))));
}
}
}
catch (Exception e) {
Log.log(e);
}
}
} catch (Exception e) {
Log.log(e);
}
return result;
}
}