diff --git a/src/messages/text_document_hover.cc b/src/messages/text_document_hover.cc index 6cfbe3a4..0c05605c 100644 --- a/src/messages/text_document_hover.cc +++ b/src/messages/text_document_hover.cc @@ -48,7 +48,7 @@ struct Out_TextDocumentHover : public lsOutMessage { }; lsRequestId id; - Result result; + optional result; }; MAKE_REFLECT_STRUCT(Out_TextDocumentHover::Result, contents, range); MAKE_REFLECT_STRUCT(Out_TextDocumentHover, jsonrpc, id, result); @@ -75,11 +75,14 @@ struct TextDocumentHoverHandler : BaseMessageHandler { if (!ls_range) continue; - out.result.contents.value = GetHoverForSymbol(db, ref.idx); - out.result.contents.language = file->def->language; - - out.result.range = *ls_range; - break; + std::string hover = GetHoverForSymbol(db, ref.idx); + if (!hover.empty()) { + out.result = Out_TextDocumentHover::Result(); + out.result->contents.value = hover; + out.result->contents.language = file->def->language; + out.result->range = *ls_range; + break; + } } IpcManager::WriteStdout(IpcId::TextDocumentHover, out);