Commit 91ee695c authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

Clang: Extract a function



Change-Id: I3041e019c2c65d9d988d31c47823e29955cd1c51
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
parent 7b8f5d98
......@@ -645,26 +645,31 @@ void ClangCompletionAssistProcessor::addCompletionItem(const QString &text,
m_completions.append(item);
}
ClangCompletionAssistProcessor::UnsavedFileContentInfo
ClangCompletionAssistProcessor::unsavedFileContent(const QByteArray &customFileContent) const
{
const bool hasCustomModification = !customFileContent.isEmpty();
UnsavedFileContentInfo info;
info.isDocumentModified = hasCustomModification || m_interface->textDocument()->isModified();
info.unsavedContent = hasCustomModification
? customFileContent
: m_interface->textDocument()->toPlainText().toUtf8();
return info;
}
void ClangCompletionAssistProcessor::sendFileContent(const QString &projectPartId,
const QByteArray &customFileContent)
{
const QTextDocument *textDocument = m_interface->textDocument();
const bool hasCustomModification = !customFileContent.isEmpty();
const bool documentIsModified = hasCustomModification || textDocument->isModified();
// TODO: Revert custom modification after the completions
QByteArray unsavedContent;
if (documentIsModified) {
unsavedContent = hasCustomModification
? customFileContent
: m_interface->textDocument()->toPlainText().toUtf8();
}
const UnsavedFileContentInfo info = unsavedFileContent(customFileContent);
IpcCommunicator &ipcCommunicator = m_interface->ipcCommunicator();
ipcCommunicator.registerFilesForCodeCompletion(
{ClangBackEnd::FileContainer(m_interface->fileName(),
projectPartId,
Utf8String::fromByteArray(unsavedContent),
documentIsModified)});
Utf8String::fromByteArray(info.unsavedContent),
info.isDocumentModified)});
}
void ClangCompletionAssistProcessor::sendCompletionRequest(int position,
......
......@@ -81,6 +81,12 @@ private:
int order = 0,
const QVariant &data = QVariant());
struct UnsavedFileContentInfo {
QByteArray unsavedContent;
bool isDocumentModified = false;
};
UnsavedFileContentInfo unsavedFileContent(const QByteArray &customFileContent) const;
void sendFileContent(const QString &projectPartId, const QByteArray &customFileContent);
void sendCompletionRequest(int position, const QByteArray &customFileContent);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment