private async Task <RazorCodeDocument> GetGeneratedOutputInitializationTaskCore(ProjectSnapshot project, DocumentSnapshot document) { var tagHelpers = await project.GetTagHelpersAsync().ConfigureAwait(false); var imports = await GetImportsAsync(project, document); if (_older != null && _older.IsResultAvailable) { var tagHelperDifference = new HashSet <TagHelperDescriptor>(TagHelperDescriptorComparer.Default); tagHelperDifference.UnionWith(_older._tagHelpers); tagHelperDifference.SymmetricExceptWith(tagHelpers); var importDifference = new HashSet <ImportItem>(); importDifference.UnionWith(_older._imports); importDifference.SymmetricExceptWith(imports); if (tagHelperDifference.Count == 0 && importDifference.Count == 0) { // We can use the cached result. var result = _older._task.Result; // Drop reference so it can be GC'ed _older = null; // Cache the tag helpers and imports so the next version can use them _tagHelpers = tagHelpers; _imports = imports; return(result); } } // Drop reference so it can be GC'ed _older = null; // Cache the tag helpers and imports so the next version can use them _tagHelpers = tagHelpers; _imports = imports; var importSources = new List <RazorSourceDocument>(); foreach (var item in imports) { var sourceDocument = await GetRazorSourceDocumentAsync(item.Import); importSources.Add(sourceDocument); } var documentSource = await GetRazorSourceDocumentAsync(document); var projectEngine = project.GetProjectEngine(); return(projectEngine.ProcessDesignTime(documentSource, importSources, tagHelpers)); }
private async Task <RazorCodeDocument> GetGeneratedOutputInitializationTaskCore(ProjectSnapshot project, DocumentSnapshot document) { var tagHelpers = await project.GetTagHelpersAsync().ConfigureAwait(false); if (_older != null && _older.IsResultAvailable) { var difference = new HashSet <TagHelperDescriptor>(TagHelperDescriptorComparer.Default); difference.UnionWith(_older._tagHelpers); difference.SymmetricExceptWith(tagHelpers); if (difference.Count == 0) { // We can use the cached result. var result = _older._task.Result; // Drop reference so it can be GC'ed _older = null; // Cache the tag helpers so the next version can use them _tagHelpers = tagHelpers; return(result); } } // Drop reference so it can be GC'ed _older = null; // Cache the tag helpers so the next version can use them _tagHelpers = tagHelpers; var projectEngine = project.GetProjectEngine(); var projectItem = projectEngine.FileSystem.GetItem(document.FilePath); return(projectItem == null ? null : projectEngine.ProcessDesignTime(projectItem)); }
private IReadOnlyList <DocumentSnapshot> GetImportsCore(ProjectSnapshot project, DocumentSnapshot document) { var projectEngine = project.GetProjectEngine(); var importFeature = projectEngine.ProjectFeatures.OfType <IImportProjectFeature>().FirstOrDefault(); var projectItem = projectEngine.FileSystem.GetItem(document.FilePath); var importItems = importFeature?.GetImports(projectItem).Where(i => i.Exists); if (importItems == null) { return(Array.Empty <DocumentSnapshot>()); } var imports = new List <DocumentSnapshot>(); foreach (var item in importItems) { if (item.PhysicalPath == null) { // This is a default import. var defaultImport = new DefaultImportDocumentSnapshot(project, item); imports.Add(defaultImport); } else { var import = project.GetDocument(item.PhysicalPath); if (import == null) { // We are not tracking this document in this project. So do nothing. continue; } imports.Add(import); } } return(imports); }