Ejemplo n.º 1
0
        /// <summary>
        /// Determines if a change will cause a structural change to the document and if not, applies it to the
        /// existing tree. If a structural change would occur, automatically starts a reparse.
        /// </summary>
        /// <remarks>
        /// NOTE: The initial incremental parsing check and actual incremental parsing (if possible) occurs
        /// on the caller's thread. However, if a full reparse is needed, this occurs on a background thread.
        /// </remarks>
        /// <param name="change">The change to apply to the parse tree.</param>
        /// <returns>A <see cref="PartialParseResult"/> value indicating the result of the incremental parse.</returns>
        public virtual PartialParseResult CheckForStructureChanges(TextChange change)
        {
#if EDITOR_TRACING
            // Validate the change
            long?elapsedMs = null;

            var sw = new Stopwatch();
            sw.Start();
#endif
            RazorEditorTrace.TraceLine(RazorResources.FormatTrace_EditorReceivedChange(Path.GetFileName(FileName), change));
            if (change.NewBuffer == null)
            {
                throw new ArgumentException(
                          RazorResources.FormatStructure_Member_CannotBeNull(nameof(change.NewBuffer), nameof(TextChange)),
                          nameof(change));
            }

            var result = PartialParseResult.Rejected;
#if EDITOR_TRACING
            // If there isn't already a parse underway, try partial-parsing
            var changeString = string.Empty;
#endif
            using (_parser.SynchronizeMainThreadState())
            {
#if EDITOR_TRACING
                // Capture the string value of the change while we're synchronized
                changeString = change.ToString();
#endif

                // Check if we can partial-parse
                if (CurrentParseTree != null && _parser.IsIdle)
                {
                    result = TryPartialParse(change);
                }
            }

            // If partial parsing failed or there were outstanding parser tasks, start a full reparse
            if ((result & PartialParseResult.Rejected) == PartialParseResult.Rejected)
            {
                _parser.QueueChange(change);
            }

            // Otherwise, remember if this was provisionally accepted for next partial parse
            LastResultProvisional = (result & PartialParseResult.Provisional) == PartialParseResult.Provisional;
            VerifyFlagsAreValid(result);

#if EDITOR_TRACING
            sw.Stop();
            elapsedMs = sw.ElapsedMilliseconds;
            sw.Reset();

            RazorEditorTrace.TraceLine(RazorResources.FormatTrace_EditorProcessedChange(
                                           Path.GetFileName(FileName),
                                           changeString,
                                           elapsedMs.HasValue ? elapsedMs.Value.ToString(CultureInfo.InvariantCulture) : "?",
                                           result.ToString()));
#endif

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines if a change will cause a structural change to the document and if not, applies it to the existing tree.
        /// If a structural change would occur, automatically starts a reparse
        /// </summary>
        /// <remarks>
        /// NOTE: The initial incremental parsing check and actual incremental parsing (if possible) occurs
        /// on the callers thread.  However, if a full reparse is needed, this occurs on a background thread.
        /// </remarks>
        /// <param name="change">The change to apply to the parse tree</param>
        /// <returns>A PartialParseResult value indicating the result of the incremental parse</returns>
        public virtual PartialParseResult CheckForStructureChanges(TextChange change)
        {
            // Validate the change
            long?elapsedMs = null;

#if EDITOR_TRACING
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif
            RazorEditorTrace.TraceLine("[P][{0}] Recieved Change: {1}", Path.GetFileName(FileName), change);
            if (change.NewBuffer == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture,
                                                          RazorResources.Structure_Member_CannotBeNull,
                                                          "Buffer",
                                                          "TextChange"), "change");
            }

            PartialParseResult result = PartialParseResult.Rejected;

            // If there isn't already a parse underway, try partial-parsing
            string changeString = String.Empty;
            using (_parser.SynchronizeMainThreadState())
            {
                // Capture the string value of the change while we're synchronized
                changeString = change.ToString();

                // Check if we can partial-parse
                if (CurrentParseTree != null && _parser.IsIdle)
                {
                    result = TryPartialParse(change);
                }
            }

            // If partial parsing failed or there were outstanding parser tasks, start a full reparse
            if (result.HasFlag(PartialParseResult.Rejected))
            {
                _parser.QueueChange(change);
            }

            // Otherwise, remember if this was provisionally accepted for next partial parse
            LastResultProvisional = result.HasFlag(PartialParseResult.Provisional);
            VerifyFlagsAreValid(result);

#if EDITOR_TRACING
            sw.Stop();
            elapsedMs = sw.ElapsedMilliseconds;
            sw.Reset();
#endif
            RazorEditorTrace.TraceLine("[P][{0}] {3} Change in {2}ms: {1}", Path.GetFileName(FileName), changeString, elapsedMs.HasValue ? elapsedMs.Value.ToString() : "?", result.ToString());
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines if a change will cause a structural change to the document and if not, applies it to the
        /// existing tree. If a structural change would occur, automatically starts a reparse.
        /// </summary>
        /// <remarks>
        /// NOTE: The initial incremental parsing check and actual incremental parsing (if possible) occurs
        /// on the caller's thread. However, if a full reparse is needed, this occurs on a background thread.
        /// </remarks>
        /// <param name="change">The change to apply to the parse tree.</param>
        /// <returns>A <see cref="PartialParseResult"/> value indicating the result of the incremental parse.</returns>
        public virtual PartialParseResult CheckForStructureChanges(TextChange change)
        {
            // Validate the change
            long? elapsedMs = null;

#if EDITOR_TRACING
            var sw = new Stopwatch();
            sw.Start();
#endif
            RazorEditorTrace.TraceLine(RazorResources.FormatTrace_EditorReceivedChange(Path.GetFileName(FileName), change));
            if (change.NewBuffer == null)
            {
                throw new ArgumentException(
                    RazorResources.FormatStructure_Member_CannotBeNull(nameof(change.NewBuffer), nameof(TextChange)),
                    nameof(change));
            }

            var result = PartialParseResult.Rejected;

            // If there isn't already a parse underway, try partial-parsing
            var changeString = string.Empty;
            using (_parser.SynchronizeMainThreadState())
            {
                // Capture the string value of the change while we're synchronized
                changeString = change.ToString();

                // Check if we can partial-parse
                if (CurrentParseTree != null && _parser.IsIdle)
                {
                    result = TryPartialParse(change);
                }
            }

            // If partial parsing failed or there were outstanding parser tasks, start a full reparse
            if ((result & PartialParseResult.Rejected) == PartialParseResult.Rejected)
            {
                _parser.QueueChange(change);
            }

            // Otherwise, remember if this was provisionally accepted for next partial parse
            LastResultProvisional = (result & PartialParseResult.Provisional) == PartialParseResult.Provisional;
            VerifyFlagsAreValid(result);

#if EDITOR_TRACING
            sw.Stop();
            elapsedMs = sw.ElapsedMilliseconds;
            sw.Reset();
#endif

            RazorEditorTrace.TraceLine(RazorResources.FormatTrace_EditorProcessedChange(
                Path.GetFileName(FileName),
                changeString,
                elapsedMs.HasValue ? elapsedMs.Value.ToString(CultureInfo.InvariantCulture) : "?",
                result.ToString()));

            return result;
        }