From 2dcb1356eb7b658f2b0fbb973cf859e93eaec2b1 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Mon, 20 Nov 2023 13:59:39 +0100 Subject: [PATCH 1/2] Remove parameter 'SourceReferences' (#1257) --- src/CommandLine/Commands/GenerateDocCommand.cs | 6 ------ src/CommandLine/Commands/ListSymbolsCommand.cs | 6 +----- .../Options/GenerateDocCommandLineOptions.cs | 4 ---- .../Options/ListSymbolsCommandLineOptions.cs | 13 ------------- 4 files changed, 1 insertion(+), 28 deletions(-) diff --git a/src/CommandLine/Commands/GenerateDocCommand.cs b/src/CommandLine/Commands/GenerateDocCommand.cs index 907358e96c..0faf70303c 100644 --- a/src/CommandLine/Commands/GenerateDocCommand.cs +++ b/src/CommandLine/Commands/GenerateDocCommand.cs @@ -193,17 +193,11 @@ DocumentationWriter CreateDocumentationWriter(DocumentationContext context) } } - SourceReferenceProvider sourceReferenceProvider = null; -#if DEBUG - if (Options.SourceReferences.Any()) - sourceReferenceProvider = SourceReferenceProvider.Load(Options.SourceReferences); -#endif var context = new DocumentationContext( documentationModel, GetUrlProvider(), documentationOptions, c => CreateDocumentationWriter(c), - sourceReferenceProvider: sourceReferenceProvider, commonNamespaces: commonNamespaces); var generator = new DocumentationGenerator(context); diff --git a/src/CommandLine/Commands/ListSymbolsCommand.cs b/src/CommandLine/Commands/ListSymbolsCommand.cs index 9bb0881407..e110429b66 100644 --- a/src/CommandLine/Commands/ListSymbolsCommand.cs +++ b/src/CommandLine/Commands/ListSymbolsCommand.cs @@ -145,14 +145,10 @@ public override async Task ExecuteAsync(ProjectOrSolution project } else if (string.Equals(extension, ".html", StringComparison.OrdinalIgnoreCase)) { - SourceReferenceProvider sourceReferenceProvider = (!string.IsNullOrEmpty(Options.SourceReferences)) - ? SourceReferenceProvider.Load(Options.SourceReferences) - : null; - var xmlWriterSettings = new XmlWriterSettings() { OmitXmlDeclaration = true, Indent = true, IndentChars = "" }; using (XmlWriter xmlWriter = XmlWriter.Create(path, xmlWriterSettings)) - using (SymbolDefinitionWriter writer = new SymbolDefinitionHtmlWriter(xmlWriter, SymbolFilterOptions, format, documentationProvider, hierarchyRoot, sourceReferenceProvider)) + using (SymbolDefinitionWriter writer = new SymbolDefinitionHtmlWriter(xmlWriter, SymbolFilterOptions, format, documentationProvider, hierarchyRoot)) { writer.WriteDocument(assemblies, cancellationToken); } diff --git a/src/CommandLine/Options/GenerateDocCommandLineOptions.cs b/src/CommandLine/Options/GenerateDocCommandLineOptions.cs index 003cdfe188..b3cc94e437 100644 --- a/src/CommandLine/Options/GenerateDocCommandLineOptions.cs +++ b/src/CommandLine/Options/GenerateDocCommandLineOptions.cs @@ -144,8 +144,4 @@ public class GenerateDocCommandLineOptions : AbstractGenerateDocCommandLineOptio HelpText = "Defines culture that should be used when searching for xml documentation files.", MetaValue = "")] public string PreferredCulture { get; set; } -#if DEBUG - [Option(longName: "source-references")] - public IEnumerable SourceReferences { get; set; } -#endif } diff --git a/src/CommandLine/Options/ListSymbolsCommandLineOptions.cs b/src/CommandLine/Options/ListSymbolsCommandLineOptions.cs index 05db3a5ee2..468051bd6e 100644 --- a/src/CommandLine/Options/ListSymbolsCommandLineOptions.cs +++ b/src/CommandLine/Options/ListSymbolsCommandLineOptions.cs @@ -91,23 +91,10 @@ public class ListSymbolsCommandLineOptions : MSBuildCommandLineOptions MetaValue = "")] public IEnumerable ExternalAssemblies { get; set; } -#if DEBUG - [Option(longName: "source-references")] - public string SourceReferences { get; set; } -#endif - [Option( longName: OptionNames.Visibility, Default = new string[] { nameof(Roslynator.Visibility.Public) }, HelpText = "Defines one or more visibility of a type or a member. Allowed values are public, internal or private.", MetaValue = "")] public IEnumerable Visibility { get; set; } - - //[Option(longName: "include-ienumerable", - // HelpText = "Indicates whether interface System.Collections.IEnumerable should be included in a documentation if a type also implements interface System.Collections.Generic.IEnumerable.")] - //public bool IncludeIEnumerable { get; set; } - - //[Option(longName: "no-precedence-for-system", - // HelpText = "Indicates whether symbols contained in 'System' namespace should be ordered as any other symbols and not before other symbols.")] - //public bool NoPrecedenceForSystem { get; set; } } From 2269ba518c407761572dfd90601b4ad339eca614 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Mon, 20 Nov 2023 14:10:00 +0100 Subject: [PATCH 2/2] Remove command find-symbols (#1256) --- .../Commands/FindSymbolsCommand.cs | 252 ------------------ .../Options/FindSymbolsCommandLineOptions.cs | 45 ---- src/CommandLine/Program.cs | 70 ----- 3 files changed, 367 deletions(-) delete mode 100644 src/CommandLine/Commands/FindSymbolsCommand.cs delete mode 100644 src/CommandLine/Options/FindSymbolsCommandLineOptions.cs diff --git a/src/CommandLine/Commands/FindSymbolsCommand.cs b/src/CommandLine/Commands/FindSymbolsCommand.cs deleted file mode 100644 index a023dbc29b..0000000000 --- a/src/CommandLine/Commands/FindSymbolsCommand.cs +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Roslynator.FindSymbols; -using Roslynator.Host.Mef; -using static Roslynator.Logger; - -namespace Roslynator.CommandLine; - -internal class FindSymbolsCommand : MSBuildWorkspaceCommand -{ - private static readonly SymbolDisplayFormat _nameAndContainingTypesSymbolDisplayFormat = SymbolDisplayFormat.CSharpErrorMessageFormat.Update( - typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypes, - parameterOptions: SymbolDisplayParameterOptions.IncludeParamsRefOut - | SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeName - | SymbolDisplayParameterOptions.IncludeDefaultValue, - miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers - | SymbolDisplayMiscellaneousOptions.UseSpecialTypes - | SymbolDisplayMiscellaneousOptions.UseErrorTypeSymbolName); - - public FindSymbolsCommand( - FindSymbolsCommandLineOptions options, - SymbolFinderOptions symbolFinderOptions, - in ProjectFilter projectFilter, - FileSystemFilter fileSystemFilter) : base(projectFilter, fileSystemFilter) - { - Options = options; - SymbolFinderOptions = symbolFinderOptions; - } - - public FindSymbolsCommandLineOptions Options { get; } - - public SymbolFinderOptions SymbolFinderOptions { get; } - - public override async Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) - { - HashSet ignoredSymbolIds = (Options.IgnoredSymbolIds.Any()) - ? new HashSet(Options.IgnoredSymbolIds) - : null; - - var progress = new FindSymbolsProgress(); - - ImmutableArray allSymbols; - - if (projectOrSolution.IsProject) - { - Project project = projectOrSolution.AsProject(); - - WriteLine($"Analyze '{project.Name}'", Verbosity.Minimal); - - allSymbols = await AnalyzeProject(project, SymbolFinderOptions, progress, cancellationToken); - } - else - { - Solution solution = projectOrSolution.AsSolution(); - - WriteLine($"Analyze solution '{solution.FilePath}'", Verbosity.Minimal); - - ImmutableArray.Builder symbols = null; - - Stopwatch stopwatch = Stopwatch.StartNew(); - - foreach (Project project in FilterProjects( - solution, - s => s - .GetProjectDependencyGraph() - .GetTopologicallySortedProjects(cancellationToken) - .ToImmutableArray())) - { - cancellationToken.ThrowIfCancellationRequested(); - - WriteLine($" Analyze '{project.Name}'", Verbosity.Minimal); - - ImmutableArray projectSymbols = await AnalyzeProject(project, SymbolFinderOptions, progress, cancellationToken); - - if (!projectSymbols.Any()) - continue; - - if (ignoredSymbolIds?.Count > 0) - { - Compilation compilation = await project.GetCompilationAsync(cancellationToken); - - ImmutableDictionary symbolsById = ignoredSymbolIds - .Select(f => (id: f, symbol: DocumentationCommentId.GetFirstSymbolForDeclarationId(f, compilation))) - .Where(f => f.id is not null) - .ToImmutableDictionary(f => f.id, f => f.symbol); - - ignoredSymbolIds.ExceptWith(symbolsById.Select(f => f.Key)); - - projectSymbols = projectSymbols.Except(symbolsById.Select(f => f.Value)).ToImmutableArray(); - - if (!projectSymbols.Any()) - continue; - } - - int maxKindLength = projectSymbols - .Select(f => f.GetSymbolGroup()) - .Distinct() - .Max(f => f.ToString().Length); - - foreach (ISymbol symbol in projectSymbols.OrderBy(f => f, SymbolDefinitionComparer.SystemFirst)) - { - WriteSymbol(symbol, Verbosity.Normal, indentation: " ", addCommentId: true, padding: maxKindLength); - } - - (symbols ??= ImmutableArray.CreateBuilder()).AddRange(projectSymbols); - } - - stopwatch.Stop(); - - allSymbols = symbols?.ToImmutableArray() ?? ImmutableArray.Empty; - - LogHelpers.WriteElapsedTime($"Analyzed solution '{solution.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal); - } - - if (allSymbols.Any()) - { - Dictionary countByGroup = allSymbols - .GroupBy(f => f.GetSymbolGroup()) - .OrderByDescending(f => f.Count()) - .ThenBy(f => f.Key) - .ToDictionary(f => f.Key, f => f.Count()); - - int maxKindLength = countByGroup.Max(f => f.Key.ToString().Length); - - int maxCountLength = countByGroup.Max(f => f.Value.ToString().Length); - - WriteLine(Verbosity.Normal); - - foreach (ISymbol symbol in allSymbols.OrderBy(f => f, SymbolDefinitionComparer.SystemFirst)) - { - WriteSymbol(symbol, Verbosity.Normal, colorNamespace: true, padding: maxKindLength); - } - - WriteLine(Verbosity.Normal); - - foreach (KeyValuePair kvp in countByGroup) - { - WriteLine($"{kvp.Value.ToString().PadLeft(maxCountLength)} {kvp.Key.ToString().ToLowerInvariant()} symbols", Verbosity.Normal); - } - } - - WriteLine(Verbosity.Minimal); - WriteLine($"{allSymbols.Length} {((allSymbols.Length == 1) ? "symbol" : "symbols")} found", ConsoleColors.Green, Verbosity.Minimal); - - return CommandResults.Success; - } - - private static Task> AnalyzeProject( - Project project, - SymbolFinderOptions options, - IFindSymbolsProgress progress, - CancellationToken cancellationToken) - { - if (!project.SupportsCompilation) - { - WriteLine(" Project does not support compilation", Verbosity.Normal); - return Task.FromResult(ImmutableArray.Empty); - } - - if (!MefWorkspaceServices.Default.SupportedLanguages.Contains(project.Language)) - { - WriteLine($" Language '{project.Language}' is not supported", Verbosity.Normal); - return Task.FromResult(ImmutableArray.Empty); - } - - return SymbolFinder.FindSymbolsAsync(project, options, progress, cancellationToken); - } - - private static void WriteSymbol( - ISymbol symbol, - Verbosity verbosity, - string indentation = "", - bool addCommentId = false, - bool colorNamespace = false, - int padding = 0) - { - if (!ShouldWrite(verbosity)) - return; - - bool isObsolete = symbol.HasAttribute(MetadataNames.System_ObsoleteAttribute); - - Write(indentation, verbosity); - - string kindText = symbol.GetSymbolGroup().ToString().ToLowerInvariant(); - - if (isObsolete) - { - Write(kindText, ConsoleColors.DarkGray, verbosity); - } - else - { - Write(kindText, verbosity); - } - - Write(' ', padding - kindText.Length + 1, verbosity); - - string namespaceText = symbol.ContainingNamespace.ToDisplayString(); - - if (namespaceText.Length > 0) - { - if (colorNamespace || isObsolete) - { - Write(namespaceText, ConsoleColors.DarkGray, verbosity); - Write(".", ConsoleColors.DarkGray, verbosity); - } - else - { - Write(namespaceText, verbosity); - Write(".", verbosity); - } - } - - string nameText = symbol.ToDisplayString(_nameAndContainingTypesSymbolDisplayFormat); - - if (isObsolete) - { - Write(nameText, ConsoleColors.DarkGray, verbosity); - } - else - { - Write(nameText, verbosity); - } - - if (addCommentId - && ShouldWrite(Verbosity.Diagnostic)) - { - WriteLine(Verbosity.Diagnostic); - Write(indentation, Verbosity.Diagnostic); - Write("ID:", ConsoleColors.DarkGray, Verbosity.Diagnostic); - Write(' ', padding - 2, Verbosity.Diagnostic); - Write(symbol.GetDocumentationCommentId(), ConsoleColors.DarkGray, Verbosity.Diagnostic); - } - - WriteLine(verbosity); - } - - private class FindSymbolsProgress : IFindSymbolsProgress - { - public void OnSymbolFound(ISymbol symbol) - { - } - } -} diff --git a/src/CommandLine/Options/FindSymbolsCommandLineOptions.cs b/src/CommandLine/Options/FindSymbolsCommandLineOptions.cs deleted file mode 100644 index 77d54a3454..0000000000 --- a/src/CommandLine/Options/FindSymbolsCommandLineOptions.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using CommandLine; - -namespace Roslynator.CommandLine; - -#if DEBUG -[Verb("find-symbols", HelpText = "Finds symbols in the specified project or solution.")] -#endif -public class FindSymbolsCommandLineOptions : MSBuildCommandLineOptions -{ - [Value( - index: 0, - HelpText = "Path to one or more project/solution files.", - MetaName = "")] - public IEnumerable Paths { get; set; } - - [Option(longName: "ignored-symbol-ids")] - public IEnumerable IgnoredSymbolIds { get; set; } - - [Option(longName: "ignore-generated-code")] - public bool IgnoreGeneratedCode { get; set; } - - [Option(longName: OptionNames.SymbolGroups)] - public IEnumerable SymbolGroups { get; set; } - - [Option(longName: "unused-only")] - public bool UnusedOnly { get; set; } - - [Option(longName: OptionNames.Visibility)] - public IEnumerable Visibility { get; set; } - - [Option(longName: "with-attributes")] - public IEnumerable WithAttributes { get; set; } - - [Option(longName: "without-attributes")] - public IEnumerable WithoutAttributes { get; set; } - - [Option(longName: OptionNames.WithFlags)] - public IEnumerable WithFlags { get; set; } - - [Option(longName: OptionNames.WithoutFlags)] - public IEnumerable WithoutFlags { get; set; } -} diff --git a/src/CommandLine/Program.cs b/src/CommandLine/Program.cs index 1e68ae35ac..bc38fe3c4a 100644 --- a/src/CommandLine/Program.cs +++ b/src/CommandLine/Program.cs @@ -106,9 +106,6 @@ private static int Main(string[] args) typeof(PhysicalLinesOfCodeCommandLineOptions), typeof(RenameSymbolCommandLineOptions), typeof(SpellcheckCommandLineOptions), -#if DEBUG - typeof(FindSymbolsCommandLineOptions), -#endif }); parserResult.WithNotParsed(e => @@ -193,10 +190,6 @@ private static int Main(string[] args) return RenameSymbolAsync(renameSymbolCommandLineOptions).Result; case SpellcheckCommandLineOptions spellcheckCommandLineOptions: return SpellcheckAsync(spellcheckCommandLineOptions).Result; -#if DEBUG - case FindSymbolsCommandLineOptions findSymbolsCommandLineOptions: - return FindSymbolsAsync(findSymbolsCommandLineOptions).Result; -#endif default: throw new InvalidOperationException(); } @@ -349,69 +342,6 @@ private static async Task AnalyzeAsync(AnalyzeCommandLineOptions options) return GetExitCode(status); } -#if DEBUG - private static async Task FindSymbolsAsync(FindSymbolsCommandLineOptions options) - { - if (!options.TryGetProjectFilter(out ProjectFilter projectFilter)) - return ExitCodes.Error; - - if (!TryParseOptionValueAsEnumFlags(options.SymbolGroups, OptionNames.SymbolGroups, out SymbolGroupFilter symbolGroups, SymbolFinderOptions.Default.SymbolGroups)) - return ExitCodes.Error; - - if (!TryParseOptionValueAsEnumFlags(options.Visibility, OptionNames.Visibility, out VisibilityFilter visibility, SymbolFinderOptions.Default.Visibility)) - return ExitCodes.Error; - - if (!TryParseMetadataNames(options.WithAttributes, out ImmutableArray withAttributes)) - return ExitCodes.Error; - - if (!TryParseMetadataNames(options.WithoutAttributes, out ImmutableArray withoutAttributes)) - return ExitCodes.Error; - - if (!TryParseOptionValueAsEnumFlags(options.WithFlags, OptionNames.WithFlags, out SymbolFlags withFlags, SymbolFlags.None)) - return ExitCodes.Error; - - if (!TryParseOptionValueAsEnumFlags(options.WithoutFlags, OptionNames.WithoutFlags, out SymbolFlags withoutFlags, SymbolFlags.None)) - return ExitCodes.Error; - - if (!TryParsePaths(options.Paths, out ImmutableArray paths)) - return ExitCodes.Error; - - ImmutableArray.Builder rules = ImmutableArray.CreateBuilder(); - - if (withAttributes.Any()) - rules.Add(new WithAttributeFilterRule(withAttributes)); - - if (withoutAttributes.Any()) - rules.Add(new WithoutAttributeFilterRule(withoutAttributes)); - - if (withFlags != SymbolFlags.None) - rules.AddRange(SymbolFilterRuleFactory.FromFlags(withFlags)); - - if (withoutFlags != SymbolFlags.None) - rules.AddRange(SymbolFilterRuleFactory.FromFlags(withoutFlags, invert: true)); - - FileSystemFilter fileSystemFilter = CreateFileSystemFilter(options); - - var symbolFinderOptions = new SymbolFinderOptions( - fileSystemFilter, - visibility: visibility, - symbolGroups: symbolGroups, - rules: rules, - ignoreGeneratedCode: options.IgnoreGeneratedCode, - unusedOnly: options.UnusedOnly); - - var command = new FindSymbolsCommand( - options: options, - symbolFinderOptions: symbolFinderOptions, - projectFilter: projectFilter, - fileSystemFilter: fileSystemFilter); - - CommandStatus status = await command.ExecuteAsync(paths, options.MSBuildPath, options.Properties); - - return GetExitCode(status); - } -#endif - private static async Task RenameSymbolAsync(RenameSymbolCommandLineOptions options) { if (!options.TryGetProjectFilter(out ProjectFilter projectFilter))