Skip to content
This repository was archived by the owner on Apr 21, 2023. It is now read-only.

Commit b133679

Browse files
committed
[#1372] update hover service to use MarkupContent
Signed-off-by: Christian Dietrich <[email protected]>
1 parent 7050b2f commit b133679

File tree

10 files changed

+94
-70
lines changed

10 files changed

+94
-70
lines changed

org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/HoverTest.xtend

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
2+
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -28,7 +28,8 @@ class HoverTest extends AbstractTestLangLanguageServerTest {
2828
column = 'type F'.length
2929
expectedHover = '''
3030
[[3, 5] .. [3, 8]]
31-
Some documentation.
31+
kind: markdown
32+
value: Some documentation.
3233
'''
3334
]
3435
}
@@ -44,6 +45,10 @@ class HoverTest extends AbstractTestLangLanguageServerTest {
4445
'''
4546
line = 3
4647
column = '{'.length
48+
expectedHover = '''
49+
kind: markdown
50+
value:
51+
'''
4752
]
4853
}
4954

@@ -62,7 +67,8 @@ class HoverTest extends AbstractTestLangLanguageServerTest {
6267
column = ' F'.length
6368
expectedHover = '''
6469
[[4, 1] .. [4, 4]]
65-
Some documentation.
70+
kind: markdown
71+
value: Some documentation.
6672
'''
6773
]
6874
}
@@ -83,7 +89,8 @@ class HoverTest extends AbstractTestLangLanguageServerTest {
8389
column = 'type Bar extends F'.length
8490
expectedHover = '''
8591
[[5, 17] .. [5, 20]]
86-
Some documentation.
92+
kind: markdown
93+
value: Some documentation.
8794
'''
8895
]
8996
}
@@ -107,7 +114,8 @@ class HoverTest extends AbstractTestLangLanguageServerTest {
107114
column = 'type Bar extends F'.length
108115
expectedHover = '''
109116
[[0, 17] .. [0, 20]]
110-
Some documentation.
117+
kind: markdown
118+
value: Some documentation.
111119
'''
112120
]
113121
}

org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/CompletionTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.eclipse.lsp4j.Hover;
2424
import org.eclipse.lsp4j.InsertTextFormat;
2525
import org.eclipse.lsp4j.Location;
26+
import org.eclipse.lsp4j.MarkupContent;
2627
import org.eclipse.lsp4j.Position;
2728
import org.eclipse.lsp4j.Range;
2829
import org.eclipse.lsp4j.SemanticHighlightingInformation;
@@ -366,6 +367,8 @@ protected String toExpectation(final Object it) {
366367
return _toExpectation((Hover)it);
367368
} else if (it instanceof Location) {
368369
return _toExpectation((Location)it);
370+
} else if (it instanceof MarkupContent) {
371+
return _toExpectation((MarkupContent)it);
369372
} else if (it instanceof Position) {
370373
return _toExpectation((Position)it);
371374
} else if (it instanceof Range) {

org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/HoverTest.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
2+
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -43,7 +43,9 @@ public void testHover_01() {
4343
StringConcatenation _builder_1 = new StringConcatenation();
4444
_builder_1.append("[[3, 5] .. [3, 8]]");
4545
_builder_1.newLine();
46-
_builder_1.append("Some documentation.");
46+
_builder_1.append("kind: markdown");
47+
_builder_1.newLine();
48+
_builder_1.append("value: Some documentation.");
4749
_builder_1.newLine();
4850
it.setExpectedHover(_builder_1.toString());
4951
};
@@ -67,6 +69,12 @@ public void testHover_02() {
6769
it.setModel(_builder.toString());
6870
it.setLine(3);
6971
it.setColumn("{".length());
72+
StringConcatenation _builder_1 = new StringConcatenation();
73+
_builder_1.append("kind: markdown");
74+
_builder_1.newLine();
75+
_builder_1.append("value: ");
76+
_builder_1.newLine();
77+
it.setExpectedHover(_builder_1.toString());
7078
};
7179
this.testHover(_function);
7280
}
@@ -96,7 +104,9 @@ public void testHover_03() {
96104
StringConcatenation _builder_1 = new StringConcatenation();
97105
_builder_1.append("[[4, 1] .. [4, 4]]");
98106
_builder_1.newLine();
99-
_builder_1.append("Some documentation.");
107+
_builder_1.append("kind: markdown");
108+
_builder_1.newLine();
109+
_builder_1.append("value: Some documentation.");
100110
_builder_1.newLine();
101111
it.setExpectedHover(_builder_1.toString());
102112
};
@@ -129,7 +139,9 @@ public void testHover_04() {
129139
StringConcatenation _builder_1 = new StringConcatenation();
130140
_builder_1.append("[[5, 17] .. [5, 20]]");
131141
_builder_1.newLine();
132-
_builder_1.append("Some documentation.");
142+
_builder_1.append("kind: markdown");
143+
_builder_1.newLine();
144+
_builder_1.append("value: Some documentation.");
133145
_builder_1.newLine();
134146
it.setExpectedHover(_builder_1.toString());
135147
};
@@ -164,7 +176,9 @@ public void testHover_05() {
164176
StringConcatenation _builder_2 = new StringConcatenation();
165177
_builder_2.append("[[0, 17] .. [0, 20]]");
166178
_builder_2.newLine();
167-
_builder_2.append("Some documentation.");
179+
_builder_2.append("kind: markdown");
180+
_builder_2.newLine();
181+
_builder_2.append("value: Some documentation.");
168182
_builder_2.newLine();
169183
it.setExpectedHover(_builder_2.toString());
170184
};

org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/HoverService.xtend

+15-25
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
2+
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-v10.html
77
*******************************************************************************/
88
package org.eclipse.xtext.ide.server.hover
99

10+
import com.google.common.annotations.Beta
1011
import com.google.inject.Inject
1112
import com.google.inject.Singleton
12-
import java.util.List
1313
import org.eclipse.emf.ecore.EObject
1414
import org.eclipse.lsp4j.Hover
15-
import org.eclipse.lsp4j.MarkedString
15+
import org.eclipse.lsp4j.MarkupContent
1616
import org.eclipse.lsp4j.Range
1717
import org.eclipse.lsp4j.TextDocumentPositionParams
18-
import org.eclipse.lsp4j.jsonrpc.messages.Either
1918
import org.eclipse.xtend.lib.annotations.Accessors
2019
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
2120
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider
@@ -27,15 +26,14 @@ import org.eclipse.xtext.resource.XtextResource
2726
import org.eclipse.xtext.util.CancelIndicator
2827
import org.eclipse.xtext.util.ITextRegion
2928

30-
import static java.util.Collections.*
31-
3229
import static extension org.eclipse.xtext.nodemodel.util.NodeModelUtils.*
3330

3431
/**
3532
* @author kosyakov - Initial contribution and API
3633
* @since 2.11
3734
*/
3835
@Singleton
36+
@Beta
3937
class HoverService implements IHoverService {
4038

4139
@Inject
@@ -88,7 +86,7 @@ class HoverService implements IHoverService {
8886
protected def Hover hover(HoverContext context) {
8987
if (context === null) return EMPTY_HOVER
9088

91-
val contents = context.contents
89+
val contents = context.markupContent
9290
if(contents === null) return EMPTY_HOVER
9391

9492
val range = context.range
@@ -103,33 +101,25 @@ class HoverService implements IHoverService {
103101
return resource.newRange(region)
104102
}
105103

106-
protected def List<Either<String, MarkedString>> getContents(HoverContext it) {
107-
val language = language
108-
return element.contents.map [ value |
109-
toContents(language, value)
110-
]
104+
protected def MarkupContent getMarkupContent(HoverContext it) {
105+
return toMarkupContent(kind, element.contents)
111106
}
112107

113-
protected def String getLanguage(HoverContext it) {
114-
return null
108+
protected def String getKind(HoverContext it) {
109+
return "markdown"
115110
}
116111

117-
protected def Either<String, MarkedString> toContents(String language, String value) {
118-
if (language === null) {
119-
return Either.forLeft(value)
120-
}
121-
return Either.forRight(new MarkedString(language, value))
112+
protected def MarkupContent toMarkupContent(String kind, String value) {
113+
return new MarkupContent(kind, value)
122114
}
123115

124-
def List<String> getContents(EObject element) {
125-
if(element === null) return emptyList
116+
def String getContents(EObject element) {
117+
if(element === null) return ""
126118

127119
val documentation = element.documentation
128-
if(documentation === null) return emptyList
120+
if(documentation === null) return ""
129121

130-
return #[
131-
documentation
132-
]
122+
return documentation
133123
}
134124

135125
}

org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/hover/IHoverService.xtend

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
2+
* Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -13,14 +13,15 @@ import org.eclipse.xtext.ide.server.Document
1313
import org.eclipse.xtext.resource.XtextResource
1414
import org.eclipse.xtext.util.CancelIndicator
1515
import com.google.inject.ImplementedBy
16+
import org.eclipse.lsp4j.MarkupContent
1617

1718
/**
1819
* @author Sven Efftinge - Initial contribution and API
1920
*/
2021
@ImplementedBy(HoverService)
2122
interface IHoverService {
2223

23-
public static val EMPTY_HOVER = new Hover(emptyList, null)
24+
public static val EMPTY_HOVER = new Hover(new MarkupContent("markdown", ""), null)
2425

2526
/**
2627
* callback for 'textDocument/hover' requests.

org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
2+
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/HoverService.java

+15-27
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
/**
2-
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
2+
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-v10.html
77
*/
88
package org.eclipse.xtext.ide.server.hover;
99

10+
import com.google.common.annotations.Beta;
1011
import com.google.inject.Inject;
1112
import com.google.inject.Singleton;
12-
import java.util.Collections;
13-
import java.util.List;
1413
import org.eclipse.emf.ecore.EObject;
1514
import org.eclipse.lsp4j.Hover;
16-
import org.eclipse.lsp4j.MarkedString;
15+
import org.eclipse.lsp4j.MarkupContent;
1716
import org.eclipse.lsp4j.Range;
1817
import org.eclipse.lsp4j.TextDocumentPositionParams;
19-
import org.eclipse.lsp4j.jsonrpc.messages.Either;
2018
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
2119
import org.eclipse.xtext.ide.server.Document;
2220
import org.eclipse.xtext.ide.server.DocumentExtensions;
@@ -30,16 +28,14 @@
3028
import org.eclipse.xtext.resource.XtextResource;
3129
import org.eclipse.xtext.util.CancelIndicator;
3230
import org.eclipse.xtext.util.ITextRegion;
33-
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
3431
import org.eclipse.xtext.xbase.lib.Extension;
35-
import org.eclipse.xtext.xbase.lib.Functions.Function1;
36-
import org.eclipse.xtext.xbase.lib.ListExtensions;
3732

3833
/**
3934
* @author kosyakov - Initial contribution and API
4035
* @since 2.11
4136
*/
4237
@Singleton
38+
@Beta
4339
@SuppressWarnings("all")
4440
public class HoverService implements IHoverService {
4541
@Inject
@@ -98,7 +94,7 @@ protected Hover hover(final HoverContext context) {
9894
if ((context == null)) {
9995
return IHoverService.EMPTY_HOVER;
10096
}
101-
final List<Either<String, MarkedString>> contents = this.getContents(context);
97+
final MarkupContent contents = this.getMarkupContent(context);
10298
if ((contents == null)) {
10399
return IHoverService.EMPTY_HOVER;
104100
}
@@ -118,34 +114,26 @@ protected Range getRange(final HoverContext it) {
118114
return this._documentExtensions.newRange(it.getResource(), it.getRegion());
119115
}
120116

121-
protected List<Either<String, MarkedString>> getContents(final HoverContext it) {
122-
final String language = this.getLanguage(it);
123-
final Function1<String, Either<String, MarkedString>> _function = (String value) -> {
124-
return this.toContents(language, value);
125-
};
126-
return ListExtensions.<String, Either<String, MarkedString>>map(this.getContents(it.getElement()), _function);
117+
protected MarkupContent getMarkupContent(final HoverContext it) {
118+
return this.toMarkupContent(this.getKind(it), this.getContents(it.getElement()));
127119
}
128120

129-
protected String getLanguage(final HoverContext it) {
130-
return null;
121+
protected String getKind(final HoverContext it) {
122+
return "markdown";
131123
}
132124

133-
protected Either<String, MarkedString> toContents(final String language, final String value) {
134-
if ((language == null)) {
135-
return Either.<String, MarkedString>forLeft(value);
136-
}
137-
MarkedString _markedString = new MarkedString(language, value);
138-
return Either.<String, MarkedString>forRight(_markedString);
125+
protected MarkupContent toMarkupContent(final String kind, final String value) {
126+
return new MarkupContent(kind, value);
139127
}
140128

141-
public List<String> getContents(final EObject element) {
129+
public String getContents(final EObject element) {
142130
if ((element == null)) {
143-
return Collections.<String>emptyList();
131+
return "";
144132
}
145133
final String documentation = this._iEObjectDocumentationProvider.getDocumentation(element);
146134
if ((documentation == null)) {
147-
return Collections.<String>emptyList();
135+
return "";
148136
}
149-
return Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(documentation));
137+
return documentation;
150138
}
151139
}

org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/hover/IHoverService.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
2+
* Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -9,22 +9,20 @@
99

1010
import com.google.inject.ImplementedBy;
1111
import org.eclipse.lsp4j.Hover;
12-
import org.eclipse.lsp4j.MarkedString;
12+
import org.eclipse.lsp4j.MarkupContent;
1313
import org.eclipse.lsp4j.TextDocumentPositionParams;
14-
import org.eclipse.lsp4j.jsonrpc.messages.Either;
1514
import org.eclipse.xtext.ide.server.Document;
1615
import org.eclipse.xtext.ide.server.hover.HoverService;
1716
import org.eclipse.xtext.resource.XtextResource;
1817
import org.eclipse.xtext.util.CancelIndicator;
19-
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
2018

2119
/**
2220
* @author Sven Efftinge - Initial contribution and API
2321
*/
2422
@ImplementedBy(HoverService.class)
2523
@SuppressWarnings("all")
2624
public interface IHoverService {
27-
static final Hover EMPTY_HOVER = new Hover(CollectionLiterals.<Either<String, MarkedString>>emptyList(), null);
25+
static final Hover EMPTY_HOVER = new Hover(new MarkupContent("markdown", ""), null);
2826

2927
/**
3028
* callback for 'textDocument/hover' requests.

0 commit comments

Comments
 (0)