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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
// 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 "pipsupport.h"
#include "pythonbuildconfiguration.h"
#include "pythonconstants.h"
#include "pythoneditor.h"
#include "pythonhighlighter.h"
#include "pythonkitaspect.h"
#include "pythonproject.h"
#include "pythonrunconfiguration.h"
#include "pythonsettings.h"
#include "pythontr.h"
#include "pythonwizardpage.h"
#ifdef WITH_TESTS
#include "tests/pyprojecttoml_test.h"
#endif // WITH_TESTS
#include <extensionsystem/iplugin.h>
#include <projectexplorer/buildtargetinfo.h>
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/taskhub.h>
#include <texteditor/texteditorsettings.h>
#include <utils/fsengine/fileiconprovider.h>
#include <utils/theme/theme.h>
using namespace ProjectExplorer;
using namespace Utils;
namespace Python::Internal {
static QFuture<QTextDocument *> highlightCode(const QString &code, const QString &mimeType)
{
QTextDocument *document = new QTextDocument;
document->setPlainText(code);
std::shared_ptr<QPromise<QTextDocument *>> promise
= std::make_shared<QPromise<QTextDocument *>>();
promise->start();
TextEditor::SyntaxHighlighter *highlighter = createPythonHighlighter();
QObject::connect(
highlighter, &TextEditor::SyntaxHighlighter::finished, document, [document, promise]() {
promise->addResult(document);
promise->finish();
});
QFutureWatcher<QTextDocument *> *watcher = new QFutureWatcher<QTextDocument *>(document);
QObject::connect(watcher, &QFutureWatcher<QTextDocument *>::canceled, document, [document]() {
document->deleteLater();
});
watcher->setFuture(promise->future());
highlighter->setParent(document);
highlighter->setFontSettings(TextEditor::TextEditorSettings::fontSettings());
highlighter->setMimeType(mimeType);
highlighter->setDocument(document);
highlighter->rehighlight();
return promise->future();
}
class PythonPlugin final : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Python.json")
void initialize() final
{
#ifdef WITH_TESTS
addTestCreator(createPyProjectTomlTest);
#endif
Core::IOptionsPage::registerCategory(
Constants::C_PYTHON_SETTINGS_CATEGORY,
Tr::tr("Python"),
":/python/images/settingscategory_python.png");
setupPythonEditorFactory(this);
setupPySideBuildStep();
setupPythonBuildConfiguration();
setupPythonRunConfiguration();
setupPythonRunWorker();
setupPythonDebugWorker();
setupPythonOutputParser();
setupPythonSettings();
setupPythonWizard();
setupPipSupport(this);
KitManager::setIrrelevantAspects(
KitManager::irrelevantAspects() + QSet<Id>{PythonKitAspect::id()});
const auto issuesGenerator = [](const Kit *k) -> Tasks {
if (!PythonKitAspect::python(k))
return {BuildSystemTask(
Task::Error,
Tr::tr("No Python interpreter set for kit \"%1\".").arg(k->displayName()))};
return {};
};
ProjectManager::registerProjectType<PythonProject>(
Constants::C_PY_PROJECT_MIME_TYPE, issuesGenerator);
ProjectManager::registerProjectType<PythonProject>(
Constants::C_PY_PROJECT_MIME_TYPE_LEGACY, issuesGenerator);
ProjectManager::registerProjectType<PythonProject>(
Constants::C_PY_PROJECT_MIME_TYPE_TOML, issuesGenerator);
auto oldHighlighter = Utils::Text::codeHighlighter();
Utils::Text::setCodeHighlighter(
[oldHighlighter](const QString &code, const QString &mimeType)
-> QFuture<QTextDocument *> {
if (mimeType == "text/python" || mimeType == "text/x-python"
|| mimeType == "text/x-python3") {
return highlightCode(code, mimeType);
}
return oldHighlighter(code, mimeType);
});
}
void extensionsInitialized() final
{
// Add MIME overlay icons (these icons displayed at Project dock panel)
const QString imageFile = Utils::creatorTheme()->imageFile(Theme::IconOverlayPro,
ProjectExplorer::Constants::FILEOVERLAY_PY);
FileIconProvider::registerIconOverlayForSuffix(imageFile, "py");
TaskHub::addCategory({PythonErrorTaskCategory,
"Python",
Tr::tr("Issues parsed from Python runtime output."),
true});
}
};
} // namespace Python::Internal
#include "pythonplugin.moc"
|