forked from qt-creator/qt-creator
TextEditor: Make text snippets available in all editors
... that do not define their own completion assist provider Change-Id: I8edb65647a55178d4388b26c95cdeb301ff9f3fa Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||||
#include <texteditor/completionsettings.h>
|
#include <texteditor/completionsettings.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
|
|
||||||
#include <utils/algorithm.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
|
} // namespace TextEditor
|
||||||
|
@@ -28,8 +28,11 @@
|
|||||||
#include "iassistprocessor.h"
|
#include "iassistprocessor.h"
|
||||||
#include "assistproposalitem.h"
|
#include "assistproposalitem.h"
|
||||||
#include "ifunctionhintproposalmodel.h"
|
#include "ifunctionhintproposalmodel.h"
|
||||||
|
#include "completionassistprovider.h"
|
||||||
#include "../snippets/snippetassistcollector.h"
|
#include "../snippets/snippetassistcollector.h"
|
||||||
|
|
||||||
|
#include "texteditor/texteditorconstants.h"
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class AssistInterface;
|
class AssistInterface;
|
||||||
@@ -38,8 +41,8 @@ class TEXTEDITOR_EXPORT Keywords
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Keywords() = default;
|
Keywords() = default;
|
||||||
Keywords(const QStringList &variables, const QStringList &functions,
|
Keywords(const QStringList &variables, const QStringList &functions = QStringList(),
|
||||||
const QMap<QString, QStringList> &functionArgs);
|
const QMap<QString, QStringList> &functionArgs = QMap<QString, QStringList>());
|
||||||
bool isVariable(const QString &word) const;
|
bool isVariable(const QString &word) const;
|
||||||
bool isFunction(const QString &word) const;
|
bool isFunction(const QString &word) const;
|
||||||
|
|
||||||
@@ -79,6 +82,21 @@ private:
|
|||||||
QStringList m_functionSymbols;
|
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
|
class TEXTEDITOR_EXPORT KeywordsCompletionAssistProcessor : public IAssistProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -57,6 +57,7 @@
|
|||||||
#include <texteditor/codeassist/assistinterface.h>
|
#include <texteditor/codeassist/assistinterface.h>
|
||||||
#include <texteditor/codeassist/codeassistant.h>
|
#include <texteditor/codeassist/codeassistant.h>
|
||||||
#include <texteditor/codeassist/completionassistprovider.h>
|
#include <texteditor/codeassist/completionassistprovider.h>
|
||||||
|
#include <texteditor/codeassist/keywordscompletionassist.h>
|
||||||
#include <texteditor/generichighlighter/context.h>
|
#include <texteditor/generichighlighter/context.h>
|
||||||
#include <texteditor/generichighlighter/highlightdefinition.h>
|
#include <texteditor/generichighlighter/highlightdefinition.h>
|
||||||
#include <texteditor/generichighlighter/highlighter.h>
|
#include <texteditor/generichighlighter/highlighter.h>
|
||||||
@@ -8263,6 +8264,7 @@ void TextEditorFactory::setParenthesesMatchingEnabled(bool on)
|
|||||||
|
|
||||||
IEditor *TextEditorFactory::createEditor()
|
IEditor *TextEditorFactory::createEditor()
|
||||||
{
|
{
|
||||||
|
static KeywordsCompletionAssistProvider basicSnippetProvider;
|
||||||
TextDocumentPtr doc(d->m_documentCreator());
|
TextDocumentPtr doc(d->m_documentCreator());
|
||||||
|
|
||||||
if (d->m_indenterCreator)
|
if (d->m_indenterCreator)
|
||||||
@@ -8271,7 +8273,8 @@ IEditor *TextEditorFactory::createEditor()
|
|||||||
if (d->m_syntaxHighlighterCreator)
|
if (d->m_syntaxHighlighterCreator)
|
||||||
doc->setSyntaxHighlighter(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);
|
return d->createEditorHelper(doc);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user