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

move to file doesn't move associated private function #60379

Open
stephane-archer opened this issue Mar 22, 2025 · 3 comments
Open

move to file doesn't move associated private function #60379

stephane-archer opened this issue Mar 22, 2025 · 3 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 P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@stephane-archer
Copy link

Future<void> revealIn(String filePath) async {
  if (Platform.isMacOS) {
    await _revealInFinder(filePath);
    return;
  }
  if (Platform.isWindows) {
    await _revealInExplorer(filePath);
    return;
  }
  throw UnsupportedError("Unsupported Platform");
}

Future<void> _revealInExplorer(String filePath) async {
  if (FileSystemEntity.isDirectorySync(filePath)) {
    final uri = Uri.file(filePath);
    await launchUrl(uri);
    return;
  }
  final uri = Uri.file(path_lib.dirname(filePath));
  await launchUrl(uri);
}

Future<void> _revealInFinder(String filePath) async {
  final openFileMacosPlugin = OpenFileMacos();
  await openFileMacosPlugin.open(
    filePath,
    viewInFinder: true,
  );
}

move to file option in vscode to revealIn doesn't move the private helper functions associated, so it doesn't work

@stephane-archer stephane-archer added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Mar 22, 2025
@bwilkerson bwilkerson added devexp-refactoring Issues with analysis server refactorings P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) 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 22, 2025
@bwilkerson
Copy link
Member

That is definitely a bug. The tool should not be producing invalid code. The only question is how to fix the bug. I can think of several options.

  1. The refactoring could be unavailable in situations where the code to be moved contains references to private declarations that are not included in the code to be moved.

  2. Same as 1, with the exception that if the code to be moved is going to a part in the same library the restriction is ignored.

  3. The refactoring could be allowed if the private declarations can be implicitly included in the move (that is, if there are no references to any of the private declarations in code that would remain in the original library), and disallowed otherwise.

  4. The private declarations that are referenced in code that would remain in the original library could be duplicated rather than moved.

  5. The private declarations that are referenced in code that would remain in the original library could be made public.

The first option is the most restrictive, but is also probably the easiest to implement, so we might want to start with that just to fix the bug as quickly as possible. Though if it proves to not be too difficult to implement the second option that would be even better.

I would be in favor of the third option if we could give the user the ability to choose whether to continue with the refactoring after being told about the references. If the user isn't aware of the references, or doesn't want the private declarations moved for some other reason, then it could be surprising to have them moved without any notification. Of course, it could also be confusing if we can't explain why the refactoring isn't available in some cases, so we have to balance those two factors.

I would not want the fourth option without the ability for the user to choose between duplicating (some of) the private members and expanding the move to include the declarations that would have been left that also reference those private declarations. In other words, if a private declaration is referenced by both code to be moved and code to be left, duplicating the code is not at all an obvious choice of action, as illustrated by the fifth option, which is also not an obvious choice.

@FMorschel
Copy link
Contributor

FMorschel commented Mar 24, 2025

I'd opened #56791 to have this discussion previously. If you prefer we can defere here or there either way. I'm on my phone now so I will only be able to move the comments easily later.


Edit: Just as a quick vote, I'd prefer 2, 3 and 5 combined if possible.

@FMorschel
Copy link
Contributor

Just reviewed that issue and there seems to be no new suggestion or info that wasn't already discussed here. Closed that one since this already has more conversation.

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 P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants