Exemplo n.º 1
0
        public int?GetDesiredIndentation(ITextSnapshotLine line)
        {
            var snapshot = line.Snapshot;
            var treeTask = parserService.GetSyntaxTree(snapshot);

            indentSize = textView.Options.GetOptionValue(DefaultOptions.IndentSizeOptionId);

            treeTask.Wait(100);

            if (!treeTask.IsCompleted)
            {
                return(null);
            }

            var root = treeTask.Result;
            var lineStartPosition = line.Start.Position;
            var indent            = FindTotalParentChainIndent(
                root,
                lineStartPosition,
                currentPosition: 0,
                indent: 0,
                indentSize: indentSize);

            return(indent);
        }
Exemplo n.º 2
0
        public int?GetDesiredIndentation(ITextSnapshotLine line)
        {
            var snapshot = line.Snapshot;
            var treeTask = parserService.GetSyntaxTree(snapshot);

            treeTask.Wait(100);

            if (!treeTask.IsCompleted)
            {
                return(null);
            }

            var root = treeTask.Result;
            var lineStartPosition = line.Start.Position;
            var indent            = FindTotalParentChainIndent(root, lineStartPosition, 0, 0);

            return(indent);
        }
Exemplo n.º 3
0
        public void UncommentSelection(ITextView textView)
        {
            var snapshot = textView.TextSnapshot;
            var treeTask = parserService.GetSyntaxTree(snapshot);

            treeTask.Wait(100);

            if (!treeTask.IsCompleted)
            {
                return;
            }

            var root      = treeTask.Result;
            var selection = textView.Selection;

            List <TextSpan> commentedSpans = new List <TextSpan>();

            int priorCount = 0;

            foreach (var selectedSpan in selection.SelectedSpans)
            {
                bool allowLineUncomment = true;
                if (selectedSpan.IsEmpty)
                {
                    // For point selection, first see which comments are returned for the point span
                    // If the strictly inside a commented node, just uncommented that node
                    // otherwise, allow line uncomment
                    var selectionCommentedSpans = root.GetCommentedSpans(new TextSpan(selectedSpan.Start, 0)).ToList();
                    foreach (var selectionCommentedSpan in selectionCommentedSpans)
                    {
                        if (selectionCommentedSpan.Contains(selectedSpan.Start) &&
                            selectionCommentedSpan.Start != selectedSpan.Start &&
                            selectionCommentedSpan.End != selectedSpan.Start)
                        {
                            commentedSpans.Add(selectionCommentedSpan);
                            allowLineUncomment = false;
                            break;
                        }
                    }
                }

                if (allowLineUncomment)
                {
                    var desiredCommentSpan = GetDesiredCommentSpan(snapshot, selectedSpan);

                    priorCount = commentedSpans.Count;
                    commentedSpans.AddRange(root.GetCommentedSpans(desiredCommentSpan));
                }
            }

            var textBuffer = textView.TextBuffer;

            int beginCommentLength = "<!--".Length;
            int endCommentLength   = "-->".Length;

            using (var edit = textBuffer.CreateEdit())
            {
                foreach (var commentSpan in commentedSpans)
                {
                    edit.Delete(commentSpan.Start, beginCommentLength);
                    edit.Delete(commentSpan.End - endCommentLength, endCommentLength);
                }

                edit.Apply();
            }
        }