Inheritance: ParsedDocument
		public override async System.Threading.Tasks.Task<ParsedDocument> Parse (MonoDevelop.Ide.TypeSystem.ParseOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
		{
			var fileName = options.FileName;
			var project = options.Project;
			var result = new CSharpParsedDocument (fileName);

			if (project != null) {
				
				var projectFile = project.Files.GetFile (fileName);
				SourceCodeKind kind;
				if (projectFile != null && !TypeSystemParserNode.IsCompileableFile (projectFile, out kind))
					result.Flags |= ParsedDocumentFlags.NonSerializable;
			}

			SyntaxTree unit = null;

			if (project != null) {
				var curDoc = options.RoslynDocument;
				if (curDoc == null) {
					var curProject = TypeSystemService.GetCodeAnalysisProject (project);
					if (curProject != null) {
						var documentId = TypeSystemService.GetDocumentId (project, fileName);
						if (documentId != null)
							curDoc = curProject.GetDocument (documentId);
					}
				}
				if (curDoc != null) {
					try {
						var model = await curDoc.GetSemanticModelAsync (cancellationToken).ConfigureAwait (false);
						unit = model.SyntaxTree;
						result.Ast = model;
					} catch (AggregateException ae) {
						ae.Flatten ().Handle (x => x is OperationCanceledException); 
						return result;
					} catch (OperationCanceledException) {
						return result;
					} catch (Exception e) {
						LoggingService.LogError ("Error while getting the semantic model for " + fileName, e); 
					}
				}
			}

			if (unit == null) {
				var compilerArguments = GetCompilerArguments (project);
				unit = CSharpSyntaxTree.ParseText (SourceText.From (options.Content.Text), compilerArguments, fileName);
			} 

			result.Unit = unit;

			DateTime time;
			try {
				time = System.IO.File.GetLastWriteTimeUtc (fileName);
			} catch (Exception) {
				time = DateTime.UtcNow;
			}
			result.LastWriteTimeUtc = time;
			return result;
		}
Esempio n. 2
0
        public override System.Threading.Tasks.Task <ParsedDocument> Parse(MonoDevelop.Ide.TypeSystem.ParseOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            var fileName = options.FileName;
            var project  = options.Project;
            var result   = new CSharpParsedDocument(options, fileName);

            if (project != null)
            {
                var projectFile = project.Files.GetFile(fileName);
                if (projectFile != null && !project.IsCompileable(projectFile.FilePath))
                {
                    result.Flags |= ParsedDocumentFlags.NonSerializable;
                }
            }

            if (project != null)
            {
                var curDoc = options.RoslynDocument;
                if (curDoc == null)
                {
                    var curProject = IdeApp.TypeSystemService.GetCodeAnalysisProject(project);
                    if (curProject != null)
                    {
                        var documentId = IdeApp.TypeSystemService.GetDocumentId(project, fileName);
                        result.DocumentId = documentId;
                    }
                }
            }
            else
            {
                var compilerArguments = GetCompilerArguments(project);
                result.ParsedUnit = CSharpSyntaxTree.ParseText(SourceText.From(options.Content.Text), compilerArguments, fileName);
            }

            DateTime time;

            try {
                time = System.IO.File.GetLastWriteTimeUtc(fileName);
            } catch (Exception) {
                time = DateTime.UtcNow;
            }
            result.LastWriteTimeUtc = time;
            return(Task.FromResult <ParsedDocument> (result));
        }
Esempio n. 3
0
        public override async System.Threading.Tasks.Task <ParsedDocument> Parse(MonoDevelop.Ide.TypeSystem.ParseOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            var fileName = options.FileName;
            var project  = options.Project;
            var result   = new CSharpParsedDocument(fileName);

            if (project != null)
            {
                var projectFile = project.Files.GetFile(fileName);
                if (projectFile != null && !TypeSystemParserNode.IsCompileBuildAction(projectFile.BuildAction))
                {
                    result.Flags |= ParsedDocumentFlags.NonSerializable;
                }
            }

            var        compilerArguments = GetCompilerArguments(project);
            SyntaxTree unit = null;

            if (project != null)
            {
                var curDoc = options.RoslynDocument;
                if (curDoc == null)
                {
                    var curProject = TypeSystemService.GetCodeAnalysisProject(project);
                    if (curProject != null)
                    {
                        var documentId = TypeSystemService.GetDocumentId(project, fileName);
                        if (documentId != null)
                        {
                            curDoc = curProject.GetDocument(documentId);
                        }
                    }
                }
                if (curDoc != null)
                {
                    try {
                        var model = await curDoc.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

                        unit       = model.SyntaxTree;
                        result.Ast = model;
                    } catch (AggregateException ae) {
                        ae.Flatten().Handle(x => x is OperationCanceledException);
                        return(result);
                    } catch (OperationCanceledException) {
                        return(result);
                    } catch (Exception e) {
                        LoggingService.LogError("Error while getting the semantic model for " + fileName, e);
                    }
                }
            }

            if (unit == null)
            {
                unit = CSharpSyntaxTree.ParseText(SourceText.From(options.Content.Text), compilerArguments, fileName);
            }

            result.Unit = unit;

            DateTime time;

            try {
                time = System.IO.File.GetLastWriteTimeUtc(fileName);
            } catch (Exception) {
                time = DateTime.UtcNow;
            }
            result.LastWriteTimeUtc = time;
            return(result);
        }