src: miscellaneous bug fixes for upcoming release

* only randomize parsing order of source files for multithreaded indexing
* fixed overview not displayed when switching projects due to MessageScrollCode being dispatched
* avoid adding duplicate TokenLocations that causes highlighting to break in QtCodeArea
* clear all controllers when switching project
* maximize unindexed file when clicking title instead of activating it
This commit is contained in:
Eberhard Graether
2016-06-09 12:30:00 +02:00
parent 5173400b8d
commit 7e3b2622ec
33 changed files with 210 additions and 90 deletions
+3 -7
View File
@@ -869,9 +869,7 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getTokenLocationsFor
for (Id fileId: fileIds)
{
StorageFile storageFile = m_sqliteStorage.getFileById(fileId);
collection->addTokenLocationFileAsPlainCopy(
m_sqliteStorage.getTokenLocationsForFile(storageFile.filePath).get()
);
collection->addTokenLocationFile(m_sqliteStorage.getTokenLocationsForFile(storageFile.filePath));
}
std::vector<StorageSourceLocation> locations = m_sqliteStorage.getTokenLocationsForElementIds(nonFileIds);
@@ -923,16 +921,14 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getTokenLocationsFor
std::shared_ptr<TokenLocationFile> PersistentStorage::getTokenLocationsForFile(const std::string& filePath) const
{
std::shared_ptr<TokenLocationFile> locationFile = m_sqliteStorage.getTokenLocationsForFile(filePath);
locationFile->isWholeCopy = true;
return locationFile;
return m_sqliteStorage.getTokenLocationsForFile(filePath);
}
std::shared_ptr<TokenLocationFile> PersistentStorage::getTokenLocationsForLinesInFile(
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
) const
{
return m_sqliteStorage.getTokenLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber);
return getTokenLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber);
}
std::shared_ptr<TokenLocationCollection> PersistentStorage::getErrorTokenLocations(std::vector<ErrorInfo>* errors) const
+3 -1
View File
@@ -504,6 +504,8 @@ std::shared_ptr<TokenLocationFile> SqliteStorage::getTokenLocationsForFile(const
loc->setType(intToLocationType(location.type));
}
ret->isWholeCopy = true;
return ret;
}
@@ -661,7 +663,7 @@ void SqliteStorage::setupTables()
);
// TODO: move to createIndexesForAnalysis() or prepareForAnalysis
m_database.execDML( // used for checking for duplicates during code analysis
m_database.execDML( // used for checking for duplicates during code analysis
"CREATE INDEX IF NOT EXISTS edge_multipart_index ON edge(type, source_node_id, target_node_id);"
);
@@ -67,13 +67,21 @@ TokenLocation* TokenLocationCollection::addTokenLocation(
{
if (startLineNumber > endLineNumber || (startLineNumber == endLineNumber && startColumnNumber > endColumnNumber))
{
LOG_ERROR("Can't create TokenLocation with wrong boundaries.");
LOG_ERROR_STREAM(<< "TokenLocation has wrong boundaries: "<< filePath.str() << " "
<< startLineNumber << ":" << startColumnNumber << " "
<< endLineNumber << ":" << endColumnNumber);
return nullptr;
}
TokenLocation* location = findTokenLocationById(locationId);
if (location)
{
return location;
}
TokenLocationFile* file = createTokenLocationFile(filePath);
TokenLocation* location =
file->addTokenLocation(locationId, tokenId, startLineNumber, startColumnNumber, endLineNumber, endColumnNumber);
location = file->addTokenLocation(
locationId, tokenId, startLineNumber, startColumnNumber, endLineNumber, endColumnNumber);
m_locations.emplace(location->getId(), location);
return location;
@@ -98,6 +106,37 @@ void TokenLocationCollection::removeTokenLocation(TokenLocation* location)
}
}
TokenLocationFile* TokenLocationCollection::addTokenLocationFile(std::shared_ptr<TokenLocationFile> locationFile)
{
TokenLocationFile* file = findTokenLocationFileByPath(locationFile->getFilePath());
if (file)
{
LOG_ERROR("TokenLocationFile with same path already exists.");
return file;
}
m_files.emplace(locationFile->getFilePath(), locationFile);
locationFile->forEachTokenLocation(
[this, &file](TokenLocation* tokenLocation) -> void
{
m_locations.emplace(tokenLocation->getId(), tokenLocation);
}
);
return locationFile.get();
}
void TokenLocationCollection::removeTokenLocationFile(TokenLocationFile* file)
{
file->forEachTokenLocation(
[&](TokenLocation* location)
{
m_locations.erase(location->getId());
}
);
m_files.erase(file->getFilePath());
}
TokenLocation* TokenLocationCollection::findTokenLocationById(Id id) const
{
std::map<Id, TokenLocation*>::const_iterator it = m_locations.find(id);
@@ -115,7 +154,8 @@ TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const Fi
return getTokenLocationFileByPath(filePath).get();
}
void TokenLocationCollection::forEachTokenLocationFile(std::function<void(std::shared_ptr<TokenLocationFile>)> func) const
void TokenLocationCollection::forEachTokenLocationFile(
std::function<void(std::shared_ptr<TokenLocationFile>)> func) const
{
for (const TokenLocationFilePairType& file : m_files)
{
@@ -139,18 +179,6 @@ void TokenLocationCollection::forEachTokenLocation(std::function<void(TokenLocat
}
}
void TokenLocationCollection::removeTokenLocationFile(TokenLocationFile* file)
{
file->forEachTokenLocation(
[&](TokenLocation* location)
{
m_locations.erase(location->getId());
}
);
m_files.erase(file->getFilePath());
}
TokenLocationFile* TokenLocationCollection::addTokenLocationFileAsPlainCopy(const TokenLocationFile* locationFile)
{
TokenLocationFile* file = createTokenLocationFile(locationFile->getFilePath());
@@ -161,7 +189,6 @@ TokenLocationFile* TokenLocationCollection::addTokenLocationFileAsPlainCopy(cons
m_locations.emplace(copy->getId(), copy);
}
);
file->isWholeCopy = true;
return file;
}
@@ -38,6 +38,9 @@ public:
unsigned int endLineNumber, unsigned int endColumnNumber);
void removeTokenLocation(TokenLocation* location);
TokenLocationFile* addTokenLocationFile(std::shared_ptr<TokenLocationFile> locationFile);
void removeTokenLocationFile(TokenLocationFile* file);
TokenLocation* findTokenLocationById(Id id) const;
TokenLocationFile* findTokenLocationFileByPath(const FilePath& filePath) const;
@@ -45,8 +48,6 @@ public:
void forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const;
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
void removeTokenLocationFile(TokenLocationFile* file);
TokenLocationFile* addTokenLocationFileAsPlainCopy(const TokenLocationFile* locationFile);
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);
+34 -7
View File
@@ -57,14 +57,41 @@ TokenLocation* TokenLocationFile::addTokenLocation(
unsigned int endLineNumber, unsigned int endColumnNumber)
{
TokenLocationLine* line = createTokenLocationLine(startLineNumber);
TokenLocation* start = line->addStartTokenLocation(locationId, tokenId, startColumnNumber);
if (startLineNumber != endLineNumber)
// Check if a TokenLocation with the same start and end was already added.
TokenLocation* start = nullptr;
line->forEachStartTokenLocation(
[&](TokenLocation* startLocation)
{
if (start)
{
return;
}
TokenLocation* endLocation = startLocation->getEndTokenLocation();
if (startLocation->getTokenId() == tokenId &&
startLocation->getColumnNumber() == startColumnNumber &&
endLocation &&
endLocation->getLineNumber() == endLineNumber &&
endLocation->getColumnNumber() == endColumnNumber)
{
start = startLocation;
}
}
);
if (!start)
{
line = createTokenLocationLine(endLineNumber);
}
start = line->addStartTokenLocation(locationId, tokenId, startColumnNumber);
line->addEndTokenLocation(start, endColumnNumber);
if (startLineNumber != endLineNumber)
{
line = createTokenLocationLine(endLineNumber);
}
line->addEndTokenLocation(start, endColumnNumber);
}
return start;
}
@@ -132,7 +159,7 @@ TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocatio
TokenLocationLine* line = createTokenLocationLine(lineNumber);
// Check whether this location was already added or if the other TokenLocation was added.
TokenLocation* otherLocation = line->getTokenLocationByIdAndType(location->getId(), location->getType());
TokenLocation* otherLocation = line->getTokenLocationById(location->getId());
if (otherLocation)
{
if (otherLocation->isStartTokenLocation() == location->isStartTokenLocation())
@@ -150,7 +177,7 @@ TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocatio
TokenLocationLine* otherLine = findTokenLocationLine(otherLineNumber);
if (otherLine)
{
otherLocation = otherLine->getTokenLocationByIdAndType(location->getId(), location->getType());
otherLocation = otherLine->getTokenLocationById(location->getId());
}
}
}
+2 -2
View File
@@ -71,11 +71,11 @@ void TokenLocationLine::removeTokenLocation(TokenLocation* location)
LOG_ERROR("TokenLocation can't be removed, it's not part of the TokenLocationLine.");
}
TokenLocation* TokenLocationLine::getTokenLocationByIdAndType(Id id, LocationType type) const
TokenLocation* TokenLocationLine::getTokenLocationById(Id id) const
{
for (const TokenLocationPairType& p : m_locations)
{
if (p.second->getId() == id && p.second->getType() == type)
if (p.second->getId() == id)
{
return p.second.get();
}
+1 -3
View File
@@ -7,8 +7,6 @@
#include <ostream>
#include <string>
#include "data/location/LocationType.h"
#include "utility/file/FilePath.h"
#include "utility/types.h"
@@ -36,7 +34,7 @@ public:
TokenLocation* addEndTokenLocation(TokenLocation* start, unsigned int columnNumber);
void removeTokenLocation(TokenLocation* location);
TokenLocation* getTokenLocationByIdAndType(Id id, LocationType type) const;
TokenLocation* getTokenLocationById(Id id) const;
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
void forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const;