Ejemplo n.º 1
0
        public override ParsedDocument Parse(bool storeAst, string fileName, System.IO.TextReader content, Project project = null)
        {
            currentDocument = openDocuments.FirstOrDefault(d => d != null && d.FileName == fileName);
            // We need document and project to be loaded to correctly initialize Razor Host.
            this.project = project as DotNetProject;
            if (currentDocument == null && !TryAddDocument(fileName))
            {
                return(new RazorCSharpParsedDocument(fileName, new RazorCSharpPageInfo()));
            }

            this.aspProject = project as AspNetAppProject;

            EnsureParserInitializedFor(fileName);

            var errors = new List <Error> ();

            using (var source = new SeekableTextReader(content)) {
                var textChange  = CreateTextChange(source);
                var parseResult = editorParser.CheckForStructureChanges(textChange);
                if (parseResult == PartialParseResult.Rejected)
                {
                    parseComplete.WaitOne();
                    if (!capturedArgs.GeneratorResults.Success)
                    {
                        GetRazorErrors(errors);
                    }
                }
            }

            ParseHtmlDocument(errors);
            CreateCSharpParsedDocument();
            ClearLastChange();

            RazorHostKind kind = RazorHostKind.WebPage;

            if (editorParser.Host is WebCodeRazorHost)
            {
                kind = RazorHostKind.WebCode;
            }
            else if (editorParser.Host is MonoDevelop.AspNet.Razor.Generator.PreprocessedRazorHost)
            {
                kind = RazorHostKind.Template;
            }

            var pageInfo = new RazorCSharpPageInfo()
            {
                HtmlRoot         = htmlParsedDocument,
                GeneratorResults = capturedArgs.GeneratorResults,
                Spans            = editorParser.CurrentParseTree.Flatten(),
                CSharpParsedFile = parsedCodeFile,
                CSharpCode       = csharpCode,
                Errors           = errors,
                FoldingRegions   = GetFoldingRegions(),
                Comments         = comments,
                Compilation      = CreateCompilation(),
                HostKind         = kind,
            };

            return(new RazorCSharpParsedDocument(fileName, pageInfo));
        }
		public RazorCSharpParsedDocument (string fileName, RazorCSharpPageInfo pageInfo) : base (fileName)
		{
			PageInfo = pageInfo;
			Flags |= ParsedDocumentFlags.NonSerializable;
			if (PageInfo.Errors != null)
				AddRange (PageInfo.Errors);
		}
Ejemplo n.º 3
0
 public RazorCSharpParsedDocument(string fileName, RazorCSharpPageInfo pageInfo) : base(fileName)
 {
     PageInfo = pageInfo;
     Flags   |= ParsedDocumentFlags.NonSerializable;
     if (PageInfo.Errors != null)
     {
         Add(PageInfo.Errors);
     }
 }
Ejemplo n.º 4
0
 public RazorCSharpParsedDocument(string fileName, RazorCSharpPageInfo pageInfo) : base(fileName)
 {
     PageInfo = pageInfo;
     Flags   |= ParsedDocumentFlags.NonSerializable | ParsedDocumentFlags.HasCustomCompletionExtension;
     if (PageInfo.Errors != null)
     {
         AddRange(PageInfo.Errors);
     }
 }
Ejemplo n.º 5
0
        System.Threading.Tasks.Task <ParsedDocument> Parse(RazorCSharpParserContext context, CancellationToken cancellationToken)
        {
            EnsureParserInitializedFor(context);

            var errors = new List <Error> ();

            using (var source = new SeekableTextReader(context.Content.CreateReader())) {
                var textChange  = CreateTextChange(context, source);
                var parseResult = context.EditorParser.CheckForStructureChanges(textChange);
                if (parseResult == PartialParseResult.Rejected)
                {
                    context.RazorDocument.ParseComplete.WaitOne();
                    if (!context.CapturedArgs.GeneratorResults.Success)
                    {
                        GetRazorErrors(context, errors);
                    }
                }
            }

            ParseHtmlDocument(context, errors);
            CreateCSharpParsedDocument(context);
            context.ClearLastTextChange();

            RazorHostKind kind = RazorHostKind.WebPage;

            if (context.EditorParser.Host is WebCodeRazorHost)
            {
                kind = RazorHostKind.WebCode;
            }
            else if (context.EditorParser.Host is MonoDevelop.AspNet.Razor.Generator.PreprocessedRazorHost)
            {
                kind = RazorHostKind.Template;
            }

            var model    = context.AnalysisDocument.GetSemanticModelAsync(cancellationToken).Result;
            var pageInfo = new RazorCSharpPageInfo()
            {
                HtmlRoot         = context.HtmlParsedDocument,
                GeneratorResults = context.CapturedArgs.GeneratorResults,
                Spans            = context.EditorParser.CurrentParseTree.Flatten(),
                CSharpSyntaxTree = context.ParsedSyntaxTree,
                ParsedDocument   = new DefaultParsedDocument("generated.cs")
                {
                    Ast = model
                },
                AnalysisDocument = context.AnalysisDocument,
                CSharpCode       = context.CSharpCode,
                Errors           = errors,
                FoldingRegions   = GetFoldingRegions(context),
                Comments         = context.Comments,
                HostKind         = kind,
            };

            return(System.Threading.Tasks.Task.FromResult((ParsedDocument) new RazorCSharpParsedDocument(context.FileName, pageInfo)));
        }
Ejemplo n.º 6
0
		public override ParsedDocument Parse (bool storeAst, string fileName, System.IO.TextReader content, Project project = null)
		{
			currentDocument = openDocuments.FirstOrDefault (d => d != null && d.FileName == fileName);
			// We need document and project to be loaded to correctly initialize Razor Host.
			this.project = project as DotNetProject;
			if (currentDocument == null && !TryAddDocument (fileName))
				return new RazorCSharpParsedDocument (fileName, new RazorCSharpPageInfo ());

			this.aspProject = project as AspNetAppProject;

			EnsureParserInitializedFor (fileName);

			var errors = new List<Error> ();

			using (var source = new SeekableTextReader (content)) {
				var textChange = CreateTextChange (source);
				var parseResult = editorParser.CheckForStructureChanges (textChange);
				if (parseResult == PartialParseResult.Rejected) {
					parseComplete.WaitOne ();
					if (!capturedArgs.GeneratorResults.Success)
						GetRazorErrors (errors);
				}
			}

			ParseHtmlDocument (errors);
			CreateCSharpParsedDocument ();
			ClearLastChange ();

			RazorHostKind kind = RazorHostKind.WebPage;
			if (editorParser.Host is WebCodeRazorHost) {
				kind = RazorHostKind.WebCode;
			} else if (editorParser.Host is MonoDevelop.AspNet.Razor.Generator.PreprocessedRazorHost) {
				kind = RazorHostKind.Template;
			}

			var pageInfo = new RazorCSharpPageInfo () {
				HtmlRoot = htmlParsedDocument,
				GeneratorResults = capturedArgs.GeneratorResults,
				Spans = editorParser.CurrentParseTree.Flatten (),
				CSharpParsedFile = parsedCodeFile,
				CSharpCode = csharpCode,
				Errors = errors,
				FoldingRegions = GetFoldingRegions (),
				Comments = comments,
				Compilation = CreateCompilation (),
				HostKind = kind,
			};

			return new RazorCSharpParsedDocument (fileName, pageInfo);
		}
Ejemplo n.º 7
0
		System.Threading.Tasks.Task<ParsedDocument> Parse (RazorCSharpParserContext context, CancellationToken cancellationToken)
		{
			EnsureParserInitializedFor (context);

			var errors = new List<Error> ();

			using (var source = new SeekableTextReader (context.Content.CreateReader ())) {
				var textChange = CreateTextChange (context, source);
				var parseResult = context.EditorParser.CheckForStructureChanges (textChange);
				if (parseResult == PartialParseResult.Rejected) {
					context.RazorDocument.ParseComplete.WaitOne ();
					if (!context.CapturedArgs.GeneratorResults.Success)
						GetRazorErrors (context, errors);
				}
			}

			ParseHtmlDocument (context, errors);
			CreateCSharpParsedDocument (context);
			context.ClearLastTextChange ();

			RazorHostKind kind = RazorHostKind.WebPage;
			if (context.EditorParser.Host is WebCodeRazorHost) {
				kind = RazorHostKind.WebCode;
			} else if (context.EditorParser.Host is MonoDevelop.AspNet.Razor.Generator.PreprocessedRazorHost) {
				kind = RazorHostKind.Template;
			}

			var model = context.AnalysisDocument.GetSemanticModelAsync (cancellationToken).Result;
			var pageInfo = new RazorCSharpPageInfo () {
				HtmlRoot = context.HtmlParsedDocument,
				GeneratorResults = context.CapturedArgs.GeneratorResults,
				Spans = context.EditorParser.CurrentParseTree.Flatten (),
				CSharpSyntaxTree = context.ParsedSyntaxTree,
				ParsedDocument = new DefaultParsedDocument ("generated.cs") { Ast = model },
				AnalysisDocument = context.AnalysisDocument,
				CSharpCode = context.CSharpCode,
				Errors = errors,
				FoldingRegions = GetFoldingRegions (context),
				Comments = context.Comments,
				HostKind = kind,
			};

			return System.Threading.Tasks.Task.FromResult((ParsedDocument)new RazorCSharpParsedDocument (context.FileName, pageInfo));
		}