Beispiel #1
0
        /// <summary>
        ///     Get the XML object (if any) at the specified position in the project file.
        /// </summary>
        /// <param name="position">
        ///     The target position.
        /// </param>
        /// <returns>
        ///     The object, or <c>null</c> if no object was found at the specified position.
        /// </returns>
        public SyntaxNode GetXmlAtPosition(Position position)
        {
            if (!HasXml)
            {
                throw new InvalidOperationException($"XML for project '{ProjectFile.FullName}' is not loaded.");
            }

            int absolutePosition = XmlPositions.GetAbsolutePosition(position);

            return(Xml.FindNode(position, XmlPositions));
        }
Beispiel #2
0
        /// <summary>
        ///     Get the expression's containing range.
        /// </summary>
        /// <param name="expression">
        ///     The MSBuild expression.
        /// </param>
        /// <param name="relativeToPosition">
        ///     The starting position of the <see cref="XSNode"/> that contains the expression.
        /// </param>
        /// <returns>
        ///     The containing <see cref="Range"/>.
        /// </returns>
        public Range GetRange(ExpressionNode expression, Position relativeToPosition)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            if (!HasXml)
            {
                throw new InvalidOperationException($"XML for project '{ProjectFile.FullName}' is not loaded.");
            }

            int absoluteBasePosition = XmlPositions.GetAbsolutePosition(relativeToPosition);

            return(XmlPositions.GetRange(
                       absoluteBasePosition + expression.AbsoluteStart,
                       absoluteBasePosition + expression.AbsoluteEnd
                       ));
        }