2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
#include <texteditor/codeassist/assistinterface.h>
|
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>
|
|
|
|
|
|
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
|
|
|
|
2012-09-06 22:38:25 +08:00
|
|
|
IAssistProcessor *CMakeFileCompletionAssistProvider::createProcessor() const
|
|
|
|
|
{
|
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;
|
2015-02-24 21:57:00 +01:00
|
|
|
QString fileName = interface->fileName();
|
|
|
|
|
if (!fileName.isEmpty() && QFileInfo(fileName).isFile()) {
|
2019-05-28 13:49:26 +02:00
|
|
|
Project *p = SessionManager::projectForFile(Utils::FilePath::fromString(fileName));
|
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
|
|
|
}
|