1
#include "script/ScriptDocumentOperation.h"
6
/// \see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover
9
variable::Value makeHoverContentsResponse(const std::u16string & kind, const std::u16string & value) {
10
return variable::Object {{
12
{ u"value", inout::encodeSpecialChars(value) },
16
variable::Value makeHoverResponse(const std::u16string & hover_text, const lsp::Range & range) {
17
return variable::Object {{
18
{ u"contents", makeHoverContentsResponse(u"plaintext", hover_text) },
19
{ u"range", lsp::DocumentContext::makeRange(range) },
24
std::u16string ScriptDocumentOperation::makeHoverText(const variable::Variable & var)
26
std::u16string text = getVariableString(var);
28
if (var.value().isObject() || var.value().isArray())
29
text += u" = " + variable::toString(var.value(), true, true, 1);
31
if (!var.spec().object()->variables().empty())
32
text += u"\n#" + variable::toString(var.spec().object());
37
variable::Value ScriptDocumentOperation::produceHoverResponse(const lsp::Position & pos) const
39
for (const variable::Variable & var : _semantic_data.declared())
40
if (isOnToken(var.location(), pos) and not var.value().isError())
41
return makeHoverResponse(makeHoverText(var), var.location().range());
43
for (const auto & [var, loc] : _semantic_data.used())
44
if (isOnToken(loc, pos)) {
45
std::u16string text = makeHoverText(var);
47
if (isRemoteFunctionLaunch(loc))
48
text += u"\nRemote launching!";
50
return makeHoverResponse(text, loc.range());
53
for (const auto & [token, ref] : _semantic_data.refs())
54
if (isOnToken(token.location(), pos))
55
return makeHoverResponse(ref, token.location().range());