mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-07-18 13:04:28 -04:00
feat: Add sharing opened files with code completion requests (#156)
This commit is contained in:
@ -25,8 +25,10 @@
|
||||
#include <QTextStream>
|
||||
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include "Logger.hpp"
|
||||
|
||||
@ -107,4 +109,48 @@ bool ContextManager::isSpecifyCompletion(const DocumentInfo &documentInfo) const
|
||||
return generalSettings.specifyPreset1() && documentLanguage == preset1Language;
|
||||
}
|
||||
|
||||
QList<QPair<QString, QString>> ContextManager::openedFiles(const QStringList excludeFiles) const
|
||||
{
|
||||
auto documents = Core::DocumentModel::openedDocuments();
|
||||
|
||||
QList<QPair<QString, QString>> files;
|
||||
|
||||
for (const auto *document : std::as_const(documents)) {
|
||||
auto textDocument = qobject_cast<const TextEditor::TextDocument *>(document);
|
||||
if (!textDocument)
|
||||
continue;
|
||||
|
||||
auto filePath = textDocument->filePath().toUrlishString();
|
||||
if (!excludeFiles.contains(filePath)) {
|
||||
files.append({filePath, textDocument->plainText()});
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
QString ContextManager::openedFilesContext(const QStringList excludeFiles)
|
||||
{
|
||||
QString context = "User files context:\n";
|
||||
|
||||
auto documents = Core::DocumentModel::openedDocuments();
|
||||
|
||||
for (const auto *document : documents) {
|
||||
auto textDocument = qobject_cast<const TextEditor::TextDocument *>(document);
|
||||
if (!textDocument)
|
||||
continue;
|
||||
|
||||
auto filePath = textDocument->filePath().toUrlishString();
|
||||
if (excludeFiles.contains(filePath))
|
||||
continue;
|
||||
|
||||
context += QString("File: %1\n").arg(filePath);
|
||||
context += textDocument->plainText();
|
||||
|
||||
context += "\n";
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Context
|
||||
|
Reference in New Issue
Block a user