Example #1
0
            protected override void Analyze(AnalysisServices services, RepoFile file)
            {
                ProjectAnalyzer.DocumentAnalysisTasks.Add(services.TaskDispatcher.Invoke(async() =>
                {
                    try
                    {
                        ReportStartAnalyze(file);

                        var project = ProjectAnalyzer.Project;
                        if (project == null)
                        {
                            file.PrimaryProject.Repo.AnalysisServices.Logger.LogError("Project is null");
                            return(null);
                        }

                        var document = project.GetDocument(DocumentInfo.Id);
                        var text     = await document.GetTextAsync();

                        SourceFile sourceFile = new SourceFile()
                        {
                            Info = AugmentSourceFileInfo(new SourceFileInfo()
                            {
                                Language         = project.Language,
                                Path             = file.LogicalPath,
                                RepoRelativePath = file.RepoRelativePath
                            }),
                        };

                        BoundSourceFileBuilder binder = CreateBuilder(sourceFile, file, file.PrimaryProject.ProjectId);
                        binder.SourceText             = text;

                        DocumentAnalyzer analyzer = new DocumentAnalyzer(
                            ProjectAnalyzer.semanticServices,
                            document,
                            ProjectAnalyzer.CompilationServices,
                            file.LogicalPath,
                            ProjectAnalyzer.ProjectContext,
                            binder);

                        var boundSourceFile = await analyzer.CreateBoundSourceFile();

                        ProjectAnalyzer.ProjectContext.ReportDocument(boundSourceFile, file);

                        UploadSourceFile(services, file, boundSourceFile);

                        return(boundSourceFile);
                    }
                    finally
                    {
                        file.Analyzer   = RepoFileAnalyzer.Null;
                        ProjectAnalyzer = null;
                    }
                }));
            }
        public static void AddSolutionProject(
            Lazy <Task <Solution> > lazySolution,
            ProjectInfo projectInfo,
            RepoFile projectFile,
            RepoProject repoProject,
            Lazy <SemanticServices> csharpSemanticServices      = null,
            Lazy <SemanticServices> visualBasicSemanticServices = null)
        {
            var semanticServices = projectInfo.Language == LanguageNames.CSharp ?
                                   csharpSemanticServices :
                                   visualBasicSemanticServices;

            Contract.Assert(semanticServices.Value != null);

            var projectAnalyzer = new ManagedProjectAnalyzer(
                semanticServices.Value,
                repoProject,
                projectInfo.Id,
                lazySolution);

            if (projectFile != null)
            {
                projectFile.HasExplicitAnalyzer = true;
            }

            repoProject.Analyzer = projectAnalyzer;

            foreach (var document in projectInfo.Documents)
            {
                if (document == null)
                {
                    throw new ArgumentNullException($"Project {projectInfo.Id} has a null document.");
                }

                if (Path.GetFileName(document.FilePath).StartsWith("TemporaryGeneratedFile_", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                var file = AddDocumentToProject(repoProject, document);
                if (file != null && projectAnalyzer != null)
                {
                    file.Analyzer = projectAnalyzer.CreateFileAnalyzer(document);
                }
            }

            foreach (var document in projectInfo.AdditionalDocuments)
            {
                AddDocumentToProject(repoProject, document);
            }
        }
Example #3
0
            public FileAnalyzer(ManagedProjectAnalyzer projectAnalyzer, DocumentInfo documentInfo)
            {
                if (projectAnalyzer == null)
                {
                    throw new ArgumentNullException(nameof(projectAnalyzer));
                }

                if (documentInfo == null)
                {
                    throw new ArgumentNullException(nameof(documentInfo));
                }

                ProjectAnalyzer = projectAnalyzer;
                DocumentInfo    = documentInfo;
            }