From 7aaaa64dd41ec9303703759e508f890c48d14a30 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 24 Aug 2023 22:32:51 +0200 Subject: [PATCH] Remove command list-references (#1185) --- .../Commands/ListReferencesCommand.cs | 115 ------------------ .../ListReferencesCommandLineOptions.cs | 28 ----- src/CommandLine/Program.cs | 31 ----- 3 files changed, 174 deletions(-) delete mode 100644 src/CommandLine/Commands/ListReferencesCommand.cs delete mode 100644 src/CommandLine/Options/ListReferencesCommandLineOptions.cs diff --git a/src/CommandLine/Commands/ListReferencesCommand.cs b/src/CommandLine/Commands/ListReferencesCommand.cs deleted file mode 100644 index 96b06ca32d..0000000000 --- a/src/CommandLine/Commands/ListReferencesCommand.cs +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) Josef Pihrt 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.Immutable; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using static Roslynator.Logger; - -namespace Roslynator.CommandLine; - -internal class ListReferencesCommand : MSBuildWorkspaceCommand -{ - public ListReferencesCommand( - ListReferencesCommandLineOptions options, - MetadataReferenceDisplay display, - MetadataReferenceFilter filter, - in ProjectFilter projectFilter, - FileSystemFilter fileSystemFilter) : base(projectFilter, fileSystemFilter) - { - Options = options; - Display = display; - Filter = filter; - } - - public ListReferencesCommandLineOptions Options { get; } - - public MetadataReferenceDisplay Display { get; } - - public MetadataReferenceFilter Filter { get; } - - public override async Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) - { - AssemblyResolver.Register(); - - ImmutableArray compilations = await GetCompilationsAsync(projectOrSolution, cancellationToken); - - int count = 0; - - foreach (string display in compilations - .SelectMany(compilation => compilation.ExternalReferences.Select(reference => (compilation, reference))) - .Select(f => GetDisplay(f.compilation, f.reference)) - .Where(f => f is not null) - .Distinct() - .OrderBy(f => f, StringComparer.InvariantCulture)) - { - WriteLine(display); - count++; - } - - if (ShouldWrite(Verbosity.Normal)) - { - WriteLine(Verbosity.Normal); - WriteLine($"{count} assembl{((count == 1) ? "y" : "ies")} found", ConsoleColors.Green, Verbosity.Normal); - } - - return CommandResults.Success; - - string GetDisplay(Compilation compilation, MetadataReference reference) - { - switch (reference) - { - case PortableExecutableReference portableReference: - { - if ((Filter & MetadataReferenceFilter.Dll) == 0) - return null; - - string path = portableReference.FilePath; - - switch (Display) - { - case MetadataReferenceDisplay.Path: - { - return path; - } - case MetadataReferenceDisplay.FileName: - { - return Path.GetFileName(path); - } - case MetadataReferenceDisplay.FileNameWithoutExtension: - { - return Path.GetFileNameWithoutExtension(path); - } - case MetadataReferenceDisplay.AssemblyName: - { - var assembly = (IAssemblySymbol)compilation.GetAssemblyOrModuleSymbol(reference); - - return assembly.Identity.ToString(); - } - default: - { - throw new InvalidOperationException(); - } - } - } - case CompilationReference compilationReference: - { - if ((Filter & MetadataReferenceFilter.Project) == 0) - return null; - - return compilationReference.Display; - } - default: - { -#if DEBUG - WriteLine(reference.GetType().FullName, ConsoleColors.Yellow); -#endif - return reference.Display; - } - } - } - } -} diff --git a/src/CommandLine/Options/ListReferencesCommandLineOptions.cs b/src/CommandLine/Options/ListReferencesCommandLineOptions.cs deleted file mode 100644 index 036b06d7e6..0000000000 --- a/src/CommandLine/Options/ListReferencesCommandLineOptions.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Josef Pihrt 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("list-references", HelpText = "Lists assembly references from the specified project or solution.")] -#endif -public class ListReferencesCommandLineOptions : MSBuildCommandLineOptions -{ - [Value( - index: 0, - HelpText = "Path to one or more project/solution files.", - MetaName = "")] - public IEnumerable Paths { get; set; } - - [Option( - longName: "display", - HelpText = "Defines how the assembly is displayed. Allowed values are path (default), file-name, file-name-without-extension or assembly-name.")] - public string Display { get; set; } - - [Option( - longName: OptionNames.Type, - HelpText = "Defines a type of a reference. Allowed values are dll and project.")] - public IEnumerable Type { get; set; } -} diff --git a/src/CommandLine/Program.cs b/src/CommandLine/Program.cs index 383f43d77c..f3bb92a11f 100644 --- a/src/CommandLine/Program.cs +++ b/src/CommandLine/Program.cs @@ -111,7 +111,6 @@ private static int Main(string[] args) #if DEBUG typeof(FindSymbolsCommandLineOptions), typeof(ListVisualStudioCommandLineOptions), - typeof(ListReferencesCommandLineOptions), typeof(SlnListCommandLineOptions), #endif }); @@ -201,8 +200,6 @@ private static int Main(string[] args) #if DEBUG case FindSymbolsCommandLineOptions findSymbolsCommandLineOptions: return FindSymbolsAsync(findSymbolsCommandLineOptions).Result; - case ListReferencesCommandLineOptions listReferencesCommandLineOptions: - return ListReferencesAsync(listReferencesCommandLineOptions).Result; case SlnListCommandLineOptions slnListCommandLineOptions: return SlnListAsync(slnListCommandLineOptions).Result; #endif @@ -880,34 +877,6 @@ private static int Migrate(MigrateCommandLineOptions options) return GetExitCode(status); } -#if DEBUG - private static async Task ListReferencesAsync(ListReferencesCommandLineOptions options) - { - if (!TryParseOptionValueAsEnum(options.Display, OptionNames.Display, out MetadataReferenceDisplay display, MetadataReferenceDisplay.Path)) - return ExitCodes.Error; - - if (!TryParseOptionValueAsEnumFlags(options.Type, OptionNames.Type, out MetadataReferenceFilter metadataReferenceFilter, MetadataReferenceFilter.Dll | MetadataReferenceFilter.Project)) - return ExitCodes.Error; - - if (!options.TryGetProjectFilter(out ProjectFilter projectFilter)) - return ExitCodes.Error; - - if (!TryParsePaths(options.Paths, out ImmutableArray paths)) - return ExitCodes.Error; - - var command = new ListReferencesCommand( - options, - display, - metadataReferenceFilter, - projectFilter, - FileSystemFilter.CreateOrDefault(options.Include, options.Exclude)); - - CommandStatus status = await command.ExecuteAsync(paths, options.MSBuildPath, options.Properties); - - return GetExitCode(status); - } -#endif - private static bool TryParsePaths(string value, out ImmutableArray paths) { return TryParsePaths(ImmutableArray.Create(value), out paths);