1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/*******************************************************************************
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
define(['xtext/services/XtextService', 'jquery'], function(XtextService, jQuery) {
/**
* Service class for hover information.
*/
function HoverService(serviceUrl, resourceId, updateService) {
this.initialize(serviceUrl, 'hover', resourceId, updateService);
};
HoverService.prototype = new XtextService();
HoverService.prototype._initServerData = function(serverData, editorContext, params) {
// In order to display hover info for a selected completion proposal while the content
// assist popup is shown, the selected proposal is passed as parameter
if (params.proposal && params.proposal.proposal)
serverData.proposal = params.proposal.proposal;
if (params.offset)
serverData.caretOffset = params.offset;
else
serverData.caretOffset = editorContext.getCaretOffset();
var selection = params.selection ? params.selection : editorContext.getSelection();
if (selection.start != serverData.caretOffset || selection.end != serverData.caretOffset) {
serverData.selectionStart = selection.start;
serverData.selectionEnd = selection.end;
}
};
HoverService.prototype._getSuccessCallback = function(editorContext, params, deferred) {
var delay = params.mouseHoverDelay;
if (!delay)
delay = 500;
var showTime = new Date().getTime() + delay;
return function(result) {
if (result.conflict || !result.title && !result.content) {
deferred.reject();
} else {
var remainingTimeout = Math.max(0, showTime - new Date().getTime());
setTimeout(function() {
if (!params.sendFullText && result.stateId !== undefined
&& result.stateId != editorContext.getServerState().stateId)
deferred.reject();
else
deferred.resolve(result);
}, remainingTimeout);
}
};
};
return HoverService;
});
|