Exemplo n.º 1
0
        private string Rename(string buffer, string renameTo)
        {
            var location = TestHelpers.GetLineAndColumnFromDollar(buffer);

            buffer = buffer.Replace("$", "");

            var solution = new FakeSolutionBuilder()
                           .AddFile(buffer)
                           .Build();

            var bufferParser  = new BufferParser(solution);
            var renameHandler = new RenameHandler(solution, bufferParser);
            var request       = new RenameRequest
            {
                Buffer   = buffer,
                Column   = location.Column - 1,
                Line     = location.Line,
                RenameTo = renameTo,
                FileName = "myfile"
            };

            var response = renameHandler.Rename(request);

            if (response.Changes.Any())
            {
                return(response.Changes.First().Buffer);
            }
            return(buffer);
        }
Exemplo n.º 2
0
        private IEnumerable <ModifiedFileResponse> Rename(string renameTo, params Buffer[] buffers)
        {
            RenameRequest request         = null;
            var           solutionBuilder = new FakeSolutionBuilder();

            foreach (var buffer in buffers)
            {
                if (buffer.Text.Contains("$"))
                {
                    var location = TestHelpers.GetLineAndColumnFromDollar(buffer.Text);
                    buffer.Text = buffer.Text.Replace("$", "");
                    request     = new RenameRequest
                    {
                        Buffer   = buffer.Text,
                        Column   = location.Column - 1,
                        Line     = location.Line,
                        RenameTo = renameTo,
                        FileName = buffer.Filename
                    };
                }
                //solutionBuilder = solutionBuilder.AddProject();
                solutionBuilder = solutionBuilder.AddFile(buffer.Text, buffer.Filename);
            }
            var solution      = solutionBuilder.Build();
            var bufferParser  = new BufferParser(solution);
            var renameHandler = new RenameHandler(solution, bufferParser, new OmniSharpConfiguration(), new FindUsagesHandler(bufferParser, solution, new ProjectFinder(solution)));

            var response = renameHandler.Rename(request);

            return(response.Changes);
        }
Exemplo n.º 3
0
 public static void RunRename(RenameFilesOptions options)
 {
     Logger.InitialiseLogger(options);
     using (IHashHandler handler = new RenameHandler(options))
     {
         handler.RunHandler();
     }
 }
Exemplo n.º 4
0
 public IDManageControl(String id, RenameHandler r = null, GetAppearanceHandler g = null)
 {
     this.InitializeComponent();
     IDname  = id;
     rename  = r;
     getAppr = g;
     //LoadDescription();
 }
Exemplo n.º 5
0
        public static void AcceptChanges(IProgressMonitor monitor, List <Change> changes, MonoDevelop.Projects.Text.ITextFileProvider fileProvider)
        {
            var rctx    = new RefactoringOptions(null);
            var handler = new RenameHandler(changes);

            FileService.FileRenamed += handler.FileRename;
            var fileNames = new HashSet <FilePath> ();

            for (int i = 0; i < changes.Count; i++)
            {
                changes[i].PerformChange(monitor, rctx);
                var replaceChange = changes[i] as TextReplaceChange;
                if (replaceChange == null)
                {
                    continue;
                }
                for (int j = i + 1; j < changes.Count; j++)
                {
                    var change = changes[j] as TextReplaceChange;
                    if (change == null)
                    {
                        continue;
                    }
                    fileNames.Add(change.FileName);
                    if (replaceChange.Offset >= 0 && change.Offset >= 0 && replaceChange.FileName == change.FileName)
                    {
                        if (replaceChange.Offset < change.Offset)
                        {
                            change.Offset -= replaceChange.RemovedChars;
                            if (!string.IsNullOrEmpty(replaceChange.InsertedText))
                            {
                                change.Offset += replaceChange.InsertedText.Length;
                            }
                        }
                        else if (replaceChange.Offset < change.Offset + change.RemovedChars)
                        {
                            change.RemovedChars = Math.Max(0, change.RemovedChars - replaceChange.RemovedChars);
                            change.Offset       = replaceChange.Offset + (!string.IsNullOrEmpty(replaceChange.InsertedText) ? replaceChange.InsertedText.Length : 0);
                        }
                    }
                }
            }
            FileService.NotifyFilesChanged(fileNames);
            FileService.FileRenamed -= handler.FileRename;
            TextReplaceChange.FinishRefactoringOperation();
        }
        public static void AcceptChanges(IProgressMonitor monitor, ProjectDom dom, List <Change> changes, MonoDevelop.Projects.Text.ITextFileProvider fileProvider)
        {
            RefactorerContext rctx    = new RefactorerContext(dom, fileProvider, null);
            RenameHandler     handler = new RenameHandler(changes);

            FileService.FileRenamed += handler.FileRename;
            for (int i = 0; i < changes.Count; i++)
            {
                changes[i].PerformChange(monitor, rctx);
                TextReplaceChange replaceChange = changes[i] as TextReplaceChange;
                if (replaceChange == null)
                {
                    continue;
                }
                for (int j = i + 1; j < changes.Count; j++)
                {
                    TextReplaceChange change = changes[j] as TextReplaceChange;
                    if (change == null)
                    {
                        continue;
                    }
                    if (replaceChange.Offset >= 0 && change.Offset >= 0 && replaceChange.FileName == change.FileName)
                    {
                        if (replaceChange.Offset < change.Offset)
                        {
                            change.Offset -= replaceChange.RemovedChars;
                            if (!string.IsNullOrEmpty(replaceChange.InsertedText))
                            {
                                change.Offset += replaceChange.InsertedText.Length;
                            }
                        }
                        else if (replaceChange.Offset < change.Offset + change.RemovedChars)
                        {
                            change.RemovedChars -= replaceChange.RemovedChars;
                            change.Offset        = replaceChange.Offset + replaceChange.InsertedText.Length;
                        }
                    }
                }
            }
            FileService.FileRenamed -= handler.FileRename;
            TextReplaceChange.FinishRefactoringOperation();
        }
        public MyGuiScreenRenameCheckpoint(string changeThis, RenameHandler renameHandler)
            : base(new Vector2(0.5f, 0.5f), new Vector2(0.33f, 0.85f))
        {
            m_oldName = changeThis;
            m_renameHandler = renameHandler;
            m_size = MyGuiConstants.TEXTBOX_MEDIUM_SIZE +
                           new Vector2(MyGuiConstants.MESSAGE_BOX_BORDER_AREA_X * 2,
                                       0.1f + MyGuiConstants.MESSAGE_BOX_BORDER_AREA_Y * 2 +
                                       MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE.Y);

            AddCaption(MyTextsWrapperEnum.RenameCheckpoint, MyGuiConstants.LABEL_TEXT_COLOR);

            m_nameTextbox = new MyGuiControlTextbox(this,
                new Vector2(0, 0.1f + MyGuiConstants.TEXTBOX_MEDIUM_SIZE.Y / 2 - m_size.Value.Y / 2),
                MyGuiControlPreDefinedSize.MEDIUM,
                changeThis, MAXIMUM_CHECKPOINT_NAME_LENGTH,
                MyGuiConstants.LABEL_TEXT_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiControlTextboxType.NORMAL);

            Controls.Add(m_nameTextbox);
            AddOkAndCancelButtonControls();
        }
Exemplo n.º 8
0
        public MyGuiScreenRenameCheckpoint(string changeThis, RenameHandler renameHandler)
            : base(new Vector2(0.5f, 0.5f), new Vector2(0.33f, 0.85f))
        {
            m_oldName       = changeThis;
            m_renameHandler = renameHandler;
            m_size          = MyGuiConstants.TEXTBOX_MEDIUM_SIZE +
                              new Vector2(MyGuiConstants.MESSAGE_BOX_BORDER_AREA_X * 2,
                                          0.1f + MyGuiConstants.MESSAGE_BOX_BORDER_AREA_Y * 2 +
                                          MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE.Y);

            AddCaption(MyTextsWrapperEnum.RenameCheckpoint, MyGuiConstants.LABEL_TEXT_COLOR);

            m_nameTextbox = new MyGuiControlTextbox(this,
                                                    new Vector2(0, 0.1f + MyGuiConstants.TEXTBOX_MEDIUM_SIZE.Y / 2 - m_size.Value.Y / 2),
                                                    MyGuiControlPreDefinedSize.MEDIUM,
                                                    changeThis, MAXIMUM_CHECKPOINT_NAME_LENGTH,
                                                    MyGuiConstants.LABEL_TEXT_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiControlTextboxType.NORMAL);

            Controls.Add(m_nameTextbox);
            AddOkAndCancelButtonControls();
        }
Exemplo n.º 9
0
        public void RenameHandler()
        {
            const string TEST_FOLDER_NAME     = "TestFolderToRename";
            const string TEST_FOLDER_NEW_NAME = "TestFolderRenamed";
            const string TEST_FOLDER_PATH     = ROOT_TEST_PATH + "\\" + TEST_FOLDER_NAME;
            const string TEST_FOLDER_NEW_PATH = ROOT_TEST_PATH + "\\" + TEST_FOLDER_NEW_NAME;

            Directory.CreateDirectory(TEST_FOLDER_PATH);

            Assert.True(Directory.Exists(TEST_FOLDER_PATH));

            if (Directory.Exists(TEST_FOLDER_NEW_PATH))
            {
                Directory.Delete(TEST_FOLDER_NEW_PATH);
            }

            var targetToRename = new RenameActionTarget
            {
                OldName = TEST_FOLDER_NAME,
                Name    = TEST_FOLDER_NEW_NAME
            };

            var param = new RenameParam
            {
                CurrentFolderPath = "/",
                Targets           = new List <RenameActionTarget> {
                    targetToRename
                }
            };

            var result = new RenameHandler(CreateHostingEnv()).Run(param) as RenameResult;

            PrintErrors(result.Errors);

            Assert.Equal(1, result.Affected);
            Assert.True(Directory.Exists(TEST_FOLDER_NEW_PATH));
            Assert.False(Directory.Exists(TEST_FOLDER_PATH));
            Assert.True(result.Errors.Count == 0);
        }
Exemplo n.º 10
0
        private Task Initialize(Extensions.LanguageServer.Server.ILanguageServer server, InitializeParams initializeParams)
        {
            CreateCompositionHost(initializeParams);

            // TODO: Make it easier to resolve handlers from MEF (without having to add more attributes to the services if we can help it)
            var workspace = _compositionHost.GetExport <OmniSharpWorkspace>();

            _compositionHost.GetExport <DiagnosticEventForwarder>().IsEnabled = true;

            foreach (var handler in TextDocumentSyncHandler.Enumerate(_handlers, workspace)
                     .Concat(DefinitionHandler.Enumerate(_handlers))
                     .Concat(HoverHandler.Enumerate(_handlers))
                     .Concat(CompletionHandler.Enumerate(_handlers))
                     .Concat(SignatureHelpHandler.Enumerate(_handlers))
                     .Concat(RenameHandler.Enumerate(_handlers))
                     .Concat(DocumentSymbolHandler.Enumerate(_handlers)))
            {
                server.AddHandlers(handler);
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 11
0
        private Task Initialize(InitializeParams initializeParams)
        {
            CreateCompositionHost(initializeParams);

            // TODO: Make it easier to resolve handlers from MEF (without having to add more attributes to the services if we can help it)
            var workspace = _compositionHost.GetExport <OmniSharpWorkspace>();

            _server.AddHandlers(TextDocumentSyncHandler.Enumerate(_handlers, workspace));
            _server.AddHandlers(DefinitionHandler.Enumerate(_handlers));
            _server.AddHandlers(HoverHandler.Enumerate(_handlers));
            _server.AddHandlers(CompletionHandler.Enumerate(_handlers));
            _server.AddHandlers(SignatureHelpHandler.Enumerate(_handlers));
            _server.AddHandlers(RenameHandler.Enumerate(_handlers));
            _server.AddHandlers(DocumentSymbolHandler.Enumerate(_handlers));

            _server.LogMessage(new LogMessageParams()
            {
                Message = "Added handlers... waiting for initialize...",
                Type    = MessageType.Log
            });

            return(Task.CompletedTask);
        }
Exemplo n.º 12
0
		public static void AcceptChanges (IProgressMonitor monitor, ProjectDom dom, List<Change> changes, MonoDevelop.Projects.Text.ITextFileProvider fileProvider)
		{
			var rctx = new RefactorerContext (dom, fileProvider, null);
			var handler = new RenameHandler (changes);
			FileService.FileRenamed += handler.FileRename;
			for (int i = 0; i < changes.Count; i++) {
				changes[i].PerformChange (monitor, rctx);
				var replaceChange = changes[i] as TextReplaceChange;
				if (replaceChange == null)
					continue;
				for (int j = i + 1; j < changes.Count; j++) {
					var change = changes[j] as TextReplaceChange;
					if (change == null)
						continue;
					if (replaceChange.Offset >= 0 && change.Offset >= 0 && replaceChange.FileName == change.FileName) {
						if (replaceChange.Offset < change.Offset) {
							change.Offset -= replaceChange.RemovedChars;
							if (!string.IsNullOrEmpty (replaceChange.InsertedText))
								change.Offset += replaceChange.InsertedText.Length;
						} else if (replaceChange.Offset < change.Offset + change.RemovedChars) {
							change.RemovedChars = Math.Max (0, change.RemovedChars - replaceChange.RemovedChars);
							change.Offset = replaceChange.Offset + (!string.IsNullOrEmpty (replaceChange.InsertedText) ? replaceChange.InsertedText.Length : 0);
						}
					}
				}
			}
			FileService.FileRenamed -= handler.FileRename;
			TextReplaceChange.FinishRefactoringOperation ();
		}
Exemplo n.º 13
0
        public static void AcceptChanges(ProgressMonitor monitor, IList <Change> changes, MonoDevelop.Ide.ITextFileProvider fileProvider)
        {
            var rctx    = new RefactoringOptions(null, null);
            var handler = new RenameHandler(changes);

            FileService.FileRenamed += handler.FileRename;
            var    fileNames = new HashSet <FilePath> ();
            var    ws        = TypeSystemService.Workspace as MonoDevelopWorkspace;
            string originalName;
            int    originalOffset;

            try {
                for (int i = 0; i < changes.Count; i++)
                {
                    var change = changes [i] as TextReplaceChange;
                    if (change == null)
                    {
                        continue;
                    }

                    if (ws.TryGetOriginalFileFromProjection(change.FileName, change.Offset, out originalName, out originalOffset))
                    {
                        fileNames.Add(change.FileName);
                        change.FileName = originalName;
                        change.Offset   = originalOffset;
                    }
                }
                if (changes.All(x => x is TextReplaceChange))
                {
                    List <Change> newChanges = new List <Change> (changes);
                    newChanges.Sort((Change x, Change y) => ((TextReplaceChange)x).Offset.CompareTo(((TextReplaceChange)y).Offset));
                    changes = newChanges;
                }


                for (int i = 0; i < changes.Count; i++)
                {
                    changes [i].PerformChange(monitor, rctx);
                    var replaceChange = changes [i] as TextReplaceChange;
                    if (replaceChange == null)
                    {
                        continue;
                    }

                    for (int j = i + 1; j < changes.Count; j++)
                    {
                        var change = changes [j] as TextReplaceChange;
                        if (change == null)
                        {
                            continue;
                        }

                        fileNames.Add(change.FileName);

                        if (replaceChange.Offset >= 0 && change.Offset >= 0 && replaceChange.FileName == change.FileName)
                        {
                            if (replaceChange.Offset < change.Offset)
                            {
                                change.Offset -= replaceChange.RemovedChars;
                                if (!string.IsNullOrEmpty(replaceChange.InsertedText))
                                {
                                    change.Offset += replaceChange.InsertedText.Length;
                                }
                            }
                            else if (replaceChange.Offset < change.Offset + change.RemovedChars)
                            {
                                change.RemovedChars = Math.Max(0, change.RemovedChars - replaceChange.RemovedChars);
                                change.Offset       = replaceChange.Offset + (!string.IsNullOrEmpty(replaceChange.InsertedText) ? replaceChange.InsertedText.Length : 0);
                            }
                        }
                    }
                }

                foreach (var renameChange in changes.OfType <RenameFileChange> ())
                {
                    if (fileNames.Contains(renameChange.OldName))
                    {
                        fileNames.Remove(renameChange.OldName);
                        fileNames.Add(renameChange.NewName);
                    }
                }

                foreach (var doc in IdeApp.Workbench.Documents)
                {
                    fileNames.Remove(doc.FileName);
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while applying refactoring changes", e);
            } finally {
                FileService.NotifyFilesChanged(fileNames);
                FileService.FileRenamed -= handler.FileRename;
                TextReplaceChange.FinishRefactoringOperation();
            }
        }
		public static void AcceptChanges (ProgressMonitor monitor, IList<Change> changes, MonoDevelop.Ide.ITextFileProvider fileProvider)
		{
			var rctx = new RefactoringOptions (null, null);
			var handler = new RenameHandler (changes);
			FileService.FileRenamed += handler.FileRename;
			var fileNames = new HashSet<FilePath> ();
			var ws = TypeSystemService.Workspace as MonoDevelopWorkspace;
			string originalName;
			int originalOffset;
			try {
				for (int i = 0; i < changes.Count; i++) {
					var change = changes [i] as TextReplaceChange;
					if (change == null)
						continue;

					if (ws.TryGetOriginalFileFromProjection (change.FileName, change.Offset, out originalName, out originalOffset)) {
						fileNames.Add (change.FileName);
						change.FileName = originalName;
						change.Offset = originalOffset;
					}
				}
				if (changes.All (x => x is TextReplaceChange)) {
					List<Change> newChanges = new List<Change> (changes);
					newChanges.Sort ((Change x, Change y) => ((TextReplaceChange)x).Offset.CompareTo (((TextReplaceChange)y).Offset));
					changes = newChanges;
				}


				for (int i = 0; i < changes.Count; i++) {
					changes [i].PerformChange (monitor, rctx);
					var replaceChange = changes [i] as TextReplaceChange;
					if (replaceChange == null)
						continue;

					for (int j = i + 1; j < changes.Count; j++) {
						var change = changes [j] as TextReplaceChange;
						if (change == null)
							continue;

						fileNames.Add (change.FileName);

						if (replaceChange.Offset >= 0 && change.Offset >= 0 && replaceChange.FileName == change.FileName) {
							if (replaceChange.Offset < change.Offset) {
								change.Offset -= replaceChange.RemovedChars;
								if (!string.IsNullOrEmpty (replaceChange.InsertedText))
									change.Offset += replaceChange.InsertedText.Length;
							} else if (replaceChange.Offset < change.Offset + change.RemovedChars) {
								change.RemovedChars = Math.Max (0, change.RemovedChars - replaceChange.RemovedChars);
								change.Offset = replaceChange.Offset + (!string.IsNullOrEmpty (replaceChange.InsertedText) ? replaceChange.InsertedText.Length : 0);
							}
						}
					}
				}

				foreach (var renameChange in changes.OfType<RenameFileChange> ()) {
					if (fileNames.Contains (renameChange.OldName)) {
						fileNames.Remove (renameChange.OldName);
						fileNames.Add (renameChange.NewName);
					}
				}

				foreach (var doc in IdeApp.Workbench.Documents) {
					fileNames.Remove (doc.FileName);
				}

			} catch (Exception e) {
				LoggingService.LogError ("Error while applying refactoring changes", e);
			} finally {
				FileService.NotifyFilesChanged (fileNames);
				FileService.FileRenamed -= handler.FileRename;
				TextReplaceChange.FinishRefactoringOperation ();
			}
		}