Commit 23fa5a7e authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Provide the language option to the backend

Provide the language option (e.g. "-x c++-header") when registering a
translation unit for the editor.

Task-number: QTCREATORBUG-14787
Change-Id: Ie06f9fdab302f1b21ba72cdb65b6aabf9f7bc04c
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 08fcb7f3
......@@ -54,9 +54,11 @@ FileContainer::FileContainer(const Utf8String &filePath,
FileContainer::FileContainer(const Utf8String &filePath,
const Utf8String &projectPartId,
const Utf8StringVector &fileArguments,
quint32 documentRevision)
: filePath_(filePath),
projectPartId_(projectPartId),
fileArguments_(fileArguments),
documentRevision_(documentRevision),
hasUnsavedFileContent_(false)
{
......@@ -72,6 +74,11 @@ const Utf8String &FileContainer::projectPartId() const
return projectPartId_;
}
const Utf8StringVector &FileContainer::fileArguments() const
{
return fileArguments_;
}
const Utf8String &FileContainer::unsavedFileContent() const
{
return unsavedFileContent_;
......@@ -91,6 +98,7 @@ QDataStream &operator<<(QDataStream &out, const FileContainer &container)
{
out << container.filePath_;
out << container.projectPartId_;
out << container.fileArguments_;
out << container.unsavedFileContent_;
out << container.documentRevision_;
out << container.hasUnsavedFileContent_;
......@@ -102,6 +110,7 @@ QDataStream &operator>>(QDataStream &in, FileContainer &container)
{
in >> container.filePath_;
in >> container.projectPartId_;
in >> container.fileArguments_;
in >> container.unsavedFileContent_;
in >> container.documentRevision_;
in >> container.hasUnsavedFileContent_;
......@@ -127,6 +136,7 @@ QDebug operator<<(QDebug debug, const FileContainer &container)
debug.nospace() << "FileContainer("
<< container.filePath() << ", "
<< container.projectPartId() << ", "
<< container.fileArguments() << ", "
<< container.documentRevision();
if (container.hasUnsavedFileContent()) {
......@@ -147,6 +157,7 @@ void PrintTo(const FileContainer &container, ::std::ostream* os)
*os << "FileContainer("
<< container.filePath().constData() << ", "
<< container.projectPartId().constData() << ", "
<< container.fileArguments().constData() << ", "
<< container.documentRevision();
if (container.hasUnsavedFileContent())
......
......@@ -34,6 +34,7 @@
#include <clangbackendipc_global.h>
#include <utf8string.h>
#include <utf8stringvector.h>
#include <QMetaType>
......@@ -54,10 +55,12 @@ public:
quint32 documentRevision = 0);
FileContainer(const Utf8String &filePath,
const Utf8String &projectPartId,
const Utf8StringVector &fileArguments,
quint32 documentRevision);
const Utf8String &filePath() const;
const Utf8String &projectPartId() const;
const Utf8StringVector &fileArguments() const;
const Utf8String &unsavedFileContent() const;
bool hasUnsavedFileContent() const;
quint32 documentRevision() const;
......@@ -65,6 +68,7 @@ public:
private:
Utf8String filePath_;
Utf8String projectPartId_;
Utf8StringVector fileArguments_;
Utf8String unsavedFileContent_;
quint32 documentRevision_;
bool hasUnsavedFileContent_ = false;
......
......@@ -310,8 +310,8 @@ void IpcCommunicator::registerEmptyProjectForProjectLessFiles()
{
QTC_CHECK(m_connection.isConnected());
registerProjectPartsForEditor({ClangBackEnd::ProjectPartContainer(
Utf8String(),
Utf8StringVector())});
Utf8String(),
Utf8StringVector())});
}
void IpcCommunicator::registerCurrentProjectParts()
......@@ -466,6 +466,7 @@ void IpcCommunicator::requestDiagnostics(Core::IDocument *document)
requestDiagnostics(FileContainer(filePath,
projectPartId,
Utf8StringVector(),
textDocument->document()->revision()));
}
......
......@@ -41,6 +41,7 @@
#include <diagnosticcontainer.h>
#include <sourcelocationcontainer.h>
#include <cpptools/cppprojects.h>
#include <cpptools/cpptoolsplugin.h>
#include <cpptools/cppworkingcopy.h>
......@@ -294,13 +295,32 @@ void ClangEditorDocumentProcessor::requestDiagnostics()
}
}
static CppTools::ProjectPart projectPartForLanguageOption(CppTools::ProjectPart *projectPart)
{
if (projectPart)
return *projectPart;
return *CppTools::CppModelManager::instance()->fallbackProjectPart().data();
}
static QStringList languageOptions(const QString &filePath, CppTools::ProjectPart *projectPart)
{
const auto theProjectPart = CppTools::ProjectPart::Ptr(
new CppTools::ProjectPart(projectPartForLanguageOption(projectPart)));
CppTools::CompilerOptionsBuilder builder(theProjectPart);
builder.addLanguageOption(CppTools::ProjectFile::classify(filePath));
return builder.options();
}
ClangBackEnd::FileContainer
ClangEditorDocumentProcessor::fileContainer(CppTools::ProjectPart *projectPart) const
{
if (projectPart)
return {filePath(), projectPart->id(), revision()};
const auto projectPartId = projectPart
? Utf8String::fromString(projectPart->id())
: Utf8String();
const auto theLanguageOption = languageOptions(filePath(), projectPart);
return {filePath(), Utf8String(), revision()};
return {filePath(), projectPartId, Utf8StringVector(theLanguageOption), revision()};
}
} // namespace Internal
......
......@@ -948,7 +948,12 @@ ProjectPart::Ptr CppModelManager::fallbackProjectPart() const
part->projectDefines = d->m_definedMacros;
part->headerPaths = d->m_headerPaths;
part->languageVersion = ProjectPart::CXX14;
// Do not activate ObjectiveCExtensions since this will lead to the
// "objective-c++" language option for a project-less *.cpp file.
part->languageExtensions = ProjectPart::AllExtensions;
part->languageExtensions &= ~ProjectPart::ObjectiveCExtensions;
part->qtVersion = ProjectPart::Qt5;
part->updateLanguageFeatures();
......
......@@ -24,7 +24,8 @@ HEADERS += $$PWD/clangipcserver.h \
$$PWD/fixit.h \
$$PWD/diagnosticsetiterator.h \
$$PWD/clangfilesystemwatcher.h \
$$PWD/translationunitalreadyexistsexception.h
$$PWD/translationunitalreadyexistsexception.h \
$$PWD/commandlinearguments.h
SOURCES += $$PWD/clangipcserver.cpp \
$$PWD/codecompleter.cpp \
......@@ -49,4 +50,5 @@ SOURCES += $$PWD/clangipcserver.cpp \
$$PWD/sourcerange.cpp \
$$PWD/fixit.cpp \
$$PWD/clangfilesystemwatcher.cpp \
$$PWD/translationunitalreadyexistsexception.cpp
$$PWD/translationunitalreadyexistsexception.cpp \
$$PWD/commandlinearguments.cpp
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "commandlinearguments.h"
namespace ClangBackEnd {
CommandLineArguments::CommandLineArguments(const std::vector<const char *> &projectPartArguments,
const Utf8StringVector &fileArguments,
bool addVerboseOption)
{
const auto elementsToReserve = projectPartArguments.size()
+ uint(fileArguments.size())
+ (addVerboseOption ? 1 : 0);
m_arguments.reserve(elementsToReserve);
m_arguments = projectPartArguments;
for (const auto &argument : fileArguments)
m_arguments.push_back(argument.constData());
if (addVerboseOption)
m_arguments.push_back("-v");
}
const char * const *CommandLineArguments::data() const
{
return m_arguments.data();
}
int CommandLineArguments::count() const
{
return int(m_arguments.size());
}
} // namespace ClangBackEnd
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLANGBACKEND_COMMANDLINEARGUMENTS_H
#define CLANGBACKEND_COMMANDLINEARGUMENTS_H
#include <utf8stringvector.h>
#include <vector>
namespace ClangBackEnd {
class CommandLineArguments
{
public:
CommandLineArguments(const std::vector<const char *> &projectPartArguments,
const Utf8StringVector &fileArguments,
bool addVerboseOption);
const char * const *data() const;
int count() const;
private:
std::vector<const char *> m_arguments;
};
} // namespace ClangBackEnd
#endif // CLANGBACKEND_COMMANDLINEARGUMENTS_H
......@@ -32,6 +32,7 @@
#include "clangstring.h"
#include "codecompleter.h"
#include "commandlinearguments.h"
#include "diagnosticset.h"
#include "projectpart.h"
#include "translationunitfilenotexitexception.h"
......@@ -50,6 +51,11 @@
static Q_LOGGING_CATEGORY(verboseLibLog, "qtc.clangbackend.verboselib");
static bool isVerboseModeEnabled()
{
return verboseLibLog().isDebugEnabled();
}
namespace ClangBackEnd {
class TranslationUnitData
......@@ -57,6 +63,7 @@ class TranslationUnitData
public:
TranslationUnitData(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
TranslationUnits &translationUnits);
~TranslationUnitData();
......@@ -65,6 +72,7 @@ public:
time_point lastProjectPartChangeTimePoint;
QSet<Utf8String> dependedFilePaths;
ProjectPart projectPart;
Utf8StringVector fileArguments;
Utf8String filePath;
CXTranslationUnit translationUnit = nullptr;
CXIndex index = nullptr;
......@@ -75,10 +83,12 @@ public:
TranslationUnitData::TranslationUnitData(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
TranslationUnits &translationUnits)
: translationUnits(translationUnits),
lastProjectPartChangeTimePoint(std::chrono::steady_clock::now()),
projectPart(projectPart),
fileArguments(fileArguments),
filePath(filePath)
{
dependedFilePaths.insert(filePath);
......@@ -92,9 +102,13 @@ TranslationUnitData::~TranslationUnitData()
TranslationUnit::TranslationUnit(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
TranslationUnits &translationUnits,
FileExistsCheck fileExistsCheck)
: d(std::make_shared<TranslationUnitData>(filePath, projectPart, translationUnits))
: d(std::make_shared<TranslationUnitData>(filePath,
projectPart,
fileArguments,
translationUnits))
{
if (fileExistsCheck == CheckIfFileExists)
checkIfFileExists();
......@@ -122,7 +136,7 @@ CXIndex TranslationUnit::index() const
checkIfNull();
if (!d->index) {
const bool displayDiagnostics = verboseLibLog().isDebugEnabled();
const bool displayDiagnostics = isVerboseModeEnabled();
d->index = clang_createIndex(1, displayDiagnostics);
}
......@@ -261,10 +275,14 @@ void TranslationUnit::createTranslationUnitIfNeeded() const
{
if (!d->translationUnit) {
d->translationUnit = CXTranslationUnit();
const bool verboseMode = isVerboseModeEnabled();
const CommandLineArguments args(d->projectPart.arguments(), d->fileArguments, verboseMode);
CXErrorCode errorCode = clang_parseTranslationUnit2(index(),
d->filePath.constData(),
d->projectPart.cxArguments(),
d->projectPart.argumentCount(),
args.data(),
args.count(),
unsavedFiles().cxUnsavedFiles(),
unsavedFiles().count(),
defaultOptions(),
......
......@@ -66,6 +66,7 @@ public:
TranslationUnit() = default;
TranslationUnit(const Utf8String &filePath,
const ProjectPart &projectPart,
const Utf8StringVector &fileArguments,
TranslationUnits &translationUnits,
FileExistsCheck fileExistsCheck = CheckIfFileExists);
~TranslationUnit();
......
......@@ -200,6 +200,7 @@ void TranslationUnits::createTranslationUnit(const FileContainer &fileContainer)
if (findIterator == translationUnits_.end()) {
translationUnits_.push_back(TranslationUnit(fileContainer.filePath(),
projectParts.project(fileContainer.projectPartId()),
fileContainer.fileArguments(),
*this,
checkIfFileExists));
translationUnits_.back().setDocumentRevision(fileContainer.documentRevision());
......
......@@ -58,6 +58,7 @@ TEST(ClangCodeCompleteResults, GetData)
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"),
projectPart,
Utf8StringVector(),
translationUnits);
CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), translationUnit.filePath().constData(), 49, 1, 0, 0, 0);
......@@ -83,6 +84,7 @@ TEST(ClangCodeCompleteResults, MoveClangCodeCompleteResults)
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"),
projectPart,
Utf8StringVector(),
translationUnits);
CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), translationUnit.filePath().constData(), 49, 1, 0, 0, 0);
......
......@@ -259,7 +259,8 @@ TEST_F(ClangIpcServer, GetCodeCompletionForUnsavedFile)
TEST_F(ClangIpcServer, GetNoCodeCompletionAfterRemovingUnsavedFile)
{
clangServer.updateTranslationUnitsForEditor(UpdateTranslationUnitsForEditorMessage({FileContainer(functionTestFilePath, projectPartId, 74)}));
clangServer.updateTranslationUnitsForEditor(UpdateTranslationUnitsForEditorMessage(
{FileContainer(functionTestFilePath, projectPartId, Utf8StringVector(), 74)}));
CompleteCodeMessage completeCodeMessage(functionTestFilePath,
20,
1,
......
......@@ -160,13 +160,13 @@ protected:
ClangBackEnd::ProjectParts projects;
ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
TranslationUnit functionTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), project, translationUnits};
TranslationUnit variableTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"), project, translationUnits};
TranslationUnit classTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_class.cpp"), project, translationUnits};
TranslationUnit namespaceTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_namespace.cpp"), project, translationUnits};
TranslationUnit enumerationTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_enumeration.cpp"), project, translationUnits};
TranslationUnit constructorTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_constructor.cpp"), project, translationUnits};
TranslationUnit briefCommentTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_brief_comment.cpp"), project, translationUnits};
TranslationUnit functionTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), project, Utf8StringVector(), translationUnits};
TranslationUnit variableTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"), project, Utf8StringVector(), translationUnits};
TranslationUnit classTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_class.cpp"), project, Utf8StringVector(), translationUnits};
TranslationUnit namespaceTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_namespace.cpp"), project, Utf8StringVector(), translationUnits};
TranslationUnit enumerationTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_enumeration.cpp"), project, Utf8StringVector(), translationUnits};
TranslationUnit constructorTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_constructor.cpp"), project, Utf8StringVector(), translationUnits};
TranslationUnit briefCommentTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_brief_comment.cpp"), project, Utf8StringVector(), translationUnits};
};
TEST_F(CodeCompletionsExtractor, Function)
......@@ -527,7 +527,7 @@ TEST_F(CodeCompletionsExtractor, NotAvailableFunction)
TEST_F(CodeCompletionsExtractor, UnsavedFile)
{
TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), project, translationUnits);
TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), project, Utf8StringVector(), translationUnits);
unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp",
TESTDATA_DIR"/complete_extractor_function_unsaved.cpp")});
ClangCodeCompleteResults completeResults(getResults(translationUnit, 20));
......@@ -542,7 +542,7 @@ TEST_F(CodeCompletionsExtractor, UnsavedFile)
TEST_F(CodeCompletionsExtractor, ChangeUnsavedFile)
{
TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), project, translationUnits);
TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), project, Utf8StringVector(), translationUnits);
unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp",
TESTDATA_DIR"/complete_extractor_function_unsaved.cpp")});
ClangCodeCompleteResults completeResults(getResults(translationUnit, 20));
......
......@@ -58,6 +58,7 @@ protected:
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
TranslationUnit translationUnit{Utf8StringLiteral(TESTDATA_DIR"/diagnostic_diagnosticset.cpp"),
projectPart,
Utf8StringVector(),
translationUnits};
};
......
......@@ -83,6 +83,7 @@ protected:
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
TranslationUnit translationUnit{Utf8StringLiteral(TESTDATA_DIR"/diagnostic_diagnostic.cpp"),
projectPart,
Utf8StringVector(),
translationUnits};
DiagnosticSet diagnosticSet{translationUnit.diagnostics()};
::Diagnostic diagnostic{diagnosticSet.back()};
......
......@@ -82,6 +82,7 @@ protected:
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
TranslationUnit translationUnit{Utf8StringLiteral(TESTDATA_DIR"/diagnostic_semicolon_fixit.cpp"),
projectPart,
Utf8StringVector(),
translationUnits};
DiagnosticSet diagnosticSet{translationUnit.diagnostics()};
Diagnostic diagnostic{diagnosticSet.front()};
......
......@@ -63,6 +63,7 @@ protected:
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
TranslationUnit translationUnit{Utf8StringLiteral(TESTDATA_DIR"/diagnostic_source_location.cpp"),
projectPart,
Utf8StringVector(),
translationUnits};
DiagnosticSet diagnosticSet{translationUnit.diagnostics()};
Diagnostic diagnostic{diagnosticSet.front()};
......
......@@ -82,6 +82,7 @@ protected:
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
TranslationUnit translationUnit{Utf8StringLiteral(TESTDATA_DIR"/diagnostic_source_range.cpp"),
projectPart,
Utf8StringVector(),
translationUnits};
DiagnosticSet diagnosticSet{translationUnit.diagnostics()};
Diagnostic diagnostic{diagnosticSet.front()};
......
......@@ -129,7 +129,7 @@ TEST_F(TranslationUnits, DoNotThrowForAddingNonExistingFileWithUnsavedContent)
TEST_F(TranslationUnits, Add)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
translationUnits.create({fileContainer});
......@@ -139,7 +139,7 @@ TEST_F(TranslationUnits, Add)
TEST_F(TranslationUnits, ThrowForCreatingAnExistingTranslationUnit)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
translationUnits.create({fileContainer});
ASSERT_THROW(translationUnits.create({fileContainer}),
......@@ -148,15 +148,15 @@ TEST_F(TranslationUnits, ThrowForCreatingAnExistingTranslationUnit)
TEST_F(TranslationUnits, ThrowForUpdatingANonExistingTranslationUnit)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ASSERT_THROW(translationUnits.update({fileContainer}),
ClangBackEnd::TranslationUnitDoesNotExistException);
}
TEST_F(TranslationUnits, Update)
{
ClangBackEnd::FileContainer createFileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8String(), 75u);
ClangBackEnd::FileContainer createFileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8String(), Utf8StringVector(), 75u);
translationUnits.create({createFileContainer});
translationUnits.update({updateFileContainer});
......@@ -167,8 +167,8 @@ TEST_F(TranslationUnits, Update)
TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForReparse)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, 74u);
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
translationUnits.create({fileContainer, headerContainer});
translationUnits.translationUnit(filePath, projectPartId).cxTranslationUnit();
......@@ -180,8 +180,8 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForReparse)
TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForDiagnostics)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, 74u);
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
translationUnits.create({fileContainer, headerContainer});
translationUnits.translationUnit(filePath, projectPartId).diagnostics();
......@@ -193,8 +193,8 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForDiagnostics)
TEST_F(TranslationUnits, RemoveFileAndCheckForDiagnostics)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, 74u);
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
translationUnits.create({fileContainer, headerContainer});
translationUnits.translationUnit(filePath, projectPartId).diagnostics();
......@@ -206,7 +206,7 @@ TEST_F(TranslationUnits, RemoveFileAndCheckForDiagnostics)
TEST_F(TranslationUnits, DontGetNewerFileContainerIfRevisionIsTheSame)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
translationUnits.create({fileContainer});
auto newerFileContainers = translationUnits.newerFileContainers({fileContainer});
......@@ -216,8 +216,8 @@ TEST_F(TranslationUnits, DontGetNewerFileContainerIfRevisionIsTheSame)
TEST_F(TranslationUnits, GetNewerFileContainerIfRevisionIsDifferent)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer newerContainer(filePath, projectPartId, 75u);
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer newerContainer(filePath, projectPartId, Utf8StringVector(), 75u);
translationUnits.create({fileContainer});
auto newerFileContainers = translationUnits.newerFileContainers({newerContainer});
......@@ -263,6 +263,7 @@ TEST_F(TranslationUnits, RemoveAllValidIfExceptionIsThrown)
ASSERT_THAT(translationUnits.translationUnits(),
Not(Contains(TranslationUnit(filePath,
projects.project(projectPartId),
Utf8StringVector(),
translationUnits))));
}
......
......@@ -82,6 +82,7 @@ protected:
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
::TranslationUnit translationUnit{translationUnitFilePath,
projectPart,
Utf8StringVector(),
translationUnits};
};
......@@ -94,13 +95,13 @@ TEST_F(TranslationUnit, DefaultTranslationUnitIsInvalid)
TEST_F(TranslationUnit, ThrowExceptionForNonExistingFilePath)
{
ASSERT_THROW(::TranslationUnit(Utf8StringLiteral("file.cpp"), projectPart, translationUnits),
ASSERT_THROW(::TranslationUnit(Utf8StringLiteral("file.cpp"), projectPart, Utf8StringVector(), translationUnits),
ClangBackEnd::TranslationUnitFileNotExitsException);
}
TEST_F(TranslationUnit, ThrowNoExceptionForNonExistingFilePathIfDoNotCheckIfFileExistsIsSet)
{
ASSERT_NO_THROW(::TranslationUnit(Utf8StringLiteral("file.cpp"), projectPart, translationUnits, ::TranslationUnit::DoNotCheckIfFileExists));
ASSERT_NO_THROW(::TranslationUnit(Utf8StringLiteral("file.cpp"), projectPart, Utf8StringVector(), translationUnits, ::TranslationUnit::DoNotCheckIfFileExists));
}
TEST_F(TranslationUnit, TranslationUnitIsValid)
......@@ -274,6 +275,7 @@ TEST_F(TranslationUnit, DeletedFileShouldBeNotSetDirty)
EXPECT_TRUE(temporaryFile.write(readContentFromTranslationUnitFile()));
::TranslationUnit translationUnit(temporaryFile.fileName(),
projectPart,
Utf8StringVector(),
translationUnits);
return translationUnit;
......
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