public FindSymbolsCommand(
     FindSymbolsCommandLineOptions options,
     SymbolFinderOptions symbolFinderOptions,
     in ProjectFilter projectFilter) : base(projectFilter)
Exemple #2
0
        private static async Task <int> FindSymbolsAsync(FindSymbolsCommandLineOptions options)
        {
            if (!options.TryGetProjectFilter(out ProjectFilter projectFilter))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.SymbolGroups, ParameterNames.SymbolGroups, out SymbolGroupFilter symbolGroups, SymbolFinderOptions.Default.SymbolGroups))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.Visibility, ParameterNames.Visibility, out VisibilityFilter visibility, SymbolFinderOptions.Default.Visibility))
            {
                return(1);
            }

            if (!TryParseMetadataNames(options.WithAttributes, out ImmutableArray <MetadataName> withAttributes))
            {
                return(1);
            }

            if (!TryParseMetadataNames(options.WithoutAttributes, out ImmutableArray <MetadataName> withoutAttributes))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.WithFlags, ParameterNames.WithFlags, out SymbolFlags withFlags, SymbolFlags.None))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.WithoutFlags, ParameterNames.WithoutFlags, out SymbolFlags withoutFlags, SymbolFlags.None))
            {
                return(1);
            }

            ImmutableArray <SymbolFilterRule> .Builder rules = ImmutableArray.CreateBuilder <SymbolFilterRule>();

            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));
            }

            var symbolFinderOptions = new SymbolFinderOptions(
                visibility: visibility,
                symbolGroups: symbolGroups,
                rules: rules,
                ignoreGeneratedCode: options.IgnoreGeneratedCode,
                unusedOnly: options.UnusedOnly);

            var command = new FindSymbolsCommand(
                options: options,
                symbolFinderOptions: symbolFinderOptions,
                projectFilter: projectFilter);

            CommandResult result = await command.ExecuteAsync(options.Path, options.MSBuildPath, options.Properties);

            return((result.Kind == CommandResultKind.Success) ? 0 : 1);
        }