Fix .kateproject generation: per-repo, not workspace-level

Kate project plugin needs .kateproject in each repo subdir for project
switching to work. A workspace-level .kateproject makes Kate treat the
whole workspace as one project, breaking repo switching.
This commit is contained in:
Levi Neely 2026-07-22 16:22:14 +02:00
parent c520e46cf5
commit fe4c618780
1 changed files with 21 additions and 13 deletions

View File

@ -2322,14 +2322,16 @@ void GitPlusPlusView::detectWorkspace()
ws.sync(); ws.sync();
} }
// Auto-generate .kateproject if missing // Auto-generate .kateproject in each repo subdir that lacks one
QString kateProjectFile = m_workspaceDir + QStringLiteral("/.kateproject"); for (const auto &repoPath : qAsConst(m_workspaceRepos)) {
if (!QFileInfo::exists(kateProjectFile)) { QString kateProjectFile = repoPath + QStringLiteral("/.kateproject");
QFile kp(kateProjectFile); if (!QFileInfo::exists(kateProjectFile)) {
if (kp.open(QIODevice::WriteOnly | QIODevice::Text)) { QFile kp(kateProjectFile);
QString wsName = QFileInfo(m_workspaceDir).fileName(); if (kp.open(QIODevice::WriteOnly | QIODevice::Text)) {
kp.write("{\n \"name\": \"" + wsName.toUtf8() + "\",\n \"files\": [ { \"git\": true } ]\n}\n"); QString repoName = QFileInfo(repoPath).fileName();
kp.close(); kp.write("{\n \"name\": \"" + repoName.toUtf8() + "\",\n \"files\": [ { \"git\": true } ]\n}\n");
kp.close();
}
} }
} }
@ -2556,11 +2558,17 @@ void GitPlusPlusView::createWorkspace()
} }
} }
// 6. Write .kateproject in new workspace // 6. Write .kateproject in each repo subdir
QFile kateProject(newWsPath + QStringLiteral("/.kateproject")); for (const auto &repoName : sourceRepos) {
if (kateProject.open(QIODevice::WriteOnly | QIODevice::Text)) { QString targetRepoPath = newWsPath + QLatin1Char('/') + repoName;
kateProject.write("{\n \"name\": \"" + name.toUtf8() + "\",\n \"files\": [ { \"git\": true } ]\n}\n"); QString kpFile = targetRepoPath + QStringLiteral("/.kateproject");
kateProject.close(); if (QFileInfo::exists(targetRepoPath) && !QFileInfo::exists(kpFile)) {
QFile kp(kpFile);
if (kp.open(QIODevice::WriteOnly | QIODevice::Text)) {
kp.write("{\n \"name\": \"" + repoName.toUtf8() + "\",\n \"files\": [ { \"git\": true } ]\n}\n");
kp.close();
}
}
} }
if (failed == 0) { if (failed == 0) {