2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2011-02-18 10:36:52 +01:00
|
|
|
|
2012-09-06 22:38:25 +08:00
|
|
|
#include "cmakefilecompletionassist.h"
|
2020-04-17 15:30:05 +02:00
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
#include "cmakekitinformation.h"
|
2020-04-17 15:30:05 +02:00
|
|
|
#include "cmakeprojectconstants.h"
|
|
|
|
|
#include "cmaketool.h"
|
2010-11-08 14:01:50 +01:00
|
|
|
|
2017-12-04 13:53:38 +01:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
2015-02-24 21:57:00 +01:00
|
|
|
#include <projectexplorer/target.h>
|
2022-07-08 17:07:33 +02:00
|
|
|
#include <texteditor/codeassist/assistinterface.h>
|
2015-02-24 21:57:00 +01:00
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <QFileInfo>
|
2010-11-08 14:01:50 +01:00
|
|
|
|
2012-09-06 22:38:25 +08:00
|
|
|
using namespace CMakeProjectManager::Internal;
|
|
|
|
|
using namespace TextEditor;
|
2015-02-24 21:57:00 +01:00
|
|
|
using namespace ProjectExplorer;
|
2010-11-08 14:01:50 +01:00
|
|
|
|
2012-09-06 22:38:25 +08:00
|
|
|
// -------------------------------
|
|
|
|
|
// CMakeFileCompletionAssistProvider
|
|
|
|
|
// -------------------------------
|
2010-11-08 14:01:50 +01:00
|
|
|
|
2021-09-15 07:04:12 +02:00
|
|
|
IAssistProcessor *CMakeFileCompletionAssistProvider::createProcessor(const AssistInterface *) const
|
2012-09-06 22:38:25 +08:00
|
|
|
{
|
2016-01-22 13:50:58 +01:00
|
|
|
return new CMakeFileCompletionAssist;
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeFileCompletionAssist::CMakeFileCompletionAssist() :
|
|
|
|
|
KeywordsCompletionAssistProcessor(Keywords())
|
2016-08-18 15:39:13 +02:00
|
|
|
{
|
|
|
|
|
setSnippetGroup(Constants::CMAKE_SNIPPETS_GROUP_ID);
|
2015-10-05 17:33:09 +02:00
|
|
|
setDynamicCompletionFunction(&TextEditor::pathComplete);
|
2016-08-18 15:39:13 +02:00
|
|
|
}
|
2015-02-24 21:57:00 +01:00
|
|
|
|
|
|
|
|
IAssistProposal *CMakeFileCompletionAssist::perform(const AssistInterface *interface)
|
|
|
|
|
{
|
2016-01-22 13:50:58 +01:00
|
|
|
Keywords kw;
|
2020-09-02 12:29:23 +02:00
|
|
|
const Utils::FilePath &filePath = interface->filePath();
|
|
|
|
|
if (!filePath.isEmpty() && filePath.toFileInfo().isFile()) {
|
|
|
|
|
Project *p = SessionManager::projectForFile(filePath);
|
2016-01-22 13:50:58 +01:00
|
|
|
if (p && p->activeTarget()) {
|
2019-02-06 12:50:51 +01:00
|
|
|
CMakeTool *cmake = CMakeKitAspect::cmakeTool(p->activeTarget()->kit());
|
2016-01-22 13:50:58 +01:00
|
|
|
if (cmake && cmake->isValid())
|
|
|
|
|
kw = cmake->keywords();
|
2015-02-24 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
2015-02-04 17:54:46 +01:00
|
|
|
|
2016-01-22 13:50:58 +01:00
|
|
|
setKeywords(kw);
|
2015-02-24 21:57:00 +01:00
|
|
|
return KeywordsCompletionAssistProcessor::perform(interface);
|
2012-09-06 22:38:25 +08:00
|
|
|
}
|