| 1744 | } |
| 1745 | |
| 1746 | void LSPClientPlugin::onDocumentHoverResponse( UICodeEditor* editor, const LSPHover& resp, |
| 1747 | bool fromMousePos, |
| 1748 | std::optional<Vector2f> screenPos ) { |
| 1749 | const auto& displayTooltipFn = [this, fromMousePos]( UICodeEditor* editor, const LSPHover& resp, |
| 1750 | const Vector2f& position ) { |
| 1751 | if ( fromMousePos ) |
| 1752 | tryDisplayTooltip( editor, resp, position.asInt() ); |
| 1753 | else |
| 1754 | displayTooltip( editor, resp, position ); |
| 1755 | }; |
| 1756 | |
| 1757 | const auto& getFinalPosFn = [screenPos]( UICodeEditor* editor ) { |
| 1758 | return screenPos ? *screenPos |
| 1759 | : editor->getScreenPosition( editor->getDocument().getSelection().start() ) |
| 1760 | .getPosition(); |
| 1761 | }; |
| 1762 | |
| 1763 | auto& doc = editor->getDocument(); |
| 1764 | json j; |
| 1765 | TextPosition textPosition = |
| 1766 | fromMousePos ? currentMouseTextPosition( editor ) : doc.getSelection().start(); |
| 1767 | j["uri"] = doc.getURI().toString(); |
| 1768 | j["line"] = textPosition.line(); |
| 1769 | j["character"] = textPosition.column(); |
| 1770 | auto errResp = mManager->sendRequest( PluginMessageType::GetErrorOrWarning, |
| 1771 | PluginMessageFormat::JSON, &j ); |
| 1772 | if ( !resp.contents.empty() && !resp.contents[0].value.empty() ) { |
| 1773 | editor->runOnMainThread( [editor, resp, errResp, this, screenPos, displayTooltipFn, |
| 1774 | getFinalPosFn]() { |
| 1775 | mSymbolInfoShowing = true; |
| 1776 | auto pos = |
| 1777 | screenPos |
| 1778 | ? *screenPos |
| 1779 | : editor->getScreenPosition( editor->getDocument().getSelection().start() ) |
| 1780 | .getPosition(); |
| 1781 | if ( errResp.isResponse() ) { |
| 1782 | LSPHover cresp( resp ); |
| 1783 | cresp.contents[0].value = errResp.getResponse().data["text"].get<std::string>() + |
| 1784 | "\n---\n\n" + cresp.contents[0].value; |
| 1785 | displayTooltipFn( editor, cresp, getFinalPosFn( editor ) ); |
| 1786 | } else { |
| 1787 | displayTooltipFn( editor, resp, pos ); |
| 1788 | } |
| 1789 | } ); |
| 1790 | } else if ( errResp.isResponse() ) { |
| 1791 | LSPHover tresp; |
| 1792 | tresp.range = |
| 1793 | TextRange::fromString( errResp.getResponse().data["range"].get<std::string>() ); |
| 1794 | tresp.contents.push_back( |
| 1795 | { LSPMarkupKind::MarkDown, errResp.getResponse().data["text"].get<std::string>() } ); |
| 1796 | editor->runOnMainThread( [editor, tresp, this, displayTooltipFn, getFinalPosFn]() { |
| 1797 | mSymbolInfoShowing = true; |
| 1798 | displayTooltipFn( editor, tresp, getFinalPosFn( editor ) ); |
| 1799 | } ); |
| 1800 | } else { |
| 1801 | json data = getURIAndPositionJSON( editor ); |
| 1802 | mManager->sendRequest( PluginMessageType::SignatureHelp, PluginMessageFormat::JSON, &data ); |
| 1803 | } |
nothing calls this directly
no test coverage detected