-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Cmdlets to help with troubleshooting
Resolves: #26
- Loading branch information
1 parent
2158e15
commit d663361
Showing
8 changed files
with
132 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Management.Automation; | ||
|
||
namespace PowerType; | ||
|
||
/// <summary> | ||
/// <para type="synopsis">Cmdlet to disable PowerType Predictor and start receiving suggestions</para> | ||
/// <para type="description">Use this cmdlet to disable PowerType Predictor and start receiving suggestions</para> | ||
/// </summary> | ||
[Cmdlet("Get", "PowerTypeHistory"), OutputType(typeof(bool))] | ||
public class GetPowerTypeHistory : PowerTypeCmdlet | ||
{ | ||
/// <inheritdoc/> | ||
protected override void ProcessRecord() | ||
{ | ||
var instance = PowerTypePredictor.Instance; | ||
if (instance == null) | ||
{ | ||
throw new InvalidOperationException("Please call 'Enable-PowerTypePredictor' first"); | ||
} | ||
this.WriteObject(instance.PredictionSummaryCollector.Get()); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Management.Automation; | ||
using System.Management.Automation.Subsystem; | ||
|
||
namespace PowerType; | ||
|
||
public record PowerTypeStatus(bool ExecutionEngineIsRunning, Exception? ExecutionEngineException); | ||
|
||
/// <summary> | ||
/// <para type="synopsis">Cmdlet to disable PowerType Predictor and start receiving suggestions</para> | ||
/// <para type="description">Use this cmdlet to disable PowerType Predictor and start receiving suggestions</para> | ||
/// </summary> | ||
[Cmdlet("Get", "PowerTypeStatus"), OutputType(typeof(bool))] | ||
public class GetPowerTypeStatus : PowerTypeCmdlet | ||
{ | ||
|
||
/// <inheritdoc/> | ||
protected override void ProcessRecord() | ||
{ | ||
var instance = PowerTypePredictor.Instance; | ||
if (instance == null) | ||
{ | ||
throw new InvalidOperationException("Please call 'Enable-PowerTypePredictor' first"); | ||
} | ||
this.WriteObject(new PowerTypeStatus(instance.ExecutionEngine.IsHealthy(out Exception? exception), exception)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Diagnostics; | ||
using System.Management.Automation.Subsystem.Prediction; | ||
|
||
namespace PowerType; | ||
|
||
public record struct PowerTypePredictionSummary(DateTime When, string Input, string? TokenAtCursor, Exception? Exception, string[] Suggestions, TimeSpan Duration); | ||
|
||
public class PowerTypePredictionSummaryCollector | ||
{ | ||
private readonly object locker = new (); | ||
private readonly PowerTypePredictionSummary[] items; | ||
private int offset = 0; | ||
|
||
public PowerTypePredictionSummaryCollector(int size = 20) | ||
{ | ||
items = new PowerTypePredictionSummary[size]; | ||
} | ||
|
||
public void Add(DateTime when, PredictionContext predictionContext, Exception? exception, SuggestionPackage suggestionPackage, TimeSpan duration) | ||
{ | ||
lock (locker) | ||
{ | ||
var index = offset++ % items.Length; | ||
items[index] = new PowerTypePredictionSummary(when, predictionContext.InputAst.ToString(), predictionContext.TokenAtCursor?.ToString(), exception, suggestionPackage.SuggestionEntries.Select(x => x.SuggestionText).ToArray(), duration); | ||
} | ||
} | ||
|
||
public List<PowerTypePredictionSummary> Get() | ||
{ | ||
lock (locker) | ||
{ | ||
return items.Take(Math.Min(offset, items.Length)) | ||
.OrderBy(x => x.When) | ||
.ToList(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters