logic: lazy load code annotations

* code annotations are loaded after showing the code file
* added traces
* refactored highlighter
* fixed error tooltip style in codeview

fortune cookie message = It's not the time that counts, but what you do with it.
This commit is contained in:
Eberhard Graether
2018-03-24 13:19:49 +01:00
parent 0d79639c96
commit aed783f5ca
24 changed files with 405 additions and 361 deletions
+196 -236
View File
@@ -93,7 +93,7 @@ void CodeController::handleMessage(MessageActivateAll* message)
CodeView::CodeParams params;
params.clearSnippets = true;
params.showContents = !message->isReplayed();
getView()->showCodeSnippets(std::vector<CodeSnippetParams>(1, statsSnippet), params);
showCodeSnippets({ statsSnippet }, params);
}
void CodeController::handleMessage(MessageActivateLocalSymbols* message)
@@ -138,43 +138,39 @@ void CodeController::handleMessage(MessageActivateTokens* message)
if (message->keepContent())
{
view->showActiveTokenIds(params.activeTokenIds);
return;
}
else
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_DEFINITION);
scrollParams.ignoreActiveReference = true;
view->scrollTo(scrollParams);
m_collection = m_storageAccess->getSourceLocationsForTokenIds(params.activeTokenIds);
showCodeSnippets(getSnippetsForActiveSourceLocations(m_collection.get(), declarationId), params);
size_t fileCount = m_collection->getSourceLocationFileCount();
size_t referenceCount = m_collection->getSourceLocationCount();
std::wstring status = L"";
if (message->tokenNames.size())
{
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_DEFINITION);
scrollParams.ignoreActiveReference = true;
view->scrollTo(scrollParams);
m_collection = m_storageAccess->getSourceLocationsForTokenIds(params.activeTokenIds);
std::vector<CodeSnippetParams> snippets = getSnippetsForActiveSourceLocations(m_collection.get(), declarationId);
expandVisibleSnippets(&snippets, true);
view->showCodeSnippets(snippets, params);
size_t fileCount = m_collection->getSourceLocationFileCount();
size_t referenceCount = m_collection->getSourceLocationCount();
std::wstring status = L"";
if (message->tokenNames.size())
{
status += L"Activate \"" + message->tokenNames[0].getQualifiedName() + L"\": ";
}
status += std::to_wstring(message->tokenIds.size()) + L" ";
status += (message->tokenIds.size() == 1 ? L"result" : L"results");
if (fileCount > 0)
{
status += L" with " + std::to_wstring(referenceCount) + L" ";
status += (referenceCount == 1 ? L"reference" : L"references");
status += L" in " + std::to_wstring(fileCount) + L" ";
status += (fileCount == 1 ? L"file" : L"files");
}
MessageStatus(status).dispatch();
status += L"Activate \"" + message->tokenNames[0].getQualifiedName() + L"\": ";
}
status += std::to_wstring(message->tokenIds.size()) + L" ";
status += (message->tokenIds.size() == 1 ? L"result" : L"results");
if (fileCount > 0)
{
status += L" with " + std::to_wstring(referenceCount) + L" ";
status += (referenceCount == 1 ? L"reference" : L"references");
status += L" in " + std::to_wstring(fileCount) + L" ";
status += (fileCount == 1 ? L"file" : L"files");
}
MessageStatus(status).dispatch();
}
void CodeController::handleMessage(MessageActivateTrailEdge* message)
@@ -192,8 +188,7 @@ void CodeController::handleMessage(MessageActivateTrailEdge* message)
params.activeTokenIds.push_back(message->tokenId);
m_collection = m_storageAccess->getSourceLocationsForTokenIds(params.activeTokenIds);
getView()->showCodeSnippets(getSnippetsForActiveSourceLocations(m_collection.get(), 0), params);
showCodeSnippets(getSnippetsForActiveSourceLocations(m_collection.get(), 0), params);
}
void CodeController::handleMessage(MessageChangeFileView* message)
@@ -224,8 +219,7 @@ void CodeController::handleMessage(MessageChangeFileView* message)
if (message->needsData && !message->filePath.empty())
{
CodeView::CodeParams params;
view->showCodeSnippets(getSnippetsForFileWithState(message->filePath, state, !message->showErrors), params);
showCodeSnippets(getSnippetsForFileWithState(message->filePath, state), CodeView::CodeParams());
}
view->setFileState(message->filePath, state);
@@ -318,17 +312,12 @@ void CodeController::handleMessage(MessageShowErrors* message)
std::sort(snippets.begin(), snippets.end(), CodeSnippetParams::sortById);
if (view->isInListMode())
{
expandVisibleSnippets(&snippets, false);
}
CodeView::CodeParams params;
params.clearSnippets = true;
params.errorInfos = errors;
params.showContents = !message->isReplayed();
view->showCodeSnippets(snippets, params);
showCodeSnippets(snippets, params, false);
}
if (message->errorId)
@@ -348,13 +337,11 @@ void CodeController::handleMessage(MessageSearchFullText* message)
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_DEFINITION);
getView()->scrollTo(scrollParams);
std::vector<CodeSnippetParams> snippets = getSnippetsForCollection(m_collection, true);
expandVisibleSnippets(&snippets, true);
CodeView::CodeParams params;
params.clearSnippets = true;
params.showContents = !message->isReplayed();
getView()->showCodeSnippets(snippets, params);
showCodeSnippets(getSnippetsForCollection(m_collection), params);
}
void CodeController::handleMessage(MessageShowScope* message)
@@ -362,7 +349,7 @@ void CodeController::handleMessage(MessageShowScope* message)
TRACE("code scope");
std::shared_ptr<SourceLocationCollection> collection =
m_storageAccess->getSourceLocationsForLocationIds({message->scopeLocationId});
m_storageAccess->getSourceLocationsForLocationIds({ message->scopeLocationId });
SourceLocation* location = collection->getSourceLocationById(message->scopeLocationId);
if (!location || !location->isScopeLocation() || !location->getOtherLocation())
@@ -371,8 +358,7 @@ void CodeController::handleMessage(MessageShowScope* message)
return;
}
std::vector<CodeSnippetParams> snippets =
getSnippetsForFile(collection->getSourceLocationFiles().begin()->second, true);
std::vector<CodeSnippetParams> snippets = getSnippetsForFile(collection->getSourceLocationFiles().begin()->second);
if (snippets.size() != 1)
{
LOG_ERROR("MessageShowScope didn't result in one single snippet to be created");
@@ -381,17 +367,10 @@ void CodeController::handleMessage(MessageShowScope* message)
snippets[0].insertSnippet = true;
if (message->showErrors)
{
snippets[0].locationFile = m_collection->getSourceLocationFileByPath(snippets[0].locationFile->getFilePath());
}
else
{
addActiveSourceLocations(snippets[0].locationFile);
}
CodeView::CodeParams params;
params.showContents = !message->isReplayed();
addAllSourceLocations(&snippets);
getView()->showCodeSnippets(snippets, params);
}
@@ -407,52 +386,8 @@ void CodeController::clear()
m_collection.reset();
}
void CodeController::expandVisibleSnippets(std::vector<CodeSnippetParams>* snippets, bool addSourceLocations) const
{
TRACE();
if (!snippets->size())
{
return;
}
bool inListMode = getView()->isInListMode();
size_t filesToExpand = inListMode ? std::min(int(snippets->size()), 3) : 1;
CodeView::FileState state = inListMode ? CodeView::FILE_SNIPPETS : CodeView::FILE_MAXIMIZED;
for (size_t i = 0; i < filesToExpand; i++)
{
CodeSnippetParams& oldSnippet = snippets->at(i);
if (!inListMode && getView()->hasSingleFileCached(oldSnippet.locationFile->getFilePath()))
{
continue;
}
CodeView::FileState fileState = oldSnippet.locationFile->isWhole() ? CodeView::FILE_MAXIMIZED : state;
std::vector<CodeSnippetParams> newSnippets =
getSnippetsForFileWithState(oldSnippet.locationFile->getFilePath(), fileState, addSourceLocations);
if (!newSnippets.size())
{
continue;
}
for (CodeSnippetParams& newSnippet : newSnippets)
{
newSnippet.isDeclaration = oldSnippet.isDeclaration;
newSnippet.isDefinition = oldSnippet.isDefinition;
newSnippet.isCollapsed = false;
}
snippets->insert(snippets->end(), newSnippets.begin(), newSnippets.end());
}
}
std::vector<CodeSnippetParams> CodeController::getSnippetsForFileWithState(
const FilePath& filePath, CodeView::FileState state, bool addSourceLocations) const
const FilePath& filePath, CodeView::FileState state) const
{
TRACE();
@@ -468,7 +403,7 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFileWithState(
return snippets;
}
snippets = getSnippetsForFile(file, addSourceLocations);
snippets = getSnippetsForFile(file);
}
break;
@@ -483,24 +418,16 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFileWithState(
params.modificationTime = m_storageAccess->getFileInfoForFilePath(filePath).lastWriteTime;
if (!addSourceLocations)
params.locationFile = m_collection->getSourceLocationFileByPath(filePath);
if (params.locationFile)
{
params.locationFile = m_collection->getSourceLocationFileByPath(filePath);
if (!params.locationFile)
{
break;
}
params.locationFile->setIsWhole(true);
}
else
{
params.locationFile = m_storageAccess->getSourceLocationsForFile(filePath);
addActiveSourceLocations(params.locationFile);
}
snippets.push_back(params);
}
break;
default:
break;
}
@@ -553,13 +480,13 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveSourceLocatio
std::sort(snippets.begin(), snippets.end(), CodeSnippetParams::sort);
addModificationTimes(snippets);
addModificationTimes(&snippets);
return snippets;
}
std::vector<CodeSnippetParams> CodeController::getSnippetsForCollection(
std::shared_ptr<SourceLocationCollection> collection, bool addSourceLocations
std::shared_ptr<SourceLocationCollection> collection
) const
{
TRACE();
@@ -578,20 +505,21 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForCollection(
}
);
addModificationTimes(snippets);
addModificationTimes(&snippets);
return snippets;
}
std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
std::shared_ptr<SourceLocationFile> activeSourceLocations, bool addSourceLocations
std::shared_ptr<SourceLocationFile> activeSourceLocations
) const
{
TRACE();
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(activeSourceLocations->getFilePath());
size_t lineCount = textAccess->getLineCount();
SnippetMerger fileScopedMerger(1, textAccess->getLineCount());
SnippetMerger fileScopedMerger(1, lineCount);
std::map<int, std::shared_ptr<SnippetMerger>> mergers;
std::shared_ptr<SourceLocationFile> scopeLocations =
@@ -599,7 +527,7 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
activeSourceLocations->forEachStartSourceLocation(
[&](SourceLocation* location)
{
buildMergerHierarchy(location, scopeLocations, fileScopedMerger, mergers);
buildMergerHierarchy(location, scopeLocations.get(), fileScopedMerger, mergers);
}
);
@@ -613,8 +541,8 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
));
}
);
atomicRanges = SnippetMerger::Range::mergeAdjacent(atomicRanges);
atomicRanges = SnippetMerger::Range::mergeAdjacent(atomicRanges);
std::deque<SnippetMerger::Range> ranges = fileScopedMerger.merge(atomicRanges);
const int snippetExpandRange = ApplicationSettings::getInstance()->getCodeSnippetExpandRange();
@@ -626,54 +554,39 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
params.refCount = activeSourceLocations->getUnscopedStartLocationCount();
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>(lineCount, range.end.row + (range.end.strong ? 0 : snippetExpandRange));
params.locationFile = activeSourceLocations->getFilteredByLines(params.startLineNumber, params.endLineNumber);
params.titleId = 0;
params.footerId = 0;
std::shared_ptr<SourceLocationFile> tempFile = m_storageAccess->getSourceLocationsForLinesInFile(
activeSourceLocations->getFilePath(), params.startLineNumber, params.endLineNumber);
const SourceLocation* firstSourceLocation =
tempFile->getSourceLocations().size() ? tempFile->getSourceLocations().begin()->get() : nullptr;
if (firstSourceLocation)
if (params.startLineNumber > 1)
{
// this SourceLocationFile only contains a single StartSourceLocation.
getSourceLocationOfParentScope(firstSourceLocation, scopeLocations)->forEachStartSourceLocation(
[&](SourceLocation* location)
{
if (location->getTokenIds().size())
{
params.title = m_storageAccess->getNameHierarchyForNodeId(location->getTokenIds()[0]).getQualifiedName();
params.titleId = location->getLocationId();
}
}
);
const SourceLocation* location =
getSourceLocationOfParentScope(params.startLineNumber, scopeLocations.get());
if (location && location->getTokenIds().size())
{
params.title = m_storageAccess->getNameHierarchyForNodeId(location->getTokenIds()[0]).getQualifiedName();
params.titleId = location->getLocationId();
}
}
if (params.titleId == 0)
if (params.endLineNumber < lineCount)
{
const SourceLocation* location =
getSourceLocationOfParentScope(params.endLineNumber + 1, scopeLocations.get());
if (location && location->getTokenIds().size())
{
params.footer = m_storageAccess->getNameHierarchyForNodeId(location->getTokenIds()[0]).getQualifiedName();
params.footerId = location->getLocationId();
}
}
if (params.titleId == 0 && params.startLineNumber > 1)
{
params.title = activeSourceLocations->getFilePath().wstr();
}
const SourceLocation* lastSourceLocation =
tempFile->getSourceLocations().size() ? tempFile->getSourceLocations().rbegin()->get() : nullptr;
if (lastSourceLocation)
else if (params.footerId == 0 && params.endLineNumber < lineCount)
{
// this SourceLocationFile only contains a single StartSourceLocation.
getSourceLocationOfParentScope(lastSourceLocation, scopeLocations)->forEachStartSourceLocation(
[&](SourceLocation* location)
{
if (location->getTokenIds().size())
{
params.footer = m_storageAccess->getNameHierarchyForNodeId(location->getTokenIds()[0]).getQualifiedName();
params.footerId = location->getLocationId();
}
}
);
params.footer = activeSourceLocations->getFilePath().wstr();
}
for (const std::string& line: textAccess->getLines(params.startLineNumber, params.endLineNumber))
@@ -681,18 +594,6 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
params.code += line;
}
if (addSourceLocations)
{
params.locationFile->forEachSourceLocation(
[&tempFile](SourceLocation* location)
{
tempFile->addSourceLocationCopy(location);
}
);
params.locationFile = tempFile;
}
snippets.push_back(params);
}
@@ -700,8 +601,8 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
}
std::shared_ptr<SnippetMerger> CodeController::buildMergerHierarchy(
SourceLocation* location,
std::shared_ptr<SourceLocationFile> scopeLocations,
const SourceLocation* location,
const SourceLocationFile* scopeLocations,
SnippetMerger& fileScopedMerger,
std::map<int, std::shared_ptr<SnippetMerger>>& mergers
) const
@@ -711,67 +612,46 @@ std::shared_ptr<SnippetMerger> CodeController::buildMergerHierarchy(
location->getEndLocation()->getLineNumber()
);
std::shared_ptr<SourceLocationFile> locationFile = getSourceLocationOfParentScope(location, scopeLocations);
if (locationFile->getSourceLocationCount() == 0)
const SourceLocation* scopeLocation = getSourceLocationOfParentScope(location->getLineNumber(), scopeLocations);
if (!scopeLocation)
{
fileScopedMerger.addChild(currentMerger);
return currentMerger;
}
std::shared_ptr<SnippetMerger> nextMerger;
locationFile->forEachStartSourceLocation( // contains just 1 start location
[&](SourceLocation* scopeLocation)
{
std::map<int, std::shared_ptr<SnippetMerger>>::iterator it = mergers.find(scopeLocation->getLocationId());
if (it == mergers.end())
{
nextMerger = buildMergerHierarchy(scopeLocation, scopeLocations, fileScopedMerger, mergers);
mergers[scopeLocation->getLocationId()] = nextMerger;
}
else
{
nextMerger = it->second;
}
}
);
std::map<int, std::shared_ptr<SnippetMerger>>::iterator it = mergers.find(scopeLocation->getLocationId());
if (it == mergers.end())
{
nextMerger = buildMergerHierarchy(scopeLocation, scopeLocations, fileScopedMerger, mergers);
mergers[scopeLocation->getLocationId()] = nextMerger;
}
else
{
nextMerger = it->second;
}
nextMerger->addChild(currentMerger);
return currentMerger;
}
std::shared_ptr<SourceLocationFile> CodeController::getSourceLocationOfParentScope(
const SourceLocation* location,
std::shared_ptr<SourceLocationFile> scopeLocations
) const
const SourceLocation* CodeController::getSourceLocationOfParentScope(
size_t lineNumber, const SourceLocationFile* scopeLocations) const
{
const SourceLocation* parent = nullptr;
const SourceLocation* location = nullptr;
scopeLocations->forEachStartSourceLocation(
[&](SourceLocation* scopeLocation) -> void
[&location, lineNumber](SourceLocation* scopeLocation)
{
if (location->getStartLocation() && *scopeLocation == *location->getStartLocation() &&
location->getEndLocation() && *scopeLocation->getEndLocation() == *location->getEndLocation())
if (scopeLocation->getLineNumber() < lineNumber &&
scopeLocation->getEndLocation()->getLineNumber() >= lineNumber &&
(!location || *location < *scopeLocation))
{
return;
}
if (!(*scopeLocation > *location) &&
!(*scopeLocation->getEndLocation() < *location) &&
// since scopeLocation is a start location the > location indicates the scope
// that is closer to the child.
(!parent || *scopeLocation > *parent))
{
parent = scopeLocation;
location = scopeLocation;
}
}
);
std::shared_ptr<SourceLocationFile> file = std::make_shared<SourceLocationFile>(location->getFilePath(), false, false);
if (parent)
{
file->addSourceLocationCopy(parent);
file->addSourceLocationCopy(parent->getOtherLocation());
}
return file;
return location;
}
std::vector<std::string> CodeController::getProjectDescription(SourceLocationFile* locationFile) const
@@ -839,12 +719,91 @@ std::vector<std::string> CodeController::getProjectDescription(SourceLocationFil
return lines;
}
void CodeController::addModificationTimes(std::vector<CodeSnippetParams>& snippets) const
void CodeController::expandVisibleSnippets(std::vector<CodeSnippetParams>* snippets) const
{
TRACE();
if (!snippets->size())
{
return;
}
bool inListMode = getView()->isInListMode();
size_t filesToExpand = inListMode ? std::min(int(snippets->size()), 3) : 1;
CodeView::FileState state = inListMode ? CodeView::FILE_SNIPPETS : CodeView::FILE_MAXIMIZED;
for (size_t i = 0; i < filesToExpand; i++)
{
CodeSnippetParams& oldSnippet = snippets->at(i);
if (!oldSnippet.isCollapsed || oldSnippet.reduced)
{
continue;
}
if (!inListMode && getView()->hasSingleFileCached(oldSnippet.locationFile->getFilePath()))
{
continue;
}
CodeView::FileState fileState = oldSnippet.locationFile->isWhole() ? CodeView::FILE_MAXIMIZED : state;
std::vector<CodeSnippetParams> newSnippets =
getSnippetsForFileWithState(oldSnippet.locationFile->getFilePath(), fileState);
if (!newSnippets.size())
{
continue;
}
for (CodeSnippetParams& newSnippet : newSnippets)
{
newSnippet.isDeclaration = oldSnippet.isDeclaration;
newSnippet.isDefinition = oldSnippet.isDefinition;
newSnippet.isCollapsed = false;
}
snippets->insert(snippets->end(), newSnippets.begin(), newSnippets.end());
}
}
void CodeController::addAllSourceLocations(std::vector<CodeSnippetParams>* snippets) const
{
TRACE();
for (CodeSnippetParams& snippet : *snippets)
{
if (!snippet.locationFile || snippet.isCollapsed || snippet.reduced)
{
continue;
}
std::shared_ptr<SourceLocationFile> file;
if (snippet.locationFile->isWhole())
{
file = m_storageAccess->getSourceLocationsForFile(snippet.locationFile->getFilePath());
}
else
{
file = m_storageAccess->getSourceLocationsForLinesInFile(
snippet.locationFile->getFilePath(), snippet.startLineNumber, snippet.endLineNumber);
}
if (file)
{
file->copySourceLocations(snippet.locationFile);
snippet.locationFile = file;
}
}
}
void CodeController::addModificationTimes(std::vector<CodeSnippetParams>* snippets) const
{
TRACE();
std::vector<FilePath> filePaths;
for (const CodeSnippetParams& snippet : snippets)
for (const CodeSnippetParams& snippet : *snippets)
{
filePaths.push_back(snippet.locationFile->getFilePath());
}
@@ -856,26 +815,12 @@ void CodeController::addModificationTimes(std::vector<CodeSnippetParams>& snippe
fileInfoMap.emplace(fileInfo.path, fileInfo);
}
for (CodeSnippetParams& snippet : snippets)
for (CodeSnippetParams& snippet : *snippets)
{
snippet.modificationTime = fileInfoMap[snippet.locationFile->getFilePath()].lastWriteTime;
}
}
void CodeController::addActiveSourceLocations(std::shared_ptr<SourceLocationFile> locationFile) const
{
SourceLocationFile* activeLocations = m_collection->getSourceLocationFileByPath(locationFile->getFilePath()).get();
if (activeLocations)
{
activeLocations->forEachSourceLocation(
[&locationFile](SourceLocation* location)
{
locationFile->addSourceLocationCopy(location);
}
);
}
}
void CodeController::saveOrRestoreViewMode(MessageBase* message)
{
if (message->isReplayed())
@@ -891,3 +836,18 @@ void CodeController::saveOrRestoreViewMode(MessageBase* message)
m_messageIdToViewModeMap.emplace(message->getId(), getView()->isInListMode());
}
}
void CodeController::showCodeSnippets(
std::vector<CodeSnippetParams> snippets, const CodeView::CodeParams params, bool addSourceLocations)
{
expandVisibleSnippets(&snippets);
CodeView* view = getView();
view->showCodeSnippets(snippets, params);
if (addSourceLocations)
{
addAllSourceLocations(&snippets);
view->updateCodeSnippets(snippets);
}
}
+12 -14
View File
@@ -77,31 +77,29 @@ private:
virtual void clear();
void expandVisibleSnippets(std::vector<CodeSnippetParams>* snippets, bool addSourceLocations) const;
std::vector<CodeSnippetParams> getSnippetsForFileWithState(
const FilePath& filePath, CodeView::FileState state, bool addSourceLocations) const;
std::vector<CodeSnippetParams> getSnippetsForFileWithState(const FilePath& filePath, CodeView::FileState state) const;
std::vector<CodeSnippetParams> getSnippetsForActiveSourceLocations(
const SourceLocationCollection* collection, Id declarationId) const;
std::vector<CodeSnippetParams> getSnippetsForCollection(
std::shared_ptr<SourceLocationCollection> collection, bool addSourceLocations = false) const;
std::vector<CodeSnippetParams> getSnippetsForFile(
std::shared_ptr<SourceLocationFile> file, bool addSourceLocations = false) const;
std::vector<CodeSnippetParams> getSnippetsForCollection(std::shared_ptr<SourceLocationCollection> collection) const;
std::vector<CodeSnippetParams> getSnippetsForFile(std::shared_ptr<SourceLocationFile> file) const;
std::shared_ptr<SnippetMerger> buildMergerHierarchy(
SourceLocation* location, std::shared_ptr<SourceLocationFile> context, SnippetMerger& fileScopedMerger,
const SourceLocation* location, const SourceLocationFile* scopeLocations, SnippetMerger& fileScopedMerger,
std::map<int, std::shared_ptr<SnippetMerger>>& mergers) const;
std::shared_ptr<SourceLocationFile> getSourceLocationOfParentScope(
const SourceLocation* location, std::shared_ptr<SourceLocationFile> context) const;
const SourceLocation* getSourceLocationOfParentScope(
size_t lineNumber, const SourceLocationFile* scopeLocations) const;
std::vector<std::string> getProjectDescription(SourceLocationFile* locationFile) const;
void addModificationTimes(std::vector<CodeSnippetParams>& snippets) const;
void addActiveSourceLocations(std::shared_ptr<SourceLocationFile> locationFile) const;
void expandVisibleSnippets(std::vector<CodeSnippetParams>* snippets) const;
void addAllSourceLocations(std::vector<CodeSnippetParams>* snippets) const;
void addModificationTimes(std::vector<CodeSnippetParams>* snippets) const;
void saveOrRestoreViewMode(MessageBase* message);
void showCodeSnippets(
std::vector<CodeSnippetParams> snippets, const CodeView::CodeParams params, bool addSourceLocations = true);
StorageAccess* m_storageAccess;
mutable std::shared_ptr<SourceLocationCollection> m_collection;
+1
View File
@@ -77,6 +77,7 @@ public:
virtual void clear() = 0;
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const CodeParams params) = 0;
virtual void updateCodeSnippets(const std::vector<CodeSnippetParams>& snippets) = 0;
virtual void scrollTo(const ScrollParams params) = 0;
virtual bool showsErrors() const = 0;
@@ -115,6 +115,16 @@ SourceLocation* SourceLocationFile::addSourceLocationCopy(const SourceLocation*
return copy.get();
}
void SourceLocationFile::copySourceLocations(std::shared_ptr<SourceLocationFile> file)
{
file->forEachSourceLocation(
[this](SourceLocation* location)
{
addSourceLocationCopy(location);
}
);
}
SourceLocation* SourceLocationFile::getSourceLocationById(Id locationId) const
{
std::map<Id, SourceLocation*>::const_iterator it = m_locationIndex.find(locationId);
@@ -45,6 +45,8 @@ public:
size_t endLineNumber, size_t endColumnNumber);
SourceLocation* addSourceLocationCopy(const SourceLocation* location);
void copySourceLocations(std::shared_ptr<SourceLocationFile> file);
SourceLocation* getSourceLocationById(Id locationId) const;
void forEachSourceLocation(std::function<void(SourceLocation*)> func) const;
+16 -1
View File
@@ -294,6 +294,21 @@ void QtCodeArea::updateLineNumberAreaWidthForDigits(int digits)
updateLineNumberAreaWidth();
}
void QtCodeArea::updateSourceLocations(std::shared_ptr<SourceLocationFile> locationFile)
{
if (locationFile->getSourceLocationCount() > getSourceLocationFile()->getSourceLocationCount())
{
if (m_hoveredAnnotations.size())
{
setHoveredAnnotations({});
}
createAnnotations(locationFile);
annotateText();
}
}
void QtCodeArea::updateContent()
{
annotateText();
@@ -582,7 +597,7 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
if (m_navigator->hasErrors() && annotations.size() == 1 && annotations[0]->tokenIds.size())
{
std::wstring errorMessage = m_navigator->getErrorMessageForId(*annotations[0]->tokenIds.begin());
QToolTip::showText(event->globalPos(), QString::fromStdWString(errorMessage));
QToolTip::showText(event->globalPos(), QString::fromStdWString(errorMessage), this);
}
}
}
+1
View File
@@ -69,6 +69,7 @@ public:
int lineNumberAreaWidth() const;
void updateLineNumberAreaWidthForDigits(int digits);
void updateSourceLocations(std::shared_ptr<SourceLocationFile> locationFile);
void updateContent();
void setIsActiveFile(bool isActiveFile);
+14 -7
View File
@@ -14,6 +14,7 @@
#include "utility/messaging/type/MessageActivateTokenIds.h"
#include "utility/messaging/type/MessageTooltipShow.h"
#include "utility/TextCodec.h"
#include "utility/tracing.h"
#include "utility/utility.h"
std::vector<QtCodeField::AnnotationColor> QtCodeField::s_annotationColors;
@@ -33,19 +34,21 @@ QtCodeField::QtCodeField(
: QPlainTextEdit(parent)
, m_startLineNumber(startLineNumber)
, m_code(code)
, m_locationFile(locationFile)
, m_endTextEditPosition(0)
{
TRACE();
setObjectName("code_area");
setReadOnly(true);
setFrameStyle(QFrame::NoFrame);
setLineWrapMode(QPlainTextEdit::NoWrap);
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
setMouseTracking(true);
viewport()->setCursor(Qt::ArrowCursor);
std::string displayCode = m_code;
if (!m_locationFile->isWhole() && !displayCode.empty() && *displayCode.rbegin() == '\n')
if (!locationFile->isWhole() && !displayCode.empty() && *displayCode.rbegin() == '\n')
{
displayCode.pop_back();
}
@@ -57,7 +60,8 @@ QtCodeField::QtCodeField(
setPlainText(convertedDisplayCode);
if (displayCode.size() != size_t(convertedDisplayCode.length()))
{
LOG_INFO("Converting displayed code to " + codec.getName() + " resulted in offset of source locations. Correcting this now.");
LOG_INFO("Converting displayed code to " + codec.getName() +
" resulted in offset of source locations. Correcting this now.");
createMultibyteCharacterLocationCache(convertedDisplayCode);
}
}
@@ -68,18 +72,16 @@ QtCodeField::QtCodeField(
createLineLengthCache();
this->setMouseTracking(true);
createAnnotations(locationFile);
FilePath path = m_locationFile->getFilePath();
FilePath path = locationFile->getFilePath();
LanguageType language = LANGUAGE_UNKNOWN;
if (!path.empty())
{
language = (path.extension() == L".java" ? LANGUAGE_JAVA : LANGUAGE_CPP);
}
m_highlighter = new QtHighlighter(document(), language);
m_highlighter = std::make_shared<QtHighlighter>(document(), language);
m_highlighter->highlightDocument();
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
@@ -328,6 +330,11 @@ bool QtCodeField::annotateText(
void QtCodeField::createAnnotations(std::shared_ptr<SourceLocationFile> locationFile)
{
TRACE();
m_locationFile = locationFile;
m_annotations.clear();
uint endLineNumber = getEndLineNumber();
std::set<Id> locationIds;
+3 -3
View File
@@ -25,8 +25,8 @@ public:
uint startLineNumber,
const std::string& code,
std::shared_ptr<SourceLocationFile> locationFile,
bool convertLocationsOnDemand = true,
QWidget* parent = nullptr);
bool convertLocationsOnDemand = true,
QWidget* parent = nullptr);
~QtCodeField();
@@ -115,7 +115,7 @@ private:
std::shared_ptr<SourceLocationFile> m_locationFile;
QtHighlighter* m_highlighter;
std::shared_ptr<QtHighlighter> m_highlighter;
std::vector<int> m_lineLengths;
std::vector<std::vector<std::pair<int, int>>> m_multibyteCharacterLocations;
+38 -68
View File
@@ -12,7 +12,6 @@
QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeNavigator* navigator)
: QFrame()
, m_navigator(navigator)
, m_fileSnippet(nullptr)
, m_filePath(filePath)
, m_isWholeFile(false)
, m_contentRequested(false)
@@ -67,6 +66,11 @@ const QtCodeFileTitleBar* QtCodeFile::getTitleBar() const
QtCodeSnippet* QtCodeFile::addCodeSnippet(const CodeSnippetParams& params)
{
if (m_isWholeFile && m_snippets.size() == 1)
{
return m_snippets[0];
}
for (QtCodeSnippet* snippet : m_snippets)
{
if (snippet->getStartLineNumber() == params.startLineNumber &&
@@ -76,11 +80,6 @@ QtCodeSnippet* QtCodeFile::addCodeSnippet(const CodeSnippetParams& params)
}
}
if (params.locationFile->isWhole() && m_fileSnippet)
{
return m_fileSnippet;
}
QtCodeSnippet* snippet = new QtCodeSnippet(params, m_navigator, this);
if (params.reduced)
@@ -89,31 +88,32 @@ QtCodeSnippet* QtCodeFile::addCodeSnippet(const CodeSnippetParams& params)
m_isWholeFile = true;
}
m_snippetLayout->addWidget(snippet);
if (params.locationFile->isWhole() || m_isWholeFile)
{
snippet->setStyleSheet("#code_snippet { border: none; }");
m_isWholeFile = true;
m_fileSnippet = snippet;
if (!m_snippets.size())
{
m_fileSnippet->setIsActiveFile(true);
}
snippet->setIsActiveFile(true);
setSnippets();
if (params.refCount != -1)
{
updateRefCount(0);
}
return m_fileSnippet;
for (QtCodeSnippet* oldSnippet : m_snippets)
{
oldSnippet->hide();
}
m_snippets.clear();
}
else
{
updateRefCount(params.refCount);
}
m_snippetLayout->addWidget(snippet);
m_snippets.push_back(snippet);
setSnippets();
updateRefCount(params.refCount);
return snippet;
}
@@ -160,13 +160,26 @@ QtCodeSnippet* QtCodeFile::insertCodeSnippet(const CodeSnippetParams& params)
return snippet;
}
std::vector<QtCodeSnippet*> QtCodeFile::getVisibleSnippets() const
void QtCodeFile::updateCodeSnippet(const CodeSnippetParams& params)
{
if (m_fileSnippet && m_fileSnippet->isVisible())
if (m_isWholeFile && m_snippets.size() == 1)
{
return { m_fileSnippet };
m_snippets[0]->updateCodeSnippet(params);
return;
}
for (QtCodeSnippet* snippet : m_snippets)
{
if (snippet->getStartLineNumber() == params.startLineNumber &&
snippet->getEndLineNumber() == params.endLineNumber)
{
snippet->updateCodeSnippet(params);
}
}
}
std::vector<QtCodeSnippet*> QtCodeFile::getVisibleSnippets() const
{
std::vector<QtCodeSnippet*> snippets;
for (QtCodeSnippet* snippet : m_snippets)
@@ -182,11 +195,6 @@ std::vector<QtCodeSnippet*> QtCodeFile::getVisibleSnippets() const
QtCodeSnippet* QtCodeFile::getSnippetForLocationId(Id locationId) const
{
if (m_fileSnippet && m_fileSnippet->isVisible() && m_fileSnippet->getLineNumberForLocationId(locationId))
{
return m_fileSnippet;
}
for (QtCodeSnippet* snippet : m_snippets)
{
if (snippet->getLineNumberForLocationId(locationId))
@@ -200,11 +208,6 @@ QtCodeSnippet* QtCodeFile::getSnippetForLocationId(Id locationId) const
QtCodeSnippet* QtCodeFile::getSnippetForLine(unsigned int line) const
{
if (m_fileSnippet && m_fileSnippet->isVisible())
{
return m_fileSnippet;
}
for (QtCodeSnippet* snippet : m_snippets)
{
if (snippet->getStartLineNumber() <= line && line <= snippet->getEndLineNumber())
@@ -216,11 +219,6 @@ QtCodeSnippet* QtCodeFile::getSnippetForLine(unsigned int line) const
return nullptr;
}
QtCodeSnippet* QtCodeFile::getFileSnippet() const
{
return m_fileSnippet;
}
std::pair<QtCodeSnippet*, Id> QtCodeFile::getFirstSnippetWithActiveLocationId(Id tokenId) const
{
std::pair<QtCodeSnippet*, Id> result(nullptr, 0);
@@ -241,7 +239,7 @@ std::pair<QtCodeSnippet*, Id> QtCodeFile::getFirstSnippetWithActiveLocationId(Id
bool QtCodeFile::isCollapsed() const
{
return !getFileSnippet() && !m_snippets.size();
return !m_snippets.size();
}
void QtCodeFile::requestContent()
@@ -257,14 +255,14 @@ void QtCodeFile::requestContent()
MessageChangeFileView::FileState state =
m_isWholeFile ? MessageChangeFileView::FILE_MAXIMIZED : MessageChangeFileView::FILE_SNIPPETS;
bool needsData = (state == MessageChangeFileView::FILE_MAXIMIZED) ? (getFileSnippet() == nullptr) : (m_snippets.size() == 0);
bool needsData = (m_snippets.size() == 0);
MessageChangeFileView(m_filePath, state, MessageChangeFileView::VIEW_LIST, needsData, m_navigator->hasErrors()).dispatch();
}
void QtCodeFile::requestWholeFileContent()
{
if (!getFileSnippet())
if (!m_isWholeFile)
{
MessageChangeFileView(
m_filePath,
@@ -288,11 +286,6 @@ void QtCodeFile::updateContent()
{
snippet->updateContent();
}
if (m_fileSnippet)
{
m_fileSnippet->updateContent();
}
}
void QtCodeFile::setWholeFile(bool isWholeFile, int refCount)
@@ -315,11 +308,6 @@ void QtCodeFile::setMinimized()
snippet->hide();
}
if (m_fileSnippet)
{
m_fileSnippet->hide();
}
m_titleBar->setMinimized();
setStyleSheet("#code_file { padding-bottom: 0; } #code_file #title_bar { border-radius: 7px; }");
@@ -327,21 +315,9 @@ void QtCodeFile::setMinimized()
void QtCodeFile::setSnippets()
{
if (m_fileSnippet)
for (QtCodeSnippet* snippet : m_snippets)
{
m_fileSnippet->show();
for (QtCodeSnippet* snippet : m_snippets)
{
snippet->hide();
}
}
else
{
for (QtCodeSnippet* snippet : m_snippets)
{
snippet->show();
}
snippet->show();
}
m_titleBar->setSnippets();
@@ -395,12 +371,6 @@ void QtCodeFile::updateTitleBar()
void QtCodeFile::findScreenMatches(const std::wstring& query, std::vector<std::pair<QtCodeArea*, Id>>* screenMatches)
{
if (m_fileSnippet && m_fileSnippet->isVisible())
{
m_fileSnippet->findScreenMatches(query, screenMatches);
return;
}
for (QtCodeSnippet* snippet : m_snippets)
{
if (snippet->isVisible())
+1 -2
View File
@@ -35,11 +35,11 @@ public:
QtCodeSnippet* addCodeSnippet(const CodeSnippetParams& params);
QtCodeSnippet* insertCodeSnippet(const CodeSnippetParams& params);
void updateCodeSnippet(const CodeSnippetParams& params);
std::vector<QtCodeSnippet*> getVisibleSnippets() const;
QtCodeSnippet* getSnippetForLocationId(Id locationId) const;
QtCodeSnippet* getSnippetForLine(unsigned int line) const;
QtCodeSnippet* getFileSnippet() const;
std::pair<QtCodeSnippet*, Id> getFirstSnippetWithActiveLocationId(Id tokenId) const;
@@ -76,7 +76,6 @@ private:
QVBoxLayout* m_snippetLayout;
std::vector<QtCodeSnippet*> m_snippets;
QtCodeSnippet* m_fileSnippet;
const FilePath m_filePath;
bool m_isWholeFile;
+8 -2
View File
@@ -137,6 +137,12 @@ void QtCodeFileList::addCodeSnippet(const CodeSnippetParams& params)
file->setIsComplete(params.locationFile->isComplete());
}
void QtCodeFileList::updateCodeSnippet(const CodeSnippetParams& params)
{
QtCodeFile* file = getFile(params.locationFile->getFilePath());
file->updateCodeSnippet(params);
}
void QtCodeFileList::requestFileContent(const FilePath& filePath)
{
getFile(filePath)->requestContent();
@@ -166,9 +172,9 @@ bool QtCodeFileList::requestScroll(const FilePath& filePath, uint lineNumber, Id
{
snippet = file->getSnippetForLine(lineNumber);
}
else if (file->getFileSnippet() && file->getFileSnippet()->isVisible())
else
{
snippet = file->getFileSnippet();
snippet = file->getSnippetForLine(1);
}
if (!snippet)
+1
View File
@@ -35,6 +35,7 @@ public:
virtual QScrollArea* getScrollArea();
virtual void addCodeSnippet(const CodeSnippetParams& params);
virtual void updateCodeSnippet(const CodeSnippetParams& params);
virtual void requestFileContent(const FilePath& filePath);
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, ScrollTarget target);
@@ -119,6 +119,15 @@ void QtCodeFileSingle::addCodeSnippet(const CodeSnippetParams& params)
}
}
void QtCodeFileSingle::updateCodeSnippet(const CodeSnippetParams& params)
{
auto it = m_fileDatas.find(params.locationFile->getFilePath());
if (it != m_fileDatas.end())
{
it->second.area->updateSourceLocations(params.locationFile);
}
}
void QtCodeFileSingle::requestFileContent(const FilePath& filePath)
{
if (m_contentRequested)
@@ -34,6 +34,7 @@ public:
virtual QAbstractScrollArea* getScrollArea() override;
virtual void addCodeSnippet(const CodeSnippetParams& params) override;
virtual void updateCodeSnippet(const CodeSnippetParams& params) override;
virtual void requestFileContent(const FilePath& filePath) override;
virtual bool requestScroll(
@@ -29,6 +29,7 @@ public:
virtual QAbstractScrollArea* getScrollArea() = 0;
virtual void addCodeSnippet(const CodeSnippetParams& params) = 0;
virtual void updateCodeSnippet(const CodeSnippetParams& params) = 0;
virtual void requestFileContent(const FilePath& filePath) = 0;
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, ScrollTarget target) = 0;
@@ -140,6 +140,11 @@ void QtCodeNavigator::addCodeSnippet(const CodeSnippetParams& params)
}
}
void QtCodeNavigator::updateCodeSnippet(const CodeSnippetParams& params)
{
m_current->updateCodeSnippet(params);
}
void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimeStamp modificationTime)
{
bool firstFile = m_references.size() == 0;
+1
View File
@@ -43,6 +43,7 @@ public:
virtual ~QtCodeNavigator();
void addCodeSnippet(const CodeSnippetParams& params);
void updateCodeSnippet(const CodeSnippetParams& params);
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimeStamp modificationTime);
void addedFiles();
+5
View File
@@ -139,6 +139,11 @@ int QtCodeSnippet::lineNumberDigits() const
return m_codeArea->lineNumberDigits();
}
void QtCodeSnippet::updateCodeSnippet(const CodeSnippetParams& params)
{
m_codeArea->updateSourceLocations(params.locationFile);
}
void QtCodeSnippet::updateLineNumberAreaWidthForDigits(int digits)
{
m_codeArea->updateLineNumberAreaWidthForDigits(digits);
+2
View File
@@ -37,6 +37,8 @@ public:
int lineNumberDigits() const;
void updateCodeSnippet(const CodeSnippetParams& params);
void updateLineNumberAreaWidthForDigits(int digits);
void updateContent();
+56 -26
View File
@@ -5,6 +5,7 @@
#include <QTextDocument>
#include "settings/ColorScheme.h"
#include "utility/tracing.h"
#include "utility/utility.h"
QVector<QtHighlighter::HighlightingRule> QtHighlighter::s_highlightingRules;
@@ -138,15 +139,22 @@ QtHighlighter::QtHighlighter(QTextDocument *document, LanguageType language)
void QtHighlighter::highlightDocument()
{
TRACE();
QTextDocument* doc = document();
int docStart = 0;
int docEnd = 0;
size_t docStart = 0;
size_t docEnd = 0;
for (int i = 0; i < doc->blockCount(); i++)
{
docEnd += doc->findBlockByLineNumber(i).length();
}
docEnd -= 1;
if (docEnd > 0)
{
docEnd -= 1;
}
applyFormat(docStart, docEnd, s_textFormat);
m_highlightedLines.clear();
@@ -157,18 +165,7 @@ void QtHighlighter::highlightDocument()
return;
}
m_quotationRanges.clear();
m_multiLineCommentRanges.clear();
std::vector<std::pair<int, int>> ranges;
ranges.push_back(std::pair<int, int>(docStart, docEnd));
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
{
utility::append(m_quotationRanges, formatBlockForRule(it, s_stringQuotationRule, &ranges));
utility::append(m_quotationRanges, formatBlockForRule(it, s_charQuotationRule, &ranges));
}
highlightMultiLineComments();
createRanges(doc, s_stringQuotationRule, s_charQuotationRule);
}
void QtHighlighter::highlightRange(int startLine, int endLine)
@@ -252,16 +249,32 @@ QTextCharFormat QtHighlighter::getFormat(int startPosition, int endPosition) con
return cursor.charFormat();
}
void QtHighlighter::highlightMultiLineComments()
void QtHighlighter::createRanges(
QTextDocument* doc, const HighlightingRule& stringRule, const HighlightingRule& charRule)
{
QTextDocument* doc = document();
m_quotationRanges.clear();
m_multiLineCommentRanges.clear();
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
{
utility::append(m_quotationRanges, getRangesForRule(it, stringRule));
utility::append(m_quotationRanges, getRangesForRule(it, charRule));
}
m_multiLineCommentRanges = createMultiLineCommentRanges(doc, &m_quotationRanges);
}
std::vector<std::pair<int, int>> QtHighlighter::createMultiLineCommentRanges(
QTextDocument* doc, std::vector<std::pair<int, int>>* ranges)
{
QRegExp commentStartExpression = QRegExp("(^([^/]|/[^/])*)/\\*");
QRegExp commentEndExpression = QRegExp("\\*/");
QTextCursor cursorStart(doc);
QTextCursor cursorEnd(doc);
std::vector<std::pair<int, int>> multiLineCommentRanges;
while (true)
{
do
@@ -272,7 +285,7 @@ void QtHighlighter::highlightMultiLineComments()
cursorStart.setPosition(cursorStart.selectionEnd() - 2);
}
}
while (isInRange(cursorStart.position(), m_quotationRanges));
while (isInRange(cursorStart.selectionEnd(), *ranges));
if (cursorStart.isNull())
{
@@ -285,9 +298,11 @@ void QtHighlighter::highlightMultiLineComments()
break;
}
m_multiLineCommentRanges.push_back(std::pair<int, int>(cursorStart.selectionStart(), cursorEnd.position()));
multiLineCommentRanges.push_back(std::pair<int, int>(cursorStart.position(), cursorEnd.position()));
cursorStart = cursorEnd;
}
return multiLineCommentRanges;
}
QtHighlighter::HighlightingRule::HighlightingRule()
@@ -313,15 +328,34 @@ bool QtHighlighter::isInRange(int pos, const std::vector<std::pair<int, int>>& r
return false;
}
std::vector<std::pair<int, int>> QtHighlighter::formatBlockForRule(
std::vector<std::pair<int, int>> QtHighlighter::getRangesForRule(
const QTextBlock& block, const HighlightingRule& rule) const
{
QRegExp expression(rule.pattern);
int pos = block.position();
int index = expression.indexIn(block.text());
std::vector<std::pair<int, int>> ranges;
while (index >= 0)
{
int length = expression.matchedLength();
ranges.push_back(std::pair<int, int>(pos + index, pos + index + length));
index = expression.indexIn(block.text(), index + length);
}
return ranges;
}
void QtHighlighter::formatBlockForRule(
const QTextBlock& block, const HighlightingRule& rule, std::vector<std::pair<int, int>>* ranges
){
QRegExp expression(rule.pattern);
int pos = block.position();
int index = expression.indexIn(block.text());
std::vector<std::pair<int, int>> newRanges;
while (index >= 0)
{
int length = expression.matchedLength();
@@ -331,12 +365,8 @@ std::vector<std::pair<int, int>> QtHighlighter::formatBlockForRule(
applyFormat(pos + index, pos + index + length, rule.format);
}
newRanges.push_back(std::pair<int, int>(pos + index, pos + index + length));
index = expression.indexIn(block.text(), index + length);
}
return newRanges;
}
void QtHighlighter::formatBlockIfInRange(
+8 -2
View File
@@ -15,6 +15,8 @@ public:
static void clearHighlightingRules();
QtHighlighter(QTextDocument *parent, LanguageType language);
~QtHighlighter() = default;
void highlightDocument();
void highlightRange(int startLine, int endLine);
@@ -34,10 +36,14 @@ private:
QTextCharFormat format;
};
void highlightMultiLineComments();
void createRanges(QTextDocument* doc, const HighlightingRule& stringRule, const HighlightingRule& charRule);
std::vector<std::pair<int, int>> createMultiLineCommentRanges(
QTextDocument* doc, std::vector<std::pair<int, int>>* ranges);
bool isInRange(int index, const std::vector<std::pair<int, int>>& ranges) const;
std::vector<std::pair<int, int>> formatBlockForRule(
std::vector<std::pair<int, int>> getRangesForRule(const QTextBlock& block, const HighlightingRule& rule) const;
void formatBlockForRule(
const QTextBlock& block, const HighlightingRule& rule, std::vector<std::pair<int, int>>* ranges = nullptr);
void formatBlockIfInRange(
const QTextBlock& block, const QTextCharFormat& format, std::vector<std::pair<int, int>>* ranges);
+13
View File
@@ -154,6 +154,19 @@ void QtCodeView::showCodeSnippets(const std::vector<CodeSnippetParams>& snippets
});
}
void QtCodeView::updateCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
{
m_onQtThread([=]()
{
TRACE("update code snippets");
for (const CodeSnippetParams& snippet : snippets)
{
m_widget->updateCodeSnippet(snippet);
}
});
}
void QtCodeView::scrollTo(const ScrollParams params)
{
m_scrollParams = params;
+1
View File
@@ -29,6 +29,7 @@ public:
virtual void clear();
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const CodeParams params);
virtual void updateCodeSnippets(const std::vector<CodeSnippetParams>& snippets);
virtual void scrollTo(const ScrollParams params);
virtual bool showsErrors() const;