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 class to file" ask to export new file from source #56692

Open
FMorschel opened this issue Sep 10, 2024 · 4 comments
Open

"Move class to file" ask to export new file from source #56692

FMorschel opened this issue Sep 10, 2024 · 4 comments
Labels
analyzer-refactoring area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@FMorschel
Copy link
Contributor

FMorschel commented Sep 10, 2024

If you have the following project:

In main.dart:

class A {}

class C extends A {}

In other.dart:

import 'main.dart';

void f(C c) {}

And you use "Move class to file" on C, the current output for other.dart is (#56658 for the unused_import):

import 'main.dart';
import 'c.dart';

void f(C c) {}

I'm not sure how this could be done, but I'd like to ask for a way for me to say if I want to add export 'c.dart'; inside main.dart so that other files don't need to change.


// CC: @DanTup

@dart-github-bot
Copy link
Collaborator

Summary: The "Move class to file" refactoring currently adds an unnecessary import statement to files that already import the original file containing the moved class. The user requests a way to specify whether to add an export statement to the original file instead, to avoid unnecessary changes in other files.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-enhancement A request for a change that isn't a bug labels Sep 10, 2024
@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Sep 10, 2024
@pq pq added analyzer-refactoring P2 A bug or feature request we're likely to work on labels Sep 10, 2024
@FMorschel
Copy link
Contributor Author

A little update, both of the following issues could also benefit from some form of "checking" before/after the assist. Imagine someone wants to add an import with both show and an alias/prefix. That might make the current list of options a little too big and noisy, so if we had some form of "check user" here, that might be interesting.

Also, as noted on (#56265) there could be some form of "hiding" some options in the list project-wise or user-wise. That could also help with this specific problem of filling up the options list.

@FMorschel
Copy link
Contributor Author

One more case: #56885

We could also ask (when making a new part file with this same feature - whenever it supports it) if we'd like to use the source file imports or add new imports on the specific file.

@bwilkerson
Copy link
Member

... I'd like to ask for a way for me to say if I want to add export 'c.dart'; inside main.dart so that other files don't need to change.

That's a reasonable request.

I'm not sure what the UI would look like for that, but the easiest solution might be to introduce a "Move Top Level to File and export" refactoring.

Alternatively, we could ask users to do something like

  1. Write an export directive for the new file.
  2. Use the 'Create file' assist to create the file.
  3. Use "Move Top Level to File" to move the declaration.

(That assumes that move-top-level checks to see whether the target file is already exported and leaves the imports in other files unchanged in the case, which I'm fairly certain it currently doesn't do but should.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-refactoring area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants