/// <summary> /// Determines whether [is refactorable item selected]. /// </summary> /// <returns> /// <c>true</c> if [is refactorable item selected]; otherwise, <c>false</c>. /// </returns> private bool IsRefactorableItemSelected() { LuaFileCodeModel codeModel = languageService.GetFileCodeModel(); CodeElement element = codeModel.GetElementByEditPoint(); return(element != null); }
/// <summary> /// Gets the root element. /// </summary> /// <param name="codeModel">LuaFileCodeModel instance.</param> /// <returns></returns> private static LuaCodeClass GetRootElement(LuaFileCodeModel codeModel) { if (codeModel != null) { return(codeModel.RootElement); } return(null); }
/// <summary> /// Rename elements in all referenced lua files. /// </summary> /// <param name="elementType">Type of element.</param> /// <param name="oldName">Old name of element.</param> /// <param name="newName">New name of element.</param> /// <param name="result">Rename result.</param> private IRenameResult RenameAllReferences(vsCMElement elementType, string oldName, string newName, IRenameResult result) { Trace.WriteLine("RenameAllReferences started..."); try { var multiResult = new MultiRenameResult(oldName, newName); Project currentProject = DTE.ActiveDocument.ProjectItem.ContainingProject; ProjectItem activeProjectItem = DTE.ActiveDocument.ProjectItem; string activeProjectFileName = activeProjectItem.get_FileNames(1); List <ProjectItem> projectItems = GetLuaProjectItems(currentProject); foreach (ProjectItem projectItem in projectItems) { string fileName = projectItem.get_FileNames(1); if (!string.IsNullOrEmpty(fileName)) { //If projectItem is the active then merge changes into MultiRenameResult if (activeProjectFileName == fileName) { multiResult.MergeChanges(projectItem, result); } else { if (IsLuaFile(fileName)) { LuaFileCodeModel fileCodeModel = GetFileCodeModel(projectItem); if (fileCodeModel != null) { CodeElement root = GetRootElement(fileCodeModel); IRenameResult renameResult; //Rename references in Lua file. if (root != null) { renameResult = refactoringService.Rename(null, root, elementType, oldName, newName); renameResult.Parents.Add(fileCodeModel); } else { string message = String.Format(Resources.RootElementCannotBeFoundMessage, fileName); renameResult = new RenameResult(false, message); Trace.WriteLine(message); } multiResult.MergeChanges(projectItem, renameResult); } } } } } return(multiResult); } catch (Exception e) { Trace.WriteLine(e); throw; } }
/// <summary> /// Rename the selected code element. /// </summary> /// <returns></returns> public IRenameResult Rename() { IRenameResult result = null; LuaFileCodeModel codeModel = GetFileCodeModel(); CodeElement element = codeModel.GetElementByEditPoint(); if (element != null) { dte.StatusBar.Text = String.Format(Resources.RenameStartedMessage, element.Name); DTE.StatusBar.Highlight(true); //Rename element. result = Rename(element, string.Empty); dte.StatusBar.Clear(); } else { dte.StatusBar.Text = Resources.RenameNotAllowedMessage; } return(result); }
public override bool OnSynchronizeDropdowns(Microsoft.VisualStudio.Package.LanguageService languageService, IVsTextView textView, int line, int col, ArrayList dropDownTypes, ArrayList dropDownMembers, ref int selectedType, ref int selectedMember) { if (isDirty) { isDirty = false; dropDownTypes.Clear(); dropDownMembers.Clear(); Source source = service.GetSource(textView); if (source != null) { string filename = source.GetFilePath(); LuaFileCodeModel codeModel = service.GetFileCodeModel(); if (codeModel != null) { foreach (CodeElement elem_ in codeModel.LuaCodeElements) { SimpleCodeElement elem = elem_ as SimpleCodeElement; if (elem != null) { if (elem is LuaCodeFunction) { dropDownMembers.Add(new DropDownMember( elem.FullName, elem.GetTextSpan(), 18, // 18 for IconImageIndex.Method DROPDOWNFONTATTR.FONTATTR_GRAY )); } else { dropDownTypes.Add(new DropDownMember( elem.FullName, elem.GetTextSpan(), 29, // 29 for IconImageIndex.Variable DROPDOWNFONTATTR.FONTATTR_PLAIN )); } } } // create dummy item to show as title if (dropDownMembers.Count > 0) { dropDownMembers.Add(new DropDownMember( String.Format("{0} function(s)", dropDownMembers.Count), new TextSpan(), 0, // 18 for IconImageIndex.Method DROPDOWNFONTATTR.FONTATTR_GRAY )); selectedMember = dropDownMembers.Count - 1; } if (dropDownTypes.Count > 0) { dropDownTypes.Add(new DropDownMember( String.Format("{0} variable(s)", dropDownTypes.Count), new TextSpan(), 0, // 29 for IconImageIndex.Variable DROPDOWNFONTATTR.FONTATTR_GRAY )); selectedType = dropDownTypes.Count - 1; } } } // TODO: set current selection to selectedType and selectedMember // for performance reason, I did not implement it. } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="FunctionConflictResolver"/> class. /// </summary> /// <param name="fileCodeModel">The LuaFileCodemodel.</param> public FunctionConflictResolver(LuaFileCodeModel fileCodeModel) : base(fileCodeModel) { }
/// <summary> /// Gets the FileCodeModel associated with specified ProjectItem. /// </summary> /// <param name="projectItem">Wow ProjectItem</param> /// <returns>LuaFileCodeModel instance.</returns> private LuaFileCodeModel GetFileCodeModel(ProjectItem projectItem) { LuaFileCodeModel codeModel = languageService.GetFileCodeModel(projectItem); return(codeModel); }
/// <summary> /// Gets the LuaFileCodeModel of active ProjectItem. /// </summary> /// <returns>LuaFileCodeModel instance.</returns> private LuaFileCodeModel GetFileCodeModel() { LuaFileCodeModel codeModel = languageService.GetFileCodeModel(); return(codeModel); }
/// <summary> /// Merges changes from IRenameResult into FileCodeModel. /// </summary> /// <param name="codeModel">The code model.</param> /// <param name="changedElements">The changed elements.</param> /// <param name="oldName">The old name.</param> private static void MergeChanges(LuaFileCodeModel codeModel, IEnumerable <CodeElement> changedElements, string oldName) { codeModel.MergeChanges(oldName, changedElements, false); }
/// <summary> /// Initializes a new instance of the <see cref="ConflictResolverBase"/> class. /// </summary> /// <param name="fileCodeModel"></param> protected ConflictResolverBase(LuaFileCodeModel fileCodeModel) { this.fileCodeModel = fileCodeModel; }
/// <summary> /// Creates IConflictResolver by elementType. /// </summary> /// <param name="elementType">Type of CodeElement.</param> /// <param name="fileCodeModel">LuaFileCodeModel instance.</param> /// <returns>IConflictResolver implementation.</returns> public static IConflictResolver CreateConflictResolver(vsCMElement elementType, LuaFileCodeModel fileCodeModel) { IConflictResolver result = null; switch (elementType) { case vsCMElement.vsCMElementFunctionInvokeStmt: case vsCMElement.vsCMElementFunction: { result = new FunctionConflictResolver(fileCodeModel); break; } } return(result); }