logic: record language for files

This commit is contained in:
mlangkabel
2018-12-12 15:50:29 +01:00
parent d3d5b961ff
commit 92f4a9e056
13 changed files with 66 additions and 35 deletions
@@ -65,28 +65,30 @@ inline StorageNode fromShared(const SharedStorageNode& node)
struct SharedStorageFile
{
SharedStorageFile(
Id id, const std::string& filePath, bool indexed, bool complete, SharedMemory::Allocator* allocator
Id id, const std::string& filePath, const std::string& languageIdentifier, bool indexed, bool complete, SharedMemory::Allocator* allocator
)
: id(id)
, filePath(filePath.c_str(), allocator)
, languageIdentifier(languageIdentifier.c_str(), allocator)
, indexed(indexed)
, complete(complete)
{}
Id id;
SharedMemory::String filePath;
SharedMemory::String languageIdentifier;
bool indexed;
bool complete;
};
inline SharedStorageFile toShared(const StorageFile& file, SharedMemory::Allocator* allocator)
{
return SharedStorageFile(file.id, utility::encodeToUtf8(file.filePath), file.indexed, file.complete, allocator);
return SharedStorageFile(file.id, utility::encodeToUtf8(file.filePath), utility::encodeToUtf8(file.languageIdentifier), file.indexed, file.complete, allocator);
}
inline StorageFile fromShared(const SharedStorageFile& file)
{
return StorageFile(file.id, utility::decodeFromUtf8(file.filePath.c_str()), file.indexed, file.complete);
return StorageFile(file.id, utility::decodeFromUtf8(file.filePath.c_str()), utility::decodeFromUtf8(file.languageIdentifier.c_str()), "", file.indexed, file.complete);
}
+1
View File
@@ -17,6 +17,7 @@ public:
virtual ~ParserClient() = default;
virtual Id recordFile(const FilePath& filePath, bool indexed) = 0;
virtual void recordFileLanguage(Id fileId, const std::wstring& languageIdentifier) = 0;
virtual Id recordSymbol(const NameHierarchy& symbolName) = 0;
virtual void recordSymbolKind(Id symbolId, SymbolKind symbolKind) = 0;
+6 -1
View File
@@ -12,10 +12,15 @@ ParserClientImpl::ParserClientImpl(IntermediateStorage* const storage)
Id ParserClientImpl::recordFile(const FilePath& filePath, bool indexed)
{
Id fileId = addFileName(filePath);
m_storage->addFile(StorageFile(fileId, filePath.wstr(), indexed, true));
m_storage->addFile(StorageFile(fileId, filePath.wstr(), L"", "", indexed, true));
return fileId;
}
void ParserClientImpl::recordFileLanguage(Id fileId, const std::wstring& languageIdentifier)
{
m_storage->setFileLanguage(fileId, languageIdentifier);
}
Id ParserClientImpl::recordSymbol(const NameHierarchy& symbolName)
{
return addNodeHierarchy(symbolName);
+1
View File
@@ -16,6 +16,7 @@ public:
ParserClientImpl(IntermediateStorage* const storage);
Id recordFile(const FilePath& filePath, bool indexed) override;
void recordFileLanguage(Id fileId, const std::wstring& languageIdentifier) override;
Id recordSymbol(const NameHierarchy& symbolName) override;
void recordSymbolKind(Id symbolId, SymbolKind symbolKind) override;
+25 -6
View File
@@ -15,6 +15,7 @@ void IntermediateStorage::clear()
m_nodes.clear();
m_filesIndex.clear();
m_filesIdIndex.clear();
m_files.clear();
m_symbols.clear();
@@ -171,12 +172,7 @@ void IntermediateStorage::addSymbols(const std::vector<StorageSymbol>& symbols)
void IntermediateStorage::addFile(const StorageFile& file)
{
auto it = m_filesIndex.find(file);
if (it == m_filesIndex.end())
{
m_filesIndex.emplace(file, m_files.size());
m_files.emplace_back(file);
}
else
if (it != m_filesIndex.end())
{
StorageFile& storedFile = m_files[it->second];
@@ -189,6 +185,27 @@ void IntermediateStorage::addFile(const StorageFile& file)
{
storedFile.complete = true;
}
if (!file.languageIdentifier.empty())
{
storedFile.languageIdentifier = file.languageIdentifier;
}
}
else
{
m_filesIndex.emplace(file, m_files.size());
m_filesIdIndex.emplace(file.id, m_files.size());
m_files.emplace_back(file);
}
}
void IntermediateStorage::setFileLanguage(Id fileId, const std::wstring& languageIdentifier)
{
auto it = m_filesIdIndex.find(fileId);
if (it != m_filesIdIndex.end())
{
m_files[it->second].languageIdentifier = languageIdentifier;
}
}
@@ -362,9 +379,11 @@ void IntermediateStorage::setStorageFiles(std::vector<StorageFile> storageFiles)
m_files = std::move(storageFiles);
m_filesIndex.clear();
m_filesIdIndex.clear();
for (size_t i = 0; i < m_files.size(); i++)
{
m_filesIndex.emplace(m_files[i], i);
m_filesIdIndex.emplace(m_files[i].id, i);
}
}
+3 -1
View File
@@ -28,6 +28,7 @@ public:
void addSymbol(const StorageSymbol& symbol) override;
void addSymbols(const std::vector<StorageSymbol>& symbols) override;
void addFile(const StorageFile& file) override;
void setFileLanguage(Id fileId, const std::wstring& languageIdentifier);
Id addEdge(const StorageEdgeData& edgeData) override;
std::vector<Id> addEdges(const std::vector<StorageEdge>& edges) override;
Id addLocalSymbol(const StorageLocalSymbolData& localSymbolData) override;
@@ -69,8 +70,9 @@ private:
std::vector<StorageNode> m_nodes;
std::map<StorageFile, size_t> m_filesIndex; // this is used to prevent duplicates (unique)
std::map<Id, size_t> m_filesIdIndex;
std::vector<StorageFile> m_files;
std::vector<StorageSymbol> m_symbols;
std::map<StorageEdgeData, size_t> m_edgesIndex;
+1
View File
@@ -54,6 +54,7 @@ void Storage::inject(Storage* injected)
addFile(StorageFile(
it->second,
file.filePath,
file.languageIdentifier,
file.modificationTime,
file.indexed,
file.complete
@@ -11,7 +11,7 @@
#include "SourceLocationFile.h"
#include "utilityString.h"
const size_t SqliteIndexStorage::s_storageVersion = 22;
const size_t SqliteIndexStorage::s_storageVersion = 23;
namespace
{
@@ -214,10 +214,11 @@ bool SqliteIndexStorage::addFile(const StorageFile& data)
{
m_insertFileStmt.bind(1, int(data.id));
m_insertFileStmt.bind(2, utility::encodeToUtf8(data.filePath).c_str());
m_insertFileStmt.bind(3, modificationTime.c_str());
m_insertFileStmt.bind(4, data.indexed);
m_insertFileStmt.bind(5, data.complete);
m_insertFileStmt.bind(6, lineCount);
m_insertFileStmt.bind(3, utility::encodeToUtf8(data.languageIdentifier).c_str());
m_insertFileStmt.bind(4, modificationTime.c_str());
m_insertFileStmt.bind(5, data.indexed);
m_insertFileStmt.bind(6, data.complete);
m_insertFileStmt.bind(7, lineCount);
success = executeStatement(m_insertFileStmt);
}
@@ -1157,6 +1158,7 @@ void SqliteIndexStorage::setupTables()
"CREATE TABLE IF NOT EXISTS file("
"id INTEGER NOT NULL, "
"path TEXT, "
"language TEXT, "
"modification_time TEXT, "
"indexed INTEGER, "
"complete INTEGER, "
@@ -1317,7 +1319,7 @@ void SqliteIndexStorage::setupPrecompiledStatements()
"INSERT INTO element(id) VALUES(NULL);"
);
m_insertFileStmt = m_database.compileStatement(
"INSERT INTO file(id, path, modification_time, indexed, complete, line_count) VALUES(?, ?, ?, ?, ?, ?);"
"INSERT INTO file(id, path, language, modification_time, indexed, complete, line_count) VALUES(?, ?, ?, ?, ?, ?, ?);"
);
m_insertFileContentStmt = m_database.compileStatement(
"INSERT INTO filecontent(id, content) VALUES(?, ?);"
@@ -1413,20 +1415,21 @@ template <>
void SqliteIndexStorage::forEach<StorageFile>(const std::string& query, std::function<void(StorageFile&&)> func) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, path, modification_time, indexed, complete FROM file " + query + ";"
"SELECT id, path, language, modification_time, indexed, complete FROM file " + query + ";"
);
while (!q.eof())
{
const Id id = q.getIntField(0, 0);
const std::string filePath = q.getStringField(1, "");
const std::string modificationTime = q.getStringField(2, "");
const bool indexed = q.getIntField(3, 0);
const bool complete = q.getIntField(4, 0);
const Id id = q.getIntField(0, 0);
const std::string filePath = q.getStringField(1, "");
const std::string languageIdentifier = q.getStringField(2, "");
const std::string modificationTime = q.getStringField(3, "");
const bool indexed = q.getIntField(4, 0);
const bool complete = q.getIntField(5, 0);
if (id != 0)
{
func(StorageFile(id, utility::decodeFromUtf8(filePath), modificationTime, indexed, complete));
func(StorageFile(id, utility::decodeFromUtf8(filePath), utility::decodeFromUtf8(languageIdentifier), modificationTime, indexed, complete));
}
q.nextRow();
}
+4 -9
View File
@@ -10,22 +10,16 @@ struct StorageFile
StorageFile()
: id(0)
, filePath(L"")
, languageIdentifier(L"")
, modificationTime("")
, indexed(true)
, complete(true)
{}
StorageFile(Id id, std::wstring filePath, bool indexed, bool complete)
: id(id)
, filePath(std::move(filePath))
, modificationTime("")
, indexed(indexed)
, complete(complete)
{}
StorageFile(Id id, std::wstring filePath, std::string modificationTime, bool indexed, bool complete)
StorageFile(Id id, std::wstring filePath, std::wstring languageIdentifier, std::string modificationTime, bool indexed, bool complete)
: id(id)
, filePath(std::move(filePath))
, languageIdentifier(std::move(languageIdentifier))
, modificationTime(std::move(modificationTime))
, indexed(indexed)
, complete(complete)
@@ -38,6 +32,7 @@ struct StorageFile
Id id;
std::wstring filePath;
std::wstring languageIdentifier;
std::string modificationTime;
bool indexed;
bool complete;
@@ -36,6 +36,7 @@ void PreprocessorCallbacks::FileChanged(
if (m_fileWasRecorded.find(fileId) == m_fileWasRecorded.end())
{
m_currentFileSymbolId = m_client->recordFile(currentPath, m_currentPathIsProjectFile); // todo: fix for tests
m_client->recordFileLanguage(m_currentFileSymbolId, L"cpp");
m_canonicalFilePathCache->addFileSymbolId(fileId, currentPath, m_currentFileSymbolId);
m_fileWasRecorded.insert(fileId);
@@ -103,6 +103,7 @@ void JavaParser::buildIndex(
{
m_currentFilePath = sourceFilePath;
m_currentFileId = m_client->recordFile(sourceFilePath, true);
m_client->recordFileLanguage(m_currentFileId, L"java");
// remove tabs because they screw with javaparser's location resolver
std::string fileContent = utility::replace(textAccess->getText(), "\t", " ");
+1 -1
View File
@@ -907,7 +907,7 @@ private:
Id addFileToStorage(const FilePath& filePath, const std::string& modificationTime, bool indexed, bool complete, std::shared_ptr<PersistentStorage> storage)
{
const Id id = storage->addNode(StorageNodeData(NodeType::NODE_FILE, NameHierarchy::serialize(NameHierarchy(filePath.wstr(), NAME_DELIMITER_FILE)))).first;
storage->addFile(StorageFile(id, filePath.wstr(), modificationTime, indexed, complete));
storage->addFile(StorageFile(id, filePath.wstr(), L"someLanguage", modificationTime, indexed, complete));
return id;
}
+1 -1
View File
@@ -22,7 +22,7 @@ public:
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
Id id = intermetiateStorage->addNode(StorageNodeData(NodeType::typeToInt(NodeType::NODE_FILE), NameHierarchy::serialize(NameHierarchy(filePath, NAME_DELIMITER_FILE)))).first;
intermetiateStorage->addFile(StorageFile(id, filePath, "someTime", true, true));
intermetiateStorage->addFile(StorageFile(id, filePath, L"someLanguage", "someTime", true, true));
storage.inject(intermetiateStorage.get());