internal static void WriteDebugTree(string sourceFile, Block document, PartialParseResult result, TextChange change, RazorEditorParser parser, bool treeStructureChanged)
        {
            if (!OutputDebuggingEnabled)
            {
                return;
            }

            RunTask(() =>
            {
                string outputFileName = Normalize(sourceFile) + "_tree";
                string outputPath = Path.Combine(Path.GetDirectoryName(sourceFile), outputFileName);

                var treeBuilder = new StringBuilder();
                WriteTree(document, treeBuilder);
                treeBuilder.AppendLine();
                treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Last Change: {0}", change);
                treeBuilder.AppendLine();
                treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Normalized To: {0}", change.Normalize());
                treeBuilder.AppendLine();
                treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Partial Parse Result: {0}", result);
                treeBuilder.AppendLine();
                if (result.HasFlag(PartialParseResult.Rejected))
                {
                    treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Tree Structure Changed: {0}", treeStructureChanged);
                    treeBuilder.AppendLine();
                }
                if (result.HasFlag(PartialParseResult.AutoCompleteBlock))
                {
                    treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Auto Complete Insert String: \"{0}\"", parser.GetAutoCompleteString());
                    treeBuilder.AppendLine();
                }
                File.WriteAllText(outputPath, treeBuilder.ToString());
            });
        }
Пример #2
0
            public static BackgroundParserTask CreateAndStart(RazorEditorParser parser, TextChange change, Block parseTree)
            {
                CancellationTokenSource cancelSource = new CancellationTokenSource();
                BackgroundParserTask    task         = new BackgroundParserTask()
                {
                    CancelSource = cancelSource
                };
                CancellationToken token = cancelSource.Token;

                task.Task = Task.Factory.StartNew(() => {
                    try {
                        Interlocked.Increment(ref _activeTaskCount);
                        parser.ProcessChange(token, change, parseTree);
                    }
                    catch (OperationCanceledException) {
                    }
#if DEBUG
                    catch (Exception ex) {
                        if (Debugger.IsAttached)
                        {
                            throw;
                        }
                        Debug.Fail("Unexpected exception thrown by parser task", ex.ToString());
                    }
#else
                    catch (Exception) {
                    }
#endif
                }, token);
                return(task);
            }
 public ShimRazorEditorParserImpl(string virtualPath, string physicalPath)
 {
     WebPageRazorHost razorWebPageRazorHost = ShimRazorEditorParserImpl.GetRazorWebPageRazorHost(virtualPath, physicalPath);
     HtmlSettings.Changed += OnSettingsChanged;
     razorWebPageRazorHost.DesignTimeMode = true;
     OnSettingsChanged(razorWebPageRazorHost);
     _codeDomProviderType = razorWebPageRazorHost.CodeLanguage.CodeDomProviderType;
     RazorEditorParser = new RazorEditorParser(razorWebPageRazorHost, physicalPath);
     RazorEditorParser.DocumentParseComplete += OnDocumentParseComplete;
 }
Пример #4
0
        internal static void WriteDebugTree(string sourceFile, Block document, PartialParseResult result, TextChange change, RazorEditorParser parser, bool treeStructureChanged)
        {
            if (!OutputDebuggingEnabled)
            {
                return;
            }

            RunTask(() =>
            {
                string outputFileName = Normalize(sourceFile) + "_tree";
                string outputPath     = Path.Combine(Path.GetDirectoryName(sourceFile), outputFileName);

                var treeBuilder = new StringBuilder();
                WriteTree(document, treeBuilder);
                treeBuilder.AppendLine();
                treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Last Change: {0}", change);
                treeBuilder.AppendLine();
                treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Normalized To: {0}", change.Normalize());
                treeBuilder.AppendLine();
                treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Partial Parse Result: {0}", result);
                treeBuilder.AppendLine();
                if (result.HasFlag(PartialParseResult.Rejected))
                {
                    treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Tree Structure Changed: {0}", treeStructureChanged);
                    treeBuilder.AppendLine();
                }
                if (result.HasFlag(PartialParseResult.AutoCompleteBlock))
                {
                    treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Auto Complete Insert String: \"{0}\"", parser.GetAutoCompleteString());
                    treeBuilder.AppendLine();
                }
                File.WriteAllText(outputPath, treeBuilder.ToString());
            });
        }
Пример #5
0
		void DisposeCurrentParser ()
		{
			editorParser.Dispose ();
			editorParser = null;
			parseComplete.Dispose ();
			parseComplete = null;
			ClearLastChange ();
		}
Пример #6
0
		void CreateParserFor (string fileName)
		{
			editorParser = new RazorEditorParser (CreateRazorHost (fileName), fileName);

			parseComplete = new AutoResetEvent (false);
			editorParser.DocumentParseComplete += (sender, args) =>
			{
				capturedArgs = args;
				parseComplete.Set ();
			};

			lastParsedFile = fileName;
		}
 public void Close()
 {
     HtmlSettings.Changed -= OnSettingsChanged;
     ((IDisposable)RazorEditorParser).Dispose();
     RazorEditorParser = null;
 }
            public static BackgroundParserTask CreateAndStart(RazorEditorParser parser, TextChange change, Block parseTree) {
                CancellationTokenSource cancelSource = new CancellationTokenSource();
                BackgroundParserTask task = new BackgroundParserTask() {
                    CancelSource = cancelSource
                };
                CancellationToken token = cancelSource.Token;

                task.Task = Task.Factory.StartNew(() => {
                    try {
                        Interlocked.Increment(ref _activeTaskCount);
                        parser.ProcessChange(token, change, parseTree);
                    }
                    catch (OperationCanceledException) {
                    }
#if DEBUG
                    catch (Exception ex) {
                        if (Debugger.IsAttached) {
                            throw;
                        }
                        Debug.Fail("Unexpected exception thrown by parser task", ex.ToString());
                    }
#else
                    catch (Exception) {

                    }
#endif
                }, token);
                return task;
            }