diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 5ee0954c..745b4ba4 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -302,29 +302,36 @@ std::vector CodeController::getSnippetsForActiveTokenLocation const TokenLocationCollection* collection, Id declarationId ) const { std::vector snippets; - size_t declarationFileCount = 0; + size_t definitionFileCount = 0; collection->forEachTokenLocationFile( [&](std::shared_ptr file) -> void { bool isDeclarationFile = false; + bool isDefinitionFile = false; file->forEachTokenLocation( [&](TokenLocation* location) { if (location->getTokenId() == declarationId) { isDeclarationFile = true; + + if (location->getType() == LOCATION_SCOPE) + { + isDefinitionFile = true; + } } } ); - if (declarationFileCount < 5 && (isDeclarationFile || collection->getTokenLocationFileCount() < 5 || file->isWholeCopy)) + if (definitionFileCount < 5 && (isDeclarationFile || collection->getTokenLocationFileCount() < 5 || file->isWholeCopy)) { std::vector fileSnippets = getSnippetsForActiveTokenLocationsInFile(file); for (CodeSnippetParams& snippet : fileSnippets) { snippet.isDeclaration = isDeclarationFile; + snippet.isDefinition = isDefinitionFile; } utility::append(snippets, fileSnippets); @@ -339,9 +346,9 @@ std::vector CodeController::getSnippetsForActiveTokenLocation snippets.push_back(params); } - if (isDeclarationFile) + if (isDefinitionFile) { - declarationFileCount++; + definitionFileCount++; } } ); diff --git a/src/lib/component/view/helper/CodeSnippetParams.cpp b/src/lib/component/view/helper/CodeSnippetParams.cpp index 2b273b86..ffa08cc2 100644 --- a/src/lib/component/view/helper/CodeSnippetParams.cpp +++ b/src/lib/component/view/helper/CodeSnippetParams.cpp @@ -10,8 +10,9 @@ CodeSnippetParams::CodeSnippetParams() , locationFile() , refCount(0) , isActive(false) - , isDeclaration(false) , isCollapsed(false) + , isDeclaration(false) + , isDefinition(false) , reduced(false) { } @@ -28,6 +29,16 @@ bool CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSnippetParams return false; } + // sort definitions + if (a.isDefinition && !b.isDefinition) + { + return true; + } + else if (!a.isDefinition && b.isDefinition) + { + return false; + } + // sort declarations if (a.isDeclaration && !b.isDeclaration) { diff --git a/src/lib/component/view/helper/CodeSnippetParams.h b/src/lib/component/view/helper/CodeSnippetParams.h index 15c14736..aadb6502 100644 --- a/src/lib/component/view/helper/CodeSnippetParams.h +++ b/src/lib/component/view/helper/CodeSnippetParams.h @@ -31,9 +31,11 @@ struct CodeSnippetParams int refCount; bool isActive; - bool isDeclaration; bool isCollapsed; + bool isDeclaration; + bool isDefinition; + bool reduced; };