logic: handling of multiple files with the same name
* implemented storing symbols and files in completely different tables
This commit is contained in:
@@ -16,8 +16,8 @@ void IntermediateStorage::clear()
|
||||
{
|
||||
m_fileNamesToIds.clear();
|
||||
m_fileIdsToData.clear();
|
||||
m_nodeNamesToIds.clear();
|
||||
m_nodeIdsToData.clear();
|
||||
m_symbolNamesToIds.clear();
|
||||
m_symbolIdsToData.clear();
|
||||
m_edgeNamesToIds.clear();
|
||||
m_edgeIdsToData.clear();
|
||||
m_localSymbolNamesToIds.clear();
|
||||
@@ -36,9 +36,9 @@ size_t IntermediateStorage::getSourceLocationCount() const
|
||||
return m_sourceLocationNamesToIds.size();
|
||||
}
|
||||
|
||||
Id IntermediateStorage::addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime)
|
||||
Id IntermediateStorage::addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime)
|
||||
{
|
||||
std::shared_ptr<StorageFile> file = std::make_shared<StorageFile>(0, name, filePath, modificationTime);
|
||||
std::shared_ptr<StorageFile> file = std::make_shared<StorageFile>(0, serializedName, filePath, modificationTime);
|
||||
|
||||
std::string serialized = serialize(*(file.get()));
|
||||
std::unordered_map<std::string, Id>::const_iterator it = m_fileNamesToIds.find(serialized);
|
||||
@@ -63,34 +63,34 @@ Id IntermediateStorage::addFile(const std::string& name, const std::string& file
|
||||
return id;
|
||||
}
|
||||
|
||||
Id IntermediateStorage::addNode(int type, const std::string& serializedName, int definitionType)
|
||||
Id IntermediateStorage::addSymbol(int type, const std::string& serializedName, int definitionType)
|
||||
{
|
||||
std::shared_ptr<StorageNode> node = std::make_shared<StorageNode>(0, type, serializedName, definitionType);
|
||||
std::shared_ptr<StorageSymbol> symbol = std::make_shared<StorageSymbol>(0, type, serializedName, definitionType);
|
||||
|
||||
std::string serialized = serialize(*(node.get()));
|
||||
std::unordered_map<std::string, Id>::const_iterator it = m_nodeNamesToIds.find(serialized);
|
||||
if (it != m_nodeNamesToIds.end())
|
||||
std::string serialized = serialize(*(symbol.get()));
|
||||
std::unordered_map<std::string, Id>::const_iterator it = m_symbolNamesToIds.find(serialized);
|
||||
if (it != m_symbolNamesToIds.end())
|
||||
{
|
||||
std::map<Id, std::shared_ptr<StorageNode>>::const_iterator it2 = m_nodeIdsToData.find(it->second);
|
||||
std::shared_ptr<StorageNode> storageNode = it2->second;
|
||||
if (storageNode->definitionType == 0)
|
||||
std::map<Id, std::shared_ptr<StorageSymbol>>::const_iterator it2 = m_symbolIdsToData.find(it->second);
|
||||
std::shared_ptr<StorageSymbol> storedSymbol = it2->second;
|
||||
if (storedSymbol->definitionType == 0)
|
||||
{
|
||||
if (definitionType > 0)
|
||||
{
|
||||
storageNode->definitionType = definitionType;
|
||||
storedSymbol->definitionType = definitionType;
|
||||
}
|
||||
|
||||
if (storageNode->type < type)
|
||||
if (storedSymbol->type < type)
|
||||
{
|
||||
storageNode->type = type;
|
||||
storedSymbol->type = type;
|
||||
}
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Id id = m_nextId++;
|
||||
m_nodeNamesToIds[serialized] = id;
|
||||
m_nodeIdsToData[id] = node;
|
||||
m_symbolNamesToIds[serialized] = id;
|
||||
m_symbolIdsToData[id] = symbol;
|
||||
|
||||
return id;
|
||||
}
|
||||
@@ -200,9 +200,9 @@ void IntermediateStorage::forEachFile(std::function<void(const Id /*id*/, const
|
||||
}
|
||||
}
|
||||
|
||||
void IntermediateStorage::forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const
|
||||
void IntermediateStorage::forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const
|
||||
{
|
||||
for (std::map<Id, std::shared_ptr<StorageNode>>::const_iterator it = m_nodeIdsToData.begin(); it != m_nodeIdsToData.end(); it++)
|
||||
for (std::map<Id, std::shared_ptr<StorageSymbol>>::const_iterator it = m_symbolIdsToData.begin(); it != m_symbolIdsToData.end(); it++)
|
||||
{
|
||||
callback(it->first, *(it->second.get()));
|
||||
}
|
||||
@@ -273,9 +273,9 @@ std::string IntermediateStorage::serialize(const StorageEdge& edge) const
|
||||
);
|
||||
}
|
||||
|
||||
std::string IntermediateStorage::serialize(const StorageNode& node) const
|
||||
std::string IntermediateStorage::serialize(const StorageSymbol& symbol) const
|
||||
{
|
||||
return node.serializedName;
|
||||
return symbol.serializedName;
|
||||
}
|
||||
|
||||
std::string IntermediateStorage::serialize(const StorageFile& file) const
|
||||
|
||||
@@ -17,8 +17,8 @@ public:
|
||||
void clear();
|
||||
size_t getSourceLocationCount() const;
|
||||
|
||||
virtual Id addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime);
|
||||
virtual Id addNode(int type, const std::string& serializedName, int definitionType);
|
||||
virtual Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime);
|
||||
virtual Id addSymbol(int type, const std::string& serializedName, int definitionType);
|
||||
virtual Id addEdge(int type, Id sourceId, Id targetId);
|
||||
virtual Id addLocalSymbol(const std::string& name);
|
||||
virtual Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
|
||||
|
||||
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const;
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
|
||||
virtual void forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachEdge(std::function<void(const Id /*id*/, const StorageEdge& /*data*/)> callback) const;
|
||||
virtual void forEachLocalSymbol(std::function<void(const Id /*id*/, const StorageLocalSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachSourceLocation(std::function<void(const Id /*id*/, const StorageSourceLocation& /*data*/)> callback) const;
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
|
||||
private:
|
||||
std::string serialize(const StorageEdge& edge) const;
|
||||
std::string serialize(const StorageNode& node) const;
|
||||
std::string serialize(const StorageSymbol& symbol) const;
|
||||
std::string serialize(const StorageFile& file) const;
|
||||
std::string serialize(const StorageLocalSymbol& localSymbol) const;
|
||||
std::string serialize(const StorageSourceLocation& sourceLocation) const;
|
||||
@@ -47,8 +47,8 @@ private:
|
||||
std::unordered_map<std::string, Id> m_fileNamesToIds; // this is used to prevent duplicates (unique)
|
||||
std::unordered_map<Id, std::shared_ptr<StorageFile>> m_fileIdsToData;
|
||||
|
||||
std::unordered_map<std::string, Id> m_nodeNamesToIds; // this is used to prevent duplicates (unique)
|
||||
std::map<Id, std::shared_ptr<StorageNode>> m_nodeIdsToData;
|
||||
std::unordered_map<std::string, Id> m_symbolNamesToIds; // this is used to prevent duplicates (unique)
|
||||
std::map<Id, std::shared_ptr<StorageSymbol>> m_symbolIdsToData;
|
||||
|
||||
std::unordered_map<std::string, Id> m_edgeNamesToIds; // this is used to prevent duplicates (unique)
|
||||
std::map<Id, std::shared_ptr<StorageEdge>> m_edgeIdsToData;
|
||||
|
||||
+238
-166
@@ -37,16 +37,13 @@ PersistentStorage::~PersistentStorage()
|
||||
{
|
||||
}
|
||||
|
||||
Id PersistentStorage::addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime)
|
||||
Id PersistentStorage::addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime)
|
||||
{
|
||||
Id fileId = m_sqliteStorage.getFileByPath(filePath).id;
|
||||
if (fileId == 0)
|
||||
{
|
||||
NameHierarchy nameHierarchy;
|
||||
nameHierarchy.push(std::make_shared<NameElement>(name));
|
||||
|
||||
fileId = m_sqliteStorage.addFile(
|
||||
NameHierarchy::serialize(nameHierarchy),
|
||||
serializedName,
|
||||
filePath,
|
||||
modificationTime
|
||||
);
|
||||
@@ -54,32 +51,32 @@ Id PersistentStorage::addFile(const std::string& name, const std::string& filePa
|
||||
return fileId;
|
||||
}
|
||||
|
||||
Id PersistentStorage::addNode(int type, const std::string& serializedName, int definitionType)
|
||||
Id PersistentStorage::addSymbol(int type, const std::string& serializedName, int definitionType)
|
||||
{
|
||||
const StorageNode storedNode = m_sqliteStorage.getNodeBySerializedName(serializedName);
|
||||
const StorageSymbol storedSymbol = m_sqliteStorage.getSymbolBySerializedName(serializedName);
|
||||
|
||||
Id nodeId = storedNode.id;
|
||||
Id symbolId = storedSymbol.id;
|
||||
|
||||
if (nodeId == 0)
|
||||
if (symbolId == 0)
|
||||
{
|
||||
nodeId = m_sqliteStorage.addNode(type, serializedName, definitionType);
|
||||
symbolId = m_sqliteStorage.addSymbol(type, serializedName, definitionType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (storedNode.definitionType == 0)
|
||||
if (storedSymbol.definitionType == 0)
|
||||
{
|
||||
if (definitionType > 0)
|
||||
{
|
||||
m_sqliteStorage.setNodeDefinitionType(definitionType, nodeId);
|
||||
m_sqliteStorage.setSymbolDefinitionType(definitionType, symbolId);
|
||||
}
|
||||
|
||||
if (storedNode.type < type)
|
||||
if (storedSymbol.type < type)
|
||||
{
|
||||
m_sqliteStorage.setNodeType(type, nodeId);
|
||||
m_sqliteStorage.setNodeType(type, symbolId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return nodeId;
|
||||
return symbolId;
|
||||
}
|
||||
|
||||
Id PersistentStorage::addEdge(int type, Id sourceId, Id targetId)
|
||||
@@ -159,23 +156,23 @@ void PersistentStorage::addError(
|
||||
|
||||
void PersistentStorage::forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageFile& file: m_sqliteStorage.getAllFiles())
|
||||
for (StorageFile& file: m_sqliteStorage.getAll<StorageFile>())
|
||||
{
|
||||
callback(file.id, file);
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const
|
||||
void PersistentStorage::forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageNode& node: m_sqliteStorage.getAllNodes())
|
||||
for (StorageSymbol& symbol: m_sqliteStorage.getAll<StorageSymbol>())
|
||||
{
|
||||
callback(node.id, node);
|
||||
callback(symbol.id, symbol);
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::forEachEdge(std::function<void(const Id /*id*/, const StorageEdge& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageEdge& edge: m_sqliteStorage.getAllEdges())
|
||||
for (StorageEdge& edge: m_sqliteStorage.getAll<StorageEdge>())
|
||||
{
|
||||
callback(edge.id, edge);
|
||||
}
|
||||
@@ -184,7 +181,7 @@ void PersistentStorage::forEachEdge(std::function<void(const Id /*id*/, const St
|
||||
void PersistentStorage::forEachLocalSymbol(std::function<void(
|
||||
const Id /*id*/, const StorageLocalSymbol& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageLocalSymbol& localSymbol: m_sqliteStorage.getAllLocalSymbols())
|
||||
for (StorageLocalSymbol& localSymbol: m_sqliteStorage.getAll<StorageLocalSymbol>())
|
||||
{
|
||||
callback(localSymbol.id, localSymbol);
|
||||
}
|
||||
@@ -192,7 +189,7 @@ void PersistentStorage::forEachLocalSymbol(std::function<void(
|
||||
|
||||
void PersistentStorage::forEachSourceLocation(std::function<void(const Id /*id*/, const StorageSourceLocation& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageSourceLocation& sourceLocation: m_sqliteStorage.getAllSourceLocations())
|
||||
for (StorageSourceLocation& sourceLocation: m_sqliteStorage.getAll<StorageSourceLocation>())
|
||||
{
|
||||
callback(sourceLocation.id, sourceLocation);
|
||||
}
|
||||
@@ -200,7 +197,7 @@ void PersistentStorage::forEachSourceLocation(std::function<void(const Id /*id*/
|
||||
|
||||
void PersistentStorage::forEachOccurrence(std::function<void(const StorageOccurrence& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageOccurrence& occurrence: m_sqliteStorage.getAllOccurrences())
|
||||
for (StorageOccurrence& occurrence: m_sqliteStorage.getAll<StorageOccurrence>())
|
||||
{
|
||||
callback(occurrence);
|
||||
}
|
||||
@@ -208,7 +205,7 @@ void PersistentStorage::forEachOccurrence(std::function<void(const StorageOccurr
|
||||
|
||||
void PersistentStorage::forEachComponentAccess(std::function<void(const StorageComponentAccess& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageComponentAccess& componentAccess: m_sqliteStorage.getAllComponentAccesses())
|
||||
for (StorageComponentAccess& componentAccess: m_sqliteStorage.getAll<StorageComponentAccess>())
|
||||
{
|
||||
callback(componentAccess);
|
||||
}
|
||||
@@ -216,7 +213,7 @@ void PersistentStorage::forEachComponentAccess(std::function<void(const StorageC
|
||||
|
||||
void PersistentStorage::forEachCommentLocation(std::function<void(const StorageCommentLocation& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageCommentLocation& commentLocation: m_sqliteStorage.getAllCommentLocations())
|
||||
for (StorageCommentLocation& commentLocation: m_sqliteStorage.getAll<StorageCommentLocation>())
|
||||
{
|
||||
callback(commentLocation);
|
||||
}
|
||||
@@ -224,7 +221,7 @@ void PersistentStorage::forEachCommentLocation(std::function<void(const StorageC
|
||||
|
||||
void PersistentStorage::forEachError(std::function<void(const StorageError& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageError& error: m_sqliteStorage.getAllErrors())
|
||||
for (StorageError& error: m_sqliteStorage.getAll<StorageError>())
|
||||
{
|
||||
callback(error);
|
||||
}
|
||||
@@ -293,7 +290,7 @@ void PersistentStorage::clear()
|
||||
|
||||
void PersistentStorage::clearCaches()
|
||||
{
|
||||
m_elementIndex.clear();
|
||||
m_symbolIndex.clear();
|
||||
m_fileIndex.clear();
|
||||
m_fileNodeIds.clear();
|
||||
m_fileNodePaths.clear();
|
||||
@@ -341,7 +338,7 @@ std::vector<FileInfo> PersistentStorage::getInfoOnAllFiles() const
|
||||
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
std::vector<StorageFile> storageFiles = m_sqliteStorage.getAllFiles();
|
||||
std::vector<StorageFile> storageFiles = m_sqliteStorage.getAll<StorageFile>();
|
||||
for (size_t i = 0; i < storageFiles.size(); i++)
|
||||
{
|
||||
boost::posix_time::ptime modificationTime = boost::posix_time::not_a_date_time;
|
||||
@@ -395,12 +392,12 @@ NameHierarchy PersistentStorage::getNameHierarchyForNodeWithId(Id nodeId) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
return NameHierarchy::deserialize(m_sqliteStorage.getNodeById(nodeId).serializedName);
|
||||
return NameHierarchy::deserialize(m_sqliteStorage.getFirstById<StorageNode>(nodeId).serializedName);
|
||||
}
|
||||
|
||||
Node::NodeType PersistentStorage::getNodeTypeForNodeWithId(Id nodeId) const
|
||||
{
|
||||
return Node::intToType(m_sqliteStorage.getNodeById(nodeId).type);
|
||||
return Node::intToType(m_sqliteStorage.getFirstById<StorageNode>(nodeId).type);
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> PersistentStorage::getFullTextSearchLocations(
|
||||
@@ -508,13 +505,45 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
||||
size_t maxResultsCount = 100;
|
||||
size_t maxBestScoredResultsLength = 100;
|
||||
|
||||
std::vector<SearchResult> results;
|
||||
utility::append(results, m_commandIndex.search(query, 0));
|
||||
utility::append(results, m_elementIndex.search(query, maxResultsCount, maxBestScoredResultsLength));
|
||||
utility::append(results, m_fileIndex.search(query, 20));
|
||||
// create SearchMatches
|
||||
std::set<SearchMatch> matchesSet;
|
||||
utility::append(matchesSet, getAutocompletionSymbolMatches(query, maxResultsCount));
|
||||
utility::append(matchesSet, getAutocompletionFileMatches(query, 20));
|
||||
utility::append(matchesSet, getAutocompletionCommandMatches(query));
|
||||
|
||||
std::vector<SearchMatch> matches = utility::toVector(matchesSet);
|
||||
|
||||
for (auto it = matches.begin(); it != matches.end(); it++)
|
||||
{
|
||||
SearchMatch& match = *it;
|
||||
// rescore match
|
||||
if (!match.subtext.empty() && match.indices.size())
|
||||
{
|
||||
SearchResult newResult =
|
||||
SearchIndex::rescoreText(match.name, match.text, match.indices, match.score, maxBestScoredResultsLength);
|
||||
|
||||
match.score = newResult.score;
|
||||
match.indices = newResult.indices;
|
||||
}
|
||||
}
|
||||
|
||||
if (matches.size() > maxResultsCount)
|
||||
{
|
||||
matches.resize(maxResultsCount);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::set<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const
|
||||
{
|
||||
// search in indices
|
||||
std::vector<SearchResult> results = m_symbolIndex.search(query, maxResultsCount, maxResultsCount); // TODO: rename symbolIndex
|
||||
|
||||
// fetch StorageNodes for node ids
|
||||
std::map<Id, StorageNode> storageNodesMap;
|
||||
std::map<Id, StorageSymbol> storageSymbolMap;
|
||||
{
|
||||
std::vector<Id> elementIds;
|
||||
|
||||
@@ -523,13 +552,13 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
||||
elementIds.insert(elementIds.end(), result.elementIds.begin(), result.elementIds.end());
|
||||
}
|
||||
|
||||
std::vector<StorageNode> storageNodes = m_sqliteStorage.getNodesByIds(elementIds);
|
||||
std::vector<StorageSymbol> storageSymbols = m_sqliteStorage.getAllByIds<StorageSymbol>(elementIds);
|
||||
|
||||
for (StorageNode& node : storageNodes)
|
||||
for (StorageSymbol& symbol : storageSymbols)
|
||||
{
|
||||
if (node.id > 0)
|
||||
if (symbol.id > 0)
|
||||
{
|
||||
storageNodesMap.emplace(node.id, node);
|
||||
storageSymbolMap.emplace(symbol.id, symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -540,87 +569,107 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
||||
{
|
||||
SearchMatch match;
|
||||
|
||||
const StorageNode* firstNode = nullptr;
|
||||
const StorageSymbol* firstSymbol = nullptr;
|
||||
for (const Id& elementId : result.elementIds)
|
||||
{
|
||||
if (elementId != 0)
|
||||
{
|
||||
const StorageNode& node = storageNodesMap[elementId];
|
||||
match.nameHierarchies.push_back(NameHierarchy::deserialize(node.serializedName));
|
||||
const StorageSymbol& symbol = storageSymbolMap[elementId];
|
||||
match.nameHierarchies.push_back(NameHierarchy::deserialize(symbol.serializedName));
|
||||
|
||||
if (!match.hasChildren)
|
||||
{
|
||||
match.hasChildren = m_hierarchyCache.nodeHasChildren(node.id);
|
||||
match.hasChildren = m_hierarchyCache.nodeHasChildren(symbol.id);
|
||||
}
|
||||
|
||||
if (!firstNode)
|
||||
if (!firstSymbol)
|
||||
{
|
||||
firstNode = &node;
|
||||
firstSymbol = &symbol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match.name = result.text;
|
||||
|
||||
match.text = result.text;
|
||||
const size_t idx = m_hierarchyCache.getIndexOfLastVisibleParentNode(firstSymbol->id);
|
||||
const NameHierarchy& name = match.nameHierarchies[0];
|
||||
match.text = name.getRange(idx, name.size()).getQualifiedName();
|
||||
match.subtext = name.getRange(0, idx).getQualifiedName();
|
||||
|
||||
match.indices = result.indices;
|
||||
match.score = result.score;
|
||||
match.nodeType = Node::intToType(firstSymbol->type);
|
||||
match.typeName = Node::getTypeString(match.nodeType);
|
||||
match.searchType = SearchMatch::SEARCH_TOKEN;
|
||||
|
||||
if (intToDefinitionType(firstSymbol->definitionType) == DEFINITION_NONE
|
||||
&& match.nodeType != Node::NODE_UNDEFINED)
|
||||
{
|
||||
match.typeName = "undefined " + match.typeName;
|
||||
}
|
||||
|
||||
matches.insert(match);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
std::set<SearchMatch> PersistentStorage::getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const
|
||||
{
|
||||
std::vector<SearchResult> results = m_fileIndex.search(query, maxResultsCount);
|
||||
|
||||
// create SearchMatches
|
||||
std::set<SearchMatch> matches;
|
||||
for (const SearchResult& result : results)
|
||||
{
|
||||
SearchMatch match;
|
||||
|
||||
match.nameHierarchies.push_back(NameHierarchy(result.text));
|
||||
|
||||
match.name = result.text;
|
||||
|
||||
FilePath path(match.name);
|
||||
match.text = path.fileName();
|
||||
match.subtext = path.str();
|
||||
|
||||
match.indices = result.indices;
|
||||
match.score = result.score;
|
||||
|
||||
match.nodeType = Node::NODE_FILE;
|
||||
match.typeName = Node::getTypeString(match.nodeType);
|
||||
|
||||
match.searchType = SearchMatch::SEARCH_TOKEN;
|
||||
|
||||
matches.insert(match);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
std::set<SearchMatch> PersistentStorage::getAutocompletionCommandMatches(const std::string& query) const
|
||||
{
|
||||
// search in indices
|
||||
std::vector<SearchResult> results = m_commandIndex.search(query, 0);
|
||||
|
||||
// create SearchMatches
|
||||
std::set<SearchMatch> matches;
|
||||
for (const SearchResult& result : results)
|
||||
{
|
||||
SearchMatch match;
|
||||
|
||||
match.name = result.text;
|
||||
match.text = result.text;
|
||||
match.indices = result.indices;
|
||||
match.score = result.score;
|
||||
|
||||
if (firstNode)
|
||||
{
|
||||
match.nodeType = Node::intToType(firstNode->type);
|
||||
match.typeName = Node::getTypeString(match.nodeType);
|
||||
|
||||
size_t idx = 0;
|
||||
if (match.nodeType == Node::NODE_FILE)
|
||||
{
|
||||
idx = 1;
|
||||
|
||||
FilePath path(match.name);
|
||||
match.text = path.fileName();
|
||||
match.subtext = path.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
idx = m_hierarchyCache.getIndexOfLastVisibleParentNode(firstNode->id);
|
||||
const NameHierarchy& name = match.nameHierarchies[0];
|
||||
|
||||
match.text = name.getRange(idx, name.size()).getQualifiedName();
|
||||
match.subtext = name.getRange(0, idx).getQualifiedName();
|
||||
}
|
||||
|
||||
// rescore match
|
||||
if (idx && match.indices.size())
|
||||
{
|
||||
SearchResult newResult =
|
||||
SearchIndex::rescoreText(match.name, match.text, match.indices, match.score, maxBestScoredResultsLength);
|
||||
|
||||
match.score = newResult.score;
|
||||
match.indices = newResult.indices;
|
||||
}
|
||||
|
||||
if (intToDefinitionType(firstNode->definitionType) == DEFINITION_NONE
|
||||
&& match.nodeType != Node::NODE_UNDEFINED)
|
||||
{
|
||||
match.typeName = "undefined " + match.typeName;
|
||||
}
|
||||
match.searchType = SearchMatch::SEARCH_TOKEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
match.searchType = SearchMatch::SEARCH_COMMAND;
|
||||
match.typeName = "command";
|
||||
}
|
||||
match.searchType = SearchMatch::SEARCH_COMMAND;
|
||||
match.typeName = "command";
|
||||
|
||||
matches.insert(match);
|
||||
}
|
||||
|
||||
std::vector<SearchMatch> matchesVector = utility::toVector(matches);
|
||||
if (matchesVector.size() > maxResultsCount)
|
||||
{
|
||||
matchesVector.resize(maxResultsCount);
|
||||
}
|
||||
|
||||
return matchesVector;
|
||||
return matches;
|
||||
}
|
||||
|
||||
std::vector<SearchMatch> PersistentStorage::getSearchMatchesForTokenIds(const std::vector<Id>& elementIds) const
|
||||
@@ -639,7 +688,7 @@ std::vector<SearchMatch> PersistentStorage::getSearchMatchesForTokenIds(const st
|
||||
}
|
||||
else if (m_sqliteStorage.isNode(elementId))
|
||||
{
|
||||
StorageNode node = m_sqliteStorage.getNodeById(elementId);
|
||||
StorageNode node = m_sqliteStorage.getFirstById<StorageNode>(elementId);
|
||||
match.nodeType = Node::intToType(node.type);
|
||||
}
|
||||
else
|
||||
@@ -647,7 +696,7 @@ std::vector<SearchMatch> PersistentStorage::getSearchMatchesForTokenIds(const st
|
||||
continue;
|
||||
}
|
||||
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(m_sqliteStorage.getNodeById(elementId).serializedName);
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(m_sqliteStorage.getFirstById<StorageNode>(elementId).serializedName);
|
||||
match.name = nameHierarchy.getQualifiedName();
|
||||
match.text = nameHierarchy.getRawName();
|
||||
match.nameHierarchies.push_back(nameHierarchy.getQualifiedName());
|
||||
@@ -666,22 +715,27 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForAll() const
|
||||
std::shared_ptr<Graph> graph = std::make_shared<Graph>();
|
||||
|
||||
std::vector<Id> tokenIds;
|
||||
for (StorageNode node: m_sqliteStorage.getAllNodes())
|
||||
for (StorageSymbol symbol: m_sqliteStorage.getAll<StorageSymbol>())
|
||||
{
|
||||
if (intToDefinitionType(node.definitionType) == DEFINITION_EXPLICIT &&
|
||||
if (intToDefinitionType(symbol.definitionType) == DEFINITION_EXPLICIT &&
|
||||
(
|
||||
!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(node.id) ||
|
||||
!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(symbol.id) ||
|
||||
(
|
||||
Node::intToType(node.type) == Node::NODE_NAMESPACE || // TODO: use & here
|
||||
Node::intToType(node.type) == Node::NODE_PACKAGE
|
||||
Node::intToType(symbol.type) == Node::NODE_NAMESPACE || // TODO: use & operator here
|
||||
Node::intToType(symbol.type) == Node::NODE_PACKAGE
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
tokenIds.push_back(node.id);
|
||||
tokenIds.push_back(symbol.id);
|
||||
}
|
||||
}
|
||||
|
||||
for (StorageFile file: m_sqliteStorage.getAll<StorageFile>())
|
||||
{
|
||||
tokenIds.push_back(file.id);
|
||||
}
|
||||
|
||||
addNodesToGraph(tokenIds, graph.get());
|
||||
|
||||
return graph;
|
||||
@@ -706,7 +760,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(const std::v
|
||||
if (tokenIds.size() == 1)
|
||||
{
|
||||
const Id elementId = tokenIds[0];
|
||||
StorageNode node = m_sqliteStorage.getNodeById(elementId);
|
||||
StorageNode node = m_sqliteStorage.getFirstById<StorageNode>(elementId);
|
||||
|
||||
if (node.id > 0)
|
||||
{
|
||||
@@ -752,18 +806,21 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(const std::v
|
||||
|
||||
if (ids.size() >= 1 || isNamespace)
|
||||
{
|
||||
std::vector<StorageNode> nodes = m_sqliteStorage.getNodesByIds(ids);
|
||||
for (const StorageNode& node : nodes)
|
||||
for (const StorageSymbol& symbol : m_sqliteStorage.getAllByIds<StorageSymbol>(ids))
|
||||
{
|
||||
if (node.id > 0 && (!isNamespace || intToDefinitionType(node.definitionType) != DEFINITION_IMPLICIT))
|
||||
if (symbol.id > 0 && (!isNamespace || intToDefinitionType(symbol.definitionType) != DEFINITION_IMPLICIT))
|
||||
{
|
||||
nodeIds.push_back(node.id);
|
||||
nodeIds.push_back(symbol.id);
|
||||
}
|
||||
}
|
||||
for (const StorageFile& file : m_sqliteStorage.getAllByIds<StorageFile>(ids))
|
||||
{
|
||||
nodeIds.push_back(file.id);
|
||||
}
|
||||
|
||||
if (nodeIds.size() != ids.size())
|
||||
{
|
||||
std::vector<StorageEdge> edges = m_sqliteStorage.getEdgesByIds(ids);
|
||||
std::vector<StorageEdge> edges = m_sqliteStorage.getAllByIds<StorageEdge>(ids);
|
||||
for (const StorageEdge& edge : edges)
|
||||
{
|
||||
if (edge.id > 0)
|
||||
@@ -831,17 +888,17 @@ std::vector<Id> PersistentStorage::getNodeIdsForLocationIds(const std::vector<Id
|
||||
{
|
||||
const Id elementId = occurrence.elementId;
|
||||
|
||||
StorageEdge edge = m_sqliteStorage.getEdgeById(elementId);
|
||||
StorageEdge edge = m_sqliteStorage.getFirstById<StorageEdge>(elementId);
|
||||
if (edge.id != 0) // here we test if location is an edge.
|
||||
{
|
||||
edgeIds.insert(edge.targetNodeId);
|
||||
}
|
||||
else if(m_sqliteStorage.isNode(elementId))
|
||||
{
|
||||
StorageNode node = m_sqliteStorage.getNodeById(elementId);
|
||||
if (node.id != 0)
|
||||
StorageSymbol symbol = m_sqliteStorage.getFirstById<StorageSymbol>(elementId);
|
||||
if (symbol.id != 0) // here we test if location is a symbol
|
||||
{
|
||||
if (intToDefinitionType(node.definitionType) == DEFINITION_IMPLICIT)
|
||||
if (intToDefinitionType(symbol.definitionType) == DEFINITION_IMPLICIT)
|
||||
{
|
||||
implicitNodeIds.insert(elementId);
|
||||
}
|
||||
@@ -850,6 +907,10 @@ std::vector<Id> PersistentStorage::getNodeIdsForLocationIds(const std::vector<Id
|
||||
nodeIds.insert(elementId);
|
||||
}
|
||||
}
|
||||
else // is file
|
||||
{
|
||||
nodeIds.insert(elementId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -874,7 +935,7 @@ std::vector<Id> PersistentStorage::getLocalSymbolIdsForLocationIds(const std::ve
|
||||
{
|
||||
Id elementId = occurrence.elementId;
|
||||
|
||||
if (m_sqliteStorage.getNodeById(elementId).id == 0 && m_sqliteStorage.getEdgeById(elementId).id == 0)
|
||||
if (m_sqliteStorage.getFirstById<StorageNode>(elementId).id == 0 && m_sqliteStorage.getFirstById<StorageEdge>(elementId).id == 0)
|
||||
{
|
||||
localSymbolIds.insert(elementId);
|
||||
}
|
||||
@@ -885,14 +946,22 @@ std::vector<Id> PersistentStorage::getLocalSymbolIdsForLocationIds(const std::ve
|
||||
|
||||
std::vector<Id> PersistentStorage::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
|
||||
{
|
||||
FilePath rootPath = getDbFilePath().parentDirectory();
|
||||
std::set<Id> idSet;
|
||||
for (const SearchMatch& match : matches)
|
||||
{
|
||||
for (size_t i = 0; i < match.nameHierarchies.size(); i++)
|
||||
if (match.nodeType == Node::NODE_FILE)
|
||||
{
|
||||
idSet.insert(
|
||||
m_sqliteStorage.getNodeBySerializedName(NameHierarchy::serialize(match.nameHierarchies[i])).id
|
||||
);
|
||||
idSet.insert(m_sqliteStorage.getFileByPath(rootPath.concat(match.subtext).str()).id);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < match.nameHierarchies.size(); i++)
|
||||
{
|
||||
idSet.insert(
|
||||
m_sqliteStorage.getNodeBySerializedName(NameHierarchy::serialize(match.nameHierarchies[i])).id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -935,10 +1004,9 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getTokenLocationsFor
|
||||
}
|
||||
}
|
||||
|
||||
for (Id fileId: fileIds)
|
||||
for (StorageFile file: m_sqliteStorage.getAllByIds<StorageFile>(fileIds))
|
||||
{
|
||||
StorageFile storageFile = m_sqliteStorage.getFileById(fileId);
|
||||
collection->addTokenLocationFile(m_sqliteStorage.getTokenLocationsForFile(storageFile.filePath));
|
||||
collection->addTokenLocationFile(m_sqliteStorage.getTokenLocationsForFile(file.filePath));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -950,7 +1018,7 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getTokenLocationsFor
|
||||
locationIdToElementIdMap[occurrence.sourceLocationId] = occurrence.elementId;
|
||||
}
|
||||
|
||||
for (const StorageSourceLocation& sourceLocation: m_sqliteStorage.getSourceLocationsByIds(locationIds))
|
||||
for (const StorageSourceLocation& sourceLocation: m_sqliteStorage.getAllByIds<StorageSourceLocation>(locationIds))
|
||||
{
|
||||
auto it = locationIdToElementIdMap.find(sourceLocation.id);
|
||||
if (it != locationIdToElementIdMap.end())
|
||||
@@ -983,10 +1051,9 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getTokenLocationsFor
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> collection = std::make_shared<TokenLocationCollection>();
|
||||
|
||||
for (size_t i = 0; i < locationIds.size(); i++)
|
||||
for (StorageSourceLocation location: m_sqliteStorage.getAllByIds<StorageSourceLocation>(locationIds))
|
||||
{
|
||||
StorageSourceLocation location = m_sqliteStorage.getSourceLocationById(locationIds[i]);
|
||||
for (const StorageOccurrence& occurrences: m_sqliteStorage.getOccurrencesForLocationId(locationIds[i]))
|
||||
for (const StorageOccurrence& occurrences: m_sqliteStorage.getOccurrencesForLocationId(location.id))
|
||||
{
|
||||
collection->addTokenLocation(
|
||||
location.id,
|
||||
@@ -1048,7 +1115,7 @@ std::shared_ptr<TextAccess> PersistentStorage::getFileContent(const FilePath& fi
|
||||
|
||||
FileInfo PersistentStorage::getFileInfoForFilePath(const FilePath& filePath) const
|
||||
{
|
||||
return FileInfo(filePath, m_sqliteStorage.getFileByPath(filePath).modificationTime);
|
||||
return FileInfo(filePath, m_sqliteStorage.getFileByPath(filePath.str()).modificationTime);
|
||||
}
|
||||
|
||||
std::vector<FileInfo> PersistentStorage::getFileInfosForFilePaths(const std::vector<FilePath>& filePaths) const
|
||||
@@ -1074,7 +1141,7 @@ StorageStats PersistentStorage::getStorageStats() const
|
||||
stats.edgeCount = m_sqliteStorage.getEdgeCount();
|
||||
|
||||
stats.fileCount = m_sqliteStorage.getFileCount();
|
||||
stats.fileLOCCount = m_sqliteStorage.getFileLOCCount();
|
||||
stats.fileLOCCount = m_sqliteStorage.getFileLineSum();
|
||||
|
||||
return stats;
|
||||
}
|
||||
@@ -1099,7 +1166,7 @@ ErrorCountInfo PersistentStorage::getErrorCount() const
|
||||
|
||||
std::vector<ErrorInfo> PersistentStorage::getErrors() const
|
||||
{
|
||||
std::vector<ErrorInfo> errors = m_sqliteStorage.getAllErrors();
|
||||
std::vector<ErrorInfo> errors = m_sqliteStorage.getAll<StorageError>();
|
||||
std::vector<ErrorInfo> filteredErrors;
|
||||
|
||||
for (const ErrorInfo& error : errors)
|
||||
@@ -1118,7 +1185,7 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getErrorTokenLocatio
|
||||
TRACE();
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> errorCollection = std::make_shared<TokenLocationCollection>();
|
||||
for (const ErrorInfo& error : m_sqliteStorage.getAllErrors())
|
||||
for (const ErrorInfo& error : m_sqliteStorage.getAll<StorageError>())
|
||||
{
|
||||
if (m_errorFilter.filter(error))
|
||||
{
|
||||
@@ -1233,7 +1300,7 @@ std::set<FilePath> PersistentStorage::getDependingFilePathsForImports(const std:
|
||||
importedSourceLocationToElementIds[occurrence.sourceLocationId] = occurrence.elementId;
|
||||
}
|
||||
|
||||
for (const StorageSourceLocation& sourceLocation: m_sqliteStorage.getSourceLocationsByIds(importedSourceLocationIds))
|
||||
for (const StorageSourceLocation& sourceLocation: m_sqliteStorage.getAllByIds<StorageSourceLocation>(importedSourceLocationIds))
|
||||
{
|
||||
auto it = importedSourceLocationToElementIds.find(sourceLocation.id);
|
||||
if (it != importedSourceLocationToElementIds.end())
|
||||
@@ -1317,16 +1384,14 @@ void PersistentStorage::addNodesToGraph(const std::vector<Id>& nodeIds, Graph* g
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<StorageNode> storageNodes = m_sqliteStorage.getNodesByIds(nodeIds);
|
||||
|
||||
for (const StorageNode& storageNode : storageNodes)
|
||||
for (const StorageSymbol& storageSymbol : m_sqliteStorage.getAllByIds<StorageSymbol>(nodeIds))
|
||||
{
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(storageNode.serializedName);
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(storageSymbol.serializedName);
|
||||
|
||||
Node::NodeType type = Node::intToType(storageNode.type);
|
||||
DefinitionType defType = intToDefinitionType(storageNode.definitionType);
|
||||
Node::NodeType type = Node::intToType(storageSymbol.type);
|
||||
DefinitionType defType = intToDefinitionType(storageSymbol.definitionType);
|
||||
Node* node = graph->createNode(
|
||||
storageNode.id,
|
||||
storageSymbol.id,
|
||||
type,
|
||||
nameHierarchy,
|
||||
defType != DEFINITION_NONE
|
||||
@@ -1352,6 +1417,17 @@ void PersistentStorage::addNodesToGraph(const std::vector<Id>& nodeIds, Graph* g
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const StorageFile& storageFile : m_sqliteStorage.getAllByIds<StorageFile>(nodeIds))
|
||||
{
|
||||
Node* node = graph->createNode(
|
||||
storageFile.id,
|
||||
Node::NODE_FILE,
|
||||
NameHierarchy::deserialize(storageFile.serializedName),
|
||||
true
|
||||
);
|
||||
node->setExplicit(true);
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::addEdgesToGraph(const std::vector<Id>& edgeIds, Graph* graph) const
|
||||
@@ -1363,8 +1439,7 @@ void PersistentStorage::addEdgesToGraph(const std::vector<Id>& edgeIds, Graph* g
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> storageEdges = m_sqliteStorage.getEdgesByIds(edgeIds);
|
||||
for (const StorageEdge& storageEdge : storageEdges)
|
||||
for (const StorageEdge& storageEdge : m_sqliteStorage.getAllByIds<StorageEdge>(edgeIds))
|
||||
{
|
||||
Node* sourceNode = graph->getNodeById(storageEdge.sourceNodeId);
|
||||
Node* targetNode = graph->getNodeById(storageEdge.targetNodeId);
|
||||
@@ -1395,8 +1470,7 @@ void PersistentStorage::addNodesWithChildrenAndEdgesToGraph(
|
||||
|
||||
if (edgeIds.size() > 0)
|
||||
{
|
||||
std::vector<StorageEdge> storageEdges = m_sqliteStorage.getEdgesByIds(edgeIds);
|
||||
for (const StorageEdge& storageEdge : storageEdges)
|
||||
for (const StorageEdge& storageEdge : m_sqliteStorage.getAllByIds<StorageEdge>(edgeIds))
|
||||
{
|
||||
parentNodeIds.insert(getLastVisibleParentNodeId(storageEdge.sourceNodeId));
|
||||
parentNodeIds.insert(getLastVisibleParentNodeId(storageEdge.targetNodeId));
|
||||
@@ -1548,30 +1622,28 @@ void PersistentStorage::buildSearchIndex()
|
||||
|
||||
FilePath dbPath = getDbFilePath();
|
||||
|
||||
for (StorageNode node : m_sqliteStorage.getAllNodes())
|
||||
for (StorageSymbol symbol : m_sqliteStorage.getAll<StorageSymbol>())
|
||||
{
|
||||
if (intToDefinitionType(node.definitionType) != DEFINITION_IMPLICIT)
|
||||
if (intToDefinitionType(symbol.definitionType) != DEFINITION_IMPLICIT)
|
||||
{
|
||||
if (Node::intToType(node.type) == Node::NODE_FILE)
|
||||
{
|
||||
FilePath filePath = m_fileNodePaths[node.id];
|
||||
|
||||
if (filePath.exists())
|
||||
{
|
||||
filePath = filePath.relativeTo(dbPath);
|
||||
}
|
||||
|
||||
m_fileIndex.addNode(node.id, filePath.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// we don't use the signature here, so elements with the same signature share the same node.
|
||||
m_elementIndex.addNode(node.id, NameHierarchy::deserialize(node.serializedName).getQualifiedName());
|
||||
}
|
||||
// we don't use the signature here, so elements with the same signature share the same node.
|
||||
m_symbolIndex.addNode(symbol.id, NameHierarchy::deserialize(symbol.serializedName).getQualifiedName());
|
||||
}
|
||||
}
|
||||
|
||||
m_elementIndex.finishSetup();
|
||||
for (StorageFile file : m_sqliteStorage.getAll<StorageFile>())
|
||||
{
|
||||
FilePath filePath = file.filePath;
|
||||
|
||||
if (filePath.exists())
|
||||
{
|
||||
filePath = filePath.relativeTo(dbPath);
|
||||
}
|
||||
|
||||
m_fileIndex.addNode(file.id, filePath.str());
|
||||
}
|
||||
|
||||
m_symbolIndex.finishSetup();
|
||||
m_fileIndex.finishSetup();
|
||||
}
|
||||
|
||||
@@ -1579,7 +1651,7 @@ void PersistentStorage::buildFilePathMaps()
|
||||
{
|
||||
TRACE();
|
||||
|
||||
for (StorageFile file: m_sqliteStorage.getAllFiles())
|
||||
for (StorageFile file: m_sqliteStorage.getAll<StorageFile>())
|
||||
{
|
||||
m_fileNodeIds.emplace(file.filePath, file.id);
|
||||
m_fileNodePaths.emplace(file.id, file.filePath);
|
||||
@@ -1590,7 +1662,7 @@ void PersistentStorage::buildFullTextSearchIndex() const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
for (StorageFile file : m_sqliteStorage.getAllFiles())
|
||||
for (StorageFile file : m_sqliteStorage.getAll<StorageFile>())
|
||||
{
|
||||
m_fullTextSearchIndex.addFile(file.id, m_sqliteStorage.getFileContentById(file.id)->getText());
|
||||
}
|
||||
@@ -1603,7 +1675,7 @@ void PersistentStorage::buildHierarchyCache()
|
||||
std::vector<StorageEdge> memberEdges = m_sqliteStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_MEMBER));
|
||||
|
||||
Cache<Id, Node::NodeType> nodeTypeCache([this](Id id){
|
||||
return Node::intToType(m_sqliteStorage.getNodeById(id).type);
|
||||
return Node::intToType(m_sqliteStorage.getFirstById<StorageNode>(id).type);
|
||||
});
|
||||
|
||||
for (const StorageEdge& edge : memberEdges)
|
||||
|
||||
@@ -27,8 +27,8 @@ public:
|
||||
PersistentStorage(const FilePath& dbPath);
|
||||
virtual ~PersistentStorage();
|
||||
|
||||
virtual Id addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime);
|
||||
virtual Id addNode(int type, const std::string& serializedName, int definitionType);
|
||||
virtual Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime);
|
||||
virtual Id addSymbol(int type, const std::string& serializedName, int definitionType);
|
||||
virtual Id addEdge(int type, Id sourceId, Id targetId);
|
||||
virtual Id addLocalSymbol(const std::string& name);
|
||||
virtual Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
|
||||
|
||||
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const;
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
|
||||
virtual void forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachEdge(std::function<void(const Id /*id*/, const StorageEdge& /*data*/)> callback) const;
|
||||
virtual void forEachLocalSymbol(std::function<void(const Id /*id*/, const StorageLocalSymbol& /*data*/)> callback) const;
|
||||
virtual void forEachSourceLocation(std::function<void(const Id /*id*/, const StorageSourceLocation& /*data*/)> callback) const;
|
||||
@@ -84,6 +84,9 @@ public:
|
||||
virtual std::shared_ptr<TokenLocationCollection> getFullTextSearchLocations(
|
||||
const std::string& searchTerm, bool caseSensitive) const;
|
||||
virtual std::vector<SearchMatch> getAutocompletionMatches(const std::string& query) const;
|
||||
std::set<SearchMatch> getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const;
|
||||
std::set<SearchMatch> getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const;
|
||||
std::set<SearchMatch> getAutocompletionCommandMatches(const std::string& query) const;
|
||||
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& elementIds) const;
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForAll() const;
|
||||
@@ -147,12 +150,10 @@ private:
|
||||
void buildFullTextSearchIndex() const;
|
||||
void buildHierarchyCache();
|
||||
|
||||
void log(std::string type, std::string str, const ParseLocation& location) const;
|
||||
|
||||
size_t m_preInjectionErrorCount;
|
||||
|
||||
SearchIndex m_commandIndex;
|
||||
SearchIndex m_elementIndex;
|
||||
SearchIndex m_symbolIndex;
|
||||
SearchIndex m_fileIndex;
|
||||
|
||||
mutable FullTextSearchIndex m_fullTextSearchIndex;
|
||||
|
||||
+171
-159
@@ -12,7 +12,7 @@
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/Version.h"
|
||||
|
||||
const size_t SqliteStorage::STORAGE_VERSION = 6;
|
||||
const size_t SqliteStorage::STORAGE_VERSION = 7;
|
||||
|
||||
SqliteStorage::SqliteStorage(const FilePath& dbFilePath)
|
||||
: m_dbFilePath(dbFilePath)
|
||||
@@ -184,14 +184,14 @@ Id SqliteStorage::addEdge(int type, Id sourceNodeId, Id targetNodeId)
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteStorage::addNode(int type, const std::string& serializedName, int definitionType)
|
||||
Id SqliteStorage::addNode(int type, const std::string& serializedName)
|
||||
{
|
||||
executeStatement("INSERT INTO element(id) VALUES(NULL);");
|
||||
Id id = m_database.lastRowId();
|
||||
|
||||
CppSQLite3Statement stmt = m_database.compileStatement((
|
||||
"INSERT INTO node(id, type, serialized_name, definition_type) VALUES("
|
||||
+ std::to_string(id) + ", " + std::to_string(type) + ", ?, " + std::to_string(definitionType) + ");"
|
||||
"INSERT INTO node(id, type, serialized_name) VALUES("
|
||||
+ std::to_string(id) + ", " + std::to_string(type) + ", ?);"
|
||||
).c_str());
|
||||
|
||||
stmt.bind(1, serializedName.c_str());
|
||||
@@ -200,15 +200,27 @@ Id SqliteStorage::addNode(int type, const std::string& serializedName, int defin
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteStorage::addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime)
|
||||
Id SqliteStorage::addSymbol(int type, const std::string& serializedName, int definitionType)
|
||||
{
|
||||
Id id = addNode(Node::NODE_FILE, serializedName, definitionTypeToInt(DEFINITION_EXPLICIT));
|
||||
std::shared_ptr<TextAccess> content = TextAccess::createFromFile(filePath);
|
||||
unsigned int loc = content->getLineCount();
|
||||
Id id = addNode(type, serializedName);
|
||||
|
||||
executeStatement(
|
||||
"INSERT INTO file(id, path, modification_time, loc) VALUES("
|
||||
+ std::to_string(id) + ", '" + filePath + "', '" + modificationTime + "', " + std::to_string(loc) + ");"
|
||||
"INSERT INTO symbol(id, definition_type) VALUES("
|
||||
+ std::to_string(id) + ", " + std::to_string(definitionType) + ");"
|
||||
);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteStorage::addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime)
|
||||
{
|
||||
Id id = addNode(Node::NODE_FILE, serializedName);
|
||||
std::shared_ptr<TextAccess> content = TextAccess::createFromFile(filePath);
|
||||
unsigned int lineCount = content->getLineCount();
|
||||
|
||||
executeStatement(
|
||||
"INSERT INTO file(id, path, modification_time, line_count) VALUES("
|
||||
+ std::to_string(id) + ", '" + filePath + "', '" + modificationTime + "', " + std::to_string(lineCount) + ");"
|
||||
);
|
||||
|
||||
CppSQLite3Statement stmt = m_database.compileStatement((
|
||||
@@ -442,83 +454,88 @@ bool SqliteStorage::isFile(Id elementId) const
|
||||
return (count > 0);
|
||||
}
|
||||
|
||||
StorageEdge SqliteStorage::getEdgeById(Id edgeId) const
|
||||
{
|
||||
return getFirst<StorageEdge>("WHERE id == " + std::to_string(edgeId));
|
||||
}
|
||||
|
||||
StorageEdge SqliteStorage::getEdgeBySourceTargetType(Id sourceId, Id targetId, int type) const
|
||||
{
|
||||
return getFirst<StorageEdge>("WHERE "
|
||||
return doGetFirst<StorageEdge>("WHERE "
|
||||
"source_node_id == " + std::to_string(sourceId) + " AND "
|
||||
"target_node_id == " + std::to_string(targetId) + " AND "
|
||||
"type == " + std::to_string(type)
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesByIds(const std::vector<Id>& edgeIds) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE id IN (" + utility::join(utility::toStrings(edgeIds), ',') + ")");
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesBySourceId(Id sourceId) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE source_node_id == " + std::to_string(sourceId));
|
||||
return doGetAll<StorageEdge>("WHERE source_node_id == " + std::to_string(sourceId));
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesBySourceIds(const std::vector<Id>& sourceIds) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE source_node_id IN (" + utility::join(utility::toStrings(sourceIds), ',') + ")");
|
||||
return doGetAll<StorageEdge>("WHERE source_node_id IN (" + utility::join(utility::toStrings(sourceIds), ',') + ")");
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesByTargetId(Id targetId) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE target_node_id == " + std::to_string(targetId));
|
||||
return doGetAll<StorageEdge>("WHERE target_node_id == " + std::to_string(targetId));
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesByTargetIds(const std::vector<Id>& targetIds) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE target_node_id IN (" + utility::join(utility::toStrings(targetIds), ',') + ")");
|
||||
return doGetAll<StorageEdge>("WHERE target_node_id IN (" + utility::join(utility::toStrings(targetIds), ',') + ")");
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesBySourceOrTargetId(Id id) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE source_node_id == " + std::to_string(id) + " OR target_node_id == " + std::to_string(id));
|
||||
return doGetAll<StorageEdge>("WHERE source_node_id == " + std::to_string(id) + " OR target_node_id == " + std::to_string(id));
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesByType(int type) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE type == " + std::to_string(type));
|
||||
return doGetAll<StorageEdge>("WHERE type == " + std::to_string(type));
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesBySourceType(Id sourceId, int type) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE source_node_id == " + std::to_string(sourceId) + " AND type == " + std::to_string(type));
|
||||
return doGetAll<StorageEdge>("WHERE source_node_id == " + std::to_string(sourceId) + " AND type == " + std::to_string(type));
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesByTargetType(Id targetId, int type) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE target_node_id == " + std::to_string(targetId) + " AND type == " + std::to_string(type));
|
||||
return doGetAll<StorageEdge>("WHERE target_node_id == " + std::to_string(targetId) + " AND type == " + std::to_string(type));
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getEdgesByTargetType(const std::vector<Id>& targetIds, int type) const
|
||||
{
|
||||
return getAll<StorageEdge>("WHERE target_node_id IN (" + utility::join(utility::toStrings(targetIds), ',') + ") AND type == " + std::to_string(type));
|
||||
}
|
||||
|
||||
StorageNode SqliteStorage::getNodeById(Id id) const
|
||||
{
|
||||
if (id != 0)
|
||||
{
|
||||
return getFirst<StorageNode>("WHERE id == " + std::to_string(id));
|
||||
}
|
||||
return StorageNode();
|
||||
return doGetAll<StorageEdge>("WHERE target_node_id IN (" + utility::join(utility::toStrings(targetIds), ',') + ") AND type == " + std::to_string(type));
|
||||
}
|
||||
|
||||
StorageNode SqliteStorage::getNodeBySerializedName(const std::string& serializedName) const
|
||||
{
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(
|
||||
"SELECT id, type, serialized_name, definition_type FROM node WHERE serialized_name == ? LIMIT 1;"
|
||||
"SELECT id, type, serialized_name FROM node WHERE serialized_name == ? LIMIT 1;"
|
||||
);
|
||||
|
||||
stmt.bind(1, serializedName.c_str());
|
||||
CppSQLite3Query q = executeQuery(stmt);
|
||||
|
||||
if (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const int type = q.getIntField(1, -1);
|
||||
const std::string serializedName = q.getStringField(2, "");
|
||||
|
||||
if (id != 0 && type != -1)
|
||||
{
|
||||
return StorageNode(id, type, serializedName);
|
||||
}
|
||||
}
|
||||
|
||||
return StorageNode();
|
||||
}
|
||||
|
||||
StorageSymbol SqliteStorage::getSymbolBySerializedName(const std::string& serializedName) const
|
||||
{
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(
|
||||
"SELECT node.id, node.type, node.serialized_name, symbol.definition_type FROM node INNER JOIN symbol ON node.id = symbol.id WHERE node.serialized_name == ? LIMIT 1;"
|
||||
);
|
||||
|
||||
stmt.bind(1, serializedName.c_str());
|
||||
@@ -533,36 +550,26 @@ StorageNode SqliteStorage::getNodeBySerializedName(const std::string& serialized
|
||||
|
||||
if (id != 0 && type != -1)
|
||||
{
|
||||
return StorageNode(id, type, serializedName, definitionType);
|
||||
return StorageSymbol(id, type, serializedName, definitionType);
|
||||
}
|
||||
}
|
||||
|
||||
return StorageNode();
|
||||
}
|
||||
|
||||
std::vector<StorageNode> SqliteStorage::getNodesByIds(const std::vector<Id>& nodeIds) const
|
||||
{
|
||||
return getAll<StorageNode>("WHERE id IN (" + utility::join(utility::toStrings(nodeIds), ',') + ")");
|
||||
return StorageSymbol();
|
||||
}
|
||||
|
||||
StorageLocalSymbol SqliteStorage::getLocalSymbolByName(const std::string& name) const
|
||||
{
|
||||
return getFirst<StorageLocalSymbol>("WHERE name == '" + name + "'");
|
||||
return doGetFirst<StorageLocalSymbol>("WHERE name == '" + name + "'");
|
||||
}
|
||||
|
||||
StorageFile SqliteStorage::getFileById(const Id id) const
|
||||
StorageFile SqliteStorage::getFileByPath(const std::string& filePath) const
|
||||
{
|
||||
return getFirst<StorageFile>("WHERE node.id == " + std::to_string(id));
|
||||
}
|
||||
|
||||
StorageFile SqliteStorage::getFileByPath(const FilePath& filePath) const
|
||||
{
|
||||
return getFirst<StorageFile>("WHERE file.path == '" + filePath.str() + "'");
|
||||
return doGetFirst<StorageFile>("WHERE file.path == '" + filePath + "'");
|
||||
}
|
||||
|
||||
std::vector<StorageFile> SqliteStorage::getFilesByPaths(const std::vector<FilePath>& filePaths) const
|
||||
{
|
||||
return getAll<StorageFile>("WHERE file.path IN ('" + utility::join(utility::toStrings(filePaths), "', '") + "')");
|
||||
return doGetAll<StorageFile>("WHERE file.path IN ('" + utility::join(utility::toStrings(filePaths), "', '") + "')");
|
||||
}
|
||||
|
||||
std::shared_ptr<TextAccess> SqliteStorage::getFileContentById(Id fileId) const
|
||||
@@ -609,30 +616,16 @@ void SqliteStorage::setNodeType(int type, Id nodeId)
|
||||
);
|
||||
}
|
||||
|
||||
void SqliteStorage::setNodeDefinitionType(int definitionType, Id nodeId)
|
||||
void SqliteStorage::setSymbolDefinitionType(int definitionType, Id symbolId)
|
||||
{
|
||||
executeStatement(
|
||||
"UPDATE node SET definition_type = " + std::to_string(definitionType) + " WHERE id == " + std::to_string(nodeId) + ";"
|
||||
);
|
||||
}
|
||||
|
||||
StorageSourceLocation SqliteStorage::getSourceLocationById(const Id id) const
|
||||
{
|
||||
return getFirst<StorageSourceLocation>(
|
||||
"WHERE id == " + std::to_string(id) + ";"
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<StorageSourceLocation> SqliteStorage::getSourceLocationsByIds(const std::vector<Id> ids) const
|
||||
{
|
||||
return getAll<StorageSourceLocation>(
|
||||
"WHERE id IN (" + utility::join(utility::toStrings(ids), ',') + ");"
|
||||
"UPDATE symbol SET definition_type = " + std::to_string(definitionType) + " WHERE id == " + std::to_string(symbolId) + ";"
|
||||
);
|
||||
}
|
||||
|
||||
StorageSourceLocation SqliteStorage::getSourceLocationByAll(const Id fileNodeId, const uint startLine, const uint startCol, const uint endLine, const uint endCol, const int type) const
|
||||
{
|
||||
return getFirst<StorageSourceLocation>(
|
||||
return doGetFirst<StorageSourceLocation>(
|
||||
"WHERE file_node_id == " + std::to_string(fileNodeId) +
|
||||
" AND start_line == " + std::to_string(startLine) +
|
||||
" AND start_column == " + std::to_string(startCol) +
|
||||
@@ -654,7 +647,7 @@ std::shared_ptr<TokenLocationFile> SqliteStorage::getTokenLocationsForFile(const
|
||||
|
||||
std::vector<Id> sourceLocationIds;
|
||||
std::unordered_map<Id, StorageSourceLocation> sourceLocationIdToData;
|
||||
for (const StorageSourceLocation& storageLocation: getAll<StorageSourceLocation>("WHERE file_node_id == " + std::to_string(fileNodeId)))
|
||||
for (const StorageSourceLocation& storageLocation: doGetAll<StorageSourceLocation>("WHERE file_node_id == " + std::to_string(fileNodeId)))
|
||||
{
|
||||
sourceLocationIds.push_back(storageLocation.id);
|
||||
sourceLocationIdToData[storageLocation.id] = storageLocation;
|
||||
@@ -690,73 +683,28 @@ std::vector<StorageOccurrence> SqliteStorage::getOccurrencesForLocationId(Id loc
|
||||
|
||||
std::vector<StorageOccurrence> SqliteStorage::getOccurrencesForLocationIds(const std::vector<Id>& locationIds) const
|
||||
{
|
||||
return getAll<StorageOccurrence>("WHERE source_location_id IN (" + utility::join(utility::toStrings(locationIds), ',') + ")");
|
||||
return doGetAll<StorageOccurrence>("WHERE source_location_id IN (" + utility::join(utility::toStrings(locationIds), ',') + ")");
|
||||
}
|
||||
|
||||
std::vector<StorageOccurrence> SqliteStorage::getOccurrencesForElementIds(const std::vector<Id>& elementIds) const
|
||||
{
|
||||
return getAll<StorageOccurrence>("WHERE element_id IN (" + utility::join(utility::toStrings(elementIds), ',') + ")");
|
||||
return doGetAll<StorageOccurrence>("WHERE element_id IN (" + utility::join(utility::toStrings(elementIds), ',') + ")");
|
||||
}
|
||||
|
||||
StorageComponentAccess SqliteStorage::getComponentAccessByNodeId(Id nodeId) const
|
||||
{
|
||||
return getFirst<StorageComponentAccess>("WHERE node_id == " + std::to_string(nodeId));
|
||||
return doGetFirst<StorageComponentAccess>("WHERE node_id == " + std::to_string(nodeId));
|
||||
}
|
||||
|
||||
std::vector<StorageComponentAccess> SqliteStorage::getComponentAccessesByNodeIds(const std::vector<Id>& nodeIds) const
|
||||
{
|
||||
return getAll<StorageComponentAccess>("WHERE node_id IN (" + utility::join(utility::toStrings(nodeIds), ',') + ")");
|
||||
return doGetAll<StorageComponentAccess>("WHERE node_id IN (" + utility::join(utility::toStrings(nodeIds), ',') + ")");
|
||||
}
|
||||
|
||||
std::vector<StorageCommentLocation> SqliteStorage::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
{
|
||||
Id fileNodeId = getFileByPath(filePath.str()).id;
|
||||
return getAll<StorageCommentLocation>("WHERE file_node_id == " + std::to_string(fileNodeId));
|
||||
}
|
||||
|
||||
std::vector<StorageFile> SqliteStorage::getAllFiles() const
|
||||
{
|
||||
return getAll<StorageFile>("");
|
||||
}
|
||||
|
||||
std::vector<StorageNode> SqliteStorage::getAllNodes() const
|
||||
{
|
||||
return getAll<StorageNode>("");
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> SqliteStorage::getAllEdges() const
|
||||
{
|
||||
return getAll<StorageEdge>("");
|
||||
}
|
||||
|
||||
std::vector<StorageLocalSymbol> SqliteStorage::getAllLocalSymbols() const
|
||||
{
|
||||
return getAll<StorageLocalSymbol>("");
|
||||
}
|
||||
|
||||
std::vector<StorageSourceLocation> SqliteStorage::getAllSourceLocations() const
|
||||
{
|
||||
return getAll<StorageSourceLocation>("");
|
||||
}
|
||||
|
||||
std::vector<StorageOccurrence> SqliteStorage::getAllOccurrences() const
|
||||
{
|
||||
return getAll<StorageOccurrence>("");
|
||||
}
|
||||
|
||||
std::vector<StorageComponentAccess> SqliteStorage::getAllComponentAccesses() const
|
||||
{
|
||||
return getAll<StorageComponentAccess>("");
|
||||
}
|
||||
|
||||
std::vector<StorageCommentLocation> SqliteStorage::getAllCommentLocations() const
|
||||
{
|
||||
return getAll<StorageCommentLocation>("");
|
||||
}
|
||||
|
||||
std::vector<StorageError> SqliteStorage::getAllErrors() const
|
||||
{
|
||||
return getAll<StorageError>("");
|
||||
return doGetAll<StorageCommentLocation>("WHERE file_node_id == " + std::to_string(fileNodeId));
|
||||
}
|
||||
|
||||
int SqliteStorage::getNodeCount() const
|
||||
@@ -774,9 +722,9 @@ int SqliteStorage::getFileCount() const
|
||||
return executeScalar("SELECT COUNT(*) FROM file;");
|
||||
}
|
||||
|
||||
int SqliteStorage::getFileLOCCount() const
|
||||
int SqliteStorage::getFileLineSum() const
|
||||
{
|
||||
return executeScalar("SELECT SUM(loc) FROM file;");
|
||||
return executeScalar("SELECT SUM(line_count) FROM file;");
|
||||
}
|
||||
|
||||
int SqliteStorage::getSourceLocationCount() const
|
||||
@@ -796,6 +744,7 @@ void SqliteStorage::clearTables()
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.local_symbol;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.filecontent;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.file;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.symbol;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.node;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.edge;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.element;");
|
||||
@@ -842,17 +791,24 @@ void SqliteStorage::setupTables()
|
||||
"id INTEGER NOT NULL, "
|
||||
"type INTEGER NOT NULL, "
|
||||
"serialized_name TEXT, "
|
||||
"definition_type INTEGER NOT NULL, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS symbol("
|
||||
"id INTEGER NOT NULL, "
|
||||
"definition_type INTEGER NOT NULL, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(id) REFERENCES node(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS file("
|
||||
"id INTEGER NOT NULL, "
|
||||
"path TEXT, "
|
||||
"modification_time TEXT, "
|
||||
"loc INTEGER, "
|
||||
"line_count INTEGER, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(id) REFERENCES node(id) ON DELETE CASCADE);"
|
||||
);
|
||||
@@ -1078,33 +1034,39 @@ void SqliteStorage::setApplicationVersion()
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageFile> SqliteStorage::getAll<StorageFile>(const std::string& query) const
|
||||
StorageSymbol SqliteStorage::getFirstById<StorageSymbol>(const Id id) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT file.id, node.serialized_name, file.path, file.modification_time FROM file "
|
||||
"INNER JOIN node ON file.id = node.id " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageFile> files;
|
||||
while (!q.eof())
|
||||
if (id != 0)
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const std::string serializedName = q.getStringField(1, "");
|
||||
const std::string filePath = q.getStringField(2, "");
|
||||
const std::string modificationTime = q.getStringField(3, "");
|
||||
|
||||
if (id != 0)
|
||||
{
|
||||
files.push_back(StorageFile(id, serializedName, filePath, modificationTime));
|
||||
}
|
||||
q.nextRow();
|
||||
return doGetFirst<StorageSymbol>("WHERE node.id == " + std::to_string(id));
|
||||
}
|
||||
|
||||
return files;
|
||||
return StorageSymbol();
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageEdge> SqliteStorage::getAll<StorageEdge>(const std::string& query) const
|
||||
StorageFile SqliteStorage::getFirstById<StorageFile>(const Id id) const
|
||||
{
|
||||
if (id != 0)
|
||||
{
|
||||
return doGetFirst<StorageFile>("WHERE node.id == " + std::to_string(id));
|
||||
}
|
||||
return StorageFile();
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageSymbol> SqliteStorage::getAllByIds<StorageSymbol>(const std::vector<Id>& ids) const
|
||||
{
|
||||
return doGetAll<StorageSymbol>("WHERE node.id IN (" + utility::join(utility::toStrings(ids), ',') + ")");
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageFile> SqliteStorage::getAllByIds<StorageFile>(const std::vector<Id>& ids) const
|
||||
{
|
||||
return doGetAll<StorageFile>("WHERE node.id IN (" + utility::join(utility::toStrings(ids), ',') + ")");
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageEdge> SqliteStorage::doGetAll<StorageEdge>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT id, type, source_node_id, target_node_id FROM edge " + query + ";"
|
||||
@@ -1129,14 +1091,38 @@ std::vector<StorageEdge> SqliteStorage::getAll<StorageEdge>(const std::string& q
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageNode> SqliteStorage::getAll<StorageNode>(const std::string& query) const
|
||||
std::vector<StorageNode> SqliteStorage::doGetAll<StorageNode>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT id, type, serialized_name, definition_type FROM node " + query + ";"
|
||||
"SELECT id, type, serialized_name FROM node " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageNode> nodes;
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const int type = q.getIntField(1, -1);
|
||||
const std::string serializedName = q.getStringField(2, "");
|
||||
|
||||
if (id != 0 && type != -1)
|
||||
{
|
||||
nodes.push_back(StorageNode(id, type, serializedName));
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageSymbol> SqliteStorage::doGetAll<StorageSymbol>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT node.id, node.type, node.serialized_name, symbol.definition_type FROM node INNER JOIN symbol ON node.id == symbol.id " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageSymbol> symbols;
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const int type = q.getIntField(1, -1);
|
||||
@@ -1145,16 +1131,42 @@ std::vector<StorageNode> SqliteStorage::getAll<StorageNode>(const std::string& q
|
||||
|
||||
if (id != 0 && type != -1)
|
||||
{
|
||||
nodes.push_back(StorageNode(id, type, serializedName, definitionType));
|
||||
symbols.push_back(StorageSymbol(id, type, serializedName, definitionType));
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
return nodes;
|
||||
return symbols;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageLocalSymbol> SqliteStorage::getAll<StorageLocalSymbol>(const std::string& query) const
|
||||
std::vector<StorageFile> SqliteStorage::doGetAll<StorageFile>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT file.id, node.serialized_name, file.path, file.modification_time FROM file "
|
||||
"INNER JOIN node ON file.id = node.id " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageFile> files;
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const std::string serializedName = q.getStringField(1, "");
|
||||
const std::string filePath = q.getStringField(2, "");
|
||||
const std::string modificationTime = q.getStringField(3, "");
|
||||
|
||||
if (id != 0)
|
||||
{
|
||||
files.push_back(StorageFile(id, serializedName, filePath, modificationTime));
|
||||
}
|
||||
q.nextRow();
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageLocalSymbol> SqliteStorage::doGetAll<StorageLocalSymbol>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT id, name FROM local_symbol " + query + ";"
|
||||
@@ -1178,7 +1190,7 @@ std::vector<StorageLocalSymbol> SqliteStorage::getAll<StorageLocalSymbol>(const
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageSourceLocation> SqliteStorage::getAll<StorageSourceLocation>(const std::string& query) const
|
||||
std::vector<StorageSourceLocation> SqliteStorage::doGetAll<StorageSourceLocation>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT id, file_node_id, start_line, start_column, end_line, end_column, type FROM source_location " + query + ";"
|
||||
@@ -1207,7 +1219,7 @@ std::vector<StorageSourceLocation> SqliteStorage::getAll<StorageSourceLocation>(
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageOccurrence> SqliteStorage::getAll<StorageOccurrence>(const std::string& query) const
|
||||
std::vector<StorageOccurrence> SqliteStorage::doGetAll<StorageOccurrence>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT element_id, source_location_id FROM occurrence " + query + ";"
|
||||
@@ -1231,7 +1243,7 @@ std::vector<StorageOccurrence> SqliteStorage::getAll<StorageOccurrence>(const st
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageComponentAccess> SqliteStorage::getAll<StorageComponentAccess>(const std::string& query) const
|
||||
std::vector<StorageComponentAccess> SqliteStorage::doGetAll<StorageComponentAccess>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT id, node_id, type FROM component_access " + query + ";"
|
||||
@@ -1256,7 +1268,7 @@ std::vector<StorageComponentAccess> SqliteStorage::getAll<StorageComponentAccess
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageCommentLocation> SqliteStorage::getAll<StorageCommentLocation>(const std::string& query) const
|
||||
std::vector<StorageCommentLocation> SqliteStorage::doGetAll<StorageCommentLocation>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT id, file_node_id, start_line, start_column, end_line, end_column FROM comment_location " + query + ";"
|
||||
@@ -1286,7 +1298,7 @@ std::vector<StorageCommentLocation> SqliteStorage::getAll<StorageCommentLocation
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageError> SqliteStorage::getAll<StorageError>(const std::string& query) const
|
||||
std::vector<StorageError> SqliteStorage::doGetAll<StorageError>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT message, fatal, indexed, file_path, line_number, column_number FROM error " + query + ";"
|
||||
|
||||
@@ -54,7 +54,11 @@ public:
|
||||
void setVersion();
|
||||
|
||||
Id addEdge(int type, Id sourceNodeId, Id targetNodeId);
|
||||
Id addNode(int type, const std::string& serializedName, int definitionType);
|
||||
|
||||
private:
|
||||
Id addNode(int type, const std::string& serializedName);
|
||||
public:
|
||||
Id addSymbol(int type, const std::string& serializedName, int definitionType);
|
||||
Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime);
|
||||
Id addLocalSymbol(const std::string& name);
|
||||
Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
@@ -73,9 +77,7 @@ public:
|
||||
bool isNode(Id elementId) const;
|
||||
bool isFile(Id elementId) const;
|
||||
|
||||
StorageEdge getEdgeById(Id edgeId) const;
|
||||
StorageEdge getEdgeBySourceTargetType(Id sourceId, Id targetId, int type) const;
|
||||
std::vector<StorageEdge> getEdgesByIds(const std::vector<Id>& edgeIds) const;
|
||||
|
||||
std::vector<StorageEdge> getEdgesBySourceId(Id sourceId) const;
|
||||
std::vector<StorageEdge> getEdgesBySourceIds(const std::vector<Id>& sourceIds) const;
|
||||
@@ -88,24 +90,20 @@ public:
|
||||
std::vector<StorageEdge> getEdgesByTargetType(Id targetId, int type) const;
|
||||
std::vector<StorageEdge> getEdgesByTargetType(const std::vector<Id>& targetIds, int type) const;
|
||||
|
||||
StorageNode getNodeById(Id id) const;
|
||||
StorageNode getNodeBySerializedName(const std::string& serializedName) const;
|
||||
std::vector<StorageNode> getNodesByIds(const std::vector<Id>& nodeIds) const;
|
||||
StorageSymbol getSymbolBySerializedName(const std::string& serializedName) const;
|
||||
|
||||
StorageLocalSymbol getLocalSymbolByName(const std::string& name) const;
|
||||
|
||||
StorageFile getFileById(const Id id) const;
|
||||
StorageFile getFileByPath(const FilePath& filePath) const;
|
||||
StorageFile getFileByPath(const std::string& filePath) const;
|
||||
|
||||
std::vector<StorageFile> getFilesByPaths(const std::vector<FilePath>& filePaths) const;
|
||||
std::shared_ptr<TextAccess> getFileContentByPath(const std::string& filePath) const;
|
||||
std::shared_ptr<TextAccess> getFileContentById(Id fileId) const;
|
||||
|
||||
void setNodeType(int type, Id nodeId);
|
||||
void setNodeDefinitionType(int definitionType, Id nodeId);
|
||||
void setSymbolDefinitionType(int definitionType, Id symbolId);
|
||||
|
||||
StorageSourceLocation getSourceLocationById(const Id id) const;
|
||||
std::vector<StorageSourceLocation> getSourceLocationsByIds(const std::vector<Id> ids) const;
|
||||
StorageSourceLocation getSourceLocationByAll(const Id fileNodeId, const uint startLine, const uint startCol, const uint endLine, const uint endCol, const int type) const;
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const FilePath& filePath) const;
|
||||
|
||||
@@ -118,20 +116,32 @@ public:
|
||||
|
||||
std::vector<StorageCommentLocation> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
|
||||
std::vector<StorageFile> getAllFiles() const;
|
||||
std::vector<StorageNode> getAllNodes() const;
|
||||
std::vector<StorageEdge> getAllEdges() const;
|
||||
std::vector<StorageLocalSymbol> getAllLocalSymbols() const;
|
||||
std::vector<StorageSourceLocation> getAllSourceLocations() const;
|
||||
std::vector<StorageOccurrence> getAllOccurrences() const;
|
||||
std::vector<StorageComponentAccess> getAllComponentAccesses() const;
|
||||
std::vector<StorageCommentLocation> getAllCommentLocations() const;
|
||||
std::vector<StorageError> getAllErrors() const;
|
||||
template <typename ResultType>
|
||||
std::vector<ResultType> getAll() const
|
||||
{
|
||||
return doGetAll<ResultType>("");
|
||||
}
|
||||
|
||||
template <typename ResultType>
|
||||
ResultType getFirstById(const Id id) const
|
||||
{
|
||||
if (id != 0)
|
||||
{
|
||||
return doGetFirst<ResultType>("WHERE id == " + std::to_string(id));
|
||||
}
|
||||
return ResultType();
|
||||
}
|
||||
|
||||
template <typename ResultType>
|
||||
std::vector<ResultType> getAllByIds(const std::vector<Id>& ids) const
|
||||
{
|
||||
return doGetAll<ResultType>("WHERE id IN (" + utility::join(utility::toStrings(ids), ',') + ")");
|
||||
}
|
||||
|
||||
int getNodeCount() const;
|
||||
int getEdgeCount() const;
|
||||
int getFileCount() const;
|
||||
int getFileLOCCount() const;
|
||||
int getFileLineSum() const;
|
||||
int getSourceLocationCount() const;
|
||||
|
||||
private:
|
||||
@@ -158,12 +168,12 @@ private:
|
||||
void setApplicationVersion();
|
||||
|
||||
template <typename ResultType>
|
||||
std::vector<ResultType> getAll(const std::string& query) const;
|
||||
std::vector<ResultType> doGetAll(const std::string& query) const;
|
||||
|
||||
template <typename ResultType>
|
||||
ResultType getFirst(const std::string& query) const
|
||||
ResultType doGetFirst(const std::string& query) const
|
||||
{
|
||||
std::vector<ResultType> results = getAll<ResultType>(query + " LIMIT 1");
|
||||
std::vector<ResultType> results = doGetAll<ResultType>(query + " LIMIT 1");
|
||||
if (results.size() > 0)
|
||||
{
|
||||
return results[0];
|
||||
@@ -179,23 +189,35 @@ private:
|
||||
};
|
||||
|
||||
template <>
|
||||
std::vector<StorageFile> SqliteStorage::getAll<StorageFile>(const std::string& query) const;
|
||||
StorageSymbol SqliteStorage::getFirstById<StorageSymbol>(const Id id) const;
|
||||
template <>
|
||||
std::vector<StorageEdge> SqliteStorage::getAll<StorageEdge>(const std::string& query) const;
|
||||
StorageFile SqliteStorage::getFirstById<StorageFile>(const Id id) const;
|
||||
|
||||
template <>
|
||||
std::vector<StorageNode> SqliteStorage::getAll<StorageNode>(const std::string& query) const;
|
||||
std::vector<StorageSymbol> SqliteStorage::getAllByIds<StorageSymbol>(const std::vector<Id>& ids) const;
|
||||
template <>
|
||||
std::vector<StorageLocalSymbol> SqliteStorage::getAll<StorageLocalSymbol>(const std::string& query) const;
|
||||
std::vector<StorageFile> SqliteStorage::getAllByIds<StorageFile>(const std::vector<Id>& ids) const;
|
||||
|
||||
template <>
|
||||
std::vector<StorageSourceLocation> SqliteStorage::getAll<StorageSourceLocation>(const std::string& query) const;
|
||||
std::vector<StorageEdge> SqliteStorage::doGetAll<StorageEdge>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageOccurrence> SqliteStorage::getAll<StorageOccurrence>(const std::string& query) const;
|
||||
std::vector<StorageNode> SqliteStorage::doGetAll<StorageNode>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageComponentAccess> SqliteStorage::getAll<StorageComponentAccess>(const std::string& query) const;
|
||||
std::vector<StorageSymbol> SqliteStorage::doGetAll<StorageSymbol>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageCommentLocation> SqliteStorage::getAll<StorageCommentLocation>(const std::string& query) const;
|
||||
std::vector<StorageFile> SqliteStorage::doGetAll<StorageFile>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageError> SqliteStorage::getAll<StorageError>(const std::string& query) const;
|
||||
std::vector<StorageLocalSymbol> SqliteStorage::doGetAll<StorageLocalSymbol>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageSourceLocation> SqliteStorage::doGetAll<StorageSourceLocation>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageOccurrence> SqliteStorage::doGetAll<StorageOccurrence>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageComponentAccess> SqliteStorage::doGetAll<StorageComponentAccess>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageCommentLocation> SqliteStorage::doGetAll<StorageCommentLocation>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageError> SqliteStorage::doGetAll<StorageError>(const std::string& query) const;
|
||||
|
||||
|
||||
#endif // SQLITE_STORAGE_H
|
||||
|
||||
@@ -27,12 +27,12 @@ void Storage::inject(Storage* injected)
|
||||
injected->forEachFile(
|
||||
[&](Id injectedId, const StorageFile& injectedData)
|
||||
{
|
||||
if (injectedData.name.size() == 0)
|
||||
if (injectedData.serializedName.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Id ownId = addFile(injectedData.name, injectedData.filePath, injectedData.modificationTime);
|
||||
Id ownId = addFile(injectedData.serializedName, injectedData.filePath, injectedData.modificationTime);
|
||||
if (ownId != 0)
|
||||
{
|
||||
injectedIdToOwnId[injectedId] = ownId;
|
||||
@@ -40,10 +40,10 @@ void Storage::inject(Storage* injected)
|
||||
}
|
||||
);
|
||||
|
||||
injected->forEachNode(
|
||||
[&](Id injectedId, const StorageNode& injectedData)
|
||||
injected->forEachSymbol(
|
||||
[&](Id injectedId, const StorageSymbol& injectedData)
|
||||
{
|
||||
Id ownId = addNode(injectedData.type, injectedData.serializedName, injectedData.definitionType);
|
||||
Id ownId = addSymbol(injectedData.type, injectedData.serializedName, injectedData.definitionType);
|
||||
if (ownId != 0)
|
||||
{
|
||||
injectedIdToOwnId[injectedId] = ownId;
|
||||
|
||||
@@ -15,8 +15,8 @@ public:
|
||||
Storage();
|
||||
virtual ~Storage();
|
||||
|
||||
virtual Id addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime) = 0;
|
||||
virtual Id addNode(int type, const std::string& serializedName, int definitionType) = 0;
|
||||
virtual Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime) = 0;
|
||||
virtual Id addSymbol(int type, const std::string& serializedName, int definitionType) = 0;
|
||||
virtual Id addEdge(int type, Id sourceId, Id targetId) = 0;
|
||||
virtual Id addLocalSymbol(const std::string& name) = 0;
|
||||
virtual Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) = 0;
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed) = 0;
|
||||
|
||||
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const = 0;
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const = 0;
|
||||
virtual void forEachSymbol(std::function<void(const Id /*id*/, const StorageSymbol& /*data*/)> callback) const = 0;
|
||||
virtual void forEachEdge(std::function<void(const Id /*id*/, const StorageEdge& /*data*/)> callback) const = 0;
|
||||
virtual void forEachLocalSymbol(std::function<void(const Id /*id*/, const StorageLocalSymbol& /*data*/)> callback) const = 0;
|
||||
virtual void forEachSourceLocation(std::function<void(const Id /*id*/, const StorageSourceLocation& /*data*/)> callback) const = 0;
|
||||
|
||||
@@ -35,10 +35,30 @@ struct StorageNode
|
||||
StorageNode()
|
||||
: id(0)
|
||||
, type(0)
|
||||
, serializedName("")
|
||||
{}
|
||||
|
||||
StorageNode(Id id, int type, const std::string& serializedName)
|
||||
: id(id)
|
||||
, type(type)
|
||||
, serializedName(serializedName)
|
||||
{}
|
||||
|
||||
Id id;
|
||||
int type;
|
||||
std::string serializedName;
|
||||
};
|
||||
|
||||
struct StorageSymbol
|
||||
{
|
||||
StorageSymbol()
|
||||
: id(0)
|
||||
, type(0)
|
||||
, serializedName("")
|
||||
, definitionType(definitionTypeToInt(DEFINITION_NONE))
|
||||
{}
|
||||
|
||||
StorageNode(Id id, int type, const std::string& serializedName, int definitionType)
|
||||
StorageSymbol(Id id, int type, const std::string& serializedName, int definitionType)
|
||||
: id(id)
|
||||
, type(type)
|
||||
, serializedName(serializedName)
|
||||
@@ -55,20 +75,20 @@ struct StorageFile
|
||||
{
|
||||
StorageFile()
|
||||
: id(0)
|
||||
, name("")
|
||||
, serializedName("")
|
||||
, filePath("")
|
||||
, modificationTime("")
|
||||
{}
|
||||
|
||||
StorageFile(Id id, const std::string& name, const std::string& filePath, const std::string& modificationTime)
|
||||
StorageFile(Id id, const std::string& serializedName, const std::string& filePath, const std::string& modificationTime)
|
||||
: id(id)
|
||||
, name(name)
|
||||
, serializedName(serializedName)
|
||||
, filePath(filePath)
|
||||
, modificationTime(modificationTime)
|
||||
{}
|
||||
|
||||
Id id;
|
||||
std::string name;
|
||||
std::string serializedName;
|
||||
std::string filePath;
|
||||
std::string modificationTime;
|
||||
};
|
||||
|
||||
@@ -91,12 +91,12 @@ void ParserClientImpl::onLocalSymbolParsed(const std::string& name, const ParseL
|
||||
|
||||
void ParserClientImpl::onFileParsed(const FileInfo& fileInfo)
|
||||
{
|
||||
addFile(fileInfo.path.fileName(), fileInfo.path.str(), fileInfo.lastWriteTime.toString());
|
||||
addFile(fileInfo.path, fileInfo.lastWriteTime.toString());
|
||||
}
|
||||
|
||||
void ParserClientImpl::onCommentParsed(const ParseLocation& location)
|
||||
{
|
||||
addFile(location.filePath.str());
|
||||
addFile(location.filePath);
|
||||
addCommentLocation(location);
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ Id ParserClientImpl::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nam
|
||||
Node::NodeType currentType = (currentIsLastElement ? nodeType : Node::NODE_UNDEFINED); // TODO: rename to unknown!
|
||||
DefinitionType currentDefinitionType = (currentIsLastElement ? definitionType : DEFINITION_NONE);
|
||||
|
||||
Id nodeId = addNode(currentType, currentNameHierarchy, currentDefinitionType);
|
||||
Id nodeId = addSymbol(currentType, currentNameHierarchy, currentDefinitionType);
|
||||
|
||||
// Todo: performance optimization: check if node exists. dont add edge if it existed before...
|
||||
if (parentNodeId != 0)
|
||||
@@ -218,35 +218,34 @@ Id ParserClientImpl::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nam
|
||||
return parentNodeId;
|
||||
}
|
||||
|
||||
|
||||
Id ParserClientImpl::addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime)
|
||||
Id ParserClientImpl::addFile(const FilePath& filePath, const std::string& modificationTime)
|
||||
{
|
||||
if (!m_storage)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_storage->addFile(name, filePath, modificationTime);
|
||||
return m_storage->addFile(NameHierarchy::serialize(NameHierarchy(filePath.fileName())), filePath.str(), modificationTime);
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addFile(const std::string& filePath)
|
||||
Id ParserClientImpl::addFile(const FilePath& filePath)
|
||||
{
|
||||
if (!m_storage)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_storage->addFile("", filePath, "");
|
||||
return m_storage->addFile("", filePath.str(), "");
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addNode(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType)
|
||||
Id ParserClientImpl::addSymbol(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType)
|
||||
{
|
||||
if (!m_storage)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_storage->addNode(Node::typeToInt(nodeType), NameHierarchy::serialize(nameHierarchy), definitionTypeToInt(definitionType));
|
||||
return m_storage->addSymbol(Node::typeToInt(nodeType), NameHierarchy::serialize(nameHierarchy), definitionTypeToInt(definitionType));
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addEdge(int type, Id sourceId, Id targetId)
|
||||
@@ -293,7 +292,7 @@ void ParserClientImpl::addSourceLocation(Id elementId, const ParseLocation& loca
|
||||
}
|
||||
|
||||
Id sourceLocationId = m_storage->addSourceLocation(
|
||||
addFile(location.filePath.str()),
|
||||
addFile(location.filePath),
|
||||
location.startLineNumber,
|
||||
location.startColumnNumber,
|
||||
location.endLineNumber,
|
||||
@@ -325,7 +324,7 @@ void ParserClientImpl::addCommentLocation(const ParseLocation& location)
|
||||
}
|
||||
|
||||
m_storage->addCommentLocation(
|
||||
addFile(location.filePath.str()),
|
||||
addFile(location.filePath),
|
||||
location.startLineNumber,
|
||||
location.startColumnNumber,
|
||||
location.endLineNumber,
|
||||
|
||||
@@ -51,9 +51,9 @@ private:
|
||||
void addAccess(Id nodeId, AccessKind access);
|
||||
Id addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType);
|
||||
|
||||
Id addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime);
|
||||
Id addFile(const std::string& filePath);
|
||||
Id addNode(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType);
|
||||
Id addFile(const FilePath& filePath, const std::string& modificationTime);
|
||||
Id addFile(const FilePath& filePath);
|
||||
Id addSymbol(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType);
|
||||
Id addEdge(int type, Id sourceId, Id targetId);
|
||||
Id addLocalSymbol(const std::string& name);
|
||||
void addSourceLocation(Id elementId, const ParseLocation& location, int type);
|
||||
|
||||
@@ -22,7 +22,26 @@ public:
|
||||
|
||||
std::string getMatchesAsString() const
|
||||
{
|
||||
return SearchMatch::searchMatchesToString(m_matches);
|
||||
std::stringstream ss;
|
||||
|
||||
for (size_t i = 0; i < m_matches.size(); i++)
|
||||
{
|
||||
ss << '@';
|
||||
if (m_matches[i].nodeType == Node::NODE_FILE)
|
||||
{
|
||||
ss << m_matches[i].subtext;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_matches[i].subtext.empty())
|
||||
{
|
||||
ss << m_matches[i].subtext << NameHierarchy::getDelimiter();
|
||||
}
|
||||
ss << m_matches[i].name;
|
||||
}
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
const std::vector<SearchMatch>& getMatches() const
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
SqliteStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
storage.addNode(0, "a", false);
|
||||
storage.addSymbol(0, "a", false);
|
||||
storage.commitTransaction();
|
||||
nodeCount = storage.getNodeCount();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
SqliteStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
int nodeId = storage.addNode(0, "a", false);
|
||||
int nodeId = storage.addSymbol(0, "a", false);
|
||||
storage.removeElement(nodeId);
|
||||
storage.commitTransaction();
|
||||
nodeCount = storage.getNodeCount();
|
||||
@@ -51,8 +51,8 @@ public:
|
||||
SqliteStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
int sourceNodeId = storage.addNode(0, "a", false);
|
||||
int targetNodeId = storage.addNode(0, "b", false);
|
||||
int sourceNodeId = storage.addSymbol(0, "a", false);
|
||||
int targetNodeId = storage.addSymbol(0, "b", false);
|
||||
storage.addEdge(0, sourceNodeId, targetNodeId);
|
||||
storage.commitTransaction();
|
||||
edgeCount = storage.getEdgeCount();
|
||||
@@ -70,8 +70,8 @@ public:
|
||||
SqliteStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
int sourceNodeId = storage.addNode(0, "a", false);
|
||||
int targetNodeId = storage.addNode(0, "b", false);
|
||||
int sourceNodeId = storage.addSymbol(0, "a", false);
|
||||
int targetNodeId = storage.addSymbol(0, "b", false);
|
||||
int edgeId = storage.addEdge(0, sourceNodeId, targetNodeId);
|
||||
storage.removeElement(edgeId);
|
||||
storage.commitTransaction();
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
TestStorage storage;
|
||||
|
||||
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
|
||||
Id id = intermetiateStorage->addFile("test.h", "path/to/test.h", "someTime");
|
||||
Id id = intermetiateStorage->addFile(NameHierarchy::serialize(NameHierarchy("test.h")), "path/to/test.h", "someTime");
|
||||
|
||||
storage.inject(intermetiateStorage.get());
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
TestStorage storage;
|
||||
|
||||
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
|
||||
intermetiateStorage->addNode(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(a), true);
|
||||
intermetiateStorage->addSymbol(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(a), true);
|
||||
|
||||
storage.inject(intermetiateStorage.get());
|
||||
|
||||
@@ -56,8 +56,8 @@ public:
|
||||
TestStorage storage;
|
||||
|
||||
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
|
||||
Id aId = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_STRUCT), NameHierarchy::serialize(a), true);
|
||||
Id bId = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_FIELD), NameHierarchy::serialize(b), true);
|
||||
Id aId = intermetiateStorage->addSymbol(Node::typeToInt(Node::NODE_STRUCT), NameHierarchy::serialize(a), true);
|
||||
Id bId = intermetiateStorage->addSymbol(Node::typeToInt(Node::NODE_FIELD), NameHierarchy::serialize(b), true);
|
||||
intermetiateStorage->addEdge(Edge::typeToInt(Edge::EDGE_MEMBER), aId, bId);
|
||||
|
||||
storage.inject(intermetiateStorage.get());
|
||||
|
||||
Reference in New Issue
Block a user