<commit_before>#include "dlanghoverhandler.h"

#include "dlangeditorconstants.h"
#include "dcdsupport.h"
#include "dlangassistprocessor.h"
#include "dlangeditor.h"

#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/idocument.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h>

using namespace DlangEditor;

DlangHoverHandler::DlangHoverHandler(QObject *parent) :
    TextEditor::BaseHoverHandler(parent)
{
}


bool DlangEditor::DlangHoverHandler::acceptEditor(Core::IEditor *editor)
{
    return editor->document()->id() == Constants::DLANG_EDITOR_ID;
}

void DlangHoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
{
    if (!editor) {
        return;
    }
    const TextEditor::ITextEditorDocument* doc = qobject_cast<TextEditor::ITextEditorDocument*>(editor->document());
    if (!doc) {
        return;
    }
    if (pos != lastPos) {
        lastPos = pos;
        int begin, size;
        if (!getFullIdentifier(doc, pos, begin, size)) {
            return;
        }
        QString ident = doc->textAt(begin, size);
        if (ident != lastSymbol) {
            ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject();
            QString projectName = currentProject ? currentProject->displayName() : QString();
            try {
                Dcd::DcdClient *client = DcdFactory::instance()->client(projectName);
                if (!client) {
                    return;
                }
                QStringList res;
                client->getDocumentationComments(doc->plainText(), pos, res);
                if (!res.empty()) {
                    lastTooltip = res.front();
                } else {
                    lastTooltip.clear();
                }
            }
            catch (...) {
                lastTooltip.clear();
            }
            lastSymbol = ident;
        }

    }
    setToolTip(lastTooltip);
}

void DlangHoverHandler::decorateToolTip()
{

}<commit_msg>Decorate tooltip +Simple documentation tooltip decoration<commit_after>#include "dlanghoverhandler.h"

#include "dlangeditorconstants.h"
#include "dcdsupport.h"
#include "dlangassistprocessor.h"
#include "dlangeditor.h"

#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/idocument.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h>

using namespace DlangEditor;

DlangHoverHandler::DlangHoverHandler(QObject *parent) :
    TextEditor::BaseHoverHandler(parent)
{
}


bool DlangEditor::DlangHoverHandler::acceptEditor(Core::IEditor *editor)
{
    return editor->document()->id() == Constants::DLANG_EDITOR_ID;
}

void DlangHoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
{
    if (!editor) {
        return;
    }
    const TextEditor::ITextEditorDocument* doc = qobject_cast<TextEditor::ITextEditorDocument*>(editor->document());
    if (!doc) {
        return;
    }
    if (pos != lastPos) {
        lastPos = pos;
        int begin, size;
        if (!getFullIdentifier(doc, pos, begin, size)) {
            return;
        }
        QString ident = doc->textAt(begin, size);
        if (ident != lastSymbol) {
            ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject();
            QString projectName = currentProject ? currentProject->displayName() : QString();
            try {
                Dcd::DcdClient *client = DcdFactory::instance()->client(projectName);
                if (!client) {
                    return;
                }
                QStringList res;
                client->getDocumentationComments(doc->plainText(), pos, res);
                if (!res.empty()) {
                    lastTooltip = res.front();
                } else {
                    lastTooltip.clear();
                }
            }
            catch (...) {
                lastTooltip.clear();
            }
            lastSymbol = ident;
        }

    }
    setToolTip(lastTooltip);
}

static const QString DLANG_DOC_META = QLatin1String("$(D");

void DlangHoverHandler::decorateToolTip()
{
    QString tip = toolTip();
    if (tip.length() > 1000) {
        tip.resize(1000);
        tip.append("...");
    }
    int pos = 0;
    while ((pos = tip.indexOf(DLANG_DOC_META, pos)) != -1) {
        int balance = 1;
        for (int end = pos + DLANG_DOC_META.length();  end < tip.length(); ++end) {
            if (tip.at(end) == QLatin1Char('(')) {
                ++balance;
            } else if (tip.at(end) == QLatin1Char(')')) {
                --balance;
                if (balance == 0) {
                    tip.replace(end, 1, QLatin1String("</b>"));
                    tip.replace(pos, DLANG_DOC_META.length(), QLatin1String("<b>"));
                    break;
                }
            }
        }
        if (balance > 0) {
            tip.replace(pos, DLANG_DOC_META.length(), QLatin1String("<b>"));
            tip.append(QLatin1String("</b>"));
        }
        ++pos;
    }
    tip.replace(QLatin1String("\\n"), QLatin1String("\n"));
    setToolTip(tip);
}
{'fraction_non_alphanumeric': 0.1335978835978836, 'fraction_numerical': 0.004346182917611489, 'mean_word_length': 2.301933873986276, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1738885', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1548, 'n_words': 273}