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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
// Copyright (C) 2025 David M. Cotter
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "issuesmanager.h"
#include <coreplugin/icore.h>
#include <coreplugin/ioutputpane.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/task.h>
#include <projectexplorer/taskhub.h>
#include <utils/id.h>
#include <QLoggingCategory>
#include <QMetaMethod>
#include <QMetaObject>
Q_LOGGING_CATEGORY(mcpIssues, "qtc.mcpserver.issues", QtWarningMsg)
namespace Mcp {
namespace Internal {
IssuesManager::IssuesManager(QObject *parent)
: QObject(parent)
{
initializeAccess();
connectSignals();
}
QStringList IssuesManager::getCurrentIssues() const
{
QStringList issues;
if (!m_accessible) {
issues.append("ERROR:Issues panel not accessible - cannot retrieve current issues");
return issues;
}
// Report on tracked tasks from signals
issues.append(QString("=== CURRENT ISSUES (Signal-Based Tracking) ==="));
issues.append(QString("Total tracked tasks: %1").arg(m_trackedTasks.size()));
int errorCount = 0;
int warningCount = 0;
int otherCount = 0;
for (const ProjectExplorer::Task &task : m_trackedTasks) {
QString taskType = task.type() == ProjectExplorer::Task::Error ? QString("ERROR")
: task.type() == ProjectExplorer::Task::Warning ? QString("WARNING")
: QString("INFO");
QString taskInfo
= formatTask(taskType, task.description(), task.file().toUserOutput(), task.line());
issues.append(taskInfo);
if (task.type() == ProjectExplorer::Task::Error) {
errorCount++;
} else if (task.type() == ProjectExplorer::Task::Warning) {
warningCount++;
} else {
otherCount++;
}
}
if (m_trackedTasks.isEmpty()) {
issues.append("No issues currently tracked via signals");
// Fallback to BuildManager information
if (ProjectExplorer::BuildManager::tasksAvailable()) {
int buildErrorCount = ProjectExplorer::BuildManager::getErrorTaskCount();
if (buildErrorCount > 0) {
issues.append(QString("INFO:BuildManager reports %1 error(s)").arg(buildErrorCount));
} else {
issues.append("INFO:BuildManager reports no errors");
}
} else {
issues.append("INFO:No build tasks available via BuildManager");
}
} else {
issues.append("");
issues.append("=== SUMMARY ===");
issues.append(QString("Errors: %1").arg(errorCount));
issues.append(QString("Warnings: %1").arg(warningCount));
issues.append(QString("Other: %1").arg(otherCount));
}
// Add connection status
issues.append("");
issues.append(QString("Signal connections: %1").arg(m_signalsConnected ? QStringLiteral("Active") : "Inactive"));
issues.append(QString("TaskWindow found: %1").arg(m_taskWindow ? QStringLiteral("Yes") : "No"));
return issues;
}
bool IssuesManager::isAccessible() const
{
return m_accessible;
}
int IssuesManager::getIssueCount() const
{
if (!m_accessible) {
return -1;
}
if (ProjectExplorer::BuildManager::tasksAvailable()) {
return ProjectExplorer::BuildManager::getErrorTaskCount();
}
return 0;
}
bool IssuesManager::initializeAccess()
{
// Check if we can access the BuildManager
if (ProjectExplorer::BuildManager::instance()) {
m_accessible = true;
qCDebug(mcpIssues) << "IssuesManager: Successfully initialized with BuildManager access";
// Find and store the TaskWindow object
const QObjectList allObjects = ExtensionSystem::PluginManager::allObjects();
for (QObject *obj : allObjects) {
if (obj && QString::fromLatin1(obj->metaObject()->className()).contains("TaskWindow")) {
m_taskWindow = obj;
qCDebug(mcpIssues) << "IssuesManager: Found TaskWindow object";
break;
}
}
return true;
}
qCDebug(mcpIssues) << "IssuesManager: Failed to initialize - BuildManager not accessible";
return false;
}
void IssuesManager::connectSignals()
{
if (m_signalsConnected) {
return;
}
// Connect to TaskHub signals
try {
ProjectExplorer::TaskHub &hub = ProjectExplorer::taskHub();
// Connect to task added/removed signals
connect(&hub, &ProjectExplorer::TaskHub::taskAdded, this, &IssuesManager::onTaskAdded);
connect(&hub, &ProjectExplorer::TaskHub::taskRemoved, this, &IssuesManager::onTaskRemoved);
qCDebug(mcpIssues) << "IssuesManager: Connected to TaskHub signals";
// Connect to TaskWindow signals if available
if (m_taskWindow) {
connect(m_taskWindow, SIGNAL(tasksChanged()), this, SLOT(onTasksChanged()));
qCDebug(mcpIssues) << "IssuesManager: Connected to TaskWindow tasksChanged signal";
}
m_signalsConnected = true;
} catch (...) {
qCDebug(mcpIssues) << "IssuesManager: Failed to connect to TaskHub signals";
}
}
void IssuesManager::onTaskAdded(const ProjectExplorer::Task &task)
{
qCDebug(mcpIssues) << "IssuesManager: Task added:" << task.description();
m_trackedTasks.append(task);
}
void IssuesManager::onTaskRemoved(const ProjectExplorer::Task &task)
{
qCDebug(mcpIssues) << "IssuesManager: Task removed:" << task.description();
// Find and remove the task from our tracked list
for (int i = 0; i < m_trackedTasks.size(); ++i) {
if (m_trackedTasks[i].id() == task.id()) {
m_trackedTasks.removeAt(i);
break;
}
}
}
void IssuesManager::onTasksChanged()
{
qCDebug(mcpIssues) << "IssuesManager: TaskWindow reports tasks changed";
}
QStringList IssuesManager::testTaskAccess() const
{
QStringList results;
results.append("=== COMPREHENSIVE TASK ACCESS TEST ===");
// Test 1: Try to access TaskWindow through PluginManager
results.append("");
results.append("Test 1: ExtensionSystem::PluginManager::getObject<TaskWindow>");
results.append("SKIPPED: TaskWindow is internal class, symbols not exported");
// Test 2: Try to access TaskWindow through IOutputPane
results.append("");
results.append("Test 2: Core::IOutputPane access");
try {
auto *outputPane = ExtensionSystem::PluginManager::getObject<Core::IOutputPane>();
if (outputPane) {
results.append("SUCCESS: IOutputPane found");
results.append(QString("IOutputPane class: %1")
.arg(QString::fromUtf8(outputPane->metaObject()->className())));
} else {
results.append("FAILED: IOutputPane not found");
}
} catch (...) {
results.append("EXCEPTION: Error accessing IOutputPane");
}
// Test 3: Try to access TaskHub
results.append("");
results.append("Test 3: TaskHub access");
try {
ProjectExplorer::TaskHub &hub = ProjectExplorer::taskHub();
results.append("SUCCESS: TaskHub reference obtained");
results.append(QString("TaskHub object: %1").arg(reinterpret_cast<quintptr>(&hub), 0, 16));
// Check if TaskHub has any useful methods we can call
const QMetaObject *metaObj = hub.metaObject();
results.append(QString("TaskHub class: %1").arg(QString::fromUtf8(metaObj->className())));
results.append("TaskHub methods:");
for (int i = 0; i < metaObj->methodCount(); ++i) {
QMetaMethod method = metaObj->method(i);
if (method.access() == QMetaMethod::Public) {
results.append(QString(" - %1").arg(QString::fromLatin1(method.methodSignature())));
}
}
} catch (...) {
results.append("EXCEPTION: Error accessing TaskHub");
}
// Test 4: Try to access TaskModel through PluginManager
results.append("");
results.append("Test 4: TaskModel access via PluginManager");
results.append("SKIPPED: TaskModel is internal class, symbols not exported");
// Test 5: BuildManager task information
results.append("");
results.append("Test 5: BuildManager task information");
try {
bool tasksAvailable = ProjectExplorer::BuildManager::tasksAvailable();
int errorCount = ProjectExplorer::BuildManager::getErrorTaskCount();
results.append(QString("BuildManager tasks available: %1")
.arg(tasksAvailable ? QStringLiteral("YES") : "NO"));
results.append(QString("BuildManager error count: %1").arg(errorCount));
} catch (...) {
results.append("EXCEPTION: Error accessing BuildManager");
}
// Test 6: List all objects in PluginManager
results.append("");
results.append("Test 6: All PluginManager objects (first 20)");
try {
QObjectList allObjects = ExtensionSystem::PluginManager::allObjects();
results.append(QString("Total objects in PluginManager: %1").arg(allObjects.size()));
for (int i = 0; i < qMin(20, allObjects.size()); ++i) {
QObject *obj = allObjects[i];
if (obj) {
QString className = QString::fromLatin1(obj->metaObject()->className());
if (className.contains("Task", Qt::CaseInsensitive)
|| className.contains("Issue", Qt::CaseInsensitive)
|| className.contains("Output", Qt::CaseInsensitive)) {
results.append(QString(" [%1] %2 (%3)")
.arg(i)
.arg(className)
.arg(reinterpret_cast<quintptr>(obj), 0, 16));
}
}
}
} catch (...) {
results.append("EXCEPTION: Error listing PluginManager objects");
}
results.append("");
results.append("=== END COMPREHENSIVE TASK ACCESS TEST ===");
return results;
}
QString IssuesManager::formatTask(
const QString &taskType,
const QString &description,
const QString &filePath,
int lineNumber) const
{
QString formatted = QString("%1:%2").arg(taskType, description);
if (!filePath.isEmpty()) {
formatted += QString(" [%1").arg(filePath);
if (lineNumber > 0) {
formatted += QString(":%1").arg(lineNumber);
}
formatted += "]";
}
return formatted;
}
} // namespace Internal
} // namespace Mcp
|