public static IEnumerable<string> FindMatches2(ScriptSession session, string command, bool aceResponse) { string lastToken; var truncatedCommand = TruncatedCommand(command, out lastToken); var teCmd = new Command("TabExpansion"); teCmd.Parameters.Add("line", command); teCmd.Parameters.Add("lastWord", lastToken); IEnumerable<string> teResult = session.ExecuteCommand(teCmd, false, true).Cast<string>(); //IEnumerable<string> teResult = session.ExecuteScriptPart(string.Format("TabExpansion \"{0}\" \"{1}\"", command, lastToken),false,true).Cast<string>(); var result = new List<string>(); WrapResults(truncatedCommand, teResult, result, aceResponse); //int prefixFileNameLength = Path.GetFileName(lastToken).Length; //string pathPrefix = lastToken.Substring(lastToken.Length - prefixFileNameLength); var splitPathResult = (session.ExecuteScriptPart(string.Format("Split-Path \"{0}*\" -IsAbsolute", lastToken), false, true).FirstOrDefault()); var isAbsolute = splitPathResult != null && (bool)splitPathResult; if (isAbsolute) { string commandLine = string.Format("Resolve-Path \"{0}*\"", lastToken); var psResults = session.ExecuteScriptPart(commandLine, false, true); IEnumerable<string> rpResult = psResults.Cast<PathInfo>().Select(p => p.Path); //result.AddRange(rpResult.Select(l => truncatedCommand + l.Path)); WrapResults(truncatedCommand, rpResult, result, aceResponse); } else { string commandLine = string.Format("Resolve-Path \"{0}*\" -Relative", lastToken); IEnumerable<string> rpResult = session.ExecuteScriptPart(commandLine, false, true).Cast<string>(); WrapResults(truncatedCommand, rpResult, result, aceResponse); } return result; }
public static IEnumerable<string> FindMatches3(ScriptSession session, string command, bool aceResponse) { string lastToken; var truncatedCommand = TruncatedCommand(command, out lastToken); string TabExpansionHelper = @"function ScPsTabExpansionHelper( [string] $inputScript, [int]$cursorColumn ){ TabExpansion2 $inputScript $cursorColumn |% { $_.CompletionMatches } |% { ""$($_.ResultType)|$($_.CompletionText)"" } }"; session.ExecuteScriptPart(TabExpansionHelper); var teCmd = new Command("ScPsTabExpansionHelper"); teCmd.Parameters.Add("inputScript", command); teCmd.Parameters.Add("cursorColumn", command.Length); string[] teResult = session.ExecuteCommand(teCmd, false, true).Cast<string>().ToArray(); var result = new List<string>(); WrapResults3(truncatedCommand, teResult, result, aceResponse); return result; }