Esempio n. 1
0
        private bool IsPreviousTokenOnSameLine()
        {
            var previous = GetPreviousToken();

            if (previous == null)
            {
                return(true);
            }

            var previousLine = _text.GetLineNumberFromPosition(previous.Span.Start);
            var currentLine  = _text.GetLineNumberFromPosition(Current.Span.Start);

            return(previousLine == currentLine);
        }
Esempio n. 2
0
        /// <summary>
        /// Finds the line number for a Target
        /// </summary>
        /// <param name="text"> The file information for the target node </param>
        /// <param name="targetName"> Name of the target to find in the file </param>
        /// <param name="taskName"> Name of the task to find in the file </param>
        /// <returns> Line number to highlight</returns>
        public static int TargetLineNumber(SourceText text, string targetName, string taskName = null)
        {
            var         xml           = text.XmlRoot;
            IXmlElement root          = xml.Root;
            int         startPosition = 0;
            int         line          = 0;

            // work around a bug in Xml Parser where a virtual parent is created around the root element
            // when the root element is preceded by trivia (comment)
            if (root.Name == null && root.Elements.FirstOrDefault() is IXmlElement firstElement && firstElement.Name == "Project")
            {
                root = firstElement;
            }

            foreach (var element in root.Elements)
            {
                if (element.Name == "Target" && element.Attributes != null)
                {
                    var nameAttribute = element.AsSyntaxElement.Attributes.FirstOrDefault(a => a.Name == "Name" && a.Value == targetName);
                    if (nameAttribute != null)
                    {
                        startPosition = nameAttribute.ValueNode.Start;

                        if (taskName != null)
                        {
                            var tasks = element.Elements.Where(e => e.Name == taskName).ToArray();
                            if (tasks.Length == 1)
                            {
                                startPosition = tasks[0].AsSyntaxElement.NameNode.Start;
                            }
                        }

                        break;
                    }
                }
            }

            if (startPosition > 0)
            {
                line = text.GetLineNumberFromPosition(startPosition);
            }

            return(line + 1);
        }
Esempio n. 3
0
 public override int GetLineNumberFromPosition(int position)
 {
     return(_sourceText.GetLineNumberFromPosition(position));
 }