QMakePM: Use generalized KeywordsCompletionProvider

Change-Id: Iaa6476be9285d814e4357b861c8fd00f1c9adc1c
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
David Schulz
2017-07-26 11:12:32 +02:00
parent c7abc41d97
commit 2c5186253f
5 changed files with 283 additions and 351 deletions

View File

@@ -24,19 +24,13 @@
****************************************************************************/
#include "profilecompletionassist.h"
#include "qmakeprojectmanagerconstants.h"
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/keywordscompletionassist.h>
#include <texteditor/texteditorconstants.h>
#include "texteditor/codeassist/keywordscompletionassist.h"
#include <coreplugin/id.h>
using namespace QmakeProjectManager::Internal;
using namespace TextEditor;
static const char *const variableKeywords[] = {
const TextEditor::Keywords &QmakeProjectManager::Internal::qmakeKeywords()
{
static TextEditor::Keywords keywords(
QStringList{ // variables
"CCFLAG",
"CLEAN_DEPS",
"CONFIG",
@@ -233,11 +227,8 @@ static const char *const variableKeywords[] = {
"YACCOBJECTS",
"YACCSOURCES",
"_PRO_FILE_",
"_PRO_FILE_PWD_",
0
};
static const char *const functionKeywords[] = {
"_PRO_FILE_PWD_"},
QStringList{ // functions
"CONFIG",
"absolute_path",
"basename",
@@ -309,45 +300,6 @@ static const char *const functionKeywords[] = {
"upper",
"val_escape",
"warning",
"write_file",
0
};
// -------------------------------
// ProFileCompletionAssistProvider
// -------------------------------
void ProFileCompletionAssistProvider::init()
{
for (uint i = 0; i < sizeof variableKeywords / sizeof variableKeywords[0] - 1; i++)
m_variables.append(QLatin1String(variableKeywords[i]));
for (uint i = 0; i < sizeof functionKeywords / sizeof functionKeywords[0] - 1; i++)
m_functions.append(QLatin1String(functionKeywords[i]));
}
ProFileCompletionAssistProvider::~ProFileCompletionAssistProvider()
{
}
IAssistProcessor *ProFileCompletionAssistProvider::createProcessor() const
{
if (m_variables.isEmpty())
const_cast<ProFileCompletionAssistProvider *>(this)->init();
TextEditor::Keywords keywords = TextEditor::Keywords(m_variables, m_functions, QMap<QString, QStringList>());
auto processor = new KeywordsCompletionAssistProcessor(keywords);
processor->setSnippetGroup(TextEditor::Constants::TEXT_SNIPPET_GROUP_ID);
return processor;
}
QStringList ProFileCompletionAssistProvider::variables() const
{
if (m_variables.isEmpty())
const_cast<ProFileCompletionAssistProvider *>(this)->init();
return m_variables;
}
QStringList ProFileCompletionAssistProvider::functions() const
{
if (m_functions.isEmpty())
const_cast<ProFileCompletionAssistProvider *>(this)->init();
return m_functions;
"write_file"});
return keywords;
}

View File

@@ -25,29 +25,11 @@
#pragma once
#include <texteditor/codeassist/completionassistprovider.h>
#include <QStringList>
namespace TextEditor { class Keywords; }
namespace QmakeProjectManager {
namespace Internal {
class ProFileCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{
Q_OBJECT
public:
void init();
~ProFileCompletionAssistProvider();
TextEditor::IAssistProcessor *createProcessor() const override;
QStringList variables() const;
QStringList functions() const;
private:
QStringList m_variables;
QStringList m_functions;
};
const TextEditor::Keywords &qmakeKeywords();
} // namespace Internal
} // namespace QmakeProjectManager

View File

@@ -182,16 +182,14 @@ ProFileEditorFactory::ProFileEditorFactory()
setDocumentCreator(createProFileDocument);
setEditorWidgetCreator([]() { return new ProFileEditorWidget; });
ProFileCompletionAssistProvider *pcap = new ProFileCompletionAssistProvider;
setCompletionAssistProvider(pcap);
setCompletionAssistProvider(new KeywordsCompletionAssistProvider(qmakeKeywords()));
setCommentDefinition(Utils::CommentDefinition::HashStyle);
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::JumpToFileUnderCursor);
Keywords keywords(pcap->variables(), pcap->functions(), QMap<QString, QStringList>());
addHoverHandler(new ProFileHoverHandler(keywords));
setSyntaxHighlighterCreator([keywords]() { return new ProFileHighlighter(keywords); });
addHoverHandler(new ProFileHoverHandler);
setSyntaxHighlighterCreator([]() { return new ProFileHighlighter; });
const QString defaultOverlay = QLatin1String(ProjectExplorer::Constants::FILEOVERLAY_QT);
Core::FileIconProvider::registerIconOverlayForSuffix(

View File

@@ -53,7 +53,7 @@ static TextStyle styleForFormat(int format)
}
ProFileHighlighter::ProFileHighlighter(const Keywords &keywords)
: m_keywords(keywords)
: m_keywords(qmakeKeywords())
{
setTextFormatCategories(NumProfileFormats, styleForFormat);
}

View File

@@ -39,8 +39,8 @@ using namespace Core;
namespace QmakeProjectManager {
namespace Internal {
ProFileHoverHandler::ProFileHoverHandler(const TextEditor::Keywords &keywords)
: m_keywords(keywords)
ProFileHoverHandler::ProFileHoverHandler()
: m_keywords(qmakeKeywords())
{
}