forked from qt-creator/qt-creator
LanguageClient: add signature help provider
Change-Id: Ia89c28b574c92802bbfda280115a50f5955f0854 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
committed by
Oliver Wolff
parent
3f32d79c99
commit
b0039f1ec8
@@ -40,6 +40,7 @@
|
||||
#include <texteditor/completionsettings.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QKeyEvent>
|
||||
@@ -431,22 +432,28 @@ void CodeAssistantPrivate::invalidateCurrentRequestData()
|
||||
|
||||
CompletionAssistProvider *CodeAssistantPrivate::identifyActivationSequence()
|
||||
{
|
||||
CompletionAssistProvider *completionProvider = m_editorWidget->textDocument()->completionAssistProvider();
|
||||
if (!completionProvider)
|
||||
return nullptr;
|
||||
auto checkActivationSequence = [this](CompletionAssistProvider *provider) {
|
||||
if (!provider)
|
||||
return false;
|
||||
const int length = provider->activationCharSequenceLength();
|
||||
if (!length)
|
||||
return false;
|
||||
QString sequence = m_editorWidget->textAt(m_editorWidget->position() - length, length);
|
||||
// In pretty much all cases the sequence will have the appropriate length. Only in the
|
||||
// case of typing the very first characters in the document for providers that request a
|
||||
// length greater than 1 (currently only C++, which specifies 3), the sequence needs to
|
||||
// be prepended so it has the expected length.
|
||||
const int lengthDiff = length - sequence.length();
|
||||
for (int j = 0; j < lengthDiff; ++j)
|
||||
sequence.prepend(m_null);
|
||||
return provider->isActivationCharSequence(sequence);
|
||||
};
|
||||
|
||||
const int length = completionProvider->activationCharSequenceLength();
|
||||
if (length == 0)
|
||||
return nullptr;
|
||||
QString sequence = m_editorWidget->textAt(m_editorWidget->position() - length, length);
|
||||
// In pretty much all cases the sequence will have the appropriate length. Only in the
|
||||
// case of typing the very first characters in the document for providers that request a
|
||||
// length greater than 1 (currently only C++, which specifies 3), the sequence needs to
|
||||
// be prepended so it has the expected length.
|
||||
const int lengthDiff = length - sequence.length();
|
||||
for (int j = 0; j < lengthDiff; ++j)
|
||||
sequence.prepend(m_null);
|
||||
return completionProvider->isActivationCharSequence(sequence) ? completionProvider : nullptr;
|
||||
auto provider = {
|
||||
m_editorWidget->textDocument()->completionAssistProvider(),
|
||||
m_editorWidget->textDocument()->functionHintAssistProvider()
|
||||
};
|
||||
return Utils::findOrDefault(provider, checkActivationSequence);
|
||||
}
|
||||
|
||||
void CodeAssistantPrivate::notifyChange()
|
||||
|
||||
Reference in New Issue
Block a user