Skip to content

Commit

Permalink
Improve tooltips (Merge pull request #7 from Shresht7:tooltip)
Browse files Browse the repository at this point in the history
Improve tooltips
  • Loading branch information
Shresht7 authored Feb 4, 2024
2 parents 955599e + 63da7fc commit 13ecba7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Binary file modified Module/Library/PSFavoritePredictor.dll
Binary file not shown.
27 changes: 26 additions & 1 deletion Predictor/PSFavoritePredictor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Management.Automation;
using System.Management.Automation.Subsystem;
using System.Management.Automation.Subsystem.Prediction;
using Microsoft.VisualBasic;

namespace PowerShell.Sample
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public SuggestionPackage GetSuggestion(PredictionClient client, PredictionContex
.Select(line => (Line: line, Score: DetermineScore(input, line))) // Determine the score for each line.
.Where(tuple => tuple.Score >= ScoreThreshold) // Filter out the lines below the score threshold.
.OrderByDescending(tuple => tuple.Score) // Order the list by the score in descending order.
.Select(tuple => new PredictiveSuggestion(tuple.Line, tuple.Score.ToString())) // Create a PredictiveSuggestion object for selected line.
.Select(tuple => new PredictiveSuggestion(tuple.Line, GetTooltip(tuple.Line))) // Create a PredictiveSuggestion object for selected line.
.ToList(); // Convert to a list of PredictiveSuggestion objects.

// Return the list of suggestions.
Expand Down Expand Up @@ -106,6 +107,30 @@ private int DetermineScore(string input, string line)
return score;
}

/// <summary>
/// Get the tooltip for the suggestion.
/// </summary>
/// <param name="line">The line from the favorite's file</param>
/// <returns>The tooltip for the suggestion</returns>
/// <remarks>
/// The tooltip is the part of the line after the first '#' character.
/// </remarks>
/// <example>
/// If the line is "Get-Process # Get the list of processes", the tooltip is "Get the list of processes".
/// </example>
private static string GetTooltip(string line)
{
string[] s = Strings.Split(line, "#");
if (s.Length > 1)
{
return s[1].Trim();
}
else
{
return string.Empty;
}
}

#region "interface methods for processing feedback"

/// <summary>
Expand Down

0 comments on commit 13ecba7

Please sign in to comment.