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:
@@ -1,9 +1,11 @@
|
||||
#include "component/controller/CodeController.h"
|
||||
|
||||
#include <memory>
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
@@ -54,7 +56,7 @@ void CodeController::handleMessage(MessageFinishedParsing* message)
|
||||
std::vector<CodeView::CodeSnippetParams> snippets;
|
||||
|
||||
errorCollection.forEachTokenLocationFile(
|
||||
[&](TokenLocationFile* file) -> void
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
{
|
||||
std::vector<CodeView::CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
snippets.insert(snippets.end(), fileSnippets.begin(), fileSnippets.end());
|
||||
@@ -101,7 +103,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
|
||||
std::vector<CodeView::CodeSnippetParams> snippets;
|
||||
|
||||
collection.forEachTokenLocationFile(
|
||||
[&](TokenLocationFile* file) -> void
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
{
|
||||
std::vector<CodeView::CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
|
||||
@@ -116,7 +118,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
|
||||
bool isDeclarationFile = false;
|
||||
for (const CodeView::CodeSnippetParams& snippet : fileSnippets)
|
||||
{
|
||||
snippet.locationFile.forEachTokenLocation(
|
||||
snippet.locationFile->forEachTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
{
|
||||
if (location->getTokenId() == declarationId)
|
||||
@@ -142,7 +144,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
|
||||
return snippets;
|
||||
}
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(const TokenLocationFile* file) const
|
||||
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const
|
||||
{
|
||||
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(file->getFilePath().str());
|
||||
|
||||
@@ -174,10 +176,24 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(cons
|
||||
for (const SnippetMerger::Range& range: ranges)
|
||||
{
|
||||
CodeView::CodeSnippetParams params;
|
||||
params.locationFile = *file;
|
||||
params.locationFile = file;
|
||||
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));
|
||||
|
||||
|
||||
std::shared_ptr<TokenLocationFile> tempFile = m_storageAccess->getTokenLocationsForLinesInFile(file->getFilePath().str(), params.startLineNumber, params.endLineNumber);
|
||||
TokenLocationLine* firstUsedLine = nullptr;
|
||||
for (rsize_t i = params.startLineNumber; i <= params.endLineNumber, firstUsedLine == nullptr; i++)
|
||||
{
|
||||
firstUsedLine = tempFile->findTokenLocationLineByNumber(i);
|
||||
}
|
||||
m_storageAccess->getTokenLocationOfParentScope(firstUsedLine->getTokenLocations().begin()->second.get())->forEachStartTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
{
|
||||
params.title = m_storageAccess->getNameForNodeWithId(location->getTokenId());
|
||||
}
|
||||
);
|
||||
|
||||
for (const std::string& line: textAccess->getLines(params.startLineNumber, params.endLineNumber))
|
||||
{
|
||||
params.code += line;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "component/controller/helper/SnippetMerger.h"
|
||||
#include "component/controller/Controller.h"
|
||||
#include "component/view/CodeView.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
@@ -14,10 +15,6 @@
|
||||
#include "utility/messaging/type/MessageShowFile.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
|
||||
|
||||
#include "component/controller/helper/SnippetMerger.h"
|
||||
|
||||
class StorageAccess;
|
||||
class TokenLocationFile;
|
||||
|
||||
@@ -46,7 +43,7 @@ private:
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForActiveTokenIds(
|
||||
const std::vector<Id>& ids, Id declarationId) const;
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForFile(const TokenLocationFile* file) const;
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const;
|
||||
std::shared_ptr<SnippetMerger> buildMergerHierarchy(
|
||||
TokenLocation* location, SnippetMerger& fileScopedMerger, std::map<int, std::shared_ptr<SnippetMerger>>& mergers) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user