Skip to content

Commit 5e28483

Browse files
committed
Refactor the code to record the history command.
1 parent 3c8e5a1 commit 5e28483

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

tools/Az.Tools.Predictor/Az.Tools.Predictor/AzPredictor.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ public void StartEarlyProcessing(string clientId, IReadOnlyList<string> history)
120120
{
121121
string secondToLastLine = history.TakeLast(AzPredictorConstants.CommandHistoryCountToProcess).First();
122122
var secondToLastCommand = GetAstAndMaskedCommandLine(secondToLastLine);
123-
_lastTwoMaskedCommands.Enqueue(secondToLastCommand.MaskedValue);
123+
_lastTwoMaskedCommands.Enqueue(secondToLastCommand.IsSupported ? secondToLastCommand.MaskedValue : AzPredictorConstants.CommandPlaceholder);
124124

125-
if (!string.Equals(AzPredictorConstants.CommandPlaceholder, secondToLastCommand.MaskedValue, StringComparison.Ordinal))
125+
if (secondToLastCommand.IsSupported)
126126
{
127127
_service.RecordHistory(secondToLastCommand.Ast);
128128
}
@@ -162,9 +162,7 @@ public void StartEarlyProcessing(string clientId, IReadOnlyList<string> history)
162162
_lastTwoMaskedCommands.Enqueue(existingInQueue);
163163
}
164164

165-
_telemetryClient.OnHistory(new HistoryTelemetryData(clientId,
166-
lastCommand.IsSupported ? lastCommand.MaskedValue:
167-
(lastCommand.Ast?.GetCommandName() ?? lastCommand.MaskedValue)));
165+
_telemetryClient.OnHistory(new HistoryTelemetryData(clientId, lastCommand.MaskedValue ?? AzPredictorConstants.CommandPlaceholder));
168166

169167
if (isLastTwoCommandsChanged)
170168
{
@@ -209,15 +207,10 @@ public void StartEarlyProcessing(string clientId, IReadOnlyList<string> history)
209207
var asts = Parser.ParseInput(commandLine, out _, out _);
210208
var allNestedAsts = asts?.FindAll((ast) => ast is CommandAst, true);
211209
var commandAst = allNestedAsts?.LastOrDefault() as CommandAst;
212-
string maskedCommandLine = AzPredictorConstants.CommandPlaceholder;
213210

214211
var commandName = commandAst?.CommandElements?.FirstOrDefault().ToString();
215212
bool isSupported = _service.IsSupportedCommand(commandName);
216-
217-
if (isSupported)
218-
{
219-
maskedCommandLine = CommandLineUtilities.MaskCommandLine(commandAst);
220-
}
213+
string maskedCommandLine = CommandLineUtilities.MaskCommandLine(commandAst);
221214

222215
return (commandAst, maskedCommandLine, isSupported);
223216
}

0 commit comments

Comments
 (0)