Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Method refactoring misses a required formal parameter #60373

Open
scheglov opened this issue Mar 20, 2025 · 2 comments
Open

Extract Method refactoring misses a required formal parameter #60373

scheglov opened this issue Mar 20, 2025 · 2 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-refactoring Issues with analysis server refactorings P3 A lower priority bug or feature request

Comments

@scheglov
Copy link
Contributor

  void _writeExportRequirements(BundleRequirementsManifest requirements) {
    var exportRequirements = requirements.exportRequirements.sortedBy(
      (requirement) => requirement.exportedUri.toString(),
    );

    sink.writeElements(
      'exportRequirements',
      exportRequirements,
      (requirement) {
        sink.writelnWithIndent(requirement.exportedUri);
        sink.withIndent(() {
          sink.writeElements(
            'combinators',
            requirement.combinators,
            (combinator) {
              switch (combinator) {
                case ExportRequirementHideCombinator():
                  var baseNames = combinator.hiddenBaseNames.sorted();
                  sink.writelnWithIndent('hide ${baseNames.join(', ')}');
                case ExportRequirementShowCombinator():
                  var baseNames = combinator.shownBaseNames.sorted();
                  sink.writelnWithIndent('show ${baseNames.join(', ')}');
              }
            },
          );

          var entries = requirement.exportedIds.sorted;
          for (var entry in entries) {
            _writeNamedId(entry);
          }
        });
      },
    );
  }

Select and try to extract it.

          sink.writeElements(
            'combinators',
            requirement.combinators,
            (combinator) {
              switch (combinator) {
                case ExportRequirementHideCombinator():
                  var baseNames = combinator.hiddenBaseNames.sorted();
                  sink.writelnWithIndent('hide ${baseNames.join(', ')}');
                case ExportRequirementShowCombinator():
                  var baseNames = combinator.shownBaseNames.sorted();
                  sink.writelnWithIndent('show ${baseNames.join(', ')}');
              }
            },
          );
Image

The extracted code uses requirement, but the extracdted method signature does not specify it.

@scheglov scheglov added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. devexp-refactoring Issues with analysis server refactorings area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Mar 20, 2025
@scheglov
Copy link
Contributor Author

Oh, I know why.
requirements has type _ExportRequirement, so it cannot be written.

@pq
Copy link
Member

pq commented Mar 20, 2025

In general we don't produce invalid code so just bail out of principle but as per our conversation, there may be some benefit in producing results that are known to be incomplete (but get you at least part of the way), notifying you with, for example, a dialog.

One rub is that while we might be able to do this in IntelliJ, we can't show dialogs in VSCode so it'd be some work to make a uniform experience.

While it's sort of WAI, let's leave this open as food for future thought!

@pq pq added the P3 A lower priority bug or feature request label Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-refactoring Issues with analysis server refactorings P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

2 participants