예제 #1
0
            async Task <ProjectCacheInfo> LoadProjectCacheInfo(
                MonoDevelop.Projects.Project p,
                DotNetProjectConfiguration config,
                string framework,
                CancellationToken token)
            {
                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var(references, projectReferences) = await metadataHandler.Value.CreateReferences(p, framework, token).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var configSelector = config?.Selector;

                if (p is MonoDevelop.Projects.DotNetProject && configSelector != null && !string.IsNullOrEmpty(framework))
                {
                    configSelector = new MonoDevelop.Projects.DotNetProjectFrameworkConfigurationSelector(config.Selector, framework);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var sourceFiles = await p.GetSourceFilesAsync(configSelector).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var analyzerFiles = await p.GetAnalyzerFilesAsync(configSelector).ConfigureAwait(false);

                return(new ProjectCacheInfo {
                    AnalyzerFiles = analyzerFiles,
                    SourceFiles = sourceFiles,
                    ProjectReferences = projectReferences,
                    References = references
                });
            }
예제 #2
0
            async Task <ProjectCacheInfo> LoadProjectCacheInfo(MonoDevelop.Projects.Project p, DotNetProjectConfiguration config, CancellationToken token)
            {
                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var(references, projectReferences) = await metadataHandler.Value.CreateReferences(p, token).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var sourceFiles = await p.GetSourceFilesAsync(config?.Selector).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var analyzerFiles = await p.GetAnalyzerFilesAsync(config?.Selector).ConfigureAwait(false);

                return(new ProjectCacheInfo {
                    AnalyzerFiles = analyzerFiles,
                    SourceFiles = sourceFiles,
                    ProjectReferences = projectReferences,
                    References = references
                });
            }
            internal async Task <ProjectInfo> LoadProject(MonoDevelop.Projects.Project p, CancellationToken token, MonoDevelop.Projects.Project oldProject)
            {
                var projectId = projectMap.GetOrCreateId(p, oldProject);

                var config = IdeApp.Workspace != null?p.GetConfiguration(IdeApp.Workspace.ActiveConfiguration) as MonoDevelop.Projects.DotNetProjectConfiguration : null;

                MonoDevelop.Projects.DotNetCompilerParameters cp = config?.CompilationParameters;
                FilePath fileName = IdeApp.Workspace != null?p.GetOutputFileName(IdeApp.Workspace.ActiveConfiguration) : (FilePath)"";

                if (fileName.IsNullOrEmpty)
                {
                    fileName = new FilePath(p.Name + ".dll");
                }

                if (!hackyCache.TryGetCachedItems(p, workspace.MetadataReferenceManager, projectMap, out var sourceFiles, out var analyzerFiles, out var references, out var projectReferences))
                {
                    (references, projectReferences) = await metadataHandler.Value.CreateReferences(p, token).ConfigureAwait(false);

                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }

                    sourceFiles = await p.GetSourceFilesAsync(config?.Selector).ConfigureAwait(false);

                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }

                    analyzerFiles = await p.GetAnalyzerFilesAsync(config?.Selector).ConfigureAwait(false);

                    if (config != null)
                    {
                        hackyCache.Update(config, p, projectMap, sourceFiles, analyzerFiles, references, projectReferences);
                    }
                }

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var loader = workspace.Services.GetService <IAnalyzerService> ().GetLoader();

                ProjectData         projectData, oldProjectData;
                List <DocumentInfo> mainDocuments, additionalDocuments;

                try {
                    await workspace.LoadLock.WaitAsync().ConfigureAwait(false);

                    //when reloading e.g. after a save, preserve document IDs
                    oldProjectData = projectMap.RemoveData(projectId);
                    projectData    = projectMap.CreateData(projectId, references);

                    var documents = await CreateDocuments(projectData, p, token, sourceFiles, oldProjectData).ConfigureAwait(false);

                    if (documents == null)
                    {
                        return(null);
                    }

                    mainDocuments       = documents.Item1;
                    additionalDocuments = documents.Item2;
                } finally {
                    workspace.LoadLock.Release();
                }

                // TODO: Pass in the WorkspaceMetadataFileReferenceResolver
                var info = ProjectInfo.Create(
                    projectId,
                    VersionStamp.Create(),
                    p.Name,
                    fileName.FileNameWithoutExtension,
                    (p as MonoDevelop.Projects.DotNetProject)?.RoslynLanguageName ?? LanguageNames.CSharp,
                    p.FileName,
                    fileName,
                    cp?.CreateCompilationOptions(),
                    cp?.CreateParseOptions(config),
                    mainDocuments,
                    projectReferences,
                    references.Select(x => x.CurrentSnapshot),
                    analyzerReferences: analyzerFiles.SelectAsArray(x => {
                    var analyzer = new MonoDevelopAnalyzer(x, hostDiagnosticUpdateSource.Value, projectId, workspace, loader, LanguageNames.CSharp);
                    analyzersToDispose.Add(analyzer);
                    return(analyzer.GetReference());
                }),
                    additionalDocuments: additionalDocuments
                    );

                return(info);
            }