forked from qt-creator/qt-creator
LanguageClient: check capabilities before find usage
Change-Id: I421c2f93c90e6b0b8198fcff5707e8a47e8022f2 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -112,6 +112,30 @@ void SymbolSupport::findLinkAt(TextEditor::TextDocument *document,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SymbolSupport::supportsFindUsages(TextEditor::TextDocument *document) const
|
||||||
|
{
|
||||||
|
if (!m_client || !m_client->reachable())
|
||||||
|
return false;
|
||||||
|
if (m_client->dynamicCapabilities().isRegistered(FindReferencesRequest::methodName)) {
|
||||||
|
QJsonObject options
|
||||||
|
= m_client->dynamicCapabilities().option(FindReferencesRequest::methodName).toObject();
|
||||||
|
const TextDocumentRegistrationOptions docOps(options);
|
||||||
|
if (docOps.isValid()
|
||||||
|
&& !docOps.filterApplies(document->filePath(),
|
||||||
|
Utils::mimeTypeForName(document->mimeType()))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (auto referencesProvider = m_client->capabilities().referencesProvider()) {
|
||||||
|
if (std::holds_alternative<bool>(*referencesProvider)) {
|
||||||
|
if (!std::get<bool>(*referencesProvider))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
struct ItemData
|
struct ItemData
|
||||||
{
|
{
|
||||||
Core::Search::TextRange range;
|
Core::Search::TextRange range;
|
||||||
@@ -199,7 +223,7 @@ void SymbolSupport::handleFindReferencesResponse(const FindReferencesRequest::Re
|
|||||||
std::optional<MessageId> SymbolSupport::findUsages(
|
std::optional<MessageId> SymbolSupport::findUsages(
|
||||||
TextEditor::TextDocument *document, const QTextCursor &cursor, const ResultHandler &handler)
|
TextEditor::TextDocument *document, const QTextCursor &cursor, const ResultHandler &handler)
|
||||||
{
|
{
|
||||||
if (!m_client->reachable())
|
if (!supportsFindUsages(document))
|
||||||
return {};
|
return {};
|
||||||
ReferenceParams params(generateDocPosParams(document, cursor));
|
ReferenceParams params(generateDocPosParams(document, cursor));
|
||||||
params.setContext(ReferenceParams::ReferenceContext(true));
|
params.setContext(ReferenceParams::ReferenceContext(true));
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public:
|
|||||||
Utils::LinkHandler callback,
|
Utils::LinkHandler callback,
|
||||||
const bool resolveTarget);
|
const bool resolveTarget);
|
||||||
|
|
||||||
|
bool supportsFindUsages(TextEditor::TextDocument *document) const;
|
||||||
using ResultHandler = std::function<void(const QList<LanguageServerProtocol::Location> &)>;
|
using ResultHandler = std::function<void(const QList<LanguageServerProtocol::Location> &)>;
|
||||||
std::optional<LanguageServerProtocol::MessageId> findUsages(
|
std::optional<LanguageServerProtocol::MessageId> findUsages(
|
||||||
TextEditor::TextDocument *document,
|
TextEditor::TextDocument *document,
|
||||||
|
|||||||
Reference in New Issue
Block a user