Filter out list of code snippets visible on the list view
-
01-07-2021 - |
Question
Following this link I have a set of code snippets.
But the snippet insertion has to be w.r.t the context, viz. if I do 'Insert Snippet' before declaring a class, it shouldn't show 'method declaration' snippet. Also required is to filter snippets as per managed or unmanaged code.
In short I am looking for a mechanism as follows:
if <condition>
{
modify list of snippets visible in the menu
}
Do we have such a mechanism or something similar? Ideas welcome.
Solution
I found a solution to my question. Hope it helps someone.
I followed the instructions on the links: Video on Code Snippets & Code Element
Got the snippet.xml file to contain the following:
<Code Language="Language"
Kind="method decl">
Code to insert
</Code>
Then called the expansionProvider.DisplayExpansionBrowser in the FilterView class (refer to the video):
string[] kind = new string[1];
kind[0] = "method decl";
return expansionProvider.DisplayExpansionBrowser(TextView,
snippets,
null, false, kind, false);
Thus the specific snippet will appear in 'method declaration' context. Thus other snippets can be done. The xml has to hold the context information.