private static IList <CompletionResult> CompleteBisect(CompleteCommandParameters completeCommandParameters) { var relativeIndex = completeCommandParameters.CurrentElementIndex - completeCommandParameters.CommandElementIndex; return(relativeIndex switch { 1 => CompleteCommands(completeCommandParameters.WordToComplete), int i when i > 1 => CompleteSubParameter(i, completeCommandParameters.Ast.CommandElements[completeCommandParameters.CommandElementIndex + 1].Extent.Text, completeCommandParameters.WordToComplete), _ => Array.Empty <CompletionResult>(), });
public static IList <CompletionResult> CompleteInput(string wordToComplete, CommandAst ast, int cursorPosition) { var completeCommandParameters = CompleteCommandParameters.Create(wordToComplete, ast, cursorPosition); if (completeCommandParameters.IsCompletingCommand) { return(CompleteGitCommands(wordToComplete: wordToComplete)); } return(CompleteGitCommand(completeCommandParameters)); }
private static IList <CompletionResult> CompleteGitCommand(CompleteCommandParameters completeCommandParameters) { var wordToComplete = completeCommandParameters.WordToComplete; bool isCompletingParameterName = completeCommandParameters.IsCompletingParameterName; switch (completeCommandParameters.CommandName) { case "add": if (!isCompletingParameterName) { return(CompleteModifiedFiles(wordToComplete)); } goto default; case "bisect": if (!isCompletingParameterName) { return(CompleteBisect(completeCommandParameters)); } goto default; case "branch": if (!isCompletingParameterName) { return(CompleteBranches(wordToComplete: wordToComplete)); } goto default; case "checkout": if (string.IsNullOrEmpty(value: completeCommandParameters.PreviousParameterName) && !isCompletingParameterName) { return(CompleteCheckout(completeCommandParameters)); } goto default; case "fetch": if (!isCompletingParameterName) { if (!string.IsNullOrEmpty(value: completeCommandParameters.PreviousParameterValue) && completeCommandParameters.PreviousParameterValue != completeCommandParameters.CommandName) { return(Git.RemoteRefs() .Where(r => r.Remote.IgnoreCaseEquals(value: completeCommandParameters.PreviousParameterValue) && r.Ref.IgnoreCaseStartsWith(value: wordToComplete)) .Select(c => new CompletionResult(completionText: c.Ref, listItemText: c.Ref, resultType: CompletionResultType.ParameterValue, toolTip: c.RemoteRef)) .ToList()); } return(Git.RemoteRefs() .Where(r => r.Remote.IgnoreCaseContains(value: wordToComplete)) .GroupBy(c => c.Remote) .Select(g => g.First()) .Select(c => new CompletionResult(completionText: c.Remote, listItemText: c.Remote, resultType: CompletionResultType.ParameterValue, toolTip: c.Remote)) .ToList()); } goto default; case "diff": case "difftool": return(CompleteDiff(completeCommandParameters)); case "rebase": return(CompleteRebase(completeCommandParameters)); case "show": return(CompleteShow(completeCommandParameters)); case "tag": return(CompleteTag(completeCommandParameters)); default: return(isCompletingParameterName ? (IList <CompletionResult>)GitOptionsToCompletionResults(gitCommandOptions: completeCommandParameters.GitCommandOptions, wordToComplete: wordToComplete) : Array.Empty <CompletionResult>()); } }
public static CompleteCommandParameters CreateCompleteCommandParameters(this string str, int cursorPosition) { var(wordToComplete, ast) = GetData(str, cursorPosition); return(CompleteCommandParameters.Create(wordToComplete, ast, cursorPosition)); }