diff --git a/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h b/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h index ef0f4bda..de8dfd79 100644 --- a/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h +++ b/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h @@ -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); } diff --git a/src/lib/data/parser/ParserClient.h b/src/lib/data/parser/ParserClient.h index 5470a66d..766aebfc 100644 --- a/src/lib/data/parser/ParserClient.h +++ b/src/lib/data/parser/ParserClient.h @@ -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; diff --git a/src/lib/data/parser/ParserClientImpl.cpp b/src/lib/data/parser/ParserClientImpl.cpp index b96d441f..1e32f0e8 100644 --- a/src/lib/data/parser/ParserClientImpl.cpp +++ b/src/lib/data/parser/ParserClientImpl.cpp @@ -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); diff --git a/src/lib/data/parser/ParserClientImpl.h b/src/lib/data/parser/ParserClientImpl.h index 00577cb5..020afc1b 100644 --- a/src/lib/data/parser/ParserClientImpl.h +++ b/src/lib/data/parser/ParserClientImpl.h @@ -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; diff --git a/src/lib/data/storage/IntermediateStorage.cpp b/src/lib/data/storage/IntermediateStorage.cpp index ab9da909..328e960a 100644 --- a/src/lib/data/storage/IntermediateStorage.cpp +++ b/src/lib/data/storage/IntermediateStorage.cpp @@ -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& 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 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); } } diff --git a/src/lib/data/storage/IntermediateStorage.h b/src/lib/data/storage/IntermediateStorage.h index 7faf6209..1a882039 100644 --- a/src/lib/data/storage/IntermediateStorage.h +++ b/src/lib/data/storage/IntermediateStorage.h @@ -28,6 +28,7 @@ public: void addSymbol(const StorageSymbol& symbol) override; void addSymbols(const std::vector& symbols) override; void addFile(const StorageFile& file) override; + void setFileLanguage(Id fileId, const std::wstring& languageIdentifier); Id addEdge(const StorageEdgeData& edgeData) override; std::vector addEdges(const std::vector& edges) override; Id addLocalSymbol(const StorageLocalSymbolData& localSymbolData) override; @@ -69,8 +70,9 @@ private: std::vector m_nodes; std::map m_filesIndex; // this is used to prevent duplicates (unique) + std::map m_filesIdIndex; std::vector m_files; - + std::vector m_symbols; std::map m_edgesIndex; diff --git a/src/lib/data/storage/Storage.cpp b/src/lib/data/storage/Storage.cpp index af36b47e..299ead7c 100644 --- a/src/lib/data/storage/Storage.cpp +++ b/src/lib/data/storage/Storage.cpp @@ -54,6 +54,7 @@ void Storage::inject(Storage* injected) addFile(StorageFile( it->second, file.filePath, + file.languageIdentifier, file.modificationTime, file.indexed, file.complete diff --git a/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp b/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp index d7d57f93..750df6ef 100644 --- a/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp +++ b/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp @@ -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(const std::string& query, std::function 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(); } diff --git a/src/lib/data/storage/type/StorageFile.h b/src/lib/data/storage/type/StorageFile.h index cd825626..12a47817 100644 --- a/src/lib/data/storage/type/StorageFile.h +++ b/src/lib/data/storage/type/StorageFile.h @@ -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; diff --git a/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp b/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp index 7c0c16ce..7f439aba 100644 --- a/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp +++ b/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp @@ -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); diff --git a/src/lib_java/data/parser/java/JavaParser.cpp b/src/lib_java/data/parser/java/JavaParser.cpp index 530b2009..c0428d72 100644 --- a/src/lib_java/data/parser/java/JavaParser.cpp +++ b/src/lib_java/data/parser/java/JavaParser.cpp @@ -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", " "); diff --git a/src/test/RefreshInfoGeneratorTestSuite.h b/src/test/RefreshInfoGeneratorTestSuite.h index 624d6c5d..b11b76ea 100644 --- a/src/test/RefreshInfoGeneratorTestSuite.h +++ b/src/test/RefreshInfoGeneratorTestSuite.h @@ -907,7 +907,7 @@ private: Id addFileToStorage(const FilePath& filePath, const std::string& modificationTime, bool indexed, bool complete, std::shared_ptr 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; } diff --git a/src/test/StorageTestSuite.h b/src/test/StorageTestSuite.h index c59b72cd..4bda2379 100644 --- a/src/test/StorageTestSuite.h +++ b/src/test/StorageTestSuite.h @@ -22,7 +22,7 @@ public: std::shared_ptr intermetiateStorage = std::make_shared(); 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());