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() {
}
}