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

Gentle auto-import that respects Scala CLI's directives #7071

Open
windymelt opened this issue Dec 27, 2024 · 6 comments
Open

Gentle auto-import that respects Scala CLI's directives #7071

windymelt opened this issue Dec 27, 2024 · 6 comments
Labels
bug Something that is making a piece of functionality unusable needs more information Use if we need more information for a specific ticket Scala 3 Generic ticket relating to Scala 3 scala-cli Relates to the scala-cli tool

Comments

@windymelt
Copy link

Is your feature request related to a problem? Please describe.

When I auto-import by completion in Scala Script for Scala CLI, Metals always adds import line top of my file. However, I want to keep Scala CLI directives top of the file...

e.g.

Before auto-import:

//> using scala 3.6.2

val d = FiniteDuration/* press TAB to complete! */

After auto-import:

import scala.concurrent.duration.FiniteDuration // aww〜〜
//> using scala 3.6.2

val d = FiniteDuration

Describe the solution you'd like

  • Metals recognizes Scala CLI directives.
  • Metals places imports below directives when auto-import.

Describe alternatives you've considered

Cut and paste

Additional context

I'm using Metals 1.4.1 on Emacs.

Search terms

autoimport auto-import import

@tgodzik
Copy link
Contributor

tgodzik commented Dec 27, 2024

This looks like an error when no imports are added yet.

@tgodzik tgodzik transferred this issue from scalameta/metals-feature-requests Dec 27, 2024
@tgodzik tgodzik added bug Something that is making a piece of functionality unusable Scala 3 Generic ticket relating to Scala 3 scala-cli Relates to the scala-cli tool labels Dec 27, 2024
@kasiaMarek
Copy link
Contributor

Hi, I can't really reproduce your issue. It puts the import in the correct place for me.

Screen.Recording.2025-01-08.at.16.09.26.mov

Are you sure that script is correctly recognised by Metals as Scala CLI script? Meaning, either scala-cli is the build server used in your project or the script is imported as a Scala CLI script in Metals.

@kasiaMarek kasiaMarek added the needs more information Use if we need more information for a specific ticket label Jan 8, 2025
@dos65
Copy link
Member

dos65 commented Jan 8, 2025

I've seen such issue when there were no \n after using directive but forgot to report it

//> using scala 3.6
val d = FiniteDuration

@kasiaMarek
Copy link
Contributor

@dos65, it also seems to work for me without the \n.

@dos65
Copy link
Member

dos65 commented Jan 8, 2025

@kasiaMarek yep, it works well on scala 3.6. my bad - the issue was on 2.13

Try this:

//> using scala 2.13
object X {
   FiniteDuration@@
}

@kubukoz
Copy link
Contributor

kubukoz commented Jan 8, 2025

I see directives and auto-imports keep fighting each other 😆 #4939 #6027

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is making a piece of functionality unusable needs more information Use if we need more information for a specific ticket Scala 3 Generic ticket relating to Scala 3 scala-cli Relates to the scala-cli tool
Projects
None yet
Development

No branches or pull requests

5 participants