logic: Showing annotations in fulltext search results
* new LocationType for errors * refactored CodeController * cache active locations in CodeController for later manipulations
This commit is contained in:
@@ -29,7 +29,8 @@ const uint CodeController::s_lineRadius = 2;
|
||||
void CodeController::handleMessage(MessageActivateAll* message)
|
||||
{
|
||||
std::vector<ErrorInfo> errors;
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForErrorLocations(&errors);
|
||||
m_collection = m_storageAccess->getErrorTokenLocations(&errors);
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForCollection(m_collection);
|
||||
|
||||
StorageStats stats = m_storageAccess->getStorageStats();
|
||||
CodeSnippetParams statsSnippet;
|
||||
@@ -79,6 +80,7 @@ void CodeController::handleMessage(MessageActivateAll* message)
|
||||
snippets.insert(snippets.begin(), statsSnippet);
|
||||
|
||||
CodeView* view = getView();
|
||||
view->clear();
|
||||
view->setErrorInfos(errors);
|
||||
view->showCodeSnippets(snippets, std::vector<Id>());
|
||||
|
||||
@@ -94,19 +96,17 @@ void CodeController::handleMessage(MessageActivateLocalSymbols* message)
|
||||
void CodeController::handleMessage(MessageActivateTokens* message)
|
||||
{
|
||||
CodeView* view = getView();
|
||||
view->setErrorInfos(std::vector<ErrorInfo>());
|
||||
|
||||
if (!message->keepContent())
|
||||
{
|
||||
view->clear();
|
||||
}
|
||||
|
||||
std::vector<Id> activeTokenIds = message->tokenIds;
|
||||
Id declarationId = 0; // 0 means that no token is found.
|
||||
|
||||
if (!message->isAggregation)
|
||||
{
|
||||
if (activeTokenIds.size() != 1)
|
||||
{
|
||||
view->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
activeTokenIds = m_storageAccess->getActiveTokenIdsForId(activeTokenIds[0], &declarationId);
|
||||
}
|
||||
|
||||
@@ -114,18 +114,17 @@ void CodeController::handleMessage(MessageActivateTokens* message)
|
||||
{
|
||||
view->showFirstActiveSnippet(activeTokenIds, message->isLast());
|
||||
}
|
||||
|
||||
if (message->keepContent())
|
||||
else if (message->keepContent())
|
||||
{
|
||||
view->showActiveTokenIds(activeTokenIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::shared_ptr<TokenLocationCollection> collection = m_storageAccess->getTokenLocationsForTokenIds(activeTokenIds);
|
||||
view->showCodeSnippets(getSnippetsForActiveTokenLocations(collection.get(), declarationId), activeTokenIds);
|
||||
m_collection = m_storageAccess->getTokenLocationsForTokenIds(activeTokenIds);
|
||||
view->showCodeSnippets(getSnippetsForActiveTokenLocations(m_collection.get(), declarationId), activeTokenIds);
|
||||
|
||||
size_t fileCount = collection->getTokenLocationFileCount();
|
||||
size_t referenceCount = collection->getTokenLocationCount();
|
||||
size_t fileCount = m_collection->getTokenLocationFileCount();
|
||||
size_t referenceCount = m_collection->getTokenLocationCount();
|
||||
|
||||
std::stringstream ss;
|
||||
ss << message->tokenIds.size() << ' ';
|
||||
@@ -158,14 +157,8 @@ void CodeController::handleMessage(MessageChangeFileView* message)
|
||||
case MessageChangeFileView::FILE_SNIPPETS:
|
||||
if (message->needsData)
|
||||
{
|
||||
if (message->showErrors)
|
||||
{
|
||||
view->addCodeSnippets(getSnippetsForFile(message->locationFile), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
view->addCodeSnippets(getSnippetsForActiveTokenLocationsInFile(message->locationFile), false);
|
||||
}
|
||||
view->addCodeSnippets(getSnippetsForFile(
|
||||
m_collection->getTokenLocationFileByPath(message->filePath), !message->showErrors), false);
|
||||
}
|
||||
view->setFileState(message->filePath, CodeView::FILE_SNIPPETS);
|
||||
break;
|
||||
@@ -184,14 +177,26 @@ void CodeController::handleMessage(MessageChangeFileView* message)
|
||||
|
||||
if (message->showErrors)
|
||||
{
|
||||
std::vector<ErrorInfo> errors;
|
||||
TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(&errors);
|
||||
params.locationFile = std::make_shared<TokenLocationFile>(*errorCollection.findTokenLocationFileByPath(message->filePath));
|
||||
params.locationFile = m_collection->getTokenLocationFileByPath(message->filePath);
|
||||
params.locationFile->isWholeCopy = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
params.locationFile = m_storageAccess->getTokenLocationsForFile(message->filePath.str());
|
||||
std::shared_ptr<TokenLocationFile> file =
|
||||
m_storageAccess->getTokenLocationsForFile(message->filePath.str());
|
||||
|
||||
TokenLocationFile* activeLocations = m_collection->findTokenLocationFileByPath(message->filePath);
|
||||
if (activeLocations)
|
||||
{
|
||||
activeLocations->forEachTokenLocation(
|
||||
[&file](TokenLocation* location)
|
||||
{
|
||||
file->addTokenLocationAsPlainCopy(location);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
params.locationFile = file;
|
||||
}
|
||||
|
||||
getView()->showCodeFile(params);
|
||||
@@ -229,9 +234,11 @@ void CodeController::handleMessage(MessageScrollCode* message)
|
||||
void CodeController::handleMessage(MessageShowErrors* message)
|
||||
{
|
||||
std::vector<ErrorInfo> errors;
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForErrorLocations(&errors);
|
||||
m_collection = m_storageAccess->getErrorTokenLocations(&errors);
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForCollection(m_collection);
|
||||
|
||||
CodeView* view = getView();
|
||||
view->clear();
|
||||
view->setErrorInfos(errors);
|
||||
view->showCodeSnippets(snippets, std::vector<Id>());
|
||||
|
||||
@@ -241,10 +248,10 @@ void CodeController::handleMessage(MessageShowErrors* message)
|
||||
void CodeController::handleMessage(MessageSearchFullText* message)
|
||||
{
|
||||
CodeView* view = getView();
|
||||
view->setErrorInfos(std::vector<ErrorInfo>());
|
||||
view->clear();
|
||||
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForFullTextSearch(message->searchTerm, message->caseSensitive);
|
||||
view->showCodeSnippets(snippets, std::vector<Id>());
|
||||
m_collection = m_storageAccess->getFullTextSearchLocations(message->searchTerm, message->caseSensitive);
|
||||
view->showCodeSnippets(getSnippetsForCollection(m_collection, true), std::vector<Id>());
|
||||
|
||||
showContents(message);
|
||||
}
|
||||
@@ -261,7 +268,8 @@ void CodeController::handleMessage(MessageShowScope* message)
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForActiveTokenLocations(collection.get(), 0);
|
||||
std::vector<CodeSnippetParams> snippets =
|
||||
getSnippetsForFile(collection->getTokenLocationFiles().begin()->second, true);
|
||||
if (snippets.size() != 1)
|
||||
{
|
||||
LOG_ERROR("MessageShowScope didn't result in one single snippet to be created");
|
||||
@@ -270,15 +278,21 @@ void CodeController::handleMessage(MessageShowScope* message)
|
||||
|
||||
if (message->showErrors)
|
||||
{
|
||||
std::vector<ErrorInfo> errors;
|
||||
std::vector<CodeSnippetParams> errorSnippets = getSnippetsForErrorLocations(&errors);
|
||||
|
||||
for (const CodeSnippetParams& error : errorSnippets)
|
||||
snippets[0].locationFile = m_collection->getTokenLocationFileByPath(snippets[0].locationFile->getFilePath());
|
||||
}
|
||||
else
|
||||
{
|
||||
TokenLocationFile* activeLocations =
|
||||
m_collection->findTokenLocationFileByPath(snippets[0].locationFile->getFilePath());
|
||||
if (activeLocations)
|
||||
{
|
||||
if (error.locationFile->getFilePath() == snippets[0].locationFile->getFilePath())
|
||||
{
|
||||
snippets[0].locationFile = error.locationFile;
|
||||
}
|
||||
std::shared_ptr<TokenLocationFile> file = snippets[0].locationFile;
|
||||
activeLocations->forEachTokenLocation(
|
||||
[&file](TokenLocation* location)
|
||||
{
|
||||
file->addTokenLocationAsPlainCopy(location);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +345,7 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocation
|
||||
(isDefinitionFile && definitionFileCount < 3) ||
|
||||
(!isDefinitionFile && isDeclarationFile && declarationFileCount < 3))
|
||||
{
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForActiveTokenLocationsInFile(file);
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForFile(file, true);
|
||||
|
||||
for (CodeSnippetParams& snippet : fileSnippets)
|
||||
{
|
||||
@@ -369,43 +383,48 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocation
|
||||
return snippets;
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocationsInFile(
|
||||
std::shared_ptr<TokenLocationFile> activeTokenLocations
|
||||
) const {
|
||||
std::shared_ptr<TokenLocationFile> fileLocations = m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str());
|
||||
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForFile(activeTokenLocations, fileLocations);
|
||||
|
||||
if (!activeTokenLocations->isWholeCopy)
|
||||
{
|
||||
for (CodeSnippetParams& params : fileSnippets)
|
||||
{
|
||||
params.locationFile = fileLocations->getFilteredByLines(params.startLineNumber, params.endLineNumber);
|
||||
}
|
||||
}
|
||||
|
||||
return fileSnippets;
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
|
||||
std::shared_ptr<TokenLocationFile> activeTokenLocations
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForCollection(
|
||||
std::shared_ptr<TokenLocationCollection> collection, bool addTokenLocations
|
||||
) const
|
||||
{
|
||||
return getSnippetsForFile(
|
||||
activeTokenLocations,
|
||||
m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str())
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
|
||||
collection->forEachTokenLocationFile(
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
{
|
||||
if (snippets.size() < 10)
|
||||
{
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForFile(file, addTokenLocations);
|
||||
snippets.insert(snippets.end(), fileSnippets.begin(), fileSnippets.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
|
||||
params.isCollapsed = true;
|
||||
snippets.push_back(params);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
addModificationTimes(snippets);
|
||||
|
||||
return snippets;
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
|
||||
std::shared_ptr<TokenLocationFile> activeTokenLocations,
|
||||
const std::shared_ptr<TokenLocationFile> fileLocations
|
||||
std::shared_ptr<TokenLocationFile> activeTokenLocations, bool addTokenLocations
|
||||
) const
|
||||
{
|
||||
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(activeTokenLocations->getFilePath());
|
||||
std::shared_ptr<TokenLocationFile> scopeLocations
|
||||
= std::make_shared<TokenLocationFile>(activeTokenLocations->getFilePath().str());
|
||||
|
||||
std::shared_ptr<TokenLocationFile> fileLocations =
|
||||
m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str());
|
||||
|
||||
fileLocations->forEachStartTokenLocation(
|
||||
[&](TokenLocation* startLoc) -> void
|
||||
{
|
||||
@@ -461,14 +480,16 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
|
||||
const int snippetExpandRange = ApplicationSettings::getInstance()->getCodeSnippetExpandRange();
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> file = m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str());
|
||||
std::shared_ptr<TokenLocationFile> file =
|
||||
m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str());
|
||||
for (const SnippetMerger::Range& range: ranges)
|
||||
{
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = activeTokenLocations;
|
||||
params.refCount = activeTokenLocations->getUnscopedStartTokenLocationCount();
|
||||
params.startLineNumber = std::max<int>(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange));
|
||||
params.endLineNumber = std::min<int>(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange));
|
||||
params.endLineNumber =
|
||||
std::min<int>(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange));
|
||||
|
||||
std::shared_ptr<TokenLocationFile> tempFile = file->getFilteredByLines(params.startLineNumber, params.endLineNumber);
|
||||
TokenLocationLine* firstUsedLine = nullptr;
|
||||
@@ -525,6 +546,24 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
|
||||
snippets.push_back(params);
|
||||
}
|
||||
|
||||
if (addTokenLocations && !activeTokenLocations->isWholeCopy)
|
||||
{
|
||||
for (CodeSnippetParams& params : snippets)
|
||||
{
|
||||
std::shared_ptr<TokenLocationFile> lines =
|
||||
fileLocations->getFilteredByLines(params.startLineNumber, params.endLineNumber);
|
||||
|
||||
params.locationFile->forEachTokenLocation(
|
||||
[&lines](TokenLocation* location)
|
||||
{
|
||||
lines->addTokenLocationAsPlainCopy(location);
|
||||
}
|
||||
);
|
||||
|
||||
params.locationFile = lines;
|
||||
}
|
||||
}
|
||||
|
||||
return snippets;
|
||||
}
|
||||
|
||||
@@ -605,79 +644,6 @@ std::shared_ptr<TokenLocationFile> CodeController::getTokenLocationOfParentScope
|
||||
return file;
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForFullTextSearch(
|
||||
const std::string& searchTerm, bool caseSensitive) const
|
||||
{
|
||||
std::shared_ptr<TokenLocationCollection> collection =
|
||||
m_storageAccess->getFullTextSearchLocations(searchTerm, caseSensitive);
|
||||
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
snippets.reserve(collection->getTokenLocationFileCount());
|
||||
|
||||
collection->forEachTokenLocationFile(
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
{
|
||||
//CodeSnippetParams params;
|
||||
//params.locationFile = file;
|
||||
//params.startLineNumber = 1;
|
||||
|
||||
//std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(file->getFilePath());
|
||||
//params.code = textAccess->getText();
|
||||
|
||||
//snippets.push_back(params);
|
||||
|
||||
//if (snippets.size() < 10)
|
||||
//{
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
snippets.insert(snippets.end(), fileSnippets.begin(), fileSnippets.end());
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
//CodeSnippetParams params;
|
||||
//params.locationFile = file;
|
||||
//params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
//params.isCollapsed = true;
|
||||
//snippets.push_back(params);
|
||||
//}
|
||||
}
|
||||
);
|
||||
|
||||
addModificationTimes(snippets);
|
||||
return snippets;
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForErrorLocations(
|
||||
std::vector<ErrorInfo>* errors) const
|
||||
{
|
||||
TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(errors);
|
||||
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
|
||||
errorCollection.forEachTokenLocationFile(
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
{
|
||||
if (snippets.size() < 10)
|
||||
{
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
snippets.insert(snippets.end(), fileSnippets.begin(), fileSnippets.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
|
||||
params.isCollapsed = true;
|
||||
snippets.push_back(params);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
addModificationTimes(snippets);
|
||||
|
||||
return snippets;
|
||||
}
|
||||
|
||||
std::vector<std::string> CodeController::getProjectDescription(TokenLocationFile* locationFile) const
|
||||
{
|
||||
std::string description = ProjectSettings::getInstance()->getDescription();
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "component/view/CodeView.h"
|
||||
|
||||
class StorageAccess;
|
||||
class TokenLocation;
|
||||
class TokenLocationCollection;
|
||||
class TokenLocationFile;
|
||||
|
||||
@@ -64,23 +65,23 @@ private:
|
||||
|
||||
std::vector<CodeSnippetParams> getSnippetsForActiveTokenLocations(
|
||||
const TokenLocationCollection* collection, Id declarationId) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForActiveTokenLocationsInFile(
|
||||
std::shared_ptr<TokenLocationFile>) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForCollection(
|
||||
std::shared_ptr<TokenLocationCollection> collection, bool addTokenLocations = false) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForFile(
|
||||
std::shared_ptr<TokenLocationFile> activeTokenLocations, std::shared_ptr<TokenLocationFile> fileLocations) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForFullTextSearch(const std::string& searchTerm, bool caseSensitive) const;
|
||||
std::shared_ptr<SnippetMerger> buildMergerHierarchy(
|
||||
TokenLocation* location, std::shared_ptr<TokenLocationFile> context, SnippetMerger& fileScopedMerger, std::map<int, std::shared_ptr<SnippetMerger>>& mergers) const;
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* location, std::shared_ptr<TokenLocationFile> context) const;
|
||||
std::shared_ptr<TokenLocationFile> file, bool addTokenLocations = false) const;
|
||||
|
||||
std::vector<CodeSnippetParams> getSnippetsForErrorLocations(std::vector<ErrorInfo>* errors) const;
|
||||
std::shared_ptr<SnippetMerger> buildMergerHierarchy(
|
||||
TokenLocation* location, std::shared_ptr<TokenLocationFile> context, SnippetMerger& fileScopedMerger,
|
||||
std::map<int, std::shared_ptr<SnippetMerger>>& mergers) const;
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(
|
||||
const TokenLocation* location, std::shared_ptr<TokenLocationFile> context) const;
|
||||
|
||||
std::vector<std::string> getProjectDescription(TokenLocationFile* locationFile) const;
|
||||
|
||||
void addModificationTimes(std::vector<CodeSnippetParams>& snippets) const;
|
||||
|
||||
StorageAccess* m_storageAccess;
|
||||
mutable std::shared_ptr<TokenLocationCollection> m_collection;
|
||||
};
|
||||
|
||||
#endif // CODE_CONTROLLER_H
|
||||
|
||||
@@ -450,7 +450,7 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getFullTextSearchLoc
|
||||
if ( addHit )
|
||||
{
|
||||
collection->addTokenLocation(
|
||||
i,
|
||||
collection->getTokenLocationCount(),
|
||||
0,
|
||||
filepath,
|
||||
location.startLineNumber,
|
||||
@@ -935,16 +935,17 @@ std::shared_ptr<TokenLocationFile> PersistentStorage::getTokenLocationsForLinesI
|
||||
return m_sqliteStorage.getTokenLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber);
|
||||
}
|
||||
|
||||
TokenLocationCollection PersistentStorage::getErrorTokenLocations(std::vector<ErrorInfo>* errors) const
|
||||
std::shared_ptr<TokenLocationCollection> PersistentStorage::getErrorTokenLocations(std::vector<ErrorInfo>* errors) const
|
||||
{
|
||||
TokenLocationCollection errorCollection;
|
||||
std::shared_ptr<TokenLocationCollection> errorCollection = std::make_shared<TokenLocationCollection>();
|
||||
|
||||
std::vector<StorageError> storageErrors = m_sqliteStorage.getAllErrors();
|
||||
for (size_t i = 0; i < storageErrors.size(); i++)
|
||||
{
|
||||
const StorageError& error = storageErrors[i];
|
||||
errorCollection.addTokenLocation(
|
||||
i, i, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber);
|
||||
errorCollection->addTokenLocation(
|
||||
i, i, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber
|
||||
)->setType(LOCATION_ERROR);
|
||||
errors->push_back(ErrorInfo(error.message, error.filePath, i, error.fatal));
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
|
||||
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
|
||||
virtual std::shared_ptr<TokenLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0;
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<ErrorInfo>* errors) const = 0;
|
||||
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const = 0;
|
||||
virtual std::shared_ptr<TokenLocationFile> getCommentLocationsInFile(const FilePath& filePath) const = 0;
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const = 0;
|
||||
|
||||
@@ -218,14 +218,14 @@ std::shared_ptr<TokenLocationFile> StorageAccessProxy::getTokenLocationsForLines
|
||||
return std::make_shared<TokenLocationFile>("");
|
||||
}
|
||||
|
||||
TokenLocationCollection StorageAccessProxy::getErrorTokenLocations(std::vector<ErrorInfo>* errors) const
|
||||
std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getErrorTokenLocations(std::vector<ErrorInfo>* errors) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getErrorTokenLocations(errors);
|
||||
}
|
||||
|
||||
return TokenLocationCollection();
|
||||
return std::make_shared<TokenLocationCollection>();
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> StorageAccessProxy::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
|
||||
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
|
||||
virtual std::shared_ptr<TokenLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
|
||||
|
||||
@@ -12,6 +12,8 @@ int locationTypeToInt(LocationType type)
|
||||
return 2;
|
||||
case LOCATION_FULLTEXT:
|
||||
return 3;
|
||||
case LOCATION_ERROR:
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +29,8 @@ LocationType intToLocationType(int value)
|
||||
return LOCATION_LOCAL_SYMBOL;
|
||||
case 3:
|
||||
return LOCATION_FULLTEXT;
|
||||
case 4:
|
||||
return LOCATION_ERROR;
|
||||
}
|
||||
return LOCATION_TOKEN;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ enum LocationType
|
||||
LOCATION_TOKEN,
|
||||
LOCATION_SCOPE,
|
||||
LOCATION_LOCAL_SYMBOL,
|
||||
LOCATION_FULLTEXT
|
||||
LOCATION_FULLTEXT,
|
||||
LOCATION_ERROR
|
||||
};
|
||||
|
||||
int locationTypeToInt(LocationType type);
|
||||
|
||||
@@ -22,6 +22,22 @@ const TokenLocationCollection::TokenLocationFileMapType& TokenLocationCollection
|
||||
return m_files;
|
||||
}
|
||||
|
||||
const std::map<Id, TokenLocation*>& TokenLocationCollection::getTokenLocations() const
|
||||
{
|
||||
return m_locations;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> TokenLocationCollection::getTokenLocationFileByPath(const FilePath& filePath) const
|
||||
{
|
||||
std::map<FilePath, std::shared_ptr<TokenLocationFile>>::const_iterator it = m_files.find(filePath);
|
||||
if (it != m_files.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t TokenLocationCollection::getTokenLocationFileCount() const
|
||||
{
|
||||
return m_files.size();
|
||||
@@ -39,11 +55,6 @@ size_t TokenLocationCollection::getTokenLocationLineCount() const
|
||||
return count;
|
||||
}
|
||||
|
||||
const std::map<Id, TokenLocation*>& TokenLocationCollection::getTokenLocations() const
|
||||
{
|
||||
return m_locations;
|
||||
}
|
||||
|
||||
size_t TokenLocationCollection::getTokenLocationCount() const
|
||||
{
|
||||
return m_locations.size();
|
||||
@@ -101,13 +112,7 @@ TokenLocation* TokenLocationCollection::findTokenLocationById(Id id) const
|
||||
|
||||
TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const FilePath& filePath) const
|
||||
{
|
||||
std::map<FilePath, std::shared_ptr<TokenLocationFile>>::const_iterator it = m_files.find(filePath);
|
||||
if (it != m_files.end())
|
||||
{
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return getTokenLocationFileByPath(filePath).get();
|
||||
}
|
||||
|
||||
void TokenLocationCollection::forEachTokenLocationFile(std::function<void(std::shared_ptr<TokenLocationFile>)> func) const
|
||||
|
||||
@@ -24,11 +24,12 @@ public:
|
||||
~TokenLocationCollection();
|
||||
|
||||
const TokenLocationFileMapType& getTokenLocationFiles() const;
|
||||
size_t getTokenLocationFileCount() const;
|
||||
|
||||
size_t getTokenLocationLineCount() const;
|
||||
|
||||
const std::map<Id, TokenLocation*>& getTokenLocations() const;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationFileByPath(const FilePath& filePath) const;
|
||||
|
||||
size_t getTokenLocationFileCount() const;
|
||||
size_t getTokenLocationLineCount() const;
|
||||
size_t getTokenLocationCount() const;
|
||||
|
||||
TokenLocation* addTokenLocation(
|
||||
|
||||
@@ -128,11 +128,11 @@ void TokenLocationFile::forEachEndTokenLocation(std::function<void(TokenLocation
|
||||
|
||||
TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocation* location)
|
||||
{
|
||||
unsigned int lineNumber = location->getTokenLocationLine()->getLineNumber();
|
||||
unsigned int lineNumber = location->getLineNumber();
|
||||
TokenLocationLine* line = createTokenLocationLine(lineNumber);
|
||||
|
||||
// Check whether this location was already added or if the other TokenLocation was added.
|
||||
TokenLocation* otherLocation = line->getTokenLocationById(location->getId());
|
||||
TokenLocation* otherLocation = line->getTokenLocationByIdAndType(location->getId(), location->getType());
|
||||
if (otherLocation)
|
||||
{
|
||||
if (otherLocation->isStartTokenLocation() == location->isStartTokenLocation())
|
||||
@@ -144,13 +144,13 @@ TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocatio
|
||||
else
|
||||
{
|
||||
// Look for the other location in it's line.
|
||||
unsigned int otherLineNumber = location->getOtherTokenLocation()->getTokenLocationLine()->getLineNumber();
|
||||
unsigned int otherLineNumber = location->getOtherTokenLocation()->getLineNumber();
|
||||
if (lineNumber != otherLineNumber)
|
||||
{
|
||||
TokenLocationLine* otherLine = findTokenLocationLine(otherLineNumber);
|
||||
if (otherLine)
|
||||
{
|
||||
otherLocation = otherLine->getTokenLocationById(location->getId());
|
||||
otherLocation = otherLine->getTokenLocationByIdAndType(location->getId(), location->getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::getTokenLocationById(Id id) const
|
||||
TokenLocation* TokenLocationLine::getTokenLocationByIdAndType(Id id, LocationType type) const
|
||||
{
|
||||
for (const TokenLocationPairType& p : m_locations)
|
||||
{
|
||||
if (p.second->getId() == id)
|
||||
if (p.second->getId() == id && p.second->getType() == type)
|
||||
{
|
||||
return p.second.get();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "data/location/LocationType.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
@@ -34,7 +36,7 @@ public:
|
||||
TokenLocation* addEndTokenLocation(TokenLocation* start, unsigned int columnNumber);
|
||||
void removeTokenLocation(TokenLocation* location);
|
||||
|
||||
TokenLocation* getTokenLocationById(Id id) const;
|
||||
TokenLocation* getTokenLocationByIdAndType(Id id, LocationType type) const;
|
||||
|
||||
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
void forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#ifndef MESSAGE_CHANGE_FILE_VIEW_H
|
||||
#define MESSAGE_CHANGE_FILE_VIEW_H
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
|
||||
class MessageChangeFileView
|
||||
: public Message<MessageChangeFileView>
|
||||
{
|
||||
@@ -21,14 +20,12 @@ public:
|
||||
const FilePath filePath,
|
||||
FileState state,
|
||||
bool needsData,
|
||||
bool showErrors,
|
||||
std::shared_ptr<TokenLocationFile> locationFile
|
||||
bool showErrors
|
||||
)
|
||||
: filePath(filePath)
|
||||
, state(state)
|
||||
, needsData(needsData)
|
||||
, showErrors(showErrors)
|
||||
, locationFile(locationFile)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -57,8 +54,6 @@ public:
|
||||
|
||||
bool needsData;
|
||||
bool showErrors;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_CHANGE_FILE_VIEW_H
|
||||
|
||||
@@ -433,10 +433,10 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
|
||||
m_eventPosition = event->pos();
|
||||
setIDECursorPosition();
|
||||
}
|
||||
else if (!m_fileWidget->hasErrors())
|
||||
else
|
||||
{
|
||||
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||
std::vector<const Annotation*> annotations = getNonScopeAnnotationsForPosition(cursor.position());
|
||||
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(cursor.position());
|
||||
|
||||
activateTokenLocations(annotations);
|
||||
activateLocalSymbols(annotations);
|
||||
@@ -464,7 +464,7 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
|
||||
|
||||
|
||||
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||
std::vector<const Annotation*> annotations = getNonScopeAnnotationsForPosition(cursor.position());
|
||||
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(cursor.position());
|
||||
|
||||
bool same = annotations.size() == m_hoveredAnnotations.size();
|
||||
if (same)
|
||||
@@ -541,13 +541,15 @@ void QtCodeArea::setIDECursorPosition()
|
||||
MessageMoveIDECursor(m_locationFile->getFilePath().str(), lineColumn.first, lineColumn.second).dispatch();
|
||||
}
|
||||
|
||||
std::vector<const QtCodeArea::Annotation*> QtCodeArea::getNonScopeAnnotationsForPosition(int pos) const
|
||||
std::vector<const QtCodeArea::Annotation*> QtCodeArea::getInteractiveAnnotationsForPosition(int pos) const
|
||||
{
|
||||
std::vector<const QtCodeArea::Annotation*> annotations;
|
||||
|
||||
for (const Annotation& annotation : m_annotations)
|
||||
{
|
||||
if (annotation.locationType != LOCATION_SCOPE && pos >= annotation.start && pos <= annotation.end)
|
||||
const LocationType& type = annotation.locationType;
|
||||
if ((type == LOCATION_TOKEN || type == LOCATION_LOCAL_SYMBOL || type == LOCATION_ERROR)
|
||||
&& pos >= annotation.start && pos <= annotation.end)
|
||||
{
|
||||
annotations.push_back(&annotation);
|
||||
}
|
||||
@@ -674,7 +676,6 @@ void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFi
|
||||
annotation.locationId = startLocation->getId();
|
||||
|
||||
annotation.locationType = startLocation->getType();
|
||||
annotation.isError = false;
|
||||
|
||||
annotation.isActive = false;
|
||||
annotation.isFocused = false;
|
||||
@@ -690,8 +691,6 @@ void QtCodeArea::annotateText()
|
||||
const std::vector<Id>& activeLocalSymbolIds = m_fileWidget->getActiveLocalSymbolIds();
|
||||
const std::vector<Id>& focusIds = m_fileWidget->getFocusedTokenIds();
|
||||
|
||||
bool isError = m_fileWidget->hasErrors();
|
||||
|
||||
bool needsUpdate = false;
|
||||
for (Annotation& annotation: m_annotations)
|
||||
{
|
||||
@@ -705,8 +704,6 @@ void QtCodeArea::annotateText()
|
||||
);
|
||||
annotation.isFocused = std::find(focusIds.begin(), focusIds.end(), annotation.tokenId) != focusIds.end();
|
||||
|
||||
annotation.isError = isError;
|
||||
|
||||
const AnnotationColor& newColor = getAnnotationColorForAnnotation(annotation);
|
||||
if ((newColor.text != oldColor.text || !m_wasAnnotated))
|
||||
{
|
||||
@@ -933,7 +930,7 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c
|
||||
{
|
||||
i = 6;
|
||||
}
|
||||
else if (annotation.isError)
|
||||
else if (annotation.locationType == LOCATION_ERROR)
|
||||
{
|
||||
i = 9;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,6 @@ private:
|
||||
Id locationId;
|
||||
|
||||
LocationType locationType;
|
||||
bool isError;
|
||||
|
||||
bool isActive;
|
||||
bool isFocused;
|
||||
@@ -141,7 +140,7 @@ private:
|
||||
std::string text;
|
||||
};
|
||||
|
||||
std::vector<const Annotation*> getNonScopeAnnotationsForPosition(int pos) const;
|
||||
std::vector<const Annotation*> getInteractiveAnnotationsForPosition(int pos) const;
|
||||
void activateTokenLocations(const std::vector<const Annotation*>& annotations);
|
||||
void activateLocalSymbols(const std::vector<const Annotation*>& annotations);
|
||||
|
||||
|
||||
@@ -431,8 +431,7 @@ void QtCodeFile::clickedMinimizeButton() const
|
||||
m_filePath,
|
||||
MessageChangeFileView::FILE_MINIMIZED,
|
||||
false,
|
||||
hasErrors(),
|
||||
nullptr
|
||||
hasErrors()
|
||||
).dispatch();
|
||||
}
|
||||
|
||||
@@ -442,8 +441,7 @@ void QtCodeFile::clickedSnippetButton() const
|
||||
m_filePath,
|
||||
MessageChangeFileView::FILE_SNIPPETS,
|
||||
(m_locationFile != nullptr),
|
||||
hasErrors(),
|
||||
m_locationFile
|
||||
hasErrors()
|
||||
).dispatch();
|
||||
}
|
||||
|
||||
@@ -453,8 +451,7 @@ void QtCodeFile::clickedMaximizeButton() const
|
||||
m_filePath,
|
||||
MessageChangeFileView::FILE_MAXIMIZED,
|
||||
(m_fileSnippet == nullptr),
|
||||
hasErrors(),
|
||||
nullptr
|
||||
hasErrors()
|
||||
).dispatch();
|
||||
}
|
||||
|
||||
@@ -471,8 +468,7 @@ void QtCodeFile::requestSnippets() const
|
||||
m_filePath,
|
||||
MessageChangeFileView::FILE_SNIPPETS,
|
||||
(m_locationFile != nullptr),
|
||||
hasErrors(),
|
||||
m_locationFile
|
||||
hasErrors()
|
||||
);
|
||||
|
||||
msg.setIsReplayed(true);
|
||||
|
||||
@@ -51,6 +51,9 @@ void QtCodeView::refreshView()
|
||||
void QtCodeView::clear()
|
||||
{
|
||||
m_clearFunctor();
|
||||
|
||||
m_errorInfos.clear();
|
||||
m_activeTokenIds.clear();
|
||||
}
|
||||
|
||||
void QtCodeView::setActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
@@ -134,9 +137,9 @@ void QtCodeView::doClear()
|
||||
|
||||
void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds)
|
||||
{
|
||||
m_widget->clearCodeSnippets();
|
||||
setActiveTokenIds(activeTokenIds);
|
||||
|
||||
m_widget->setActiveTokenIds(activeTokenIds);
|
||||
m_widget->setActiveTokenIds(m_activeTokenIds);
|
||||
m_widget->setErrorInfos(m_errorInfos);
|
||||
|
||||
for (const CodeSnippetParams& params : snippets)
|
||||
|
||||
Reference in New Issue
Block a user