Skip to content

Instantly share code, notes, and snippets.

@bielawb
Created September 7, 2022 22:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bielawb/f6b41130a04b5c0cf07f3bab39d75004 to your computer and use it in GitHub Desktop.
Save bielawb/f6b41130a04b5c0cf07f3bab39d75004 to your computer and use it in GitHub Desktop.
Podpowiedzi - przykłady pomocy
// do konstruktora dodajemy _examples pobrane z pliku, by nie czytać ich za każdym razem...
internal HelpExamplePredictor(string guid)
{
_guid = new Guid(guid);
string moduleFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string ewsHelpPath = Path.Combine(moduleFolder, "EWS-help.xml");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(ewsHelpPath);
XmlNamespaceManager manager = new XmlNamespaceManager(xmlDoc.NameTable);
manager.AddNamespace("dev", "http://schemas.microsoft.com/maml/dev/2004/10");
_examples = new List<string>{};
foreach (XmlNode node in xmlDoc.SelectNodes("*//dev:code", manager))
{
_examples.Add(node.InnerText.Replace(@"PS C:\> ", ""));
}
}
public SuggestionPackage GetSuggestion(PredictionClient client, PredictionContext context, CancellationToken cancellationToken)
{
if (context.TokenAtCursor.TokenFlags == TokenFlags.CommandName)
{
string command = context.TokenAtCursor.Text;
List<PredictiveSuggestion> suggestions = new List<PredictiveSuggestion>{};
foreach (string example in _examples)
{
if (example.ToLower().StartsWith(command.ToLower()))
{
suggestions.Add(new PredictiveSuggestion(example));
}
}
if (suggestions.Count == 0)
{
return default;
}
else
{
return new SuggestionPackage(suggestions);
}
}
else
{
return default;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment