Updated coloring LSP extension service API.

- Renamed semantic highlighting to coloring.
 - Updated abstract test class to provide coloring parameters.

Signed-off-by: Akos Kitta <kittaakos@gmail.com>
This commit is contained in:
Akos Kitta 2016-11-15 13:33:21 +01:00
parent 1547a9b496
commit fd8aa2f397
10 changed files with 213 additions and 63 deletions

View file

@ -28,6 +28,7 @@ Export-Package: org.eclipse.xtext.ide;x-friends:="org.eclipse.xtend.ide",
org.eclipse.xtext.ide.editor.syntaxcoloring,
org.eclipse.xtext.ide.labels;x-friends:="org.eclipse.xtext.web",
org.eclipse.xtext.ide.server,
org.eclipse.xtext.ide.server.coloring,
org.eclipse.xtext.ide.server.concurrent,
org.eclipse.xtext.ide.server.contentassist,
org.eclipse.xtext.ide.server.findReferences,
@ -36,5 +37,4 @@ Export-Package: org.eclipse.xtext.ide;x-friends:="org.eclipse.xtend.ide",
org.eclipse.xtext.ide.server.occurrences,
org.eclipse.xtext.ide.server.signatureHelp,
org.eclipse.xtext.ide.server.symbol,
org.eclipse.xtext.ide.server.syntaxColoring,
org.eclipse.xtext.ide.util

View file

@ -5,20 +5,20 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.ide.server.syntaxColoring
package org.eclipse.xtext.ide.server.coloring
import java.util.List
import org.eclipse.lsp4j.Range
import org.eclipse.lsp4j.annotations.LanguageServerAPI
import org.eclipse.lsp4j.generator.LanguageServerAPI
/**
* Representation of a range and highlighting style identifiers that should be
* highlighted based on semantic information of the underlying model.
* highlighted based on the underlying model.
*
* @author akos.kitta - Initial contribution and API
*/
@LanguageServerAPI
class SemanticHighlightInformation {
class ColoringInformation {
/**
* The range that should be highlighted on the client-side.

View file

@ -5,10 +5,11 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.ide.server.syntaxColoring
package org.eclipse.xtext.ide.server.coloring
import java.util.List
import org.eclipse.lsp4j.annotations.LanguageServerAPI
import org.eclipse.lsp4j.generator.LanguageServerAPI
import org.eclipse.lsp4j.jsonrpc.validation.NonNull
/**
* Representation of a computed mapping from ranges to the appropriate
@ -17,11 +18,17 @@ import org.eclipse.lsp4j.annotations.LanguageServerAPI
* @author akos.kitta - Initial contribution and API
*/
@LanguageServerAPI
class SemanticHighlight {
class ColoringParams {
/**
* A list of semantic highlight information.
* The URI for which coloring information is reported.
*/
List<? extends SemanticHighlightInformation> infos;
@NonNull
String uri;
/**
* A list of coloring information instances.
*/
List<? extends ColoringInformation> infos;
}

View file

@ -5,30 +5,30 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.ide.server.syntaxColoring;
package org.eclipse.xtext.ide.server.coloring;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.eclipse.xtext.ide.server.ILanguageServerExtension;
/**
* Representation of a language-server client that can receive
* {@link SemanticHighlight semantic highlight} push notifications from the
* {@link ColoringParams coloring parameters} as push notifications from the
* language-server as part of the
* <a href="https://github.com/Microsoft/language-server-protocol">Language
* Server Protocol</a> {@link ILanguageServerExtension extension}.
*
* @author akos.kitta - Initial contribution and API
*/
public interface ISemanticHighlightClient {
public interface IColoringClient {
/**
* Pushes the {@link SemanticHighlight semantic highlight} to the client.
* Pushes the {@link ColoringParams coloring parameter} to the client.
*
* @param highlight
* the information that should be pushed to the client side. Must
* not be {@code null}.
* @param params
* the information that should be pushed to the client side for
* coloring purposes. Must not be {@code null}.
*/
@JsonNotification("lsp4j/pushSemanticHighlight")
void pushSemanticHighlight(SemanticHighlight highlight);
@JsonNotification("textDocument/updateColoring")
void updateColoring(ColoringParams params);
}

View file

@ -5,33 +5,28 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.ide.server.syntaxColoring;
package org.eclipse.xtext.ide.server.coloring;
import static java.util.Collections.*;
import org.eclipse.xtext.ide.server.Document;
import org.eclipse.xtext.ide.server.coloring.ColoringParams;
import org.eclipse.xtext.resource.XtextResource;
import com.google.inject.ImplementedBy;
/**
* Representation of a generic, IDE independent semantic highlighting service.
* Provides coloring and semantic highlighting information for clients based on
* the underlying model.
* Representation of a generic, IDE independent coloring service. Provides
* coloring and highlighting information for clients based on the underlying
* model.
*
* @author akos.kitta - Initial contribution and API
*/
@ImplementedBy(ISemanticHighlightService.Noop.class)
public interface ISemanticHighlightService {
@ImplementedBy(IColoringService.Noop.class)
public interface IColoringService {
/**
* Shared, immutable empty instance.
*/
SemanticHighlight EMPTY = new SemanticHighlight(emptyList());
/**
* Provides semantic highlighting information based on the offset in the
* document.
* Provides all available coloring information for the resource.
*
* @param resource
* the resource that will be highlighted. May be {@code null} in
@ -39,22 +34,21 @@ public interface ISemanticHighlightService {
* @param document
* the IDE and Xtext independent document that can be used to
* convert the document based offsets to line based positions.
* @return the semantic highlight proposal for the resource.
* @return the coloring and highlighting proposal for the resource.
*/
SemanticHighlight getSemanticHighlight(XtextResource resource, Document document);
ColoringParams getColoring(XtextResource resource, Document document);
/**
* NOOP {@link ISemanticHighlightService semantic highlighting service}
* implementation. Always provides an {@link ISemanticHighlightService#EMPTY
* empty} instance.
* NOOP {@link IColoringService coloring service} implementation. Always
* provides an {@link IColoringService#EMPTY empty} instance.
*
* @author akos.kitta - Initial contribution and API
*/
public static class Noop implements ISemanticHighlightService {
public static class Noop implements IColoringService {
@Override
public SemanticHighlight getSemanticHighlight(final XtextResource resource, final Document document) {
return EMPTY;
public ColoringParams getColoring(final XtextResource resource, final Document document) {
return new ColoringParams(resource.getURI().toString(), emptyList());
}
}

View file

@ -5,7 +5,7 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.ide.server.syntaxColoring;
package org.eclipse.xtext.ide.server.coloring;
import java.util.List;
import org.eclipse.lsp4j.Range;
@ -14,12 +14,12 @@ import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
/**
* Representation of a range and highlighting style identifiers that should be
* highlighted based on semantic information of the underlying model.
* highlighted based on the underlying model.
*
* @author akos.kitta - Initial contribution and API
*/
@SuppressWarnings("all")
public class SemanticHighlightInformation {
public class ColoringInformation {
/**
* The range that should be highlighted on the client-side.
*/
@ -66,11 +66,11 @@ public class SemanticHighlightInformation {
this.ids = ids;
}
public SemanticHighlightInformation() {
public ColoringInformation() {
}
public SemanticHighlightInformation(final Range range, final List<String> ids) {
public ColoringInformation(final Range range, final List<String> ids) {
this.range = range;
this.ids = ids;
}
@ -95,7 +95,7 @@ public class SemanticHighlightInformation {
return false;
if (!super.equals(obj))
return false;
SemanticHighlightInformation other = (SemanticHighlightInformation) obj;
ColoringInformation other = (ColoringInformation) obj;
if (this.range == null) {
if (other.range != null)
return false;

View file

@ -5,10 +5,11 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.ide.server.syntaxColoring;
package org.eclipse.xtext.ide.server.coloring;
import java.util.List;
import org.eclipse.xtext.ide.server.syntaxColoring.SemanticHighlightInformation;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.xtext.ide.server.coloring.ColoringInformation;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
@ -19,32 +20,54 @@ import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
* @author akos.kitta - Initial contribution and API
*/
@SuppressWarnings("all")
public class SemanticHighlight {
public class ColoringParams {
/**
* A list of semantic highlight information.
* The URI for which coloring information is reported.
*/
private List<? extends SemanticHighlightInformation> infos;
@NonNull
private String uri;
/**
* A list of semantic highlight information.
* A list of coloring information instances.
*/
private List<? extends ColoringInformation> infos;
/**
* The URI for which coloring information is reported.
*/
@Pure
public List<? extends SemanticHighlightInformation> getInfos() {
public String getUri() {
return this.uri;
}
/**
* The URI for which coloring information is reported.
*/
public void setUri(final String uri) {
this.uri = uri;
}
/**
* A list of coloring information instances.
*/
@Pure
public List<? extends ColoringInformation> getInfos() {
return this.infos;
}
/**
* A list of semantic highlight information.
* A list of coloring information instances.
*/
public void setInfos(final List<? extends SemanticHighlightInformation> infos) {
public void setInfos(final List<? extends ColoringInformation> infos) {
this.infos = infos;
}
public SemanticHighlight() {
public ColoringParams() {
}
public SemanticHighlight(final List<? extends SemanticHighlightInformation> infos) {
public ColoringParams(final String uri, final List<? extends ColoringInformation> infos) {
this.uri = uri;
this.infos = infos;
}
@ -52,6 +75,7 @@ public class SemanticHighlight {
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("uri", this.uri);
b.add("infos", this.infos);
return b.toString();
}
@ -67,7 +91,12 @@ public class SemanticHighlight {
return false;
if (!super.equals(obj))
return false;
SemanticHighlight other = (SemanticHighlight) obj;
ColoringParams other = (ColoringParams) obj;
if (this.uri == null) {
if (other.uri != null)
return false;
} else if (!this.uri.equals(other.uri))
return false;
if (this.infos == null) {
if (other.infos != null)
return false;
@ -81,6 +110,7 @@ public class SemanticHighlight {
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.uri== null) ? 0 : this.uri.hashCode());
result = prime * result + ((this.infos== null) ? 0 : this.infos.hashCode());
return result;
}

View file

@ -19,6 +19,7 @@ import java.util.List
import java.util.Map
import java.util.concurrent.CompletableFuture
import org.eclipse.lsp4j.CompletionItem
import org.eclipse.lsp4j.CompletionList
import org.eclipse.lsp4j.Diagnostic
import org.eclipse.lsp4j.DidChangeWatchedFilesParams
import org.eclipse.lsp4j.DidCloseTextDocumentParams
@ -35,6 +36,7 @@ import org.eclipse.lsp4j.InitializeParams
import org.eclipse.lsp4j.InitializeResult
import org.eclipse.lsp4j.Location
import org.eclipse.lsp4j.Position
import org.eclipse.lsp4j.PublishDiagnosticsParams
import org.eclipse.lsp4j.Range
import org.eclipse.lsp4j.ReferenceContext
import org.eclipse.lsp4j.ReferenceParams
@ -55,6 +57,7 @@ import org.eclipse.xtext.ide.server.Document
import org.eclipse.xtext.ide.server.LanguageServerImpl
import org.eclipse.xtext.ide.server.ServerModule
import org.eclipse.xtext.ide.server.UriExtensions
import org.eclipse.xtext.ide.server.coloring.ColoringParams
import org.eclipse.xtext.ide.server.concurrent.RequestManager
import org.eclipse.xtext.resource.IResourceServiceProvider
import org.eclipse.xtext.util.CancelIndicator
@ -62,8 +65,7 @@ import org.eclipse.xtext.util.Files
import org.eclipse.xtext.util.Modules2
import org.junit.Assert
import org.junit.Before
import org.eclipse.lsp4j.PublishDiagnosticsParams
import org.eclipse.lsp4j.CompletionList
import org.eclipse.xtext.ide.server.coloring.ColoringInformation
/**
* @author Sven Efftinge - Initial contribution and API
@ -107,7 +109,7 @@ abstract class AbstractLanguageServerTest implements Endpoint {
languageServer.supportedMethods()
// create workingdir
root = new File("./test-data/test-project")
root = new File(new File("").absoluteFile, "/test-data/test-project")
if (!root.mkdirs) {
Files.cleanFolder(root, null, true, false)
}
@ -256,6 +258,14 @@ abstract class AbstractLanguageServerTest implements Endpoint {
protected dispatch def String toExpectation(DocumentHighlightKind kind) {
return kind.toString.substring(0, 1).toUpperCase;
}
protected dispatch def String toExpectation(Map<Object, Object> it) {
return '''«FOR entry : entrySet SEPARATOR '\n'»«entry.key.toExpectation» -> «IF entry.value instanceof Iterable<?>»«FOR item : (entry.value as Iterable<?>)»«"\n * "»«item.toExpectation»«ENDFOR»«ELSE»«entry.value.toExpectation»«ENDIF»«ENDFOR»''';
}
protected dispatch def String toExpectation(ColoringInformation it) {
return '''«range.toExpectation» -> [«ids.join(', ')»]''';
}
protected def void testCompletion((TestCompletionConfiguration)=>void configurator) {
val extension configuration = new TestCompletionConfiguration
@ -465,6 +475,10 @@ abstract class AbstractLanguageServerTest implements Endpoint {
}
return result
}
protected def getColoringParams() {
return notifications.map[value].filter(ColoringParams).toMap([uri], [infos]);
}
}
@Data class FileInfo {
@ -539,6 +553,11 @@ class FormattingConfiguration extends TextDocumentConfiguration {
String expectedText = ''
}
@Accessors
class ColoringConfiguration extends TextDocumentConfiguration {
String expectedColoredRangesWithStyles = '';
}
@Accessors
class RangeFormattingConfiguration extends FormattingConfiguration {
Range range = new Range => [

View file

@ -70,6 +70,8 @@ import org.eclipse.xtext.ide.server.Document;
import org.eclipse.xtext.ide.server.LanguageServerImpl;
import org.eclipse.xtext.ide.server.ServerModule;
import org.eclipse.xtext.ide.server.UriExtensions;
import org.eclipse.xtext.ide.server.coloring.ColoringInformation;
import org.eclipse.xtext.ide.server.coloring.ColoringParams;
import org.eclipse.xtext.ide.server.concurrent.RequestManager;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.testing.DefinitionTestConfiguration;
@ -151,8 +153,10 @@ public abstract class AbstractLanguageServerTest implements Endpoint {
LanguageClient _serviceObject = ServiceEndpoints.<LanguageClient>toServiceObject(this, LanguageClient.class);
this.languageServer.connect(_serviceObject);
this.languageServer.supportedMethods();
File _file = new File("./test-data/test-project");
this.root = _file;
File _file = new File("");
File _absoluteFile = _file.getAbsoluteFile();
File _file_1 = new File(_absoluteFile, "/test-data/test-project");
this.root = _file_1;
boolean _mkdirs = this.root.mkdirs();
boolean _not = (!_mkdirs);
if (_not) {
@ -549,6 +553,56 @@ public abstract class AbstractLanguageServerTest implements Endpoint {
return _substring.toUpperCase();
}
protected String _toExpectation(final Map<Object, Object> it) {
StringConcatenation _builder = new StringConcatenation();
{
Set<Map.Entry<Object, Object>> _entrySet = it.entrySet();
boolean _hasElements = false;
for(final Map.Entry<Object, Object> entry : _entrySet) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate("\n", "");
}
Object _key = entry.getKey();
String _expectation = this.toExpectation(_key);
_builder.append(_expectation, "");
_builder.append(" -> ");
{
Object _value = entry.getValue();
if ((_value instanceof Iterable<?>)) {
{
Object _value_1 = entry.getValue();
for(final Object item : ((Iterable<?>) _value_1)) {
_builder.append("\n * ", "");
String _expectation_1 = this.toExpectation(item);
_builder.append(_expectation_1, "");
}
}
} else {
Object _value_2 = entry.getValue();
String _expectation_2 = this.toExpectation(_value_2);
_builder.append(_expectation_2, "");
}
}
}
}
return _builder.toString();
}
protected String _toExpectation(final ColoringInformation it) {
StringConcatenation _builder = new StringConcatenation();
Range _range = it.getRange();
String _expectation = this.toExpectation(_range);
_builder.append(_expectation, "");
_builder.append(" -> [");
List<String> _ids = it.getIds();
String _join = IterableExtensions.join(_ids, ", ");
_builder.append(_join, "");
_builder.append("]");
return _builder.toString();
}
protected void testCompletion(final Procedure1<? super TestCompletionConfiguration> configurator) {
try {
@Extension
@ -960,6 +1014,21 @@ public abstract class AbstractLanguageServerTest implements Endpoint {
return result;
}
protected Map<String, List<? extends ColoringInformation>> getColoringParams() {
final Function1<Pair<String, Object>, Object> _function = (Pair<String, Object> it) -> {
return it.getValue();
};
List<Object> _map = ListExtensions.<Pair<String, Object>, Object>map(this.notifications, _function);
Iterable<ColoringParams> _filter = Iterables.<ColoringParams>filter(_map, ColoringParams.class);
final Function1<ColoringParams, String> _function_1 = (ColoringParams it) -> {
return it.getUri();
};
final Function1<ColoringParams, List<? extends ColoringInformation>> _function_2 = (ColoringParams it) -> {
return it.getInfos();
};
return IterableExtensions.<ColoringParams, String, List<? extends ColoringInformation>>toMap(_filter, _function_1, _function_2);
}
protected String toExpectation(final Object elements) {
if (elements instanceof List) {
return _toExpectation((List<?>)elements);
@ -969,6 +1038,8 @@ public abstract class AbstractLanguageServerTest implements Endpoint {
return _toExpectation((String)elements);
} else if (elements == null) {
return _toExpectation((Void)null);
} else if (elements instanceof Map) {
return _toExpectation((Map<Object, Object>)elements);
} else if (elements instanceof CompletionItem) {
return _toExpectation((CompletionItem)elements);
} else if (elements instanceof DocumentHighlight) {
@ -987,6 +1058,8 @@ public abstract class AbstractLanguageServerTest implements Endpoint {
return _toExpectation((SymbolInformation)elements);
} else if (elements instanceof TextEdit) {
return _toExpectation((TextEdit)elements);
} else if (elements instanceof ColoringInformation) {
return _toExpectation((ColoringInformation)elements);
} else {
throw new IllegalArgumentException("Unhandled parameter types: " +
Arrays.<Object>asList(elements).toString());

View file

@ -0,0 +1,27 @@
/**
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* 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
*/
package org.eclipse.xtext.testing;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtext.testing.TextDocumentConfiguration;
import org.eclipse.xtext.xbase.lib.Pure;
@Accessors
@SuppressWarnings("all")
public class ColoringConfiguration extends TextDocumentConfiguration {
private String expectedColoredRangesWithStyles = "";
@Pure
public String getExpectedColoredRangesWithStyles() {
return this.expectedColoredRangesWithStyles;
}
public void setExpectedColoredRangesWithStyles(final String expectedColoredRangesWithStyles) {
this.expectedColoredRangesWithStyles = expectedColoredRangesWithStyles;
}
}