From 5601ac29526500471a745beb03a42320a4fadd5a Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Tue, 23 Oct 2018 13:42:58 +0200 Subject: [PATCH] TextEditor: Fix requesting more proposals than needed Since commit d61d29cf16745f50a4e77a8ed268a72dfafa0d0d Introduce a basic client for the language server protocol extra proprosals were requested in the fragile case on a change notification, e.g. for function signature completion. Restrict this to the language client proposal, as it was actually intended. The language client does not support prefixes, so introduce this concept for deciding whether to request new proposals or not. Done-with: David Schulz Change-Id: Ibc1ad82dbeeea93b85f279c59b8c7289fe6ec726 Reviewed-by: David Schulz --- .../languageclient/languageclientcodeassist.cpp | 1 + src/plugins/texteditor/codeassist/codeassistant.cpp | 2 +- src/plugins/texteditor/codeassist/iassistproposal.cpp | 10 ++++++++++ src/plugins/texteditor/codeassist/iassistproposal.h | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/plugins/languageclient/languageclientcodeassist.cpp b/src/plugins/languageclient/languageclientcodeassist.cpp index 4a813889f9b..497d9596b06 100644 --- a/src/plugins/languageclient/languageclientcodeassist.cpp +++ b/src/plugins/languageclient/languageclientcodeassist.cpp @@ -372,6 +372,7 @@ void LanguageClientCompletionAssistProcessor::handleCompletionResponse( proposal->m_document = m_document; proposal->m_pos = m_pos; proposal->setFragile(true); + proposal->setSupportsPrefix(false); setAsyncProposalAvailable(proposal); qCDebug(LOGLSPCOMPLETION) << QTime::currentTime() << " : " << items.count() << " completions handled"; diff --git a/src/plugins/texteditor/codeassist/codeassistant.cpp b/src/plugins/texteditor/codeassist/codeassistant.cpp index 15c7f56cc82..9abbe3a8f19 100644 --- a/src/plugins/texteditor/codeassist/codeassistant.cpp +++ b/src/plugins/texteditor/codeassist/codeassistant.cpp @@ -440,7 +440,7 @@ void CodeAssistantPrivate::notifyChange() QTC_ASSERT(m_proposal, return); if (m_editorWidget->position() < m_proposal->basePosition()) { destroyContext(); - } else if (!m_proposal->isFragile()) { + } else if (m_proposal->supportsPrefix()) { m_proposalWidget->updateProposal( m_editorWidget->textAt(m_proposal->basePosition(), m_editorWidget->position() - m_proposal->basePosition())); diff --git a/src/plugins/texteditor/codeassist/iassistproposal.cpp b/src/plugins/texteditor/codeassist/iassistproposal.cpp index fcbe2e83862..bfce6360712 100644 --- a/src/plugins/texteditor/codeassist/iassistproposal.cpp +++ b/src/plugins/texteditor/codeassist/iassistproposal.cpp @@ -90,6 +90,11 @@ bool IAssistProposal::isFragile() const return m_isFragile; } +bool IAssistProposal::supportsPrefix() const +{ + return m_supportsPrefix; +} + /*! \fn bool TextEditor::IAssistProposal::isCorrective() const @@ -120,6 +125,11 @@ void IAssistProposal::setFragile(bool fragile) m_isFragile = fragile; } +void IAssistProposal::setSupportsPrefix(bool supportsPrefix) +{ + m_supportsPrefix = supportsPrefix; +} + /*! \fn IAssistModel *TextEditor::IAssistProposal::model() const diff --git a/src/plugins/texteditor/codeassist/iassistproposal.h b/src/plugins/texteditor/codeassist/iassistproposal.h index 0dbf24462fc..e7ac9131965 100644 --- a/src/plugins/texteditor/codeassist/iassistproposal.h +++ b/src/plugins/texteditor/codeassist/iassistproposal.h @@ -43,6 +43,7 @@ public: int basePosition() const; bool isFragile() const; + bool supportsPrefix() const; virtual bool hasItemsToPropose(const QString &, AssistReason) const { return true; } virtual bool isCorrective(TextEditorWidget *editorWidget) const; virtual void makeCorrection(TextEditorWidget *editorWidget); @@ -50,9 +51,11 @@ public: virtual IAssistProposalWidget *createWidget() const = 0; void setFragile(bool fragile); + void setSupportsPrefix(bool supportsPrefix); protected: int m_basePosition; bool m_isFragile = false; + bool m_supportsPrefix = true; }; } // TextEditor