/// <summary> /// Check codeObject location. /// </summary> /// <param name="codeObject">The code object.</param> /// <param name="point">The point.</param> /// <param name="element">The element.</param> /// <returns> /// <c>true</c> if [is in range] [the specified code object]; otherwise, <c>false</c>. /// </returns> private bool IsInRange(Node codeObject, TextPoint point, CodeElement element) { if (codeObject is Chunk || codeObject == null) { return(false); } int startLine = codeObject.Location.sLin; int endLine = codeObject.Location.eLin; // match in the middle of a block //if (line < point.Line && point.Line < endLine) //{ // return true; //} if (startLine == point.Line || endLine == startLine || element is LuaCodeVariableTable) { // single line match, make sure the columns are right int startCol = codeObject.Location.sCol + 1; int endCol = codeObject.Location.eCol + 1; if (codeObject is FunctionDeclaration) { var endPoint = LuaCodeDomHelper.GetFunctionDeclarationFromSource (codeObject as FunctionDeclaration, (TextDocument)parent.Document.Object("TextDocument")); endLine = startLine; endCol = endPoint == null ? startCol : endPoint.DisplayColumn; } if (element is LuaCodeVariableTable) { var table = element as LuaCodeVariableTable; if (table.IdentifierLocation != null) { startLine = table.IdentifierLocation.sLin; startCol = table.IdentifierLocation.sCol; endCol = table.IdentifierLocation.eCol; } } if (startLine == point.Line && startCol <= point.LineCharOffset && point.LineCharOffset < endCol) { return(true); } if (endLine != startLine && endLine == point.Line && endCol <= point.LineCharOffset && point.LineCharOffset < endCol) { return(true); } } return(false); }
/// <summary> /// Finds a function pattern in the specified range of text and replaces it with the specified text. /// </summary> /// <param name="startLine">The start line of the specified range of text.</param> /// <param name="startRow">The start row of the specified range of text.</param> /// <param name="endLine">The end line of the specified range of text.</param> /// <param name="endRow">The end row of the specified range of text.</param> /// <param name="oldName">The text to replace.</param> /// <param name="newName">The replacement text for pattern.</param> public bool RenameFunction(int startLine, int startRow, int endLine, int endRow, string oldName, string newName) { TextPoint textPoint = new LuaTextPoint(Document, startRow, startLine); TextPoint endTextPoint = new LuaTextPoint(Document, endRow, startLine); var functionLineText = LuaCodeDomHelper.GetCodeLineText(Document, startLine); if (!string.IsNullOrEmpty(functionLineText)) { int startIndex = functionLineText.ToLower().IndexOf("function", StringComparison.CurrentCultureIgnoreCase); if (startIndex > -1) { int nameIndex = functionLineText.IndexOf(oldName); textPoint = new LuaTextPoint(Document, nameIndex, startLine); endTextPoint = new LuaTextPoint(Document, nameIndex + oldName.Length + 2, startLine); } } return(Replace(textPoint, endTextPoint, oldName, newName)); //ep.ReplaceText(textPoint, newName, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat); }