Example #1
0
        async void ShowMultipleFiles(string[] files)
        {
            var openDocuments = EditorHost.GetOpenDocuments();
            var searchCtx     = Presenter.StartSearch($"Go to files", null, false);

            try {
                var msbuildContentType = ContentTypeRegistry.GetContentType(MSBuildContentType.Name);
                foreach (var file in files)
                {
                    string lineText;
                    try {
                        if (!File.Exists(file))
                        {
                            continue;
                        }
                        if (!openDocuments.TryGetValue(file, out var buf))
                        {
                            buf = BufferFactory.CreateTextBuffer(File.OpenText(file), msbuildContentType);
                        }
                        lineText = buf.CurrentSnapshot.GetLineFromPosition(0).GetText();
                    } catch (Exception ex) {
                        LoggingService.LogError($"Error getting text for file {file}", ex);
                        continue;
                    }
                    var classifiedSpans = ImmutableArray <ClassifiedText> .Empty;
                    classifiedSpans = classifiedSpans.Add(new ClassifiedText(lineText, PredefinedClassificationTypeNames.NaturalLanguage));
                    await searchCtx.OnReferenceFoundAsync(new FoundReference (file, 0, 0, ReferenceUsage.Declaration, classifiedSpans, new TextSpan(-1, 0)));
                }
            } catch (Exception ex) when(!(ex is OperationCanceledException && searchCtx.CancellationToken.IsCancellationRequested))
            {
                LoggingService.LogError($"Error in show multiple imports", ex);
            }
            await searchCtx.OnCompletedAsync();
        }