public MetadataItem Extract(ExtractMetadataOptions options) { var preserveRawInlineComments = options.PreserveRawInlineComments; var filterConfigFile = options.FilterConfigFile; var extensionMethods = options.ExtensionMethods; object visitorContext = new object(); SymbolVisitorAdapter visitor; if (_compilation.Language == "Visual Basic") { visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.VB, _compilation, preserveRawInlineComments, filterConfigFile, extensionMethods); } else if (_compilation.Language == "C#") { visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.CSharp, _compilation, preserveRawInlineComments, filterConfigFile, extensionMethods); } else { Debug.Assert(false, "Language not supported: " + _compilation.Language); Logger.Log(LogLevel.Error, "Language not supported: " + _compilation.Language); return(null); } MetadataItem item = _assembly.Accept(visitor); return(item); }
public SourceFileInputParameters(ExtractMetadataOptions options, IEnumerable <string> files) { Options = options; Files = files; Key = StringExtension.GetNormalizedFullPathKey(Files); Cache = ProjectLevelCache.Get(files); BuildInfo = Cache?.GetValidConfig(Key); }
public AssemblyFileInputParameters(ExtractMetadataOptions options, string key) { Options = options; Files = new string[] { key }; Key = StringExtension.GetNormalizedFullPathKey(Files); Cache = ProjectLevelCache.Get(key); BuildInfo = Cache?.GetValidConfig(Key); }
public ProjectFileInputParameters(ExtractMetadataOptions options, IEnumerable <string> files, string projectFile, bool dependencyRebuilt) { Options = options; Files = files; DependencyRebuilt = dependencyRebuilt; Key = StringExtension.ToNormalizedFullPath(projectFile); Cache = ProjectLevelCache.Get(projectFile); BuildInfo = Cache?.GetValidConfig(Key); }
public ExtractMetadataWorker(ExtractMetadataInputModel input) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (string.IsNullOrEmpty(input.OutputFolder)) { throw new ArgumentNullException(nameof(input.OutputFolder), "Output folder must be specified"); } _files = input.Files?.Select(s => new FileInformation(s)) .GroupBy(f => f.Type) .ToDictionary(s => s.Key, s => s.Distinct().ToList()); _references = input.References?.Select(s => new FileInformation(s)) .Select(f => f.NormalizedPath) .Distinct() .ToList(); _rebuild = input.ForceRebuild; var msbuildProperties = input.MSBuildProperties ?? new Dictionary <string, string>(); if (!msbuildProperties.ContainsKey("Configuration")) { msbuildProperties["Configuration"] = "Release"; } _options = new ExtractMetadataOptions { ShouldSkipMarkup = input.ShouldSkipMarkup, PreserveRawInlineComments = input.PreserveRawInlineComments, FilterConfigFile = input.FilterConfigFile != null ? new FileInformation(input.FilterConfigFile).NormalizedPath : null, MSBuildProperties = msbuildProperties, CodeSourceBasePath = input.CodeSourceBasePath, DisableDefaultFilter = input.DisableDefaultFilter, }; _useCompatibilityFileName = input.UseCompatibilityFileName; _outputFolder = StringExtension.ToNormalizedFullPath(Path.Combine(EnvironmentContext.OutputDirectory, input.OutputFolder)); _workspace = new Lazy <MSBuildWorkspace>(() => { var workspace = MSBuildWorkspace.Create(msbuildProperties); workspace.WorkspaceFailed += (s, e) => { Logger.LogWarning($"Workspace failed with: {e.Diagnostic}"); }; return(workspace); }); var roslynLoader = new RoslynProjectLoader(_workspace); var fsharpLoader = new FSharpProjectLoader(msbuildProperties); _loader = new AbstractProjectLoader(new IProjectLoader[] { roslynLoader, fsharpLoader }); }
internal static MetadataItem GenerateYamlMetadata(Compilation compilation, IAssemblySymbol assembly = null, bool preserveRawInlineComments = false, string filterConfigFile = null, IReadOnlyDictionary <Compilation, IEnumerable <IMethodSymbol> > extensionMethods = null) { if (compilation == null) { return(null); } var options = new ExtractMetadataOptions { PreserveRawInlineComments = preserveRawInlineComments, FilterConfigFile = filterConfigFile, ExtensionMethods = extensionMethods, }; return(new MetadataExtractor(compilation, assembly).Extract(options)); }
private static void PatchMetadataItem(ExtractMetadataOptions options, MetadataItem assembly, IEnumerable <CommentIdAndComment> list) { var allItemsInAssembly = new Dictionary <string, MetadataItem>(StringComparer.OrdinalIgnoreCase); GetAllItemByCommentId(allItemsInAssembly, assembly); foreach (var uidAndComment in list) { MetadataItem item = null; if (allItemsInAssembly.TryGetValue(uidAndComment.CommentId, out item)) { PatchViewModel(options, item, uidAndComment.Comment); } } }
public static void MergeComments(ExtractMetadataOptions options, MetadataItem item, IEnumerable <string> commentFiles) { if (item == null || commentFiles == null) { return; } var list = from file in commentFiles let name = Path.GetFileNameWithoutExtension(file) where string.Equals(name, item.Name, StringComparison.OrdinalIgnoreCase) from uidAndReader in EnumerateDeveloperComments(file) select uidAndReader.ToCommentIdAndComment(); PatchMetadataItem(options, item, list); RebuildReference(item); }
public void SaveToCache(string key, IEnumerable <string> containedFiles, DateTime triggeredTime, string outputFolder, IList <string> fileRelativePaths, ExtractMetadataOptions options) { var dict = new Dictionary <string, List <string> > { { key, containedFiles.ToList() } }; SaveToCache(key, dict, triggeredTime, outputFolder, fileRelativePaths, options); }
public void SaveToCache(IEnumerable <string> inputProjects, IDictionary <string, List <string> > containedFiles, DateTime triggeredTime, string outputFolder, IList <string> fileRelativePaths, ExtractMetadataOptions options) { var key = StringExtension.GetNormalizedFullPathKey(inputProjects); SaveToCache(key, containedFiles, triggeredTime, outputFolder, fileRelativePaths, options); }
public void SaveToCache(string key, IDictionary <string, List <string> > containedFiles, DateTime triggeredTime, string outputFolder, IList <string> fileRelativePaths, ExtractMetadataOptions options) { DateTime completeTime = DateTime.UtcNow; BuildInfo info = new BuildInfo { InputFilesKey = key, ContainedFiles = containedFiles, TriggeredUtcTime = triggeredTime, CompleteUtcTime = completeTime, OutputFolder = StringExtension.ToNormalizedFullPath(outputFolder), RelativeOutputFiles = StringExtension.GetNormalizedPathList(fileRelativePaths), BuildAssembly = AssemblyName, Options = options, }; SaveConfig(key, info); }
internal static MetadataItem GenerateYamlMetadata(Compilation compilation, IAssemblySymbol assembly = null, ExtractMetadataOptions options = null) { if (compilation == null) { return(null); } options = options ?? new ExtractMetadataOptions(); return(new MetadataExtractor(compilation, assembly).Extract(options)); }
public SymbolVisitorAdapter(YamlModelGenerator generator, SyntaxLanguage language, Compilation compilation, ExtractMetadataOptions options) { _generator = generator; Language = language; _currentCompilation = compilation; _currentCompilationRef = compilation.ToMetadataReference(); _preserveRawInlineComments = options.PreserveRawInlineComments; var configFilterRule = ConfigFilterRule.LoadWithDefaults(options.FilterConfigFile); var filterVisitor = options.DisableDefaultFilter ? (IFilterVisitor) new AllMemberFilterVisitor() : new DefaultFilterVisitor(); FilterVisitor = filterVisitor.WithConfig(configFilterRule).WithCache(); _extensionMethods = options.RoslynExtensionMethods != null?options.RoslynExtensionMethods.ToDictionary(p => p.Key, p => p.Value.Where(e => FilterVisitor.CanVisitApi(e))) : new Dictionary <Compilation, IEnumerable <IMethodSymbol> >(); _codeSourceBasePath = options.CodeSourceBasePath; }
private static void PatchViewModel(ExtractMetadataOptions options, MetadataItem item, string comment) { var context = new TripleSlashCommentParserContext { AddReferenceDelegate = (s, e) => { }, CodeSourceBasePath = options.CodeSourceBasePath, }; var commentModel = TripleSlashCommentModel.CreateModel(comment, SyntaxLanguage.CSharp, context); var summary = commentModel.Summary; if (!string.IsNullOrEmpty(summary)) { item.Summary = summary; } var remarks = commentModel.Remarks; if (!string.IsNullOrEmpty(remarks)) { item.Remarks = remarks; } var exceptions = commentModel.Exceptions; if (exceptions != null && exceptions.Count > 0) { item.Exceptions = exceptions; } var sees = commentModel.Sees; if (sees != null && sees.Count > 0) { item.Sees = sees; } var seeAlsos = commentModel.SeeAlsos; if (seeAlsos != null && seeAlsos.Count > 0) { item.SeeAlsos = seeAlsos; } var examples = commentModel.Examples; if (examples != null && examples.Count > 0) { item.Examples = examples; } if (item.Syntax != null) { if (item.Syntax.Parameters != null) { foreach (var p in item.Syntax.Parameters) { var description = commentModel.GetParameter(p.Name); if (!string.IsNullOrEmpty(description)) { p.Description = description; } } } if (item.Syntax.TypeParameters != null) { foreach (var p in item.Syntax.TypeParameters) { var description = commentModel.GetTypeParameter(p.Name); if (!string.IsNullOrEmpty(description)) { p.Description = description; } } } if (item.Syntax.Return != null) { var returns = commentModel.Returns; if (!string.IsNullOrEmpty(returns)) { item.Syntax.Return.Description = returns; } } } item.InheritDoc = commentModel.InheritDoc; // todo more. }