| 1682 | } |
| 1683 | |
| 1684 | void LSPClientPlugin::displayTooltip( UICodeEditor* editor, const LSPHover& resp, |
| 1685 | const Vector2f& position ) { |
| 1686 | // HACK: Gets the old font style to restore it when the tooltip is hidden |
| 1687 | UITooltip* tooltip = editor->createTooltip(); |
| 1688 | if ( tooltip == nullptr ) |
| 1689 | return; |
| 1690 | mOldWordWrap = tooltip->isWordWrap(); |
| 1691 | mOldMaxWidth = tooltip->getMaxWidthEq(); |
| 1692 | tooltip->setWordWrap( true ); |
| 1693 | tooltip->setMaxWidthEq( "50vw" ); |
| 1694 | editor->setTooltipText( resp.contents[0].value ); |
| 1695 | mOldTextStyle = tooltip->getFontStyle(); |
| 1696 | mOldTextAlign = tooltip->getHorizontalAlign(); |
| 1697 | mOldDontAutoHideOnMouseMove = tooltip->dontAutoHideOnMouseMove(); |
| 1698 | mOldUsingCustomStyling = tooltip->getUsingCustomStyling(); |
| 1699 | mOldBackgroundColor = tooltip->getBackgroundColor(); |
| 1700 | if ( Color::Transparent == mOldBackgroundColor ) { |
| 1701 | tooltip->reloadStyle( true, true, true, true ); |
| 1702 | mOldBackgroundColor = tooltip->getBackgroundColor(); |
| 1703 | } |
| 1704 | tooltip->setHorizontalAlign( UI_HALIGN_LEFT ); |
| 1705 | tooltip->setPixelsPosition( tooltip->getTooltipPosition( position ) ); |
| 1706 | tooltip->setDontAutoHideOnMouseMove( true ); |
| 1707 | tooltip->setUsingCustomStyling( true ); |
| 1708 | tooltip->setFontStyle( Text::Regular ); |
| 1709 | tooltip->setData( String::hash( "lsp" ) ); |
| 1710 | tooltip->setBackgroundColor( editor->getColorScheme().getEditorColor( "background"_sst ) ); |
| 1711 | tooltip->getUIStyle()->setStyleSheetProperty( StyleSheetProperty( |
| 1712 | "background-color", |
| 1713 | editor->getColorScheme().getEditorColor( "background"_sst ).toHexString(), true, |
| 1714 | StyleSheetSelectorRule::SpecificityImportant ) ); |
| 1715 | |
| 1716 | if ( tooltip->getText().empty() ) |
| 1717 | return; |
| 1718 | |
| 1719 | const auto& syntaxDef = resp.contents[0].kind == LSPMarkupKind::MarkDown |
| 1720 | ? SyntaxDefinitionManager::instance()->getByLSPName( "markdown" ) |
| 1721 | : editor->getSyntaxDefinition(); |
| 1722 | |
| 1723 | SyntaxTokenizer::tokenizeText( syntaxDef, editor->getColorScheme(), tooltip->getTextCache(), 0, |
| 1724 | 0xFFFFFFFF, true, "\n\t " ); |
| 1725 | |
| 1726 | tooltip->notifyTextChangedFromTextCache(); |
| 1727 | |
| 1728 | if ( editor->hasFocus() && !tooltip->isVisible() && |
| 1729 | !tooltip->getTextCache()->getString().empty() ) |
| 1730 | tooltip->show(); |
| 1731 | } |
| 1732 | |
| 1733 | void LSPClientPlugin::tryDisplayTooltip( UICodeEditor* editor, const LSPHover& resp, |
| 1734 | const Vector2i& position ) { |
nothing calls this directly
no test coverage detected