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);
            }
        }
Exemplo n.º 2
0
        public void OnWorkspaceApplyEdit(JToken arg)
        {
            try {
                Log(Methods.WorkspaceApplyEditName, arg);

                var message = arg.ToObject <ApplyWorkspaceEditParams> ();
                Runtime.RunInMainThread(() => {
                    WorkspaceEditHandler.ApplyChanges(message.Edit);
                }).LogFault();
            } catch (Exception ex) {
                LanguageClientLoggingService.LogError("OnWorkspaceApplyEdit 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);
            }
        }