当前位置: 首页>>代码示例>>C#>>正文


C# IAstNode.NodeFromRange方法代码示例

本文整理汇总了C#中IAstNode.NodeFromRange方法的典型用法代码示例。如果您正苦于以下问题:C# IAstNode.NodeFromRange方法的具体用法?C# IAstNode.NodeFromRange怎么用?C# IAstNode.NodeFromRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAstNode的用法示例。


在下文中一共展示了IAstNode.NodeFromRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDataTipExpression

        /// <summary>
        /// Given an R AST, and a range in that AST, determines the DataTip expression for that range.
        /// </summary>
        /// <returns>
        /// AST node corresponding to the DataTip expression, or <c>null</c> if there is no valid DataTip for the given range.
        /// </returns>
        /// <remarks>
        /// DataTip expression is defined as the outermost expression enclosing the range, such that the sequence 
        /// of operators from that outermost expression to the innermost node still enclosing the range only consists
        /// of operators: <c>$ @ :: ::: [ [[</c>. Furthermore, in case of <c>[ [[</c>, only their left operands
        /// are considered.
        /// </remarks>
        public static IAstNode GetDataTipExpression(IAstNode ast, ITextRange range) {
            var node = ast.NodeFromRange(range, inclusiveEnd: true);
            if (node == null || !IsValidInitialNode(node)) {
                return null;
            }

            // When the lookup starts at [ or [[, the immediate node is the token, but its parent is an Indexer node,
            // and the parent of the indexer is the Operator. The loop below assumes that Operator is the immediate
            // parent, so walk one level up before entering it in this case.
            var indexer = node.Parent as Indexer;
            if (indexer != null) {
                node = indexer;
            }

            // Walk the AST tree up to determine the expression that should be evaluated, according to the following rules:
            // - if current node is a child of $, @, :: or ::: (on either side of the operator), keep walking;
            // - if current node is a left child of [ or [[, keep walking;
            // - otherwise, stop.
            // Thus, for an expression like a::[email protected], the entire expression will be considered when hovering over a, b, c or d.
            // But for a[b$c][[d]], hovering over a will consider a[b$c][d], but hovering over b or c will only consider b$c.
            while (true) {
                var parent = node.Parent as Operator;
                if (parent == null) {
                    break;
                }

                var op = parent.OperatorType;
                if (op == OperatorType.Index) {
                    // This is a[b] or a[[b]], and the current node is either a or b. If it is a, then we want to continue
                    // walking up; but if it is b, we want to stop here, so that only b is shown.
                    if (parent.Children.FirstOrDefault() != node) {
                        break;
                    }
                } else if (op != OperatorType.ListIndex && op != OperatorType.Namespace) {
                    break;
                }

                node = parent;
            }

            return node;
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:54,代码来源:RDataTip.cs


注:本文中的IAstNode.NodeFromRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。