/// <summary> /// Try to find the document location that belongs to the given method + offset. /// </summary> /// <returns>null, if not found. If we know the document, but the offset is marked to /// have no source code attached (compiler generated), the returned position will /// be marked as IsSpecial.</returns> public SourceCodePosition FindSourceCode(MethodEntry method, int methodOffset, bool allowSpecial = true) { var locs = GetSourceCodePositions(method); // perform a binary search int idx = locs.FindLastIndexSmallerThanOrEqualTo(methodOffset, p => p.Position.MethodOffset); if (idx != -1 && (allowSpecial || !locs[idx].IsSpecial)) { return(locs[idx]); } if (allowSpecial && locs.Count > 0) { // this can only happen at the beginning of the method. // forge a special location. var pos = locs[0].Position; var forgedPos = new DocumentPosition(pos.Start.Line, pos.Start.Column, pos.End.Line, pos.End.Column, pos.TypeId, pos.MethodId, DocumentPosition.SpecialOffset); return(new SourceCodePosition(locs[0].Document, forgedPos)); } return(null); }
public SourceCodePosition(Document document, DocumentPosition position) { Document = document; Position = position; }
internal static SourceCodePosition Create(Document document, DocumentPosition position) { return(new SourceCodePosition(document, position)); }
/// <summary> /// Try to find the document location that belongs to the given type, method + offset. /// </summary> public bool TryFindLocation(TypeEntry type, MethodEntry method, int methodOffset, out Document document, out DocumentPosition position) { document = null; position = null; foreach (var doc in documents.Values) { foreach (var docPos in doc.Positions) { if ((docPos.TypeId != type.Id) || (docPos.MethodId != method.Id)) { continue; } // type and method matches if ((docPos.MethodOffset <= methodOffset) || (position == null)) { // Found possible result if ((position == null) || (docPos.MethodOffset > position.MethodOffset)) { // Found better result document = doc; position = docPos; } } } } return(position != null); }