public Task <IEnumerable <AutoCompleteWord> > GetAutoCompleteWords(CancellationTokenSource cts) { var cancellationToken = cts.Token; return(Task.Factory.StartNew( () => { cancellationToken.ThrowIfCancellationRequested(); var autoCompleteWords = new HashSet <string>(); foreach (var file in _module.GetAllChangedFiles()) { cancellationToken.ThrowIfCancellationRequested(); var regex = GetRegexForExtension(Path.GetExtension(file.Name)); if (regex != null) { var text = GetChangedFileText(_module, file); var matches = regex.Matches(text); foreach (Match match in matches) { // Skip first group since it always contains the entire matched string (regardless of capture groups) foreach (Group @group in match.Groups.OfType <Group>().Skip(1)) { foreach (Capture capture in @group.Captures) { autoCompleteWords.Add(capture.Value); } } } } autoCompleteWords.Add(Path.GetFileNameWithoutExtension(file.Name)); autoCompleteWords.Add(Path.GetFileName(file.Name)); if (!string.IsNullOrWhiteSpace(file.OldName)) { autoCompleteWords.Add(Path.GetFileNameWithoutExtension(file.OldName)); autoCompleteWords.Add(Path.GetFileName(file.OldName)); } } return autoCompleteWords.Select(w => new AutoCompleteWord(w)); }, cancellationToken)); }
public async Task <IEnumerable <AutoCompleteWord> > GetAutoCompleteWordsAsync(CancellationToken cancellationToken) { await TaskScheduler.Default.SwitchTo(alwaysYield : true); cancellationToken.ThrowIfCancellationRequested(); var autoCompleteWords = new HashSet <string>(); foreach (var file in _module.GetAllChangedFiles()) { cancellationToken.ThrowIfCancellationRequested(); var regex = GetRegexForExtension(Path.GetExtension(file.Name)); if (regex != null) { var text = GetChangedFileText(_module, file); var matches = regex.Matches(text); foreach (Match match in matches) { // Skip first group since it always contains the entire matched string (regardless of capture groups) foreach (Group group in match.Groups.OfType <Group>().Skip(1)) { foreach (Capture capture in group.Captures) { autoCompleteWords.Add(capture.Value); } } } } autoCompleteWords.Add(Path.GetFileNameWithoutExtension(file.Name)); autoCompleteWords.Add(Path.GetFileName(file.Name)); if (!string.IsNullOrWhiteSpace(file.OldName)) { autoCompleteWords.Add(Path.GetFileNameWithoutExtension(file.OldName)); autoCompleteWords.Add(Path.GetFileName(file.OldName)); } } return(autoCompleteWords.Select(w => new AutoCompleteWord(w))); }