ui: Sort snippets to always show definition on top
This commit is contained in:
@@ -302,29 +302,36 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocation
|
||||
const TokenLocationCollection* collection, Id declarationId
|
||||
) const {
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
size_t declarationFileCount = 0;
|
||||
size_t definitionFileCount = 0;
|
||||
|
||||
collection->forEachTokenLocationFile(
|
||||
[&](std::shared_ptr<TokenLocationFile> 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<CodeSnippetParams> fileSnippets = getSnippetsForActiveTokenLocationsInFile(file);
|
||||
|
||||
for (CodeSnippetParams& snippet : fileSnippets)
|
||||
{
|
||||
snippet.isDeclaration = isDeclarationFile;
|
||||
snippet.isDefinition = isDefinitionFile;
|
||||
}
|
||||
|
||||
utility::append(snippets, fileSnippets);
|
||||
@@ -339,9 +346,9 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocation
|
||||
snippets.push_back(params);
|
||||
}
|
||||
|
||||
if (isDeclarationFile)
|
||||
if (isDefinitionFile)
|
||||
{
|
||||
declarationFileCount++;
|
||||
definitionFileCount++;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -31,9 +31,11 @@ struct CodeSnippetParams
|
||||
int refCount;
|
||||
|
||||
bool isActive;
|
||||
bool isDeclaration;
|
||||
bool isCollapsed;
|
||||
|
||||
bool isDeclaration;
|
||||
bool isDefinition;
|
||||
|
||||
bool reduced;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user