diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index 6d92a7c05df..7c62a6bca27 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -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( + 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) { auto uri = DocumentUri::fromFilePath(document->filePath()); @@ -390,10 +418,7 @@ void Client::activateDocument(TextEditor::TextDocument *document) SemanticHighligtingSupport::applyHighlight(document, m_highlights.value(uri), capabilities()); // only replace the assist provider if the language server support it updateCompletionProvider(document); - if (m_serverCapabilities.signatureHelpProvider()) { - m_resetAssistProvider[document].functionHintProvider = document->functionHintAssistProvider(); - document->setFunctionHintAssistProvider(m_clientProviders.functionHintProvider); - } + updateFunctionHintProvider(document); if (m_serverCapabilities.codeActionProvider()) { m_resetAssistProvider[document].quickFixAssistProvider = document->quickFixAssistProvider(); document->setQuickFixAssistProvider(m_clientProviders.quickFixAssistProvider); @@ -551,11 +576,17 @@ void Client::documentContentsChanged(TextEditor::TextDocument *document, void Client::registerCapabilities(const QList ®istrations) { m_dynamicCapabilities.registerCapability(registrations); - if (Utils::anyOf(registrations, - Utils::equal(&Registration::method, QString(CompletionRequest::methodName)))) { + auto methodRegistered = [&](const QString &method) { + return Utils::anyOf(registrations, Utils::equal(&Registration::method, method)); + }; + if (methodRegistered(CompletionRequest::methodName)) { for (auto document : m_openedDocument.keys()) updateCompletionProvider(document); } + if (methodRegistered(SignatureHelpRequest::methodName)) { + for (auto document : m_openedDocument.keys()) + updateFunctionHintProvider(document); + } } void Client::unregisterCapabilities(const QList &unregistrations) @@ -1299,8 +1330,7 @@ void Client::initializeCallback(const InitializeRequest::Response &initResponse) functionHintAssistProvider->setTriggerCharacters( m_serverCapabilities.signatureHelpProvider() .value_or(ServerCapabilities::SignatureHelpOptions()) - .triggerCharacters() - .value_or(QList())); + .triggerCharacters()); } qCDebug(LOGLSPCLIENT) << "language server " << m_displayName << " initialized"; diff --git a/src/plugins/languageclient/client.h b/src/plugins/languageclient/client.h index ae5c7887242..29cf89a5365 100644 --- a/src/plugins/languageclient/client.h +++ b/src/plugins/languageclient/client.h @@ -206,6 +206,7 @@ private: void sendPostponedDocumentUpdates(); void updateCompletionProvider(TextEditor::TextDocument *document); + void updateFunctionHintProvider(TextEditor::TextDocument *document); using ContentHandler = std::function triggerChars) +void FunctionHintAssistProvider::setTriggerCharacters( + const Utils::optional> &triggerChars) { - m_triggerChars = triggerChars; - for (const QString &trigger : triggerChars) { + m_triggerChars = triggerChars.value_or(QList()); + for (const QString &trigger : qAsConst(m_triggerChars)) { if (trigger.length() > m_activationCharSequenceLength) m_activationCharSequenceLength = trigger.length(); } diff --git a/src/plugins/languageclient/languageclientfunctionhint.h b/src/plugins/languageclient/languageclientfunctionhint.h index d7547894f11..6d6181f4503 100644 --- a/src/plugins/languageclient/languageclientfunctionhint.h +++ b/src/plugins/languageclient/languageclientfunctionhint.h @@ -26,6 +26,7 @@ #pragma once #include +#include namespace LanguageClient { @@ -45,7 +46,7 @@ public: bool isActivationCharSequence(const QString &sequence) const override; bool isContinuationChar(const QChar &c) const override; - void setTriggerCharacters(QList triggerChars); + void setTriggerCharacters(const Utils::optional> &triggerChars); private: QList m_triggerChars; int m_activationCharSequenceLength = 0;