public string[] FindReferences(string editorText, int offset, string fileName) { var retval = new List <string>(); if (Project != null) { string pattern = SimpleCodeCompletion.GetWordAt(editorText, offset); var target = ResolveFromPosition(editorText, offset, fileName); if (target != null && !string.IsNullOrEmpty(pattern)) { var references = new List <string>(); foreach (string sourceFile in Project.Files.Select(x => x.FileName)) { bool isEditedFile = (sourceFile == fileName); string text = (isEditedFile ? editorText : File.ReadAllText(sourceFile)); retval.AddRange(FindReferences(text, pattern, target, sourceFile)); } } } return(retval.ToArray()); }
public string[] GetMemberInfo(string editorText, int offset, string fileName, bool collapseOverloads, out int methodStartPos) { methodStartPos = offset; bool isInstantiation = false; try { string nameToResolve = ""; if (collapseOverloads) //simple resolving from the position { isInstantiation = SimpleCodeCompletion.GetPrevWordAt(editorText, offset) == "new"; nameToResolve = SimpleCodeCompletion.GetWordAt(editorText, offset); } else { int pos = editorText.LastIndexOf('(', offset - 1); if (pos == -1) { return(new string[0]); } else { offset = pos; } nameToResolve = SimpleCodeCompletion.GetWordAt(editorText, offset); } methodStartPos = offset; IEnumerable <ICompletionData> data = GetCompletionData(editorText, offset, fileName, true).ToNRef(); string[] usedNamespaces = new CSharpParser().Parse(editorText, fileName) .GetUsingNamepseces(); var match = data.Where(x => x.matchesToken(nameToResolve)).FirstOrDefault();//it will be either one or no records if (match != null) { bool fullInfo = !collapseOverloads; //Note x.OverloadedData includes all instances of the same-name member. Thus '-1' should be applied if (collapseOverloads) { string[] infoParts = match.GetDisplayInfo(fullInfo, isInstantiation).HideKnownNamespaces(usedNamespaces).GetLines(2); string desctription = infoParts.First(); string documentation = (infoParts.Length > 1 ? "\r\n" + infoParts[1] : ""); string info = desctription; int overloadsCount = 0; if (match.HasOverloads) { overloadsCount = match.OverloadedData.Count() - 1; } if (match is TypeCompletionData) { if (isInstantiation) { info += "()"; } else { overloadsCount = 0; } } info += (overloadsCount > 0 ? (" (+ " + overloadsCount + " overload(s))") : "") + documentation; if (!string.IsNullOrEmpty(info)) { return new string[] { info } } ; } else { if (match.HasOverloads) { return(match.OverloadedData .Where(d => d is IEntityCompletionData) .Cast <IEntityCompletionData>() .Select(d => d.Entity.ToTooltip(fullInfo).HideKnownNamespaces(usedNamespaces)) .Where(x => !string.IsNullOrEmpty(x)) .ToArray()); } else { string info = match.GetDisplayInfo(fullInfo).HideKnownNamespaces(usedNamespaces); if (!string.IsNullOrEmpty(info)) { return new string[] { info } } ; } } } } catch { //the exception can happens even for the internal NRefactor-related reasons } return(new string[0]); }