Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Tools 4 - now GA 3 https://spring.io/tools Spring Tools 4 for Eclipse Spring Tools 4 for Visual Studio Code Spring Tools 4 for Atom IDE
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Integration with JDT is key
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Part 1 - Understanding Java inside the LS
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Understanding Java • Language Servers are different from Eclipse extensions • they know about files • there is no API to understand and analyze languages • You have to build your own language understanding for Java • heavyweight approach: re-use full-blown Eclipse JDT on OSGi • lightweight approach: use a Java language parser of your choice and go 6
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Resolving Projects • first attempt: • understand the project structure on our own (use Gradle, Maven, etc.) • => slow, error-prone, could result in mismatches with Java language tooling • second attempt: • ask the Java tooling (Java language server) for resolved projects and updates • requires extra work on the Eclipse side (needs to deliver that information) • requires extra communication 10
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Part 2 - Running the Language Server
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Language Server <extension point="org.eclipse.lsp4e.languageServer"> <server class="org.springframework.tooling.boot.ls.DelegatingStreamConnectionProvider" id="org.eclipse.languageserver.languages.springboot" clientImpl="org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl" label="Spring Boot Language Server"> </server> <contentTypeMapping contentType="org.eclipse.jdt.core.javaSource" id="org.eclipse.languageserver.languages.springboot"> </contentTypeMapping> </extension> 12
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Language Server - Definition <extension point="org.eclipse.lsp4e.languageServer"> <server class="org.springframework.tooling.boot.ls.DelegatingStreamConnectionProvider" id="org.eclipse.languageserver.languages.springboot" clientImpl="org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl" label="Spring Boot Language Server"> </server> <contentTypeMapping contentType="org.eclipse.jdt.core.javaSource" id="org.eclipse.languageserver.languages.springboot"> </contentTypeMapping> </extension> 13 define the language server via the LSP4E extension point
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Language Server - Mapping <extension point="org.eclipse.lsp4e.languageServer"> <server class="org.springframework.tooling.boot.ls.DelegatingStreamConnectionProvider" id="org.eclipse.languageserver.languages.springboot" clientImpl="org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl" label="Spring Boot Language Server"> </server> <contentTypeMapping contentType="org.eclipse.jdt.core.javaSource" id="org.eclipse.languageserver.languages.springboot"> </contentTypeMapping> </extension> 14 map the language server to the existing Java source content type
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Connect Document Events <extension point="org.eclipse.core.filebuffers.documentSetup"> <participant class="org.eclipse.lsp4e.ConnectDocumentToLanguageServerSetupParticipant" contentTypeId="org.eclipse.jdt.core.javaSource"> </participant> </extension> 15 the document connector is responsible for starting and stopping language servers automatically, independent of the used editor
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Part 3 - Connecting to the Java Editor
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Connecting Content-Assist <extension id="springbootjava-completion-computer" point="org.eclipse.jdt.ui.javaCompletionProposalComputer"> <javaCompletionProposalComputer activate="true" categoryId="org.eclipse.jdt.ui.defaultProposalCategory" class="org.springframework.tooling.boot.ls.jdt.SpringBootJavaCompletionProposalComputer" needsSortingAfterFiltering="false"> </javaCompletionProposalComputer> </extension> 17 write and define a regular content-assist proposal computer for JDT
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Connecting Live Hovers <extension id="springbootjava-hover-provider" point="org.eclipse.jdt.ui.javaEditorTextHovers"> <hover activate="true" class="org.springframework.tooling.boot.ls.jdt.SpringBootJavaHoverProvider" id="org.springframework.boot.ide.java.servers.hoverprovider"> </hover> </extension> 22 write and define a regular hover provider for JDT
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hover Provider public class SpringBootJavaHoverProvider implements IJavaEditorTextHover, ITextHoverExtension { private LSBasedHover lsBasedHover; public SpringBootJavaHoverProvider() { lsBasedHover = new LSBasedHover(); } @Override public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { return this.lsBasedHover.getHoverInfo(textViewer, hoverRegion); } @Override public IRegion getHoverRegion(ITextViewer textViewer, int offset) { return this.lsBasedHover.getHoverRegion(textViewer, offset); } ... } 25 call the LSP4E hover provider, that’s it
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Side Notes • to improve reliability, wrap calls to LS… into futures 27
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Code Lenses you need to do NOTHING… 28
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outlook • get push model in LSP for: • code lenses (custom messages at the moment) • green highlights in the code (custom messages at the moment) • investigate more complicated code analysis tasks • e.g. what happens if we implement more comprehensive content-assist 31