public static void RunFindReferences(LocalResolveResult local)
        {
            var monitor = SD.StatusBar.CreateProgressMonitor();
            var results = FindReferenceService.FindLocalReferences(local.Variable, monitor);

            SearchResultsPad.Instance.ShowSearchResults(StringParser.Parse("${res:SharpDevelop.Refactoring.ReferencesTo}", new StringTagPair("Name", local.Variable.Name)), results);
            SearchResultsPad.Instance.BringToFront();
        }
        /*
         * public static ITextEditor OpenDefinitionFile(IMember member, bool switchTo)
         * {
         *      IViewContent viewContent = null;
         *      ISyntaxTree cu = member.DeclaringType.SyntaxTree;
         *      if (cu != null) {
         *              string fileName = cu.FileName;
         *              if (fileName != null) {
         *                      viewContent = FileService.OpenFile(fileName, switchTo);
         *              }
         *      }
         *      ITextEditorProvider tecp = viewContent as ITextEditorProvider;
         *      return (tecp == null) ? null : tecp.TextEditor;
         * }
         *
         * public static ITextEditor JumpBehindDefinition(IMember member)
         * {
         *      IViewContent viewContent = null;
         *      ISyntaxTree cu = member.DeclaringType.SyntaxTree;
         *      if (cu != null) {
         *              string fileName = cu.FileName;
         *              if (fileName != null) {
         *                      if (!member.Region.IsEmpty) {
         *                              viewContent = FileService.JumpToFilePosition(fileName, member.Region.EndLine + 1, 1);
         *                      } else {
         *                              FileService.OpenFile(fileName);
         *                      }
         *              }
         *      }
         *      ITextEditorProvider tecp = viewContent as ITextEditorProvider;
         *      return (tecp == null) ? null : tecp.TextEditor;
         * }
         *
         * public static bool CheckName(string name, string oldName)
         * {
         *      if (name == null || name.Length == 0 || name == oldName)
         *              return false;
         *      if (!char.IsLetter(name, 0) && name[0] != '_') {
         *              MessageService.ShowError("${res:SharpDevelop.Refactoring.InvalidNameStart}");
         *              return false;
         *      }
         *      for (int i = 1; i < name.Length; i++) {
         *              if (!char.IsLetterOrDigit(name, i) && name[i] != '_') {
         *                      MessageService.ShowError("${res:SharpDevelop.Refactoring.InvalidName}");
         *                      return false;
         *              }
         *      }
         *      return true;
         * }
         *
         * public struct Modification
         * {
         *      public IDocument Document;
         *      public int Offset;
         *      public int LengthDifference;
         *
         *      public Modification(IDocument document, int offset, int lengthDifference)
         *      {
         *              this.Document = document;
         *              this.Offset = offset;
         *              this.LengthDifference = lengthDifference;
         *      }
         * }
         *
         * public static void ModifyDocument(List<Modification> modifications, IDocument doc, int offset, int length, string newName)
         * {
         *      using (doc.OpenUndoGroup()) {
         *              foreach (Modification m in modifications) {
         *                      if (m.Document == doc) {
         *                              if (m.Offset < offset)
         *                                      offset += m.LengthDifference;
         *                      }
         *              }
         *              int lengthDifference = newName.Length - length;
         *              doc.Replace(offset, length, newName);
         *              if (lengthDifference != 0) {
         *                      for (int i = 0; i < modifications.Count; ++i) {
         *                              Modification m = modifications[i];
         *                              if (m.Document == doc) {
         *                                      if (m.Offset > offset) {
         *                                              m.Offset += lengthDifference;
         *                                              modifications[i] = m; // Modification is a value type
         *                                      }
         *                              }
         *                      }
         *                      modifications.Add(new Modification(doc, offset, lengthDifference));
         *              }
         *      }
         * }
         */

        /* TODO: these are refactorings and don't belong here
         * public static void MoveClassToFile(IClass c, string newFileName)
         * {
         *      LanguageProperties language = c.ProjectContent.Language;
         *      string existingCode = ParserService.GetParseableFileContent(c.SyntaxTree.FileName).Text;
         *      DomRegion fullRegion = language.RefactoringProvider.GetFullCodeRangeForType(existingCode, c);
         *      if (fullRegion.IsEmpty) return;
         *
         *      Action removeExtractedCodeAction;
         *      string newCode = ExtractCode(c, fullRegion, c.BodyRegion.BeginLine, out removeExtractedCodeAction);
         *
         *      newCode = language.RefactoringProvider.CreateNewFileLikeExisting(existingCode, newCode);
         *      if (newCode == null)
         *              return;
         *      IViewContent viewContent = FileService.NewFile(newFileName, newCode);
         *      viewContent.PrimaryFile.SaveToDisk(newFileName);
         *      // now that the code is saved in the other file, remove it from the original document
         *      removeExtractedCodeAction();
         *
         *      IProject project = (IProject)c.ProjectContent.Project;
         *      if (project != null) {
         *              FileProjectItem projectItem = new FileProjectItem(project, ItemType.Compile);
         *              projectItem.FileName = newFileName;
         *              ProjectService.AddProjectItem(project, projectItem);
         *              FileService.FireFileCreated(newFileName, false);
         *              project.Save();
         *              ProjectBrowserPad.RefreshViewAsync();
         *      }
         * }
         *
         * public static string ExtractCode(IClass c, DomRegion codeRegion, int indentationLine, out Action removeExtractedCodeAction)
         * {
         *      IDocument doc = GetDocument(c);
         *      if (indentationLine < 1) indentationLine = 1;
         *      if (indentationLine >= doc.TotalNumberOfLines) indentationLine = doc.TotalNumberOfLines;
         *
         *      IDocumentLine segment = doc.GetLine(indentationLine);
         *      string mainLine = doc.GetText(segment.Offset, segment.Length);
         *      string indentation = mainLine.Substring(0, mainLine.Length - mainLine.TrimStart().Length);
         *
         *      segment = doc.GetLine(codeRegion.BeginLine);
         *      int startOffset = segment.Offset;
         *      segment = doc.GetLine(codeRegion.EndLine);
         *      int endOffset = segment.Offset + segment.Length;
         *
         *      StringReader reader = new StringReader(doc.GetText(startOffset, endOffset - startOffset));
         *      removeExtractedCodeAction = delegate {
         *              doc.Remove(startOffset, endOffset - startOffset);
         *      };
         *
         *      // now remove indentation from extracted source code
         *      string line;
         *      StringBuilder b = new StringBuilder();
         *      int endOfLastFilledLine = 0;
         *      while ((line = reader.ReadLine()) != null) {
         *              int startpos;
         *              for (startpos = 0; startpos < line.Length && startpos < indentation.Length; startpos++) {
         *                      if (line[startpos] != indentation[startpos])
         *                              break;
         *              }
         *              if (startpos == line.Length) {
         *                      // empty line
         *                      if (b.Length > 0) {
         *                              b.AppendLine();
         *                      }
         *              } else {
         *                      b.Append(line, startpos, line.Length - startpos);
         *                      b.AppendLine();
         *                      endOfLastFilledLine = b.Length;
         *              }
         *      }
         *      b.Length = endOfLastFilledLine;
         *      return b.ToString();
         * }
         *
         * public static IDocument GetDocument(IClass c)
         * {
         *      if (c is CompoundClass)
         *              throw new ArgumentException("Cannot get document from compound class - must pass a specific class part");
         *
         *      ITextEditorProvider tecp = FileService.OpenFile(c.SyntaxTree.FileName) as ITextEditorProvider;
         *      if (tecp == null) return null;
         *      return tecp.TextEditor.Document;
         * }
         */
        #endregion


        #region Find references
        public static void RunFindReferences(IEntity entity)
        {
            string entityName = (entity.DeclaringTypeDefinition != null ? entity.DeclaringTypeDefinition.Name + "." + entity.Name : entity.Name);
            var    monitor    = SD.StatusBar.CreateProgressMonitor();
            var    results    = FindReferenceService.FindReferences(entity, monitor);

            SearchResultsPad.Instance.ShowSearchResults(StringParser.Parse("${res:SharpDevelop.Refactoring.ReferencesTo}", new StringTagPair("Name", entityName)), results);
            SearchResultsPad.Instance.BringToFront();
        }