initial steps towards content-assist for simple XML config files, but still far away from a first working version

This commit is contained in:
Martin Lippert
2019-04-05 16:32:02 +02:00
parent 468b189bac
commit 4d6d659d98
7 changed files with 236 additions and 12 deletions

View File

@@ -25,7 +25,8 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.9.0",
org.eclipse.jdt.core,
org.eclipse.ui.editors;bundle-version="3.11.100",
org.springsource.ide.eclipse.commons.livexp,
org.apache.commons.lang3
org.apache.commons.lang3,
org.eclipse.wst.sse.ui;bundle-version="1.5.100";resolution:=optional
Import-Package: com.google.gson;version="2.7.0",
org.eclipse.jface.preference,
org.osgi.framework

View File

@@ -10,52 +10,72 @@
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>
<contentTypeMapping
contentType="org.springframework.boot.ide.properties.application.properties"
id="org.eclipse.languageserver.languages.springboot"
languageId="spring-boot-properties">
</contentTypeMapping>
<contentTypeMapping
contentType="org.springframework.boot.ide.properties.application.yml"
id="org.eclipse.languageserver.languages.springboot"
languageId="spring-boot-properties-yaml">
</contentTypeMapping>
<contentTypeMapping
contentType="org.springframework.boot.ide.xmlconfig"
id="org.eclipse.languageserver.languages.springboot">
</contentTypeMapping>
</extension>
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
default-charset="ISO-8859-1"
id="org.springframework.boot.ide.properties.application.properties"
name="Spring Properties File"
priority="high">
</content-type>
<file-association
content-type="org.springframework.boot.ide.properties.application.properties"
file-names="application.properties,application-dev.properties"
file-patterns="application-*.properties">
</file-association>
</extension>
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
default-charset="UTF-8"
id="org.springframework.boot.ide.properties.application.yml"
name="Spring Yaml Properties File"
priority="high">
</content-type>
<content-type id="org.springframework.boot.ide.xmlconfig"
name="Spring XML Config File"
base-type="org.eclipse.core.runtime.xml"
priority="normal"
default-charset="UTF-8">
<describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber2">
<parameter name="element" value="beans"/>
</describer>
</content-type>
<file-association
content-type="org.springframework.boot.ide.properties.application.properties"
file-names="application.properties,application-dev.properties"
file-patterns="application-*.properties">
</file-association>
<file-association
content-type="org.springframework.boot.ide.properties.application.yml"
file-names="application.yml,bootstrap.yml,application-dev.yml,application.yaml,bootstrap.yaml,application-dev.yaml"
file-patterns="application-*.yml,application-*.yaml">
</file-association>
</extension>
</extension>
<extension
id="springbootjava-completion-computer"
point="org.eclipse.jdt.ui.javaCompletionProposalComputer">
@@ -250,6 +270,25 @@
scopeName="source.java-properties">
</scopeNameContentTypeBinding>
</extension>
<extension
id="idome.xml.generator.contentassist"
point="org.eclipse.wst.sse.ui.completionProposal">
<proposalCategory
id="org.springframework.boot.ide.xmlconfig.contentassist"
name="Spring XML Content Assist">
</proposalCategory>
<proposalComputer
activate="true"
categoryId="org.springframework.boot.ide.xmlconfig.contentassist"
class="org.springframework.tooling.boot.ls.xml.XMLContentAssistProposalComputer"
id="org.springframework.boot.ide.xmlconfig.contentassist.proposalcomputer">
<contentType id="org.springframework.boot.ide.xmlconfig"/>
</proposalComputer>
</extension>
</plugin>

View File

@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.boot.ls.xml;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor;
import org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext;
import org.eclipse.wst.sse.ui.contentassist.IAsyncCompletionProposalComputer;
/**
* @author Martin Lippert
*/
@SuppressWarnings("restriction")
public class XMLContentAssistProposalComputer implements IAsyncCompletionProposalComputer {
private static TimeUnit TIMEOUT_UNIT = TimeUnit.MILLISECONDS;
private static long TIMEOUT_LENGTH = 2000;
private LSContentAssistProcessor lsContentAssistProcessor;
public XMLContentAssistProposalComputer() {
lsContentAssistProcessor = new LSContentAssistProcessor();
}
@Override
public List<ICompletionProposal> computeCompletionProposals(CompletionProposalInvocationContext context, IProgressMonitor monitor) {
CompletableFuture<ICompletionProposal[]> future = CompletableFuture.supplyAsync(() -> {
return lsContentAssistProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset());
});
try {
return Arrays.asList(future.get(TIMEOUT_LENGTH, TIMEOUT_UNIT));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
@Override
public List<IContextInformation> computeContextInformation(CompletionProposalInvocationContext context, IProgressMonitor monitor) {
IContextInformation[] contextInformation = lsContentAssistProcessor.computeContextInformation(context.getViewer(), context.getInvocationOffset());
return Arrays.asList(contextInformation);
}
@Override
public String getErrorMessage() {
return lsContentAssistProcessor.getErrorMessage();
}
@Override
public void sessionEnded() {
}
@Override
public void sessionStarted() {
}
}

View File

@@ -23,6 +23,7 @@ import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.metadata.ProjectBasedPropertyIndexProvider;
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServerComponents;
import org.springframework.ide.vscode.boot.xml.SpringXMLLanguageServerComponents;
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.composable.CompositeLanguageServerComponents;
@@ -78,6 +79,7 @@ public class BootLanguageServerInitializer implements InitializingBean {
CompositeLanguageServerComponents.Builder builder = new CompositeLanguageServerComponents.Builder();
builder.add(new BootPropertiesLanguageServerComponents(server, params, javaElementLocationProvider, parser, yamlStructureProvider, yamlAssistContextProvider, sourceLinks));
builder.add(new BootJavaLanguageServerComponents(server, params, sourceLinks, cuCache, adHocProperties, symbolCache, config, springIndexer, runningAppProvider));
builder.add(new SpringXMLLanguageServerComponents(server, params));
components = builder.build(server);
params.projectObserver.addListener(reconcileOpenDocuments(server, components));

View File

@@ -92,7 +92,7 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
// Do not add more components here. You should instead just make your new
// components into separate beans.
public static final Set<LanguageId> LANGUAGES = ImmutableSet.of(LanguageId.JAVA, LanguageId.XML);
public static final Set<LanguageId> LANGUAGES = ImmutableSet.of(LanguageId.JAVA);
private static final Logger log = LoggerFactory.getLogger(BootJavaLanguageServerComponents.class);

View File

@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.xml;
import java.util.Collection;
import java.util.Collections;
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
/**
* @author Martin Lippert
*/
public class SpringXMLCompletionEngine implements ICompletionEngine {
public SpringXMLCompletionEngine(SpringXMLLanguageServerComponents springXMLLanguageServerComponents) {
}
@Override
public Collection<ICompletionProposal> getCompletions(TextDocument document, int offset) throws Exception {
System.out.println(" SUPER COOL SPRING XML COMPLETION PROPOSALS COMING SOON... STAY TUNED...");
return Collections.emptyList();
}
}

View File

@@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.xml;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
import org.springframework.ide.vscode.commons.languageserver.composable.LanguageServerComponents;
import org.springframework.ide.vscode.commons.languageserver.util.HoverHandler;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspaceService;
import org.springframework.ide.vscode.commons.util.text.LanguageId;
import com.google.common.collect.ImmutableSet;
/**
* @author Martin Lippert
*/
public class SpringXMLLanguageServerComponents implements LanguageServerComponents {
public static final Set<LanguageId> LANGUAGES = ImmutableSet.of(LanguageId.XML);
private static final Logger log = LoggerFactory.getLogger(SpringXMLLanguageServerComponents.class);
private final SimpleLanguageServer server;
private final BootLanguageServerParams serverParams;
public SpringXMLLanguageServerComponents(
SimpleLanguageServer server,
BootLanguageServerParams serverParams) {
this.server = server;
this.serverParams = serverParams;
server.doOnInitialized(this::initialized);
server.onShutdown(this::shutdown);
}
@Override
public Set<LanguageId> getInterestingLanguages() {
return LANGUAGES;
}
@Override
public ICompletionEngine getCompletionEngine() {
return new SpringXMLCompletionEngine(this);
}
@Override
public HoverHandler getHoverProvider() {
return null;
}
private void initialized() {
}
private void shutdown() {
}
}