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

Add fix command for extracting using directives into project.scala file #2309

Merged
merged 5 commits into from
Sep 29, 2023

Conversation

MaciejG604
Copy link
Contributor

@MaciejG604 MaciejG604 commented Jul 25, 2023

Fixes #2104

Introduces a new subcommand fix that extracts all using directives that exist througout the project sources (not only files on disk but everything that's linked to the project build). Those extracted directives are then written to project.scala file.

This process can be split into two parts (their order is not exactly 1. -> 2. in code):

  1. Extraction of directives and writing them into project.scala
  2. Modification of directives in their original sources.

Rules regarding the 1. part:

  • if a source contains any target using directive then it's directives are not extracted, since it's a correct way to create projects with cross-configuration (the warning about using directives in multiple files has been modified accordingly)
  • directives from sources belonging to the Test scope are extracted and written to project.scala using their test. equivalents (using dep -> using test.dep) if possible, if not possible they are not written to project.scala

Rules regarding the 2. part:

  • if a source is writable (is on local disk) and it is a member of original inputs then the extracted directives are removed from its contents, otherwise no modification takes place
  • if a source belonging to the Test scope contains directives that do not have test. equivalents they are kept in this source and are not moved to project.scala, all the others extracted using directives are removed from the source if rule above applies

@MaciejG604 MaciejG604 requested a review from lwronski July 25, 2023 09:52
@MaciejG604 MaciejG604 marked this pull request as draft July 25, 2023 09:52
@MaciejG604 MaciejG604 force-pushed the extract-directives branch from db07f80 to c737202 Compare July 25, 2023 11:42
@MaciejG604 MaciejG604 marked this pull request as ready for review July 25, 2023 11:42
@MaciejG604 MaciejG604 force-pushed the extract-directives branch 4 times, most recently from c0b5672 to 6f5bd19 Compare July 26, 2023 12:35
@mpkocher
Copy link
Contributor

Where are the requirements of this defined? I'm not really seeing anything in the original issue.

You're adding a new subcommand called "fix"?

@MaciejG604
Copy link
Contributor Author

Where are the requirements of this defined? I'm not really seeing anything in the original issue.

The requirements for this were discussed internally by the Scala CLI team. I can list them in the description since they are quite simple.

You're adding a new subcommand called "fix"?

Yes, the proposal right now is to add this functionaility in a fix subcommand. However, all suggestions are highly appreciated.

@MaciejG604 MaciejG604 force-pushed the extract-directives branch 3 times, most recently from 103cb07 to 92e2f09 Compare July 30, 2023 07:39
@MaciejG604 MaciejG604 force-pushed the extract-directives branch 4 times, most recently from 024fed6 to e261683 Compare August 7, 2023 10:50
@MaciejG604 MaciejG604 force-pushed the extract-directives branch 3 times, most recently from 4f1d06f to 9aadf65 Compare August 17, 2023 06:55
@MaciejG604 MaciejG604 force-pushed the extract-directives branch 2 times, most recently from 050f8d8 to 608fe6c Compare August 18, 2023 10:07
@MaciejG604 MaciejG604 force-pushed the extract-directives branch 5 times, most recently from fcd8df9 to 72612a5 Compare August 31, 2023 15:04
-Add logging to Fix command
-Format the copied directives in project.scala
-Add support for test. directives in main scope
-Add support for sources with shebang
-Move removing directives as the last operation in Fix command
-Remove ordering via hardcoded names
-Apply review fixes
@MaciejG604 MaciejG604 merged commit e42039e into VirtusLab:main Sep 29, 2023
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a way to extract all directives declared across different scala files into a single file
3 participants