1
1
/**
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.
3
3
* All rights reserved. This program and the accompanying materials
4
4
* are made available under the terms of the Eclipse Public License v1.0
5
5
* which accompanies this distribution, and is available at
6
6
* http://www.eclipse.org/legal/epl-v10.html
7
7
*/
8
8
package org .eclipse .xtext .ide .server .hover ;
9
9
10
+ import com .google .common .annotations .Beta ;
10
11
import com .google .inject .Inject ;
11
12
import com .google .inject .Singleton ;
12
- import java .util .Collections ;
13
- import java .util .List ;
14
13
import org .eclipse .emf .ecore .EObject ;
15
14
import org .eclipse .lsp4j .Hover ;
16
- import org .eclipse .lsp4j .MarkedString ;
15
+ import org .eclipse .lsp4j .MarkupContent ;
17
16
import org .eclipse .lsp4j .Range ;
18
17
import org .eclipse .lsp4j .TextDocumentPositionParams ;
19
- import org .eclipse .lsp4j .jsonrpc .messages .Either ;
20
18
import org .eclipse .xtext .documentation .IEObjectDocumentationProvider ;
21
19
import org .eclipse .xtext .ide .server .Document ;
22
20
import org .eclipse .xtext .ide .server .DocumentExtensions ;
30
28
import org .eclipse .xtext .resource .XtextResource ;
31
29
import org .eclipse .xtext .util .CancelIndicator ;
32
30
import org .eclipse .xtext .util .ITextRegion ;
33
- import org .eclipse .xtext .xbase .lib .CollectionLiterals ;
34
31
import org .eclipse .xtext .xbase .lib .Extension ;
35
- import org .eclipse .xtext .xbase .lib .Functions .Function1 ;
36
- import org .eclipse .xtext .xbase .lib .ListExtensions ;
37
32
38
33
/**
39
34
* @author kosyakov - Initial contribution and API
40
35
* @since 2.11
41
36
*/
42
37
@ Singleton
38
+ @ Beta
43
39
@ SuppressWarnings ("all" )
44
40
public class HoverService implements IHoverService {
45
41
@ Inject
@@ -98,7 +94,7 @@ protected Hover hover(final HoverContext context) {
98
94
if ((context == null )) {
99
95
return IHoverService .EMPTY_HOVER ;
100
96
}
101
- final List < Either < String , MarkedString >> contents = this .getContents (context );
97
+ final MarkupContent contents = this .getMarkupContent (context );
102
98
if ((contents == null )) {
103
99
return IHoverService .EMPTY_HOVER ;
104
100
}
@@ -118,34 +114,26 @@ protected Range getRange(final HoverContext it) {
118
114
return this ._documentExtensions .newRange (it .getResource (), it .getRegion ());
119
115
}
120
116
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 ()));
127
119
}
128
120
129
- protected String getLanguage (final HoverContext it ) {
130
- return null ;
121
+ protected String getKind (final HoverContext it ) {
122
+ return "markdown" ;
131
123
}
132
124
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 );
139
127
}
140
128
141
- public List < String > getContents (final EObject element ) {
129
+ public String getContents (final EObject element ) {
142
130
if ((element == null )) {
143
- return Collections .< String > emptyList () ;
131
+ return "" ;
144
132
}
145
133
final String documentation = this ._iEObjectDocumentationProvider .getDocumentation (element );
146
134
if ((documentation == null )) {
147
- return Collections .< String > emptyList () ;
135
+ return "" ;
148
136
}
149
- return Collections .< String > unmodifiableList ( CollectionLiterals .< String > newArrayList ( documentation )) ;
137
+ return documentation ;
150
138
}
151
139
}
0 commit comments