void ShowMultipleDeclarations(Location[] locations)
 {
     using (var monitor = LanguageClientProgressMonitors.GetSearchProgressMonitor()) {
         List <SearchResult> references = locations.Select(CreateSearchResult).ToList();
         monitor.ReportResults(references);
     }
 }
        public async Task OpenDeclaration(FilePath fileName, DocumentLocation location)
        {
            ProgressMonitor monitor = null;

            try {
                using (monitor = LanguageClientProgressMonitors.GetOpenDeclarationProgressMonitor()) {
                    Location[] locations = await session.FindDefinitions(
                        fileName,
                        location.CreatePosition(),
                        monitor.CancellationToken);

                    if (locations == null || locations.Length == 0)
                    {
                        monitor.ReportNoDeclarationFound();
                    }
                    else if (locations.Length == 1)
                    {
                        OpenDeclaration(locations [0]);
                    }
                    else
                    {
                        ShowMultipleDeclarations(locations);
                    }
                }
            } catch (OperationCanceledException) {
                LanguageClientLoggingService.Log("Go to declaration canceled.");
                if (monitor != null)
                {
                    monitor.ReportGoToDeclarationCanceled();
                }
            } catch (Exception ex) {
                LanguageClientLoggingService.LogError("OpenDeclaration error.", ex);
            }
        }
        public async Task FindReferences(FilePath fileName, DocumentLocation location)
        {
            try {
                using (var monitor = LanguageClientProgressMonitors.GetSearchProgressMonitor()) {
                    Location[] locations = await session.GetReferences(
                        fileName,
                        location.CreatePosition(),
                        monitor.CancellationToken);

                    if (locations == null)
                    {
                        monitor.ReportResults(Enumerable.Empty <SearchResult> ());
                    }
                    else
                    {
                        List <SearchResult> references = ToSearchResults(locations).ToList();
                        monitor.ReportResults(references);
                    }
                }
            } catch (OperationCanceledException) {
                LanguageClientLoggingService.Log("Find references was canceled.");
            } catch (Exception ex) {
                LanguageClientLoggingService.LogError("FindReferences error.", ex);
            }
        }
        public async Task Rename(FilePath fileName, DocumentLocation location, string newName)
        {
            try {
                using (var monitor = LanguageClientProgressMonitors.GetSearchProgressMonitorForRename()) {
                    WorkspaceEdit edit = await session.Rename(
                        fileName,
                        location.CreatePosition(),
                        newName,
                        monitor.CancellationToken);

                    if (edit?.Changes == null)
                    {
                        monitor.ReportNothingToRename();
                    }
                    else
                    {
                        WorkspaceEditHandler.ApplyChanges(edit);
                    }
                }
            } catch (OperationCanceledException) {
                LanguageClientLoggingService.Log("Rename was canceled.");
            } catch (Exception ex) {
                LanguageClientLoggingService.LogError("Rename error.", ex);
            }
        }
        public async Task RenameOccurrences(FilePath fileName, DocumentLocation location)
        {
            try {
                using (var monitor = LanguageClientProgressMonitors.GetSearchProgressMonitorForRename()) {
                    Location[] locations = await session.GetReferences(
                        fileName,
                        location.CreatePosition(),
                        monitor.CancellationToken);

                    if (locations == null)
                    {
                        monitor.ReportNoReferencesFound();
                        return;
                    }

                    List <SearchResult> references = ToSearchResults(locations).ToList();
                    if (!references.Any())
                    {
                        monitor.ReportNoReferencesFound();
                    }
                    else if (AllSearchResultsExistInCurrentEditor(references))
                    {
                        editor.StartTextEditorRename(references);
                    }
                    else
                    {
                        // Multiple files - cannot use text editor edit links.
                        string oldName = GetSearchResultItemText(references [0]);
                        string newName = RenameItemDialog.PromptForNewName(oldName);
                        WorkspaceEditHandler.ApplyChanges(locations, newName);
                    }
                }
            } catch (OperationCanceledException) {
                LanguageClientLoggingService.Log("Rename was canceled.");
            } catch (Exception ex) {
                LanguageClientLoggingService.LogError("RenameOccurrences error.", ex);
            }
        }