add method to record file language
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ cmake_minimum_required (VERSION 2.6)
|
|||||||
set(TEST_CORE "test_core")
|
set(TEST_CORE "test_core")
|
||||||
|
|
||||||
set(INTERFACE_VERSION 0)
|
set(INTERFACE_VERSION 0)
|
||||||
set(DATABASE_VERSION 22)
|
set(DATABASE_VERSION 23)
|
||||||
set(COMMIT_VERSION 1)
|
set(COMMIT_VERSION 1)
|
||||||
set(VERSION_STRING "v${INTERFACE_VERSION}_db${DATABASE_VERSION}_c${COMMIT_VERSION}")
|
set(VERSION_STRING "v${INTERFACE_VERSION}_db${DATABASE_VERSION}_c${COMMIT_VERSION}")
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ namespace sourcetrail
|
|||||||
int addError(const StorageErrorData& storageErrorData);
|
int addError(const StorageErrorData& storageErrorData);
|
||||||
|
|
||||||
void setNodeType(int nodeId, int nodeKind);
|
void setNodeType(int nodeId, int nodeKind);
|
||||||
|
void setFileLanguage(int fileId, const std::string& languageIdentifier);
|
||||||
|
|
||||||
template <typename ResultType>
|
template <typename ResultType>
|
||||||
std::vector<ResultType> getAll() const
|
std::vector<ResultType> getAll() const
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ namespace sourcetrail
|
|||||||
bool recordReferenceLocation(int referenceId, const SourceRange& location);
|
bool recordReferenceLocation(int referenceId, const SourceRange& location);
|
||||||
|
|
||||||
int recordFile(const std::string& filePath);
|
int recordFile(const std::string& filePath);
|
||||||
|
bool recordFileLanguage(int fileId, const std::string& languageIdentifier);
|
||||||
|
|
||||||
int recordLocalSymbol(const std::string& name);
|
int recordLocalSymbol(const std::string& name);
|
||||||
bool recordLocalSymbolLocation(int localSymbolId, const SourceRange& location);
|
bool recordLocalSymbolLocation(int localSymbolId, const SourceRange& location);
|
||||||
|
|||||||
@@ -26,22 +26,16 @@ namespace sourcetrail
|
|||||||
StorageFile()
|
StorageFile()
|
||||||
: id(0)
|
: id(0)
|
||||||
, filePath("")
|
, filePath("")
|
||||||
|
, languageIdentifier("")
|
||||||
, modificationTime("")
|
, modificationTime("")
|
||||||
, indexed(true)
|
, indexed(true)
|
||||||
, complete(true)
|
, complete(true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
StorageFile(int id, std::string filePath, bool indexed, bool complete)
|
StorageFile(int id, std::string filePath, std::string languageIdentifier, std::string modificationTime, bool indexed, bool complete)
|
||||||
: id(id)
|
|
||||||
, filePath(std::move(filePath))
|
|
||||||
, modificationTime("")
|
|
||||||
, indexed(indexed)
|
|
||||||
, complete(complete)
|
|
||||||
{}
|
|
||||||
|
|
||||||
StorageFile(int id, std::string filePath, std::string modificationTime, bool indexed, bool complete)
|
|
||||||
: id(id)
|
: id(id)
|
||||||
, filePath(std::move(filePath))
|
, filePath(std::move(filePath))
|
||||||
|
, languageIdentifier(std::move(languageIdentifier))
|
||||||
, modificationTime(std::move(modificationTime))
|
, modificationTime(std::move(modificationTime))
|
||||||
, indexed(indexed)
|
, indexed(indexed)
|
||||||
, complete(complete)
|
, complete(complete)
|
||||||
@@ -49,6 +43,7 @@ namespace sourcetrail
|
|||||||
|
|
||||||
int id;
|
int id;
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
|
std::string languageIdentifier;
|
||||||
std::string modificationTime;
|
std::string modificationTime;
|
||||||
bool indexed;
|
bool indexed;
|
||||||
bool complete;
|
bool complete;
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ namespace sourcetrail
|
|||||||
"CREATE TABLE IF NOT EXISTS file("
|
"CREATE TABLE IF NOT EXISTS file("
|
||||||
" id INTEGER NOT NULL, "
|
" id INTEGER NOT NULL, "
|
||||||
" path TEXT, "
|
" path TEXT, "
|
||||||
|
" language TEXT, "
|
||||||
" modification_time TEXT, "
|
" modification_time TEXT, "
|
||||||
" indexed INTEGER, "
|
" indexed INTEGER, "
|
||||||
" complete INTEGER, "
|
" complete INTEGER, "
|
||||||
@@ -352,14 +353,15 @@ namespace sourcetrail
|
|||||||
|
|
||||||
{
|
{
|
||||||
CppSQLite3Statement stmt = m_database.compileStatement(
|
CppSQLite3Statement stmt = m_database.compileStatement(
|
||||||
"INSERT OR IGNORE INTO file(id, path, modification_time, indexed, complete, line_count) VALUES(?, ?, ?, ?, ?, ?);"
|
"INSERT OR IGNORE INTO file(id, path, language, modification_time, indexed, complete, line_count) VALUES(?, ?, ?, ?, ?, ?, ?);"
|
||||||
);
|
);
|
||||||
stmt.bind(1, storageFile.id);
|
stmt.bind(1, storageFile.id);
|
||||||
stmt.bind(2, storageFile.filePath.c_str());
|
stmt.bind(2, storageFile.filePath.c_str());
|
||||||
stmt.bind(3, storageFile.modificationTime.c_str());
|
stmt.bind(3, storageFile.languageIdentifier.c_str());
|
||||||
stmt.bind(4, storageFile.indexed);
|
stmt.bind(4, storageFile.modificationTime.c_str());
|
||||||
stmt.bind(5, storageFile.complete);
|
stmt.bind(5, storageFile.indexed);
|
||||||
stmt.bind(6, lineCount);
|
stmt.bind(6, storageFile.complete);
|
||||||
|
stmt.bind(7, lineCount);
|
||||||
executeStatement(stmt);
|
executeStatement(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,6 +563,16 @@ namespace sourcetrail
|
|||||||
executeStatement(stmt);
|
executeStatement(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseStorage::setFileLanguage(int fileId, const std::string& languageIdentifier)
|
||||||
|
{
|
||||||
|
CppSQLite3Statement stmt = m_database.compileStatement(
|
||||||
|
"UPDATE file SET language = ? WHERE id == ?;"
|
||||||
|
);
|
||||||
|
stmt.bind(1, languageIdentifier.c_str());
|
||||||
|
stmt.bind(2, fileId);
|
||||||
|
executeStatement(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
// --- Private Interface ---
|
// --- Private Interface ---
|
||||||
|
|
||||||
void DatabaseStorage::insertOrUpdateMetaValue(const std::string& key, const std::string& value)
|
void DatabaseStorage::insertOrUpdateMetaValue(const std::string& key, const std::string& value)
|
||||||
@@ -701,7 +713,7 @@ namespace sourcetrail
|
|||||||
std::vector<StorageFile> DatabaseStorage::doGetAll<StorageFile>(const std::string& query) const
|
std::vector<StorageFile> DatabaseStorage::doGetAll<StorageFile>(const std::string& query) const
|
||||||
{
|
{
|
||||||
CppSQLite3Query q = executeQuery(
|
CppSQLite3Query q = executeQuery(
|
||||||
"SELECT id, path, modification_time, indexed, complete FROM file " + query + ";"
|
"SELECT id, path, language, modification_time, indexed, complete FROM file " + query + ";"
|
||||||
);
|
);
|
||||||
|
|
||||||
std::vector<StorageFile> files;
|
std::vector<StorageFile> files;
|
||||||
@@ -709,13 +721,14 @@ namespace sourcetrail
|
|||||||
{
|
{
|
||||||
const int id = q.getIntField(0, 0);
|
const int id = q.getIntField(0, 0);
|
||||||
const std::string filePath = q.getStringField(1, "");
|
const std::string filePath = q.getStringField(1, "");
|
||||||
const std::string modificationTime = q.getStringField(2, "");
|
const std::string languageIdentifier = q.getStringField(2, "");
|
||||||
const bool indexed = q.getIntField(3, 0);
|
const std::string modificationTime = q.getStringField(3, "");
|
||||||
const bool complete = q.getIntField(4, 0);
|
const bool indexed = q.getIntField(4, 0);
|
||||||
|
const bool complete = q.getIntField(5, 0);
|
||||||
|
|
||||||
if (id != 0)
|
if (id != 0)
|
||||||
{
|
{
|
||||||
files.emplace_back(StorageFile(id, filePath, modificationTime, indexed, complete));
|
files.emplace_back(StorageFile(id, filePath, languageIdentifier, modificationTime, indexed, complete));
|
||||||
}
|
}
|
||||||
q.nextRow();
|
q.nextRow();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -480,6 +480,27 @@ namespace sourcetrail
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SourcetrailDBWriter::recordFileLanguage(int fileId, const std::string& languageIdentifier)
|
||||||
|
{
|
||||||
|
if (!m_storage)
|
||||||
|
{
|
||||||
|
m_lastError = "Unable to record file language, because no database is currently open.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_storage->setFileLanguage(fileId, languageIdentifier);
|
||||||
|
}
|
||||||
|
catch (const SourcetrailException e)
|
||||||
|
{
|
||||||
|
m_lastError = e.getMessage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int SourcetrailDBWriter::recordLocalSymbol(const std::string& name)
|
int SourcetrailDBWriter::recordLocalSymbol(const std::string& name)
|
||||||
{
|
{
|
||||||
if (!m_storage)
|
if (!m_storage)
|
||||||
@@ -678,7 +699,7 @@ namespace sourcetrail
|
|||||||
const int nodeId = addNodeHierarchy(nameHierarchy);
|
const int nodeId = addNodeHierarchy(nameHierarchy);
|
||||||
m_storage->setNodeType(nodeId, nodeKindToInt(NODE_FILE));
|
m_storage->setNodeType(nodeId, nodeKindToInt(NODE_FILE));
|
||||||
|
|
||||||
m_storage->addFile(StorageFile(nodeId, filePath, utility::getDateTimeString(time(0)), true, true));
|
m_storage->addFile(StorageFile(nodeId, filePath, "", utility::getDateTimeString(time(0)), true, true));
|
||||||
|
|
||||||
return nodeId;
|
return nodeId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,6 +300,7 @@ namespace sourcetrail
|
|||||||
REQUIRE(files.size() == 1);
|
REQUIRE(files.size() == 1);
|
||||||
REQUIRE(files.front().id == idFile1);
|
REQUIRE(files.front().id == idFile1);
|
||||||
REQUIRE(files.front().filePath == filePath);
|
REQUIRE(files.front().filePath == filePath);
|
||||||
|
REQUIRE(files.front().languageIdentifier == "");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("writer does not record file twice")
|
SECTION("writer does not record file twice")
|
||||||
@@ -312,6 +313,23 @@ namespace sourcetrail
|
|||||||
REQUIRE(files.size() == 1);
|
REQUIRE(files.size() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("writer records file language")
|
||||||
|
{
|
||||||
|
const std::string languageIdentifier = "testlanguage";
|
||||||
|
|
||||||
|
const bool success = writer.recordFileLanguage(
|
||||||
|
idFile1,
|
||||||
|
languageIdentifier
|
||||||
|
);
|
||||||
|
REQUIRE(success);
|
||||||
|
REQUIRE(writer.getLastError() == "");
|
||||||
|
|
||||||
|
const std::vector<StorageFile> files = storage->getAll<StorageFile>();
|
||||||
|
REQUIRE(files.size() == 1);
|
||||||
|
REQUIRE(files.front().id == idFile1);
|
||||||
|
REQUIRE(files.front().languageIdentifier == languageIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
writer.close();
|
writer.close();
|
||||||
REQUIRE(writer.getLastError() == "");
|
REQUIRE(writer.getLastError() == "");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ bool recordReferenceLocation(int referenceId, std::string filePath, int startLin
|
|||||||
|
|
||||||
int recordFile(std::string filePath);
|
int recordFile(std::string filePath);
|
||||||
|
|
||||||
|
bool recordFileLanguage(int fileId, std::string languageIdentifier);
|
||||||
|
|
||||||
int recordLocalSymbol(std::string name);
|
int recordLocalSymbol(std::string name);
|
||||||
|
|
||||||
bool recordLocalSymbolLocation(int localSymbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
|
bool recordLocalSymbolLocation(int localSymbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
|
||||||
|
|||||||
@@ -191,6 +191,11 @@ int recordFile(std::string filePath)
|
|||||||
return dbWriter.recordFile(filePath);
|
return dbWriter.recordFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool recordFileLanguage(int fileId, std::string languageIdentifier)
|
||||||
|
{
|
||||||
|
return dbWriter.recordFileLanguage(fileId, languageIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
int recordLocalSymbol(std::string name)
|
int recordLocalSymbol(std::string name)
|
||||||
{
|
{
|
||||||
return dbWriter.recordLocalSymbol(name);
|
return dbWriter.recordLocalSymbol(name);
|
||||||
|
|||||||
Reference in New Issue
Block a user