aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp
blob: 325a6012a537025b40659fab2d0b849b76b689d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "cmakefilecompletionassist.h"

#include "cmakekitinformation.h"
#include "cmakeprojectconstants.h"
#include "cmaketool.h"

#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <texteditor/codeassist/assistinterface.h>

#include <QFileInfo>

using namespace TextEditor;
using namespace ProjectExplorer;

namespace CMakeProjectManager::Internal {

class CMakeFileCompletionAssist : public KeywordsCompletionAssistProcessor
{
public:
    CMakeFileCompletionAssist();

    IAssistProposal *performAsync() final;
};

CMakeFileCompletionAssist::CMakeFileCompletionAssist() :
    KeywordsCompletionAssistProcessor(Keywords())
{
    setSnippetGroup(Constants::CMAKE_SNIPPETS_GROUP_ID);
    setDynamicCompletionFunction(&TextEditor::pathComplete);
}

IAssistProposal *CMakeFileCompletionAssist::performAsync()
{
    Keywords kw;
    const Utils::FilePath &filePath = interface()->filePath();
    if (!filePath.isEmpty() && filePath.toFileInfo().isFile()) {
        Project *p = SessionManager::projectForFile(filePath);
        if (p && p->activeTarget()) {
            CMakeTool *cmake = CMakeKitAspect::cmakeTool(p->activeTarget()->kit());
            if (cmake && cmake->isValid())
                kw = cmake->keywords();
        }
    }

    setKeywords(kw);
    return KeywordsCompletionAssistProcessor::performAsync();
}

IAssistProcessor *CMakeFileCompletionAssistProvider::createProcessor(const AssistInterface *) const
{
    return new CMakeFileCompletionAssist;
}

} // CMakeProjectManager::Internal