forked from qt-creator/qt-creator
QMakePM: Use generalized KeywordsCompletionProvider
Change-Id: Iaa6476be9285d814e4357b861c8fd00f1c9adc1c Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -24,19 +24,13 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "profilecompletionassist.h"
|
#include "profilecompletionassist.h"
|
||||||
#include "qmakeprojectmanagerconstants.h"
|
|
||||||
|
|
||||||
#include <texteditor/codeassist/assistinterface.h>
|
#include "texteditor/codeassist/keywordscompletionassist.h"
|
||||||
#include <texteditor/codeassist/keywordscompletionassist.h>
|
|
||||||
#include <texteditor/texteditorconstants.h>
|
|
||||||
|
|
||||||
#include <coreplugin/id.h>
|
const TextEditor::Keywords &QmakeProjectManager::Internal::qmakeKeywords()
|
||||||
|
{
|
||||||
using namespace QmakeProjectManager::Internal;
|
static TextEditor::Keywords keywords(
|
||||||
using namespace TextEditor;
|
QStringList{ // variables
|
||||||
|
|
||||||
|
|
||||||
static const char *const variableKeywords[] = {
|
|
||||||
"CCFLAG",
|
"CCFLAG",
|
||||||
"CLEAN_DEPS",
|
"CLEAN_DEPS",
|
||||||
"CONFIG",
|
"CONFIG",
|
||||||
@@ -233,11 +227,8 @@ static const char *const variableKeywords[] = {
|
|||||||
"YACCOBJECTS",
|
"YACCOBJECTS",
|
||||||
"YACCSOURCES",
|
"YACCSOURCES",
|
||||||
"_PRO_FILE_",
|
"_PRO_FILE_",
|
||||||
"_PRO_FILE_PWD_",
|
"_PRO_FILE_PWD_"},
|
||||||
0
|
QStringList{ // functions
|
||||||
};
|
|
||||||
|
|
||||||
static const char *const functionKeywords[] = {
|
|
||||||
"CONFIG",
|
"CONFIG",
|
||||||
"absolute_path",
|
"absolute_path",
|
||||||
"basename",
|
"basename",
|
||||||
@@ -309,45 +300,6 @@ static const char *const functionKeywords[] = {
|
|||||||
"upper",
|
"upper",
|
||||||
"val_escape",
|
"val_escape",
|
||||||
"warning",
|
"warning",
|
||||||
"write_file",
|
"write_file"});
|
||||||
0
|
return keywords;
|
||||||
};
|
|
||||||
|
|
||||||
// -------------------------------
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
@@ -25,29 +25,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <texteditor/codeassist/completionassistprovider.h>
|
namespace TextEditor { class Keywords; }
|
||||||
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
namespace QmakeProjectManager {
|
namespace QmakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class ProFileCompletionAssistProvider : public TextEditor::CompletionAssistProvider
|
const TextEditor::Keywords &qmakeKeywords();
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
void init();
|
|
||||||
~ProFileCompletionAssistProvider();
|
|
||||||
|
|
||||||
TextEditor::IAssistProcessor *createProcessor() const override;
|
|
||||||
QStringList variables() const;
|
|
||||||
QStringList functions() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QStringList m_variables;
|
|
||||||
QStringList m_functions;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace QmakeProjectManager
|
} // namespace QmakeProjectManager
|
||||||
|
@@ -182,16 +182,14 @@ ProFileEditorFactory::ProFileEditorFactory()
|
|||||||
setDocumentCreator(createProFileDocument);
|
setDocumentCreator(createProFileDocument);
|
||||||
setEditorWidgetCreator([]() { return new ProFileEditorWidget; });
|
setEditorWidgetCreator([]() { return new ProFileEditorWidget; });
|
||||||
|
|
||||||
ProFileCompletionAssistProvider *pcap = new ProFileCompletionAssistProvider;
|
setCompletionAssistProvider(new KeywordsCompletionAssistProvider(qmakeKeywords()));
|
||||||
setCompletionAssistProvider(pcap);
|
|
||||||
|
|
||||||
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
||||||
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
||||||
| TextEditorActionHandler::JumpToFileUnderCursor);
|
| TextEditorActionHandler::JumpToFileUnderCursor);
|
||||||
|
|
||||||
Keywords keywords(pcap->variables(), pcap->functions(), QMap<QString, QStringList>());
|
addHoverHandler(new ProFileHoverHandler);
|
||||||
addHoverHandler(new ProFileHoverHandler(keywords));
|
setSyntaxHighlighterCreator([]() { return new ProFileHighlighter; });
|
||||||
setSyntaxHighlighterCreator([keywords]() { return new ProFileHighlighter(keywords); });
|
|
||||||
|
|
||||||
const QString defaultOverlay = QLatin1String(ProjectExplorer::Constants::FILEOVERLAY_QT);
|
const QString defaultOverlay = QLatin1String(ProjectExplorer::Constants::FILEOVERLAY_QT);
|
||||||
Core::FileIconProvider::registerIconOverlayForSuffix(
|
Core::FileIconProvider::registerIconOverlayForSuffix(
|
||||||
|
@@ -53,7 +53,7 @@ static TextStyle styleForFormat(int format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProFileHighlighter::ProFileHighlighter(const Keywords &keywords)
|
ProFileHighlighter::ProFileHighlighter(const Keywords &keywords)
|
||||||
: m_keywords(keywords)
|
: m_keywords(qmakeKeywords())
|
||||||
{
|
{
|
||||||
setTextFormatCategories(NumProfileFormats, styleForFormat);
|
setTextFormatCategories(NumProfileFormats, styleForFormat);
|
||||||
}
|
}
|
||||||
|
@@ -39,8 +39,8 @@ using namespace Core;
|
|||||||
namespace QmakeProjectManager {
|
namespace QmakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
ProFileHoverHandler::ProFileHoverHandler(const TextEditor::Keywords &keywords)
|
ProFileHoverHandler::ProFileHoverHandler()
|
||||||
: m_keywords(keywords)
|
: m_keywords(qmakeKeywords())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user