2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2019 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2019-05-15 11:19:31 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-06-04 12:40:26 +02:00
|
|
|
#include "languageclient_global.h"
|
|
|
|
|
|
2019-05-15 11:19:31 +02:00
|
|
|
#include <languageserverprotocol/languagefeatures.h>
|
|
|
|
|
#include <texteditor/basehoverhandler.h>
|
|
|
|
|
|
2021-06-04 12:40:26 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
2019-05-15 11:19:31 +02:00
|
|
|
namespace LanguageClient {
|
|
|
|
|
|
|
|
|
|
class Client;
|
|
|
|
|
|
2021-06-04 12:40:26 +02:00
|
|
|
using HelpItemProvider = std::function<void(const LanguageServerProtocol::HoverRequest::Response &,
|
|
|
|
|
const LanguageServerProtocol::DocumentUri &uri)>;
|
|
|
|
|
|
|
|
|
|
class LANGUAGECLIENT_EXPORT HoverHandler final : public TextEditor::BaseHoverHandler
|
2019-05-15 11:19:31 +02:00
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(HoverHandler)
|
|
|
|
|
public:
|
|
|
|
|
explicit HoverHandler(Client *client);
|
|
|
|
|
~HoverHandler() override;
|
|
|
|
|
|
|
|
|
|
void abort() override;
|
|
|
|
|
|
2022-05-16 14:36:06 +02:00
|
|
|
/// If prefer diagnostics is enabled the hover handler checks whether a diagnostics is at the
|
|
|
|
|
/// pos passed to identifyMatch _before_ sending hover request to the server. If a diagnostic
|
|
|
|
|
/// can be found it will be used as a tooltip and no hover request is sent to the server.
|
|
|
|
|
/// If prefer diagnostics is disabled the diagnostics are only checked if the response is empty.
|
|
|
|
|
/// Defaults to prefer diagnostics.
|
|
|
|
|
void setPreferDiagnosticts(bool prefer);
|
|
|
|
|
|
2021-06-04 12:40:26 +02:00
|
|
|
void setHelpItemProvider(const HelpItemProvider &provider) { m_helpItemProvider = provider; }
|
|
|
|
|
void setHelpItem(const LanguageServerProtocol::MessageId &msgId, const Core::HelpItem &help);
|
|
|
|
|
|
2019-05-15 11:19:31 +02:00
|
|
|
protected:
|
|
|
|
|
void identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
|
|
|
|
int pos,
|
|
|
|
|
ReportPriority report) override;
|
|
|
|
|
|
|
|
|
|
private:
|
2022-05-16 14:36:06 +02:00
|
|
|
void handleResponse(const LanguageServerProtocol::HoverRequest::Response &response,
|
|
|
|
|
const QTextCursor &cursor);
|
2019-05-15 11:19:31 +02:00
|
|
|
void setContent(const LanguageServerProtocol::HoverContent &content);
|
2022-05-16 14:36:06 +02:00
|
|
|
bool reportDiagnostics(const QTextCursor &cursor);
|
2019-05-15 11:19:31 +02:00
|
|
|
|
|
|
|
|
QPointer<Client> m_client;
|
2022-08-26 10:30:00 +02:00
|
|
|
std::optional<LanguageServerProtocol::MessageId> m_currentRequest;
|
2021-06-04 12:40:26 +02:00
|
|
|
LanguageServerProtocol::DocumentUri m_uri;
|
|
|
|
|
LanguageServerProtocol::HoverRequest::Response m_response;
|
2019-05-15 11:19:31 +02:00
|
|
|
TextEditor::BaseHoverHandler::ReportPriority m_report;
|
2021-06-04 12:40:26 +02:00
|
|
|
HelpItemProvider m_helpItemProvider;
|
2022-05-16 14:36:06 +02:00
|
|
|
bool m_preferDiagnostics = true;
|
2019-05-15 11:19:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace LanguageClient
|