Merge branch 'master' of github.com:spring-projects/sts4

This commit is contained in:
Kris De Volder
2018-08-22 12:09:56 -07:00
10 changed files with 113 additions and 14 deletions

View File

@@ -50,7 +50,7 @@
"dependencies": { "dependencies": {
"atom-package-deps": "^4.6.0", "atom-package-deps": "^4.6.0",
"download": "^6.2.5", "download": "^6.2.5",
"@pivotal-tools/atom-languageclient-commons": "0.0.8" "@pivotal-tools/atom-languageclient-commons": "0.0.9"
}, },
"devDependencies": { "devDependencies": {
"typescript": "^2.7.2", "typescript": "^2.7.2",

View File

@@ -1,3 +1,3 @@
{ {
"jarUrl": "https://s3-us-west-1.amazonaws.com/s3-test.spring.io/sts4/fatjars/snapshots/bosh-language-server-0.1.5-201803080105.jar" "jarUrl": "https://s3-us-west-1.amazonaws.com/s3-test.spring.io/sts4/fatjars/snapshots/bosh-language-server-0.6.0-201808212257.jar"
} }

View File

@@ -19,7 +19,7 @@
"properties.json" "properties.json"
], ],
"dependencies": { "dependencies": {
"@pivotal-tools/atom-languageclient-commons": "0.0.8", "@pivotal-tools/atom-languageclient-commons": "0.0.9",
"atom-package-deps": "^4.6.0", "atom-package-deps": "^4.6.0",
"download": "^6.2.5" "download": "^6.2.5"
}, },

View File

@@ -1,3 +1,3 @@
{ {
"jarUrl": "https://s3-us-west-1.amazonaws.com/s3-test.spring.io/sts4/fatjars/snapshots/manifest-yaml-language-server-0.2.1-201805102140.jar" "jarUrl": "https://s3-us-west-1.amazonaws.com/s3-test.spring.io/sts4/fatjars/snapshots/manifest-yaml-language-server-0.6.0-201808212257.jar"
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "@pivotal-tools/atom-languageclient-commons", "name": "@pivotal-tools/atom-languageclient-commons",
"version": "0.0.8", "version": "0.0.9",
"description": "Atom language client commons for STS4 language servers", "description": "Atom language client commons for STS4 language servers",
"repository": "https://github.com/spring-projects/sts4", "repository": "https://github.com/spring-projects/sts4",
"license": "MIT", "license": "MIT",
@@ -22,7 +22,7 @@
}, },
"dependencies": { "dependencies": {
"@pivotal-tools/jvm-launch-utils": "0.0.11", "@pivotal-tools/jvm-launch-utils": "0.0.11",
"atom-languageclient": "0.9.5", "atom-languageclient": "0.9.6",
"portfinder": "^1.0.13", "portfinder": "^1.0.13",
"@types/atom": "^1.24.1", "@types/atom": "^1.24.1",
"@types/node": "^8.0.41", "@types/node": "^8.0.41",

View File

@@ -21,7 +21,7 @@
"dependencies": { "dependencies": {
"atom-package-deps": "^4.6.0", "atom-package-deps": "^4.6.0",
"download": "^6.2.5", "download": "^6.2.5",
"@pivotal-tools/atom-languageclient-commons": "0.0.8" "@pivotal-tools/atom-languageclient-commons": "0.0.9"
}, },
"devDependencies": { "devDependencies": {
"typescript": "^2.7.2", "typescript": "^2.7.2",

View File

@@ -1,3 +1,3 @@
{ {
"jarUrl": "https://s3-us-west-1.amazonaws.com/s3-test.spring.io/sts4/fatjars/snapshots/concourse-language-server-0.1.5-201802272051.jar" "jarUrl": "https://s3-us-west-1.amazonaws.com/s3-test.spring.io/sts4/fatjars/snapshots/concourse-language-server-0.6.0-201808212257.jar"
} }

View File

@@ -29,11 +29,26 @@
"type": "boolean", "type": "boolean",
"default": false, "default": false,
"description": "Enable/Disable detecting changes of running Spring Boot applications" "description": "Enable/Disable detecting changes of running Spring Boot applications"
},
"remote-apps": {
"type": "array",
"items": {
"type": "object",
"properties": {
"jmxurl": {
"type": "string"
},
"host": {
"type": "string"
}
}
},
"description": "Array of jmx urls pointing to remote spring boot applications to poll for live hover information. A typical url looks something like this: `service:jmx:rmi://localhost:9111/jndi/rmi://localhost:9111/jmxrmi`"
} }
}, },
"dependencies": { "dependencies": {
"atom-languageclient": "0.9.5", "atom-languageclient": "0.9.6",
"@pivotal-tools/atom-languageclient-commons": "0.0.8", "@pivotal-tools/atom-languageclient-commons": "0.0.9",
"atom-package-deps": "^4.6.0", "atom-package-deps": "^4.6.0",
"download": "^6.2.5" "download": "^6.2.5"
}, },

View File

@@ -1,3 +1,3 @@
{ {
"jarUrl": "https://s3-us-west-1.amazonaws.com/s3-test.spring.io/sts4/fatjars/snapshots/spring-boot-language-server-0.4.0-201807190033.jar" "jarUrl": "https://s3-us-west-1.amazonaws.com/s3-test.spring.io/sts4/fatjars/snapshots/spring-boot-language-server-0.6.0-201808212257.jar"
} }

View File

@@ -23,6 +23,7 @@ import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.lsp4j.CodeLens; import org.eclipse.lsp4j.CodeLens;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.MarkedString; import org.eclipse.lsp4j.MarkedString;
import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.Range;
@@ -34,9 +35,9 @@ import org.springframework.ide.vscode.boot.java.livehover.LiveHoverUtils;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp; import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping; import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping;
import org.springframework.ide.vscode.commons.java.IJavaProject; import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.util.BadLocationException;
import org.springframework.ide.vscode.commons.util.Renderable; import org.springframework.ide.vscode.commons.util.Renderable;
import org.springframework.ide.vscode.commons.util.Renderables; import org.springframework.ide.vscode.commons.util.Renderables;
import org.springframework.ide.vscode.commons.util.StringUtil;
import org.springframework.ide.vscode.commons.util.text.TextDocument; import org.springframework.ide.vscode.commons.util.text.TextDocument;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@@ -51,6 +52,8 @@ public class RequestMappingHoverProvider implements HoverProvider {
private static final Logger log = LoggerFactory.getLogger(RequestMappingHoverProvider.class); private static final Logger log = LoggerFactory.getLogger(RequestMappingHoverProvider.class);
private static final int CODE_LENS_LIMIT = 3;
@Override @Override
public Hover provideHover(ASTNode node, Annotation annotation, public Hover provideHover(ASTNode node, Annotation annotation,
ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) { ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
@@ -64,17 +67,38 @@ public class RequestMappingHoverProvider implements HoverProvider {
List<Tuple2<RequestMapping, SpringBootApp>> val = getRequestMappingMethodFromRunningApp(annotation, runningApps); List<Tuple2<RequestMapping, SpringBootApp>> val = getRequestMappingMethodFromRunningApp(annotation, runningApps);
if (!val.isEmpty()) { if (!val.isEmpty()) {
Range hoverRange = doc.toRange(annotation.getStartPosition(), annotation.getLength()); Range hoverRange = doc.toRange(annotation.getStartPosition(), annotation.getLength());
return ImmutableList.of(new CodeLens(hoverRange)); List<String> urls = getUrls(val);
return assembleCodeLenses(hoverRange, urls);
} }
} }
} }
catch (BadLocationException e) { catch (Exception e) {
log.error("", e); log.error("", e);
} }
return null; return null;
} }
private Collection<CodeLens> assembleCodeLenses(Range range, List<String> urls) {
Collection<CodeLens> lenses = new ArrayList<>();
if (urls != null) {
int limit = urls.size() > CODE_LENS_LIMIT ? CODE_LENS_LIMIT : urls.size();
for (int i = 0; i < limit; i++) {
CodeLens codeLens = createCodeLensForRequestMapping(range, urls.get(i));
lenses.add(codeLens);
}
if (urls.size() > CODE_LENS_LIMIT) {
CodeLens codeLens = createCodeLensForRemaining(range, urls.size() - CODE_LENS_LIMIT);
lenses.add(codeLens);
}
}
return lenses;
}
private Hover provideHover(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) { private Hover provideHover(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) {
try { try {
@@ -153,6 +177,30 @@ public class RequestMappingHoverProvider implements HoverProvider {
return false; return false;
} }
private List<String> getUrls(List<Tuple2<RequestMapping, SpringBootApp>> mappingMethods) throws Exception {
List<String> urls = new ArrayList<>();
for (int i = 0; i < mappingMethods.size(); i++) {
Tuple2<RequestMapping, SpringBootApp> mappingMethod = mappingMethods.get(i);
String port = mappingMethod.getT2().getPort();
String host = mappingMethod.getT2().getHost();
String[] paths = mappingMethod.getT1().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(host, port, path);
urls.add(url);
}
}
return urls;
}
private void addHoverContent(List<Tuple2<RequestMapping, SpringBootApp>> mappingMethods, List<Either<String, MarkedString>> hoverContent) throws Exception { private void addHoverContent(List<Tuple2<RequestMapping, SpringBootApp>> mappingMethods, List<Either<String, MarkedString>> hoverContent) throws Exception {
for (int i = 0; i < mappingMethods.size(); i++) { for (int i = 0; i < mappingMethods.size(); i++) {
Tuple2<RequestMapping, SpringBootApp> mappingMethod = mappingMethods.get(i); Tuple2<RequestMapping, SpringBootApp> mappingMethod = mappingMethods.get(i);
@@ -189,4 +237,40 @@ public class RequestMappingHoverProvider implements HoverProvider {
} }
} }
private CodeLens createCodeLensForRequestMapping(Range range, String content) {
CodeLens codeLens = new CodeLens();
codeLens.setRange(range);
Command cmd = new Command();
if (StringUtil.hasText(content)) {
codeLens.setData(content);
cmd.setTitle(content);
// cmd.setCommand("editor.action.openLink");
// Show hover for now, as it contains a link. Ideally the command to set is a vscode
// one that jumps to URL directly
cmd.setCommand("org.springframework.showHoverAtPosition");
cmd.setArguments(ImmutableList.of(range.getStart()));
}
codeLens.setCommand(cmd);
return codeLens;
}
private CodeLens createCodeLensForRemaining(Range range, int remaining) {
CodeLens codeLens = new CodeLens();
codeLens.setRange(range);
Command cmd = new Command();
cmd.setTitle(remaining + " more...");
cmd.setCommand("org.springframework.showHoverAtPosition");
cmd.setArguments(ImmutableList.of(range.getStart()));
codeLens.setCommand(cmd);
return codeLens;
}
} }