Commit e4d4d977 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Mark Nauwelaerts
Browse files

LSP: Add support for textDocument/implementation

parent 33545f31
......@@ -208,6 +208,7 @@ class LSPClientActionView : public QObject
QPointer<QAction> m_findDef;
QPointer<QAction> m_findDecl;
QPointer<QAction> m_findRef;
QPointer<QAction> m_findImpl;
QPointer<QAction> m_triggerHighlight;
QPointer<QAction> m_triggerSymbolInfo;
QPointer<QAction> m_triggerFormat;
......@@ -328,6 +329,8 @@ public:
m_findDecl->setText(i18n("Go to Declaration"));
m_findRef = actionCollection()->addAction(QStringLiteral("lspclient_find_references"), this, &self_type::findReferences);
m_findRef->setText(i18n("Find References"));
m_findImpl = actionCollection()->addAction(QStringLiteral("lspclient_find_implementations"), this, &self_type::findImplementation);
m_findImpl->setText(i18n("Find Implementations"));
m_triggerHighlight = actionCollection()->addAction(QStringLiteral("lspclient_highlight"), this, &self_type::highlight);
m_triggerHighlight->setText(i18n("Highlight"));
m_triggerSymbolInfo = actionCollection()->addAction(QStringLiteral("lspclient_symbol_info"), this, &self_type::symbolInfo);
......@@ -395,6 +398,7 @@ public:
menu->addAction(m_findDef);
menu->addAction(m_findDecl);
menu->addAction(m_findRef);
menu->addAction(m_findImpl);
menu->addAction(m_triggerHighlight);
menu->addAction(m_triggerSymbolInfo);
menu->addAction(m_triggerFormat);
......@@ -1231,6 +1235,17 @@ public:
processLocations<LSPLocation>(title, req, true, &self_type::locationToRangeItem);
}
void findImplementation()
{
auto title = i18nc("@title:tab", "Implementation: %1", currentWord());
// clang-format off
auto req = [](LSPClientServer &server, const QUrl &document, const LSPPosition &pos, const QObject *context, const DocumentDefinitionReplyHandler &h)
{ return server.documentImplementation(document, pos, context, h); };
// clang-format on
processLocations<LSPLocation>(title, req, true, &self_type::locationToRangeItem);
}
void highlight()
{
// determine current url to capture and use later on
......@@ -1861,7 +1876,7 @@ public:
KTextEditor::View *activeView = m_mainWindow->activeView();
auto doc = activeView ? activeView->document() : nullptr;
auto server = m_serverManager->findServer(activeView);
bool defEnabled = false, declEnabled = false, refEnabled = false;
bool defEnabled = false, declEnabled = false, refEnabled = false, implEnabled = false;
bool hoverEnabled = false, highlightEnabled = false;
bool formatEnabled = false;
bool renameEnabled = false;
......@@ -1872,6 +1887,7 @@ public:
// FIXME no real official protocol way to detect, so enable anyway
declEnabled = caps.declarationProvider || true;
refEnabled = caps.referencesProvider;
implEnabled = caps.implementationProvider;
hoverEnabled = caps.hoverProvider;
highlightEnabled = caps.documentHighlightProvider;
formatEnabled = caps.documentFormattingProvider || caps.documentRangeFormattingProvider;
......@@ -1903,6 +1919,8 @@ public:
m_findDecl->setEnabled(declEnabled);
if (m_findRef)
m_findRef->setEnabled(refEnabled);
if (m_findImpl)
m_findImpl->setEnabled(implEnabled);
if (m_triggerHighlight)
m_triggerHighlight->setEnabled(highlightEnabled);
if (m_triggerSymbolInfo)
......
......@@ -78,6 +78,7 @@ struct LSPServerCapabilities {
// FIXME ? clangd unofficial extension
bool declarationProvider = false;
bool referencesProvider = false;
bool implementationProvider = false;
bool documentSymbolProvider = false;
bool documentHighlightProvider = false;
bool documentFormattingProvider = false;
......
......@@ -290,6 +290,7 @@ static void from_json(LSPServerCapabilities &caps, const QJsonObject &json)
caps.definitionProvider = json.value(QStringLiteral("definitionProvider")).toBool();
caps.declarationProvider = json.value(QStringLiteral("declarationProvider")).toBool();
caps.referencesProvider = json.value(QStringLiteral("referencesProvider")).toBool();
caps.implementationProvider = json.value(QStringLiteral("implementationProvider")).toBool();
caps.documentSymbolProvider = json.value(QStringLiteral("documentSymbolProvider")).toBool();
caps.documentHighlightProvider = json.value(QStringLiteral("documentHighlightProvider")).toBool();
caps.documentFormattingProvider = json.value(QStringLiteral("documentFormattingProvider")).toBool();
......@@ -1119,6 +1120,12 @@ public:
return send(init_request(QStringLiteral("textDocument/declaration"), params), h);
}
RequestHandle documentImplementation(const QUrl &document, const LSPPosition &pos, const GenericReplyHandler &h)
{
auto params = textDocumentPositionParams(document, pos);
return send(init_request(QStringLiteral("textDocument/implementation"), params), h);
}
RequestHandle documentHover(const QUrl &document, const LSPPosition &pos, const GenericReplyHandler &h)
{
auto params = textDocumentPositionParams(document, pos);
......@@ -1356,6 +1363,11 @@ LSPClientServer::RequestHandle LSPClientServer::documentDefinition(const QUrl &d
return d->documentDefinition(document, pos, make_handler(h, context, parseDocumentLocation));
}
LSPClientServer::RequestHandle LSPClientServer::documentImplementation(const QUrl &document, const LSPPosition &pos, const QObject *context, const DocumentDefinitionReplyHandler &h)
{
return d->documentImplementation(document, pos, make_handler(h, context, parseDocumentLocation));
}
LSPClientServer::RequestHandle LSPClientServer::documentDeclaration(const QUrl &document, const LSPPosition &pos, const QObject *context, const DocumentDefinitionReplyHandler &h)
{
return d->documentDeclaration(document, pos, make_handler(h, context, parseDocumentLocation));
......
......@@ -106,6 +106,7 @@ public:
RequestHandle documentSymbols(const QUrl &document, const QObject *context, const DocumentSymbolsReplyHandler &h, const ErrorReplyHandler &eh = nullptr);
RequestHandle documentDefinition(const QUrl &document, const LSPPosition &pos, const QObject *context, const DocumentDefinitionReplyHandler &h);
RequestHandle documentDeclaration(const QUrl &document, const LSPPosition &pos, const QObject *context, const DocumentDefinitionReplyHandler &h);
RequestHandle documentImplementation(const QUrl &document, const LSPPosition &pos, const QObject *context, const DocumentDefinitionReplyHandler &h);
RequestHandle documentHighlight(const QUrl &document, const LSPPosition &pos, const QObject *context, const DocumentHighlightReplyHandler &h);
RequestHandle documentHover(const QUrl &document, const LSPPosition &pos, const QObject *context, const DocumentHoverReplyHandler &h);
RequestHandle documentReferences(const QUrl &document, const LSPPosition &pos, bool decl, const QObject *context, const DocumentDefinitionReplyHandler &h);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment