forked from qt-creator/qt-creator
LanguageClient: Fix dynamic registered signature help
Change-Id: Ie7427f4a0aede5c933995610d03791e837ad39e4 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -383,6 +383,34 @@ void Client::updateCompletionProvider(TextEditor::TextDocument *document)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::updateFunctionHintProvider(TextEditor::TextDocument *document)
|
||||||
|
{
|
||||||
|
bool useLanguageServer = m_serverCapabilities.signatureHelpProvider().has_value();
|
||||||
|
auto clientFunctionHintProvider = static_cast<FunctionHintAssistProvider *>(
|
||||||
|
m_clientProviders.functionHintProvider.data());
|
||||||
|
if (m_dynamicCapabilities.isRegistered(SignatureHelpRequest::methodName).value_or(false)) {
|
||||||
|
const QJsonValue &options = m_dynamicCapabilities.option(SignatureHelpRequest::methodName);
|
||||||
|
const TextDocumentRegistrationOptions docOptions(options);
|
||||||
|
useLanguageServer = docOptions.filterApplies(document->filePath(),
|
||||||
|
Utils::mimeTypeForName(document->mimeType()));
|
||||||
|
|
||||||
|
const ServerCapabilities::SignatureHelpOptions signatureOptions(options);
|
||||||
|
if (signatureOptions.isValid(nullptr))
|
||||||
|
clientFunctionHintProvider->setTriggerCharacters(signatureOptions.triggerCharacters());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document->functionHintAssistProvider() != clientFunctionHintProvider) {
|
||||||
|
if (useLanguageServer) {
|
||||||
|
m_resetAssistProvider[document].functionHintProvider
|
||||||
|
= document->functionHintAssistProvider();
|
||||||
|
document->setFunctionHintAssistProvider(clientFunctionHintProvider);
|
||||||
|
}
|
||||||
|
} else if (!useLanguageServer) {
|
||||||
|
document->setFunctionHintAssistProvider(
|
||||||
|
m_resetAssistProvider[document].functionHintProvider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Client::activateDocument(TextEditor::TextDocument *document)
|
void Client::activateDocument(TextEditor::TextDocument *document)
|
||||||
{
|
{
|
||||||
auto uri = DocumentUri::fromFilePath(document->filePath());
|
auto uri = DocumentUri::fromFilePath(document->filePath());
|
||||||
@@ -390,10 +418,7 @@ void Client::activateDocument(TextEditor::TextDocument *document)
|
|||||||
SemanticHighligtingSupport::applyHighlight(document, m_highlights.value(uri), capabilities());
|
SemanticHighligtingSupport::applyHighlight(document, m_highlights.value(uri), capabilities());
|
||||||
// only replace the assist provider if the language server support it
|
// only replace the assist provider if the language server support it
|
||||||
updateCompletionProvider(document);
|
updateCompletionProvider(document);
|
||||||
if (m_serverCapabilities.signatureHelpProvider()) {
|
updateFunctionHintProvider(document);
|
||||||
m_resetAssistProvider[document].functionHintProvider = document->functionHintAssistProvider();
|
|
||||||
document->setFunctionHintAssistProvider(m_clientProviders.functionHintProvider);
|
|
||||||
}
|
|
||||||
if (m_serverCapabilities.codeActionProvider()) {
|
if (m_serverCapabilities.codeActionProvider()) {
|
||||||
m_resetAssistProvider[document].quickFixAssistProvider = document->quickFixAssistProvider();
|
m_resetAssistProvider[document].quickFixAssistProvider = document->quickFixAssistProvider();
|
||||||
document->setQuickFixAssistProvider(m_clientProviders.quickFixAssistProvider);
|
document->setQuickFixAssistProvider(m_clientProviders.quickFixAssistProvider);
|
||||||
@@ -551,11 +576,17 @@ void Client::documentContentsChanged(TextEditor::TextDocument *document,
|
|||||||
void Client::registerCapabilities(const QList<Registration> ®istrations)
|
void Client::registerCapabilities(const QList<Registration> ®istrations)
|
||||||
{
|
{
|
||||||
m_dynamicCapabilities.registerCapability(registrations);
|
m_dynamicCapabilities.registerCapability(registrations);
|
||||||
if (Utils::anyOf(registrations,
|
auto methodRegistered = [&](const QString &method) {
|
||||||
Utils::equal(&Registration::method, QString(CompletionRequest::methodName)))) {
|
return Utils::anyOf(registrations, Utils::equal(&Registration::method, method));
|
||||||
|
};
|
||||||
|
if (methodRegistered(CompletionRequest::methodName)) {
|
||||||
for (auto document : m_openedDocument.keys())
|
for (auto document : m_openedDocument.keys())
|
||||||
updateCompletionProvider(document);
|
updateCompletionProvider(document);
|
||||||
}
|
}
|
||||||
|
if (methodRegistered(SignatureHelpRequest::methodName)) {
|
||||||
|
for (auto document : m_openedDocument.keys())
|
||||||
|
updateFunctionHintProvider(document);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::unregisterCapabilities(const QList<Unregistration> &unregistrations)
|
void Client::unregisterCapabilities(const QList<Unregistration> &unregistrations)
|
||||||
@@ -1299,8 +1330,7 @@ void Client::initializeCallback(const InitializeRequest::Response &initResponse)
|
|||||||
functionHintAssistProvider->setTriggerCharacters(
|
functionHintAssistProvider->setTriggerCharacters(
|
||||||
m_serverCapabilities.signatureHelpProvider()
|
m_serverCapabilities.signatureHelpProvider()
|
||||||
.value_or(ServerCapabilities::SignatureHelpOptions())
|
.value_or(ServerCapabilities::SignatureHelpOptions())
|
||||||
.triggerCharacters()
|
.triggerCharacters());
|
||||||
.value_or(QList<QString>()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(LOGLSPCLIENT) << "language server " << m_displayName << " initialized";
|
qCDebug(LOGLSPCLIENT) << "language server " << m_displayName << " initialized";
|
||||||
|
@@ -206,6 +206,7 @@ private:
|
|||||||
void sendPostponedDocumentUpdates();
|
void sendPostponedDocumentUpdates();
|
||||||
|
|
||||||
void updateCompletionProvider(TextEditor::TextDocument *document);
|
void updateCompletionProvider(TextEditor::TextDocument *document);
|
||||||
|
void updateFunctionHintProvider(TextEditor::TextDocument *document);
|
||||||
|
|
||||||
using ContentHandler = std::function<void(const QByteArray &, QTextCodec *, QString &,
|
using ContentHandler = std::function<void(const QByteArray &, QTextCodec *, QString &,
|
||||||
LanguageServerProtocol::ResponseHandlers,
|
LanguageServerProtocol::ResponseHandlers,
|
||||||
|
@@ -149,10 +149,11 @@ bool FunctionHintAssistProvider::isContinuationChar(const QChar &/*c*/) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionHintAssistProvider::setTriggerCharacters(QList<QString> triggerChars)
|
void FunctionHintAssistProvider::setTriggerCharacters(
|
||||||
|
const Utils::optional<QList<QString>> &triggerChars)
|
||||||
{
|
{
|
||||||
m_triggerChars = triggerChars;
|
m_triggerChars = triggerChars.value_or(QList<QString>());
|
||||||
for (const QString &trigger : triggerChars) {
|
for (const QString &trigger : qAsConst(m_triggerChars)) {
|
||||||
if (trigger.length() > m_activationCharSequenceLength)
|
if (trigger.length() > m_activationCharSequenceLength)
|
||||||
m_activationCharSequenceLength = trigger.length();
|
m_activationCharSequenceLength = trigger.length();
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <texteditor/codeassist/completionassistprovider.h>
|
#include <texteditor/codeassist/completionassistprovider.h>
|
||||||
|
#include <utils/optional.h>
|
||||||
|
|
||||||
namespace LanguageClient {
|
namespace LanguageClient {
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ public:
|
|||||||
bool isActivationCharSequence(const QString &sequence) const override;
|
bool isActivationCharSequence(const QString &sequence) const override;
|
||||||
bool isContinuationChar(const QChar &c) const override;
|
bool isContinuationChar(const QChar &c) const override;
|
||||||
|
|
||||||
void setTriggerCharacters(QList<QString> triggerChars);
|
void setTriggerCharacters(const Utils::optional<QList<QString>> &triggerChars);
|
||||||
private:
|
private:
|
||||||
QList<QString> m_triggerChars;
|
QList<QString> m_triggerChars;
|
||||||
int m_activationCharSequenceLength = 0;
|
int m_activationCharSequenceLength = 0;
|
||||||
|
Reference in New Issue
Block a user