cmakefilecompletionassist.cpp 2.71 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Tobias Hunger's avatar
Tobias Hunger committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Tobias Hunger's avatar
Tobias Hunger committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** 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
12 13 14
** 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.
Tobias Hunger's avatar
Tobias Hunger committed
15
**
16 17 18 19 20 21 22
** 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.
Tobias Hunger's avatar
Tobias Hunger committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
Tobias Hunger's avatar
Tobias Hunger committed
25

26 27 28
#include "cmakefilecompletionassist.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectmanager.h"
29
#include "cmakesettingspage.h"
30
#include "cmaketoolmanager.h"
31
#include "cmakekitinformation.h"
32

33 34
#include <texteditor/codeassist/assistinterface.h>
#include <projectexplorer/kit.h>
35 36
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
37 38 39
#include <projectexplorer/target.h>

#include <coreplugin/editormanager/editormanager.h>
40

41 42
using namespace CMakeProjectManager::Internal;
using namespace TextEditor;
43
using namespace ProjectExplorer;
44

45 46 47
// -------------------------------
// CMakeFileCompletionAssistProvider
// -------------------------------
48

49 50
IAssistProcessor *CMakeFileCompletionAssistProvider::createProcessor() const
{
51
    return new CMakeFileCompletionAssist;
52 53 54 55
}

CMakeFileCompletionAssist::CMakeFileCompletionAssist() :
    KeywordsCompletionAssistProcessor(Keywords())
56 57 58
{
    setSnippetGroup(Constants::CMAKE_SNIPPETS_GROUP_ID);
}
59 60 61

IAssistProposal *CMakeFileCompletionAssist::perform(const AssistInterface *interface)
{
62
    Keywords kw;
63 64
    QString fileName = interface->fileName();
    if (!fileName.isEmpty() && QFileInfo(fileName).isFile()) {
65 66 67 68 69
        Project *p = SessionManager::projectForFile(Utils::FileName::fromString(fileName));
        if (p && p->activeTarget()) {
            CMakeTool *cmake = CMakeKitInformation::cmakeTool(p->activeTarget()->kit());
            if (cmake && cmake->isValid())
                kw = cmake->keywords();
70 71
        }
    }
72

73
    setKeywords(kw);
74
    return KeywordsCompletionAssistProcessor::perform(interface);
75
}