internal static List <CompletionResult> PSv2GenerateMatchSetOfFiles(CompletionExecutionHelper helper, string lastWord, bool completingAtStartOfLine, string quote) { List <CompletionResult> list = new List <CompletionResult>(); lastWord = lastWord ?? string.Empty; bool flag = string.IsNullOrEmpty(lastWord); bool flag2 = !flag && lastWord.EndsWith("*", StringComparison.Ordinal); bool flag3 = WildcardPattern.ContainsWildcardCharacters(lastWord); string str = lastWord + "*"; bool shouldFullyQualifyPaths = PSv2ShouldFullyQualifyPathsPath(helper, lastWord); bool flag5 = lastWord.StartsWith(@"\\", StringComparison.Ordinal) || lastWord.StartsWith("//", StringComparison.Ordinal); List <PathItemAndConvertedPath> list2 = null; List <PathItemAndConvertedPath> list3 = null; if (flag3 && !flag) { list2 = PSv2FindMatches(helper, lastWord, shouldFullyQualifyPaths); } if (!flag2) { list3 = PSv2FindMatches(helper, str, shouldFullyQualifyPaths); } IEnumerable <PathItemAndConvertedPath> enumerable = CombineMatchSets(list2, list3); if (enumerable != null) { foreach (PathItemAndConvertedPath path in enumerable) { string str2 = WildcardPattern.Escape(path.Path); string str3 = WildcardPattern.Escape(path.ConvertedPath); string completionText = flag5 ? str3 : str2; completionText = AddQuoteIfNecessary(completionText, quote, completingAtStartOfLine); bool? nullable = SafeGetProperty <bool?>(path.Item, "PSIsContainer"); string listItemText = SafeGetProperty <string>(path.Item, "PSChildName"); string toolTip = CompletionExecutionHelper.SafeToString(path.ConvertedPath); if (nullable.HasValue && !string.IsNullOrEmpty(listItemText) && toolTip != null) { CompletionResultType resultType = nullable.Value ? CompletionResultType.ProviderContainer : CompletionResultType.ProviderItem; list.Add(new CompletionResult(completionText, listItemText, resultType, toolTip)); } } } return(list); }
private static List <PathItemAndConvertedPath> PSv2FindMatches(CompletionExecutionHelper helper, string path, bool shouldFullyQualifyPaths) { Exception exception; List <PathItemAndConvertedPath> list = new List <PathItemAndConvertedPath>(); PowerShell currentPowerShell = helper.CurrentPowerShell; if (!shouldFullyQualifyPaths) { currentPowerShell.AddScript(string.Format(CultureInfo.InvariantCulture, "& {{ trap {{ continue }} ; resolve-path {0} -Relative -WarningAction SilentlyContinue | %{{,($_,(get-item $_ -WarningAction SilentlyContinue),(convert-path $_ -WarningAction SilentlyContinue))}} }}", new object[] { path })); } else { currentPowerShell.AddScript(string.Format(CultureInfo.InvariantCulture, "& {{ trap {{ continue }} ; resolve-path {0} -WarningAction SilentlyContinue | %{{,($_,(get-item $_ -WarningAction SilentlyContinue),(convert-path $_ -WarningAction SilentlyContinue))}} }}", new object[] { path })); } Collection <PSObject> collection = helper.ExecuteCurrentPowerShell(out exception, null); if ((collection == null) || (collection.Count == 0)) { return(null); } foreach (PSObject obj2 in collection) { IList baseObject = obj2.BaseObject as IList; if ((baseObject != null) && (baseObject.Count == 3)) { object obj3 = baseObject[0]; PSObject item = baseObject[1] as PSObject; object obj5 = baseObject[1]; if (((obj3 != null) && (item != null)) && (obj5 != null)) { list.Add(new PathItemAndConvertedPath(CompletionExecutionHelper.SafeToString(obj3), item, CompletionExecutionHelper.SafeToString(obj5))); } } } if (list.Count == 0) { return(null); } list.Sort((Comparison <PathItemAndConvertedPath>)((x, y) => string.Compare(x.Path, y.Path, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase))); return(list); }