///////////////////////////////////////////////////////////////////////////////////////////////////// // NON-PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Finds the statement AST node that contains the specified offset. /// </summary> /// <param name="parseData">The parse data.</param> /// <param name="snapshotOffset">The target snapshot offset.</param> /// <returns>The statement AST node that contains the specified offset.</returns> private static IAstNode FindContainingStatement(IDotNetParseData parseData, TextSnapshotOffset snapshotOffset) { // Get the offset relative to the AST's snapshot var offset = snapshotOffset.Offset; if (parseData.Snapshot != null) { offset = snapshotOffset.TranslateTo(parseData.Snapshot, TextOffsetTrackingMode.Negative); } // Loop upwards through the AST to find a containing statement var node = parseData.Ast.FindDescendantNode(offset); Statement statmentNode = null; while (node != null) { statmentNode = node as Statement; if (statmentNode != null) { return(statmentNode); } node = node.Parent; } return(null); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // OBJECT ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes an instance of the <c>CustomDotNetParseData</c> class. /// </summary> public CustomDotNetParseData(IDotNetParseData parseData) { if (parseData == null) { throw new ArgumentNullException(nameof(parseData)); } this.wrappedParseData = parseData; }
///////////////////////////////////////////////////////////////////////////////////////////////////// // OBJECT ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the <c>CodeLensParseData</c> class. /// </summary> /// <param name="wrappedParseData">The parse data to wrap.</param> public CodeLensParseData(IDotNetParseData wrappedParseData) { if (wrappedParseData == null) { throw new ArgumentNullException("wrappedParseData"); } // Initialize this.wrappedParseData = wrappedParseData; this.InitializeDeclarationsRecursive(this.Ast); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Translates the specified snapshot offset to the parse data's <see cref="IParseErrorProvider.Snapshot"/>, if possible, prior to containing AST node lookup. /// </summary> /// <param name="parseData">The <see cref="IDotNetParseData"/> to examine.</param> /// <param name="snapshotOffset">The <see cref="TextSnapshotOffset"/> to translate.</param> /// <returns>The translated offset.</returns> protected override TextSnapshotOffset TranslateToParseDataSnapshot(IDotNetParseData parseData, TextSnapshotOffset snapshotOffset) { var generatedSnapshotOffset = translateFunc(snapshotOffset); if (generatedSnapshotOffset.HasValue) { return(base.TranslateToParseDataSnapshot(parseData, generatedSnapshotOffset.Value)); } else { return(base.TranslateToParseDataSnapshot(parseData, snapshotOffset)); } }