diff --git a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/HoverTest.xtend b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/HoverTest.xtend index f7cce2b5fd..f599d4ba02 100644 --- a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/HoverTest.xtend +++ b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/HoverTest.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2020 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 @@ -28,7 +28,8 @@ class HoverTest extends AbstractTestLangLanguageServerTest { column = 'type F'.length expectedHover = ''' [[3, 5] .. [3, 8]] - Some documentation. + kind: markdown + value: Some documentation. ''' ] } @@ -44,6 +45,10 @@ class HoverTest extends AbstractTestLangLanguageServerTest { ''' line = 3 column = '{'.length + expectedHover = ''' + kind: markdown + value: + ''' ] } @@ -62,7 +67,8 @@ class HoverTest extends AbstractTestLangLanguageServerTest { column = ' F'.length expectedHover = ''' [[4, 1] .. [4, 4]] - Some documentation. + kind: markdown + value: Some documentation. ''' ] } @@ -83,7 +89,8 @@ class HoverTest extends AbstractTestLangLanguageServerTest { column = 'type Bar extends F'.length expectedHover = ''' [[5, 17] .. [5, 20]] - Some documentation. + kind: markdown + value: Some documentation. ''' ] } @@ -107,7 +114,8 @@ class HoverTest extends AbstractTestLangLanguageServerTest { column = 'type Bar extends F'.length expectedHover = ''' [[0, 17] .. [0, 20]] - Some documentation. + kind: markdown + value: Some documentation. ''' ] } diff --git a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/CompletionTest.java b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/CompletionTest.java index 133aa6ffa0..777a3b3aa9 100644 --- a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/CompletionTest.java +++ b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/CompletionTest.java @@ -23,6 +23,7 @@ import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.InsertTextFormat; import org.eclipse.lsp4j.Location; +import org.eclipse.lsp4j.MarkupContent; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.SemanticHighlightingInformation; @@ -366,6 +367,8 @@ protected String toExpectation(final Object it) { return _toExpectation((Hover)it); } else if (it instanceof Location) { return _toExpectation((Location)it); + } else if (it instanceof MarkupContent) { + return _toExpectation((MarkupContent)it); } else if (it instanceof Position) { return _toExpectation((Position)it); } else if (it instanceof Range) { diff --git a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/HoverTest.java b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/HoverTest.java index 623e71fb96..b6bba95a3f 100644 --- a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/HoverTest.java +++ b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/HoverTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2020 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 @@ -43,7 +43,9 @@ public void testHover_01() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("[[3, 5] .. [3, 8]]"); _builder_1.newLine(); - _builder_1.append("Some documentation."); + _builder_1.append("kind: markdown"); + _builder_1.newLine(); + _builder_1.append("value: Some documentation."); _builder_1.newLine(); it.setExpectedHover(_builder_1.toString()); }; @@ -67,6 +69,12 @@ public void testHover_02() { it.setModel(_builder.toString()); it.setLine(3); it.setColumn("{".length()); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("kind: markdown"); + _builder_1.newLine(); + _builder_1.append("value: "); + _builder_1.newLine(); + it.setExpectedHover(_builder_1.toString()); }; this.testHover(_function); } @@ -96,7 +104,9 @@ public void testHover_03() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("[[4, 1] .. [4, 4]]"); _builder_1.newLine(); - _builder_1.append("Some documentation."); + _builder_1.append("kind: markdown"); + _builder_1.newLine(); + _builder_1.append("value: Some documentation."); _builder_1.newLine(); it.setExpectedHover(_builder_1.toString()); }; @@ -129,7 +139,9 @@ public void testHover_04() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("[[5, 17] .. [5, 20]]"); _builder_1.newLine(); - _builder_1.append("Some documentation."); + _builder_1.append("kind: markdown"); + _builder_1.newLine(); + _builder_1.append("value: Some documentation."); _builder_1.newLine(); it.setExpectedHover(_builder_1.toString()); }; @@ -164,7 +176,9 @@ public void testHover_05() { StringConcatenation _builder_2 = new StringConcatenation(); _builder_2.append("[[0, 17] .. [0, 20]]"); _builder_2.newLine(); - _builder_2.append("Some documentation."); + _builder_2.append("kind: markdown"); + _builder_2.newLine(); + _builder_2.append("value: Some documentation."); _builder_2.newLine(); it.setExpectedHover(_builder_2.toString()); }; diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/HoverService.xtend b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/HoverService.xtend index 42f08d7ec7..0c9a305006 100644 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/HoverService.xtend +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/HoverService.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2020 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 @@ -7,15 +7,14 @@ *******************************************************************************/ package org.eclipse.xtext.ide.server.hover +import com.google.common.annotations.Beta import com.google.inject.Inject import com.google.inject.Singleton -import java.util.List import org.eclipse.emf.ecore.EObject import org.eclipse.lsp4j.Hover -import org.eclipse.lsp4j.MarkedString +import org.eclipse.lsp4j.MarkupContent import org.eclipse.lsp4j.Range import org.eclipse.lsp4j.TextDocumentPositionParams -import org.eclipse.lsp4j.jsonrpc.messages.Either import org.eclipse.xtend.lib.annotations.Accessors import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor import org.eclipse.xtext.documentation.IEObjectDocumentationProvider @@ -27,8 +26,6 @@ import org.eclipse.xtext.resource.XtextResource import org.eclipse.xtext.util.CancelIndicator import org.eclipse.xtext.util.ITextRegion -import static java.util.Collections.* - import static extension org.eclipse.xtext.nodemodel.util.NodeModelUtils.* /** @@ -36,6 +33,7 @@ import static extension org.eclipse.xtext.nodemodel.util.NodeModelUtils.* * @since 2.11 */ @Singleton +@Beta class HoverService implements IHoverService { @Inject @@ -88,7 +86,7 @@ class HoverService implements IHoverService { protected def Hover hover(HoverContext context) { if (context === null) return EMPTY_HOVER - val contents = context.contents + val contents = context.markupContent if(contents === null) return EMPTY_HOVER val range = context.range @@ -103,33 +101,25 @@ class HoverService implements IHoverService { return resource.newRange(region) } - protected def List> getContents(HoverContext it) { - val language = language - return element.contents.map [ value | - toContents(language, value) - ] + protected def MarkupContent getMarkupContent(HoverContext it) { + return toMarkupContent(kind, element.contents) } - protected def String getLanguage(HoverContext it) { - return null + protected def String getKind(HoverContext it) { + return "markdown" } - protected def Either toContents(String language, String value) { - if (language === null) { - return Either.forLeft(value) - } - return Either.forRight(new MarkedString(language, value)) + protected def MarkupContent toMarkupContent(String kind, String value) { + return new MarkupContent(kind, value) } - def List getContents(EObject element) { - if(element === null) return emptyList + def String getContents(EObject element) { + if(element === null) return "" val documentation = element.documentation - if(documentation === null) return emptyList + if(documentation === null) return "" - return #[ - documentation - ] + return documentation } } diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/IHoverService.xtend b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/IHoverService.xtend index 1b134a2b05..fc3a0c141b 100644 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/IHoverService.xtend +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/IHoverService.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2017, 2020 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 @@ -13,6 +13,7 @@ import org.eclipse.xtext.ide.server.Document import org.eclipse.xtext.resource.XtextResource import org.eclipse.xtext.util.CancelIndicator import com.google.inject.ImplementedBy +import org.eclipse.lsp4j.MarkupContent /** * @author Sven Efftinge - Initial contribution and API @@ -20,7 +21,7 @@ import com.google.inject.ImplementedBy @ImplementedBy(HoverService) interface IHoverService { - public static val EMPTY_HOVER = new Hover(emptyList, null) + public static val EMPTY_HOVER = new Hover(new MarkupContent("markdown", ""), null) /** * callback for 'textDocument/hover' requests. diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverContext.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverContext.java index c2914705c7..592c4176c8 100644 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverContext.java +++ b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverContext.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2020 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 diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverService.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverService.java index 94f5845367..476f2e17cf 100644 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverService.java +++ b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverService.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2020 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 @@ -7,16 +7,14 @@ */ package org.eclipse.xtext.ide.server.hover; +import com.google.common.annotations.Beta; import com.google.inject.Inject; import com.google.inject.Singleton; -import java.util.Collections; -import java.util.List; import org.eclipse.emf.ecore.EObject; import org.eclipse.lsp4j.Hover; -import org.eclipse.lsp4j.MarkedString; +import org.eclipse.lsp4j.MarkupContent; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextDocumentPositionParams; -import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.xtext.documentation.IEObjectDocumentationProvider; import org.eclipse.xtext.ide.server.Document; import org.eclipse.xtext.ide.server.DocumentExtensions; @@ -30,16 +28,14 @@ import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.util.CancelIndicator; import org.eclipse.xtext.util.ITextRegion; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.ListExtensions; /** * @author kosyakov - Initial contribution and API * @since 2.11 */ @Singleton +@Beta @SuppressWarnings("all") public class HoverService implements IHoverService { @Inject @@ -98,7 +94,7 @@ protected Hover hover(final HoverContext context) { if ((context == null)) { return IHoverService.EMPTY_HOVER; } - final List> contents = this.getContents(context); + final MarkupContent contents = this.getMarkupContent(context); if ((contents == null)) { return IHoverService.EMPTY_HOVER; } @@ -118,34 +114,26 @@ protected Range getRange(final HoverContext it) { return this._documentExtensions.newRange(it.getResource(), it.getRegion()); } - protected List> getContents(final HoverContext it) { - final String language = this.getLanguage(it); - final Function1> _function = (String value) -> { - return this.toContents(language, value); - }; - return ListExtensions.>map(this.getContents(it.getElement()), _function); + protected MarkupContent getMarkupContent(final HoverContext it) { + return this.toMarkupContent(this.getKind(it), this.getContents(it.getElement())); } - protected String getLanguage(final HoverContext it) { - return null; + protected String getKind(final HoverContext it) { + return "markdown"; } - protected Either toContents(final String language, final String value) { - if ((language == null)) { - return Either.forLeft(value); - } - MarkedString _markedString = new MarkedString(language, value); - return Either.forRight(_markedString); + protected MarkupContent toMarkupContent(final String kind, final String value) { + return new MarkupContent(kind, value); } - public List getContents(final EObject element) { + public String getContents(final EObject element) { if ((element == null)) { - return Collections.emptyList(); + return ""; } final String documentation = this._iEObjectDocumentationProvider.getDocumentation(element); if ((documentation == null)) { - return Collections.emptyList(); + return ""; } - return Collections.unmodifiableList(CollectionLiterals.newArrayList(documentation)); + return documentation; } } diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/IHoverService.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/IHoverService.java index f214c453fa..c8f931c316 100644 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/IHoverService.java +++ b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/IHoverService.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2017, 2020 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 @@ -9,14 +9,12 @@ import com.google.inject.ImplementedBy; import org.eclipse.lsp4j.Hover; -import org.eclipse.lsp4j.MarkedString; +import org.eclipse.lsp4j.MarkupContent; import org.eclipse.lsp4j.TextDocumentPositionParams; -import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.xtext.ide.server.Document; import org.eclipse.xtext.ide.server.hover.HoverService; import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.util.CancelIndicator; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; /** * @author Sven Efftinge - Initial contribution and API @@ -24,7 +22,7 @@ @ImplementedBy(HoverService.class) @SuppressWarnings("all") public interface IHoverService { - static final Hover EMPTY_HOVER = new Hover(CollectionLiterals.>emptyList(), null); + static final Hover EMPTY_HOVER = new Hover(new MarkupContent("markdown", ""), null); /** * callback for 'textDocument/hover' requests. diff --git a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend index a8ccf75885..77bb9d4f79 100644 --- a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend +++ b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend @@ -85,6 +85,7 @@ import org.junit.jupiter.api.BeforeEach import static extension org.eclipse.lsp4j.util.Ranges.containsRange import static extension org.eclipse.xtext.util.Strings.* import org.eclipse.lsp4j.SignatureHelpParams +import org.eclipse.lsp4j.MarkupContent /** * @author Sven Efftinge - Initial contribution and API @@ -404,6 +405,11 @@ abstract class AbstractLanguageServerTest implements Endpoint { assertEquals(expectedCodeLensItems, result.toExpectation) } } + + protected dispatch def String toExpectation(MarkupContent it) ''' + kind: «kind» + value: «value» + ''' protected dispatch def String toExpectation(Command it) ''' command : «command» diff --git a/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java b/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java index 028d6ba90b..cbf7c7db58 100644 --- a/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java +++ b/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java @@ -56,6 +56,7 @@ import org.eclipse.lsp4j.InitializeResult; import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.LocationLink; +import org.eclipse.lsp4j.MarkupContent; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.PublishDiagnosticsParams; import org.eclipse.lsp4j.Range; @@ -867,6 +868,19 @@ protected void testCodeLens(final Procedure1