Example #1
0
        public TreeValidator(IEditorTree editorTree)
        {
#if DEBUG
            TraceValidation.Enabled = false;
#endif

            _editorTree = editorTree;

            _editorTree.NodesRemoved    += OnNodesRemoved;
            _editorTree.UpdateCompleted += OnTreeUpdateCompleted;
            _editorTree.Closing         += OnTreeClose;

            _syntaxCheckEnabled = IsSyntaxCheckEnabled(_editorTree.TextBuffer);

            // Advise to settings changed *after* accessing the RSettings,
            // since accessing the host application (VS) settings object may
            // cause it fire Changed notification in some cases.
            REditorSettings.Changed += OnSettingsChanged;

            // We don't want to start validation right away since it may
            // interfere with the editor perceived startup performance.

            StartValidationNextIdle();
            ValidationResults = new ConcurrentQueue <IValidationError>();

            ServiceManager.AddService <TreeValidator>(this, editorTree.TextBuffer);
        }
Example #2
0
        public TreeValidator(IEditorTree editorTree)
        {
#if DEBUG
            TraceValidation.Enabled = false;
#endif

            _editorTree = editorTree;

            _editorTree.NodesRemoved += OnNodesRemoved;
            _editorTree.UpdateCompleted += OnTreeUpdateCompleted;
            _editorTree.Closing += OnTreeClose;

            _syntaxCheckEnabled = IsSyntaxCheckEnabled(_editorTree.TextBuffer);

            // Advise to settings changed *after* accessing the RSettings, 
            // since accessing the host application (VS) settings object may 
            // cause it fire Changed notification in some cases.
            REditorSettings.Changed += OnSettingsChanged;

            // We don't want to start validation right away since it may 
            // interfere with the editor perceived startup performance.

            StartValidationNextIdle();
            ValidationResults = new ConcurrentQueue<IValidationError>();

            ServiceManager.AddService<TreeValidator>(this, editorTree.TextBuffer);
        }
Example #3
0
        private static bool ShouldFormatScope(ITextView textView, ITextBuffer textBuffer, int lineOffset)
        {
            IREditorDocument document = REditorDocument.TryFromTextBuffer(textBuffer);

            if (document != null)
            {
                IEditorTree tree = document.EditorTree;
                tree.EnsureTreeReady();

                SnapshotPoint?caret = MapCaretToBuffer(textView, textBuffer);
                if (caret.HasValue)
                {
                    try {
                        int lineNumber             = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(caret.Value.Position);
                        ITextSnapshotLine line     = textBuffer.CurrentSnapshot.GetLineFromLineNumber(Math.Max(lineNumber - 1, 0));
                        string            lineText = line.GetText();
                        if (lineText.IndexOfAny(new char[] { '{', '}' }) >= 0)
                        {
                            IKeywordScopeStatement scopeStatement = tree.AstRoot.GetNodeOfTypeFromPosition <IKeywordScopeStatement>(caret.Value);
                            return(scopeStatement != null);
                        }
                    } catch (Exception) { }
                }
            }

            return(false);
        }
        /// <summary>
        /// Creates an <see cref="IBraceCompletionContext"/> to handle
        /// language-specific actions such as parsing and formatting.
        /// </summary>
        /// <remarks>
        /// Opening points within strings and comments are usually invalid points to start
        /// an <see cref="IBraceCompletionSession"/> and will return false.
        /// </remarks>
        /// <param name="textView">View containing the <paramref name="openingPoint"/>.</param>
        /// <param name="openingPoint">Insertion point of the <paramref name="openingBrace"/>.</param>
        /// <param name="openingBrace">Opening brace that has been typed by the user.</param>
        /// <param name="closingBrace">Closing brace character</param>
        /// <param name="context">Brace completion context if created.</param>
        /// <returns>Returns true if the <paramref name="openingPoint"/>
        /// was a valid point in the buffer to start a <see cref="IBraceCompletionSession"/>.
        /// </returns>
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
        {
            IREditorDocument document = REditorDocument.TryFromTextBuffer(openingPoint.Snapshot.TextBuffer);

            if (document != null)
            {
                IEditorTree tree = document.EditorTree;
                tree.EnsureTreeReady();

                // We don't want to complete inside strings
                if (tree.AstRoot.IsPositionInsideString(openingPoint.Position))
                {
                    context = null;
                    return(false);
                }

                // We don't want to complete inside comments
                int index = tree.AstRoot.Comments.GetItemContaining(openingPoint.Position);
                if (index >= 0)
                {
                    context = null;
                    return(false);
                }
            }
            context = new BraceCompletionContext();
            return(true);
        }
Example #5
0
        public ErrorTagCollection(IEditorTree editorTree) {
            RemovedTags = new ConcurrentQueue<EditorErrorTag>();

            _editorTree = editorTree;

            _editorTree.Closing += OnTreeClosing;
            _editorTree.NodesRemoved += OnNodesRemoved;
            _editorTree.UpdateCompleted += OnUpdateCompleted;
        }
Example #6
0
        public ROutlineRegionBuilder(IREditorDocument document)
            : base(document.EditorTree.TextBuffer)
        {
            EditorDocument = document;
            EditorDocument.DocumentClosing += OnDocumentClosing;

            EditorTree = document.EditorTree;
            EditorTree.UpdateCompleted += OnTreeUpdateCompleted;
        }
Example #7
0
        public ROutlineRegionBuilder(IREditorDocument document, IEditorShell shell)
            : base(document.EditorTree.TextBuffer, shell) {
            EditorDocument = document;
            EditorDocument.DocumentClosing += OnDocumentClosing;

            EditorTree = document.EditorTree;
            EditorTree.UpdateCompleted += OnTreeUpdateCompleted;
            EditorTree.Closing += OnEditorTreeClosing;
        }
Example #8
0
        public ROutlineRegionBuilder(IREditorDocument document, IEditorShell shell)
            : base(document.EditorTree.TextBuffer, shell)
        {
            EditorDocument = document;
            EditorDocument.DocumentClosing += OnDocumentClosing;

            EditorTree = document.EditorTree;
            EditorTree.UpdateCompleted += OnTreeUpdateCompleted;
            EditorTree.Closing         += OnEditorTreeClosing;
        }
Example #9
0
        public ErrorTagCollection(IEditorTree editorTree)
        {
            RemovedTags = new ConcurrentQueue <EditorErrorTag>();

            _editorTree = editorTree;

            _editorTree.Closing         += OnTreeClosing;
            _editorTree.NodesRemoved    += OnNodesRemoved;
            _editorTree.UpdateCompleted += OnUpdateCompleted;
        }
Example #10
0
        private void OnTreeClosing(object sender, EventArgs e)
        {
            if (_editorTree != null)
            {
                _editorTree.Closing         -= OnTreeClosing;
                _editorTree.NodesRemoved    -= OnNodesRemoved;
                _editorTree.UpdateCompleted -= OnUpdateCompleted;

                _editorTree = null;
            }
        }
Example #11
0
        /// <summary>
        /// Retrieves (or creates) the validator (syntax checker)
        /// for the document that is associated with the text buffer
        /// </summary>
        /// <param name="textBuffer">Text buffer</param>
        public static TreeValidator EnsureFromTextBuffer(ITextBuffer textBuffer, IEditorTree editorTree)
        {
            TreeValidator validator = ServiceManager.GetService <TreeValidator>(textBuffer);

            if (validator == null)
            {
                validator = new TreeValidator(editorTree);
            }

            return(validator);
        }
Example #12
0
        public RSectionsCollection(IEditorTree tree, IReadOnlyList<ITextRange> sections) {
            _tree = tree;
            _tree.TextBuffer.Changed += OnTextBufferChanged;

            foreach (var s in sections) {
                var span = s.ToSpan();
                _spans.Add(new SpanContent() {
                    TrackingSpan = _tree.TextSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgePositive),
                    OriginalLength = s.Length
                });
            }
        }
Example #13
0
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                EditorDocument.DocumentClosing -= OnDocumentClosing;
                EditorDocument = null;

                EditorTree.UpdateCompleted -= OnTreeUpdateCompleted;
                EditorTree = null;
            }

            base.Dispose(disposing);
        }
Example #14
0
        private void OnTreeClose(object sender, EventArgs e)
        {
            ServiceManager.RemoveService <TreeValidator>(_editorTree.TextBuffer);

            StopValidation();

            _editorTree.NodesRemoved    -= OnNodesRemoved;
            _editorTree.UpdateCompleted -= OnTreeUpdateCompleted;
            _editorTree.Closing         -= OnTreeClose;

            _editorTree = null;

            REditorSettings.Changed -= OnSettingsChanged;
        }
Example #15
0
        public EditorErrorTag(IEditorTree editorTree, IValidationError error)
            : base(GetErrorType(error), error.Message)
        {
            _textBuffer = editorTree.TextBuffer;

            Description = error.Message;
            TaskType    = GetTaskType(error);

            _range = error;

            if (_range == null || _range.Start < 0)
            {
                _range = TextRange.EmptyRange;
            }
        }
        public RSectionsCollection(IEditorTree tree, IReadOnlyList <ITextRange> sections)
        {
            _tree = tree;
            _tree.TextBuffer.Changed += OnTextBufferChanged;

            foreach (var s in sections)
            {
                var span = s.ToSpan();
                _spans.Add(new SpanContent()
                {
                    TrackingSpan   = _tree.TextSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgePositive),
                    OriginalLength = s.Length
                });
            }
        }
Example #17
0
        public EditorErrorTag(IEditorTree editorTree, IValidationError error)
            : base(GetErrorType(error), error.Message)
        {
            _textBuffer = editorTree.TextBuffer;

            var document = REditorDocument.FromTextBuffer(editorTree.TextBuffer);

            FileName = document?.FilePath;

            Description = error.Message;
            TaskType    = GetTaskType(error);

            _range = error;

            if (_range == null || _range.Start < 0)
            {
                _range = TextRange.EmptyRange;
            }
        }
Example #18
0
        private static SnapshotPoint?GetCaretPointInBuffer(ITextView textView, out IEditorTree tree)
        {
            tree = null;
            IREditorDocument document = REditorDocument.TryFromTextBuffer(textView.TextBuffer);

            if (document != null)
            {
                tree = document.EditorTree;
                tree.EnsureTreeReady();
                return(textView.BufferGraph.MapDownToFirstMatch(
                           textView.Caret.Position.BufferPosition,
                           PointTrackingMode.Positive,
                           snapshot => snapshot.TextBuffer.ContentType.IsOfType(RContentTypeDefinition.ContentType),
                           PositionAffinity.Successor
                           ));
            }

            return(null);
        }
Example #19
0
        private static SnapshotPoint? GetCaretPointInBuffer(ITextView textView, out IEditorTree tree) {
            tree = null;
            IREditorDocument document = REditorDocument.TryFromTextBuffer(textView.TextBuffer);
            if (document != null) {
                tree = document.EditorTree;
                tree.EnsureTreeReady();
                return textView.BufferGraph.MapDownToFirstMatch(
                    textView.Caret.Position.BufferPosition,
                    PointTrackingMode.Positive,
                    snapshot => snapshot.TextBuffer.ContentType.IsOfType(RContentTypeDefinition.ContentType),
                    PositionAffinity.Successor
                );
            }

            return null;
        }
Example #20
0
 public EditorDocumentMock(IEditorTree tree)
 {
     EditorTree = tree;
     ServiceManager.AddService <IREditorDocument>(this, tree.TextBuffer, null);
 }
Example #21
0
 public static AstRoot GetCurrentRootOrPreviousIfNotReady(this IEditorTree tree)
 {
     return((!tree.IsReady && tree.PreviousAstRoot != null) ? tree.PreviousAstRoot : tree.AstRoot);
 }
 public EditorDocumentMock(IEditorTree tree)
 {
     EditorTree = tree;
     ServiceManager.AddService<IREditorDocument>(this, tree.TextBuffer);
 }
Example #23
0
        private void OnTreeClose(object sender, EventArgs e)
        {
            ServiceManager.RemoveService<TreeValidator>(_editorTree.TextBuffer);

            StopValidation();

            _editorTree.NodesRemoved -= OnNodesRemoved;
            _editorTree.UpdateCompleted -= OnTreeUpdateCompleted;
            _editorTree.Closing -= OnTreeClose;

            _editorTree = null;

            REditorSettings.Changed -= OnSettingsChanged;
        }
Example #24
0
        /// <summary>
        /// Retrieves (or creates) the validator (syntax checker) 
        /// for the document that is associated with the text buffer
        /// </summary>
        /// <param name="textBuffer">Text buffer</param>
        public static TreeValidator EnsureFromTextBuffer(ITextBuffer textBuffer, IEditorTree editorTree)
        {
            TreeValidator validator = ServiceManager.GetService<TreeValidator>(textBuffer);
            if (validator == null)
            {
                validator = new TreeValidator(editorTree);
            }

            return validator;
        }
Example #25
0
        private void OnTreeClosing(object sender, EventArgs e) {
            if (_editorTree != null) {
                _editorTree.Closing -= OnTreeClosing;
                _editorTree.NodesRemoved -= OnNodesRemoved;
                _editorTree.UpdateCompleted -= OnUpdateCompleted;

                _editorTree = null;
            }
        }