logic: Reloading ProjectSettings on refresh
This commit is contained in:
@@ -101,6 +101,7 @@ void Application::reloadProject()
|
||||
m_storageCache->clear();
|
||||
m_componentManager->refreshViews();
|
||||
|
||||
m_project->reloadProjectSettings();
|
||||
m_project->parseCode();
|
||||
}
|
||||
|
||||
|
||||
+21
-25
@@ -28,7 +28,8 @@ bool Project::loadProjectSettings(const std::string& projectSettingsFile)
|
||||
{
|
||||
m_projectSettingsFilepath = projectSettingsFile;
|
||||
|
||||
createFileManager();
|
||||
m_fileManager.reset();
|
||||
updateFileManager();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -60,6 +61,15 @@ void Project::clearProjectSettings()
|
||||
m_fileManager.reset();
|
||||
}
|
||||
|
||||
void Project::reloadProjectSettings()
|
||||
{
|
||||
if (m_projectSettingsFilepath.size())
|
||||
{
|
||||
ProjectSettings::getInstance()->load(m_projectSettingsFilepath);
|
||||
updateFileManager();
|
||||
}
|
||||
}
|
||||
|
||||
bool Project::setSourceDirectoryPath(const std::string& sourceDirectoryPath)
|
||||
{
|
||||
m_projectSettingsFilepath = sourceDirectoryPath + "/ProjectSettings.xml";
|
||||
@@ -67,7 +77,8 @@ bool Project::setSourceDirectoryPath(const std::string& sourceDirectoryPath)
|
||||
|
||||
if (success)
|
||||
{
|
||||
createFileManager();
|
||||
m_fileManager.reset();
|
||||
updateFileManager();
|
||||
}
|
||||
|
||||
return success;
|
||||
@@ -83,18 +94,12 @@ void Project::clearStorage()
|
||||
|
||||
void Project::parseCode()
|
||||
{
|
||||
if (!m_fileManager)
|
||||
{
|
||||
LOG_ERROR("No FileManger was created.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
|
||||
|
||||
m_fileManager->fetchFilePaths();
|
||||
std::set<FilePath> addedFilePaths = m_fileManager->getAddedFilePaths();
|
||||
std::set<FilePath> updatedFilePaths = m_fileManager->getUpdatedFilePaths();
|
||||
std::set<FilePath> removedFilePaths = m_fileManager->getRemovedFilePaths();
|
||||
m_fileManager.fetchFilePaths();
|
||||
std::set<FilePath> addedFilePaths = m_fileManager.getAddedFilePaths();
|
||||
std::set<FilePath> updatedFilePaths = m_fileManager.getUpdatedFilePaths();
|
||||
std::set<FilePath> removedFilePaths = m_fileManager.getRemovedFilePaths();
|
||||
|
||||
utility::append(updatedFilePaths, m_storage->getDependingFilePathsAndRemoveFileNodes(updatedFilePaths));
|
||||
utility::append(updatedFilePaths, m_storage->getDependingFilePathsAndRemoveFileNodes(removedFilePaths));
|
||||
@@ -114,7 +119,7 @@ void Project::parseCode()
|
||||
|
||||
Task::dispatch(std::make_shared<TaskParseCxx>(
|
||||
m_storage.get(),
|
||||
m_fileManager.get(),
|
||||
&m_fileManager,
|
||||
getParserArguments(),
|
||||
filesToParse
|
||||
));
|
||||
@@ -127,7 +132,7 @@ void Project::logStats() const
|
||||
m_storage->logStats();
|
||||
}
|
||||
|
||||
void Project::createFileManager()
|
||||
void Project::updateFileManager()
|
||||
{
|
||||
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
|
||||
|
||||
@@ -137,10 +142,7 @@ void Project::createFileManager()
|
||||
std::vector<std::string> sourceExtensions = projSettings->getSourceExtensions();
|
||||
std::vector<std::string> includeExtensions = projSettings->getHeaderExtensions();
|
||||
|
||||
if (sourcePaths.size())
|
||||
{
|
||||
m_fileManager = std::make_shared<FileManager>(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
}
|
||||
m_fileManager.setPaths(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
}
|
||||
|
||||
Parser::Arguments Project::getParserArguments() const
|
||||
@@ -150,17 +152,11 @@ Parser::Arguments Project::getParserArguments() const
|
||||
|
||||
Parser::Arguments args;
|
||||
|
||||
if (!m_fileManager)
|
||||
{
|
||||
LOG_ERROR("No FileManger was created.");
|
||||
return args;
|
||||
}
|
||||
|
||||
utility::append(args.compilerFlags, projSettings->getCompilerFlags());
|
||||
utility::append(args.compilerFlags, appSettings->getCompilerFlags());
|
||||
|
||||
// Add the include paths as HeaderSearchPaths as well, so clang will also look here when searching include files.
|
||||
utility::append(args.systemHeaderSearchPaths, m_fileManager->getIncludePaths());
|
||||
utility::append(args.systemHeaderSearchPaths, m_fileManager.getIncludePaths());
|
||||
utility::append(args.systemHeaderSearchPaths, projSettings->getHeaderSearchPaths());
|
||||
utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPaths());
|
||||
|
||||
|
||||
+5
-4
@@ -20,6 +20,7 @@ public:
|
||||
bool loadProjectSettings(const std::string& projectSettingsFile);
|
||||
bool saveProjectSettings(const std::string& projectSettingsFile);
|
||||
void clearProjectSettings();
|
||||
void reloadProjectSettings();
|
||||
|
||||
bool setSourceDirectoryPath(const std::string& sourceDirectoryPath);
|
||||
|
||||
@@ -33,16 +34,16 @@ private:
|
||||
Project(const Project&);
|
||||
Project operator=(const Project&);
|
||||
|
||||
void createFileManager();
|
||||
void updateFileManager();
|
||||
|
||||
Parser::Arguments getParserArguments() const;
|
||||
|
||||
std::string m_projectSettingsFilepath;
|
||||
|
||||
StorageAccessProxy* const m_storageAccessProxy;
|
||||
|
||||
std::string m_projectSettingsFilepath;
|
||||
FileManager m_fileManager;
|
||||
|
||||
std::shared_ptr<Storage> m_storage;
|
||||
std::shared_ptr<FileManager> m_fileManager;
|
||||
};
|
||||
|
||||
#endif // PROJECT_H
|
||||
|
||||
@@ -5,16 +5,7 @@
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
|
||||
FileManager::FileManager(
|
||||
std::vector<FilePath> sourcePaths,
|
||||
std::vector<FilePath> includePaths,
|
||||
std::vector<std::string> sourceExtensions,
|
||||
std::vector<std::string> includeExtensions
|
||||
)
|
||||
: m_sourcePaths(sourcePaths)
|
||||
, m_includePaths(includePaths)
|
||||
, m_sourceExtensions(sourceExtensions)
|
||||
, m_includeExtensions(includeExtensions)
|
||||
FileManager::FileManager()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -32,6 +23,18 @@ const std::vector<FilePath>& FileManager::getIncludePaths() const
|
||||
return m_includePaths;
|
||||
}
|
||||
|
||||
void FileManager::setPaths(
|
||||
std::vector<FilePath> sourcePaths,
|
||||
std::vector<FilePath> includePaths,
|
||||
std::vector<std::string> sourceExtensions,
|
||||
std::vector<std::string> includeExtensions
|
||||
){
|
||||
m_sourcePaths = sourcePaths;
|
||||
m_includePaths = includePaths;
|
||||
m_sourceExtensions = sourceExtensions;
|
||||
m_includeExtensions = includeExtensions;
|
||||
}
|
||||
|
||||
void FileManager::reset()
|
||||
{
|
||||
m_files.clear();
|
||||
|
||||
@@ -10,16 +10,18 @@
|
||||
class FileManager
|
||||
{
|
||||
public:
|
||||
FileManager(
|
||||
FileManager();
|
||||
~FileManager();
|
||||
|
||||
const std::vector<FilePath>& getSourcePaths() const;
|
||||
const std::vector<FilePath>& getIncludePaths() const;
|
||||
|
||||
void setPaths(
|
||||
std::vector<FilePath> sourcePaths,
|
||||
std::vector<FilePath> includePaths,
|
||||
std::vector<std::string> sourceExtensions,
|
||||
std::vector<std::string> includeExtensions
|
||||
);
|
||||
~FileManager();
|
||||
|
||||
const std::vector<FilePath>& getSourcePaths() const;
|
||||
const std::vector<FilePath>& getIncludePaths() const;
|
||||
|
||||
void reset();
|
||||
void fetchFilePaths();
|
||||
|
||||
@@ -7,18 +7,7 @@ class FileManagerTestSuite : public CxxTest::TestSuite
|
||||
public:
|
||||
void test_file_manager_is_created_empty()
|
||||
{
|
||||
std::vector<FilePath> sourcePaths;
|
||||
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
|
||||
std::vector<FilePath> includePaths;
|
||||
includePaths.push_back("./data/FileManagerTestSuite/include/");
|
||||
std::vector<std::string> sourceExtensions;
|
||||
sourceExtensions.push_back(".cpp");
|
||||
sourceExtensions.push_back(".c");
|
||||
std::vector<std::string> includeExtensions;
|
||||
includeExtensions.push_back(".hpp");
|
||||
includeExtensions.push_back(".h");
|
||||
|
||||
FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
FileManager fm = FileManager();
|
||||
|
||||
TS_ASSERT_EQUALS(fm.getAddedFilePaths().size(), 0);
|
||||
TS_ASSERT_EQUALS(fm.getUpdatedFilePaths().size(), 0);
|
||||
@@ -38,7 +27,8 @@ public:
|
||||
includeExtensions.push_back(".hpp");
|
||||
includeExtensions.push_back(".h");
|
||||
|
||||
FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
FileManager fm;
|
||||
fm.setPaths(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
fm.fetchFilePaths();
|
||||
|
||||
TS_ASSERT_EQUALS(fm.getAddedFilePaths().size(), 4);
|
||||
@@ -57,7 +47,8 @@ public:
|
||||
includeExtensions.push_back(".hpp");
|
||||
includeExtensions.push_back(".h");
|
||||
|
||||
FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
FileManager fm;
|
||||
fm.setPaths(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
fm.fetchFilePaths();
|
||||
fm.fetchFilePaths();
|
||||
|
||||
@@ -77,7 +68,8 @@ public:
|
||||
includeExtensions.push_back(".hpp");
|
||||
includeExtensions.push_back(".h");
|
||||
|
||||
FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
FileManager fm;
|
||||
fm.setPaths(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
fm.fetchFilePaths();
|
||||
|
||||
std::fstream fileStream;
|
||||
@@ -91,4 +83,33 @@ public:
|
||||
TS_ASSERT_EQUALS(fm.getUpdatedFilePaths().size(), 1);
|
||||
TS_ASSERT_EQUALS(fm.getRemovedFilePaths().size(), 0);
|
||||
}
|
||||
|
||||
void test_file_manager_has_added_and_removed_file_paths_after_setting_different_paths()
|
||||
{
|
||||
std::vector<FilePath> sourcePaths(1, "./data/FileManagerTestSuite/src/a.cpp");
|
||||
std::vector<FilePath> includePaths(1, "./data/FileManagerTestSuite/include/c.h");
|
||||
std::vector<std::string> sourceExtensions;
|
||||
sourceExtensions.push_back(".cpp");
|
||||
sourceExtensions.push_back(".c");
|
||||
std::vector<std::string> includeExtensions;
|
||||
includeExtensions.push_back(".hpp");
|
||||
includeExtensions.push_back(".h");
|
||||
|
||||
FileManager fm;
|
||||
fm.setPaths(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
fm.fetchFilePaths();
|
||||
|
||||
TS_ASSERT_EQUALS(fm.getAddedFilePaths().size(), 2);
|
||||
TS_ASSERT_EQUALS(fm.getUpdatedFilePaths().size(), 0);
|
||||
TS_ASSERT_EQUALS(fm.getRemovedFilePaths().size(), 0);
|
||||
|
||||
sourcePaths[0] = "./data/FileManagerTestSuite/src/d.c";
|
||||
|
||||
fm.setPaths(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
fm.fetchFilePaths();
|
||||
|
||||
TS_ASSERT_EQUALS(fm.getAddedFilePaths().size(), 1);
|
||||
TS_ASSERT_EQUALS(fm.getUpdatedFilePaths().size(), 0);
|
||||
TS_ASSERT_EQUALS(fm.getRemovedFilePaths().size(), 1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
#include "TestFileManager.h"
|
||||
|
||||
TestFileManager::TestFileManager()
|
||||
: FileManager(
|
||||
std::vector<FilePath>(),
|
||||
std::vector<FilePath>(),
|
||||
std::vector<std::string>(),
|
||||
std::vector<std::string>()
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
#include "utility/file/FileManager.h"
|
||||
|
||||
class TestFileManager: public FileManager
|
||||
class TestFileManager
|
||||
: public FileManager
|
||||
{
|
||||
public:
|
||||
TestFileManager();
|
||||
|
||||
Reference in New Issue
Block a user