From 0a545759d9e1741e9c20750cab9e141dde0ea751 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 24 Aug 2023 22:04:03 +0200 Subject: [PATCH] Remove command generate-source-references (#1184) --- .../GenerateSourceReferencesCommand.cs | 148 ------------------ ...erateSourceReferencesCommandLineOptions.cs | 65 -------- src/CommandLine/Program.cs | 31 ---- 3 files changed, 244 deletions(-) delete mode 100644 src/CommandLine/Commands/GenerateSourceReferencesCommand.cs delete mode 100644 src/CommandLine/Options/GenerateSourceReferencesCommandLineOptions.cs diff --git a/src/CommandLine/Commands/GenerateSourceReferencesCommand.cs b/src/CommandLine/Commands/GenerateSourceReferencesCommand.cs deleted file mode 100644 index 7439a46140..0000000000 --- a/src/CommandLine/Commands/GenerateSourceReferencesCommand.cs +++ /dev/null @@ -1,148 +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.Diagnostics; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using System.Xml; -using Microsoft.CodeAnalysis; -using Roslynator.Documentation; -using Roslynator.FindSymbols; -using static Roslynator.Logger; - -namespace Roslynator.CommandLine; - -internal class GenerateSourceReferencesCommand : MSBuildWorkspaceCommand -{ - public GenerateSourceReferencesCommand( - GenerateSourceReferencesCommandLineOptions options, - DocumentationDepth depth, - Visibility visibility, - in ProjectFilter projectFilter, - FileSystemFilter fileSystemFilter) : base(projectFilter, fileSystemFilter) - { - Options = options; - Depth = depth; - Visibility = visibility; - } - - public GenerateSourceReferencesCommandLineOptions Options { get; } - - public DocumentationDepth Depth { get; } - - public Visibility Visibility { get; } - - public override async Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) - { - AssemblyResolver.Register(); - - var filter = new SymbolFilterOptions(FileSystemFilter, Visibility.ToVisibilityFilter()); - - WriteLine($"Save source references to '{Options.Output}'.", Verbosity.Minimal); - - using (XmlWriter writer = XmlWriter.Create(Options.Output, new XmlWriterSettings() { Indent = true })) - { - writer.WriteStartDocument(); - writer.WriteStartElement("source"); - writer.WriteStartElement("repository"); - - writer.WriteAttributeString("type", Options.RepositoryType); - writer.WriteAttributeString("url", Options.RepositoryUrl); - writer.WriteAttributeString("version", Options.Version); - writer.WriteAttributeString("branch", Options.Branch); - writer.WriteAttributeString("commit", Options.Commit); - writer.WriteStartElement("members"); - - foreach (Project project in FilterProjects(projectOrSolution)) - { - Compilation compilation = await project.GetCompilationAsync(cancellationToken); - - IAssemblySymbol assembly = compilation.Assembly; - - foreach (INamedTypeSymbol type in assembly.GetTypes(symbol => filter.IsMatch(symbol))) - { - WriteSymbol(writer, type, cancellationToken); - - foreach (ISymbol member in type.GetMembers()) - { - if (!member.IsKind(SymbolKind.NamedType)) - { - if (filter.IsMatch(member) - || member.IsExplicitImplementation()) - { - WriteSymbol(writer, member, cancellationToken); - } - } - } - } - } - - writer.WriteEndDocument(); - } - - WriteLine($"Source references successfully saved to '{Options.Output}'.", Verbosity.Minimal); - - return CommandResults.Success; - } - - private void WriteSymbol(XmlWriter writer, ISymbol symbol, CancellationToken cancellationToken) - { - writer.WriteStartElement("member"); - writer.WriteAttributeString("name", symbol.GetDocumentationCommentId()); - - ImmutableArray syntaxReferences = symbol.DeclaringSyntaxReferences; - - Debug.Assert(syntaxReferences.Any() || IsImplicitConstructor(symbol), symbol.ToDisplayString()); - - ImmutableArray.Enumerator en = syntaxReferences.GetEnumerator(); - - if (en.MoveNext()) - { - writer.WriteStartElement("locations"); - - do - { - writer.WriteStartElement("location"); - - SyntaxTree tree = en.Current.SyntaxTree; - - string path = tree.FilePath; - - if (path.StartsWith(Options.RootPath, StringComparison.OrdinalIgnoreCase)) - path = path.Remove(0, Options.RootPath.Length).TrimStart(Path.DirectorySeparatorChar); - - if (Path.DirectorySeparatorChar == '\\') - path = path.Replace(Path.DirectorySeparatorChar, '/'); - - Debug.Assert(path is not null, symbol.ToDisplayString()); - - writer.WriteAttributeString("path", path); - - int line = tree.GetLineSpan(en.Current.Span, cancellationToken).StartLine() + 1; - - writer.WriteAttributeString("line", line.ToString(CultureInfo.InvariantCulture)); - - writer.WriteEndElement(); - } - while (en.MoveNext()); - - writer.WriteEndElement(); - } - - writer.WriteEndElement(); - } - -#pragma warning disable RS1024 - private static bool IsImplicitConstructor(ISymbol symbol) - { - return symbol is IMethodSymbol methodSymbol - && methodSymbol.MethodKind == MethodKind.Constructor - && !methodSymbol.Parameters.Any() - && methodSymbol.ContainingType.InstanceConstructors.SingleOrDefault(shouldThrow: false) == methodSymbol; - } -#pragma warning restore RS1024 -} diff --git a/src/CommandLine/Options/GenerateSourceReferencesCommandLineOptions.cs b/src/CommandLine/Options/GenerateSourceReferencesCommandLineOptions.cs deleted file mode 100644 index d85d3c4f6f..0000000000 --- a/src/CommandLine/Options/GenerateSourceReferencesCommandLineOptions.cs +++ /dev/null @@ -1,65 +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 CommandLine; - -namespace Roslynator.CommandLine; - -#if DEBUG -[Verb("generate-source-references")] -#endif -public class GenerateSourceReferencesCommandLineOptions : MSBuildCommandLineOptions -{ - [Value( - index: 0, - HelpText = "The project or solution file.", - MetaName = "")] - public string Path { get; set; } - - [Option( - longName: "output", - Required = true, - HelpText = "Defines a path for the output file.", - MetaValue = "")] - public string Output { get; set; } - - [Option( - longName: "repository-url", - Required = true)] - public string RepositoryUrl { get; set; } - - [Option( - longName: "root-path", - Required = true)] - public string RootPath { get; set; } - - [Option( - longName: "version", - Required = true)] - public string Version { get; set; } - - [Option( - longName: "branch", - Default = "main")] - public string Branch { get; set; } - - [Option(longName: "commit")] - public string Commit { get; set; } - - [Option( - longName: OptionNames.Depth, - HelpText = "Defines a depth of a documentation. Allowed values are member (default), type or namespace.", - MetaValue = "")] - public string Depth { get; set; } - - [Option( - longName: "repository-type", - Default = "git")] - public string RepositoryType { get; set; } - - [Option( - longName: OptionNames.Visibility, - Default = nameof(Roslynator.Visibility.Public), - HelpText = "Defines a visibility of a type or a member. Allowed values are public (default), internal or private.", - MetaValue = "")] - public string Visibility { get; set; } -} diff --git a/src/CommandLine/Program.cs b/src/CommandLine/Program.cs index a78fce06e4..383f43d77c 100644 --- a/src/CommandLine/Program.cs +++ b/src/CommandLine/Program.cs @@ -110,7 +110,6 @@ private static int Main(string[] args) typeof(SpellcheckCommandLineOptions), #if DEBUG typeof(FindSymbolsCommandLineOptions), - typeof(GenerateSourceReferencesCommandLineOptions), typeof(ListVisualStudioCommandLineOptions), typeof(ListReferencesCommandLineOptions), typeof(SlnListCommandLineOptions), @@ -202,8 +201,6 @@ private static int Main(string[] args) #if DEBUG case FindSymbolsCommandLineOptions findSymbolsCommandLineOptions: return FindSymbolsAsync(findSymbolsCommandLineOptions).Result; - case GenerateSourceReferencesCommandLineOptions generateSourceReferencesCommandLineOptions: - return GenerateSourceReferencesAsync(generateSourceReferencesCommandLineOptions).Result; case ListReferencesCommandLineOptions listReferencesCommandLineOptions: return ListReferencesAsync(listReferencesCommandLineOptions).Result; case SlnListCommandLineOptions slnListCommandLineOptions: @@ -847,34 +844,6 @@ private static async Task GenerateDocRootAsync(GenerateDocRootCommandLineOp return GetExitCode(status); } -#if DEBUG - private static async Task GenerateSourceReferencesAsync(GenerateSourceReferencesCommandLineOptions options) - { - if (!TryParseOptionValueAsEnum(options.Depth, OptionNames.Depth, out DocumentationDepth depth, DocumentationOptions.DefaultValues.Depth)) - return ExitCodes.Error; - - if (!TryParseOptionValueAsEnum(options.Visibility, OptionNames.Visibility, out Visibility visibility)) - return ExitCodes.Error; - - if (!options.TryGetProjectFilter(out ProjectFilter projectFilter)) - return ExitCodes.Error; - - if (!TryParsePaths(options.Path, out ImmutableArray paths)) - return ExitCodes.Error; - - var command = new GenerateSourceReferencesCommand( - options, - depth, - visibility, - projectFilter, - FileSystemFilter.CreateOrDefault(options.Include, options.Exclude)); - - CommandStatus status = await command.ExecuteAsync(paths, options.MSBuildPath, options.Properties); - - return GetExitCode(status); - } -#endif - private static int Migrate(MigrateCommandLineOptions options) { if (!string.Equals(options.Identifier, "roslynator.analyzers", StringComparison.Ordinal))