ui: scope names in snippet titles
* added title for snippets * title displays name of parent scope. * when new TokenLocationFiles are created in the storage they are now returned as shared_ptr to ensure correct linking in the contained data. * Storage::getTokenLocationsForLinesInFile() now always returns pairs of start and end locations. * Adjusted code snippet view to regard the change described above.
This commit is contained in:
@@ -976,9 +976,9 @@ TokenLocationCollection Storage::getTokenLocationsForTokenIds(const std::vector<
|
||||
return ret;
|
||||
}
|
||||
|
||||
TokenLocationFile Storage::getTokenLocationsForFile(const std::string& filePath) const
|
||||
std::shared_ptr<TokenLocationFile> Storage::getTokenLocationsForFile(const std::string& filePath) const
|
||||
{
|
||||
TokenLocationFile ret(filePath);
|
||||
std::shared_ptr<TokenLocationFile> ret = std::make_shared<TokenLocationFile>(filePath);
|
||||
|
||||
TokenLocationFile* locationFile = m_locationCollection.findTokenLocationFileByPath(filePath);
|
||||
if (!locationFile)
|
||||
@@ -989,18 +989,18 @@ TokenLocationFile Storage::getTokenLocationsForFile(const std::string& filePath)
|
||||
locationFile->forEachTokenLocation(
|
||||
[&](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
ret.addTokenLocationAsPlainCopy(tokenLocation);
|
||||
ret->addTokenLocationAsPlainCopy(tokenLocation);
|
||||
}
|
||||
);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
TokenLocationFile Storage::getTokenLocationsForLinesInFile(
|
||||
std::shared_ptr<TokenLocationFile> Storage::getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const
|
||||
{
|
||||
TokenLocationFile ret(filePath);
|
||||
std::shared_ptr<TokenLocationFile> ret = std::make_shared<TokenLocationFile>(filePath);
|
||||
|
||||
TokenLocationFile* locationFile = m_locationCollection.findTokenLocationFileByPath(filePath);
|
||||
if (!locationFile)
|
||||
@@ -1009,7 +1009,7 @@ TokenLocationFile Storage::getTokenLocationsForLinesInFile(
|
||||
}
|
||||
|
||||
uint endLineNumber = locationFile->getTokenLocationLines().rbegin()->first;
|
||||
|
||||
std::set<int> addedLocationIds;
|
||||
for (uint i = firstLineNumber; i <= endLineNumber; i++)
|
||||
{
|
||||
TokenLocationLine* locationLine = locationFile->findTokenLocationLineByNumber(i);
|
||||
@@ -1023,7 +1023,13 @@ TokenLocationFile Storage::getTokenLocationsForLinesInFile(
|
||||
locationLine->forEachTokenLocation(
|
||||
[&](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
ret.addTokenLocationAsPlainCopy(tokenLocation);
|
||||
const Id tokenId = tokenLocation->getId();
|
||||
if (addedLocationIds.find(tokenId) == addedLocationIds.end())
|
||||
{
|
||||
ret->addTokenLocationAsPlainCopy(tokenLocation->getStartTokenLocation());
|
||||
ret->addTokenLocationAsPlainCopy(tokenLocation->getEndTokenLocation());
|
||||
addedLocationIds.insert(tokenId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -1036,7 +1042,8 @@ TokenLocationFile Storage::getTokenLocationsForLinesInFile(
|
||||
if (tokenLocation->isEndTokenLocation() &&
|
||||
tokenLocation->getStartTokenLocation()->getLineNumber() < firstLineNumber)
|
||||
{
|
||||
ret.addTokenLocationAsPlainCopy(tokenLocation->getStartTokenLocation());
|
||||
ret->addTokenLocationAsPlainCopy(tokenLocation->getStartTokenLocation());
|
||||
ret->addTokenLocationAsPlainCopy(tokenLocation->getEndTokenLocation());
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -1062,7 +1069,6 @@ std::shared_ptr<TokenLocationFile> Storage::getTokenLocationOfParentScope(const
|
||||
[&](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
if (tokenLocation->getType() == TokenLocation::LOCATION_SCOPE &&
|
||||
tokenLocation->isStartTokenLocation() &&
|
||||
(*tokenLocation) < *(child->getStartTokenLocation()) &&
|
||||
(*tokenLocation->getEndTokenLocation()) > *(child->getEndTokenLocation()))
|
||||
{
|
||||
|
||||
@@ -119,8 +119,8 @@ public:
|
||||
virtual std::vector<Id> getTokenIdsForQuery(std::string query) const;
|
||||
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ public:
|
||||
virtual std::vector<Id> getTokenIdsForQuery(std::string query) const = 0;
|
||||
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const = 0;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const = 0;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0;
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const = 0;
|
||||
|
||||
@@ -122,17 +122,17 @@ TokenLocationCollection StorageAccessProxy::getTokenLocationsForTokenIds(const s
|
||||
return TokenLocationCollection();
|
||||
}
|
||||
|
||||
TokenLocationFile StorageAccessProxy::getTokenLocationsForFile(const std::string& filePath) const
|
||||
std::shared_ptr<TokenLocationFile> StorageAccessProxy::getTokenLocationsForFile(const std::string& filePath) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForFile(filePath);
|
||||
}
|
||||
|
||||
return TokenLocationFile("");
|
||||
return std::make_shared<TokenLocationFile>("");
|
||||
}
|
||||
|
||||
TokenLocationFile StorageAccessProxy::getTokenLocationsForLinesInFile(
|
||||
std::shared_ptr<TokenLocationFile> StorageAccessProxy::getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const
|
||||
{
|
||||
@@ -141,7 +141,7 @@ TokenLocationFile StorageAccessProxy::getTokenLocationsForLinesInFile(
|
||||
return m_subject->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
}
|
||||
|
||||
return TokenLocationFile("");
|
||||
return std::make_shared<TokenLocationFile>("");
|
||||
}
|
||||
|
||||
TokenLocationCollection StorageAccessProxy::getErrorTokenLocations(std::vector<std::string>* errorMessages) const
|
||||
|
||||
@@ -27,8 +27,8 @@ public:
|
||||
virtual std::vector<Id> getTokenIdsForQuery(std::string query) const;
|
||||
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
|
||||
@@ -105,11 +105,11 @@ TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const Fi
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TokenLocationCollection::forEachTokenLocationFile(std::function<void(TokenLocationFile*)> func) const
|
||||
void TokenLocationCollection::forEachTokenLocationFile(std::function<void(std::shared_ptr<TokenLocationFile>)> func) const
|
||||
{
|
||||
for (const TokenLocationFilePairType& file : m_files)
|
||||
{
|
||||
func(file.second.get());
|
||||
func(file.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,9 +188,9 @@ TokenLocationFile* TokenLocationCollection::createTokenLocationFile(const FilePa
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocationCollection& base)
|
||||
{
|
||||
ostream << "Locations:\n";
|
||||
base.forEachTokenLocationFile([&ostream](TokenLocationFile* f)
|
||||
base.forEachTokenLocationFile([&ostream](std::shared_ptr<TokenLocationFile> f)
|
||||
{
|
||||
ostream << *f;
|
||||
ostream << *(f.get());
|
||||
});
|
||||
return ostream;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
TokenLocation* findTokenLocationById(Id id) const;
|
||||
TokenLocationFile* findTokenLocationFileByPath(const FilePath& filePath) const;
|
||||
|
||||
void forEachTokenLocationFile(std::function<void(TokenLocationFile*)> func) const;
|
||||
void forEachTokenLocationFile(std::function<void(std::shared_ptr<TokenLocationFile>)> func) const;
|
||||
void forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const;
|
||||
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user