Commit c7abc41d authored by David Schulz's avatar David Schulz
Browse files

TextEditor: Make text snippets available in all editors



... that do not define their own completion assist provider

Change-Id: I8edb65647a55178d4388b26c95cdeb301ff9f3fa
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent d68f2587
......@@ -31,6 +31,7 @@
#include <texteditor/codeassist/genericproposalmodel.h>
#include <texteditor/completionsettings.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditor.h>
#include <utils/algorithm.h>
......@@ -243,4 +244,22 @@ KeywordsCompletionAssistProcessor::generateProposalList(const QStringList &words
});
}
KeywordsCompletionAssistProvider::KeywordsCompletionAssistProvider(const Keywords &keyWords,
const QString &snippetGroup)
: m_keyWords(keyWords)
, m_snippetGroup(snippetGroup)
{ }
IAssistProvider::RunType KeywordsCompletionAssistProvider::runType() const
{
return Synchronous;
}
IAssistProcessor *KeywordsCompletionAssistProvider::createProcessor() const
{
auto processor = new KeywordsCompletionAssistProcessor(m_keyWords);
processor->setSnippetGroup(m_snippetGroup);
return processor;
}
} // namespace TextEditor
......@@ -28,8 +28,11 @@
#include "iassistprocessor.h"
#include "assistproposalitem.h"
#include "ifunctionhintproposalmodel.h"
#include "completionassistprovider.h"
#include "../snippets/snippetassistcollector.h"
#include "texteditor/texteditorconstants.h"
namespace TextEditor {
class AssistInterface;
......@@ -38,8 +41,8 @@ class TEXTEDITOR_EXPORT Keywords
{
public:
Keywords() = default;
Keywords(const QStringList &variables, const QStringList &functions,
const QMap<QString, QStringList> &functionArgs);
Keywords(const QStringList &variables, const QStringList &functions = QStringList(),
const QMap<QString, QStringList> &functionArgs = QMap<QString, QStringList>());
bool isVariable(const QString &word) const;
bool isFunction(const QString &word) const;
......@@ -79,6 +82,21 @@ private:
QStringList m_functionSymbols;
};
class TEXTEDITOR_EXPORT KeywordsCompletionAssistProvider : public CompletionAssistProvider
{
public:
KeywordsCompletionAssistProvider(const Keywords &keyWords = Keywords(),
const QString &snippetGroup = Constants::TEXT_SNIPPET_GROUP_ID);
// IAssistProvider interface
RunType runType() const override;
IAssistProcessor *createProcessor() const override;
private:
Keywords m_keyWords;
QString m_snippetGroup;
};
class TEXTEDITOR_EXPORT KeywordsCompletionAssistProcessor : public IAssistProcessor
{
public:
......
......@@ -57,6 +57,7 @@
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/codeassistant.h>
#include <texteditor/codeassist/completionassistprovider.h>
#include <texteditor/codeassist/keywordscompletionassist.h>
#include <texteditor/generichighlighter/context.h>
#include <texteditor/generichighlighter/highlightdefinition.h>
#include <texteditor/generichighlighter/highlighter.h>
......@@ -8263,6 +8264,7 @@ void TextEditorFactory::setParenthesesMatchingEnabled(bool on)
IEditor *TextEditorFactory::createEditor()
{
static KeywordsCompletionAssistProvider basicSnippetProvider;
TextDocumentPtr doc(d->m_documentCreator());
if (d->m_indenterCreator)
......@@ -8271,7 +8273,8 @@ IEditor *TextEditorFactory::createEditor()
if (d->m_syntaxHighlighterCreator)
doc->setSyntaxHighlighter(d->m_syntaxHighlighterCreator());
doc->setCompletionAssistProvider(d->m_completionAssistProvider);
doc->setCompletionAssistProvider(d->m_completionAssistProvider ? d->m_completionAssistProvider
: &basicSnippetProvider);
return d->createEditorHelper(doc);
}
......
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