Skip to content

feat(repl): support the toolkit directive and :toolkit command - #26788

Open
warcholjakub wants to merge 6 commits into
scala:mainfrom
warcholjakub:feat/repl/toolkit-directive
Open

feat(repl): support the toolkit directive and :toolkit command#26788
warcholjakub wants to merge 6 commits into
scala:mainfrom
warcholjakub:feat/repl/toolkit-directive

Conversation

@warcholjakub

Copy link
Copy Markdown
Member

Fixes #26744

Adds //> using toolkit directive and :toolkit command.

Have you relied on LLM-based tools in this contribution?

Yes, and I checked the output by testing manually with bin/replQ

How was the solution tested?

New automated tests (including the issue's reproducer, if applicable)

@warcholjakub
warcholjakub force-pushed the feat/repl/toolkit-directive branch from c2adf51 to 1d0737e Compare August 12, 2026 13:27

@SolalPirelli SolalPirelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The underlying logic looks sound but toolkitCoordinates and the Toolkit trait are rather convoluted. Do we really expect to support weird new toolkits whose matchesFlavor isn't set membership? Could we use a Map[String, String] to map aliases instead?

Comment thread repl/src/dotty/tools/repl/ReplDirectives.scala Outdated
Comment thread repl/src/dotty/tools/repl/ReplDirectives.scala Outdated
Comment on lines +69 to +70
val rawVersion = tokens.lastOption.filter(_.nonEmpty).getOrElse("default")
val flavor = tokens.dropRight(1).headOption.getOrElse("scala")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm rather confused by what's going on here. Is it OK to have more than 2 tokens? Is it ever OK to have an empty token? Do we really need to support xyz: ? It seems like this should match on Nil, version :: Nil, and flavor :: version :: Nil and reject everything else, as well as reject empty versions and flavors?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a fair point, but the logic is pretty much copied from the scala-cli. Although I'm not sure what's a better option: to do this as scala-cli does (not perfect), or deviate from the original behaviour and handle it better(?).

@warcholjakub warcholjakub Aug 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed it offline with @Gedochao, and it's indeed not intended. Also applies to the second comment (: and :: shouldn't be supported). Anyhow, I'll fix it.

"com.example:1.2.3" -> ("com.example", "1.2.3"),
"com.example:latest" -> ("com.example", "latest.release"),
":" -> ("org.scala-lang", "0.9.2"),
"::" -> ("org.scala-lang", "0.9.2")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a supported use case? 😱

@warcholjakub warcholjakub Aug 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it doesn't work in scala-cli. But it's not really because it's unsupported per se (at least that's what I think). Scala-cli uses tokens.last and it throws an error when trying to use .last on an EmptyArray. I used lastOption and it works, but at a cost of allowing this particular use case. I agree that's a lil bit cursed, and I'm open to suggestions on what to do with that.

@warcholjakub

warcholjakub commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

The underlying logic looks sound but toolkitCoordinates and the Toolkit trait are rather convoluted. Do we really expect to support weird new toolkits whose matchesFlavor isn't set membership? Could we use a Map[String, String] to map aliases instead?

Fair, I got a little carried away 😅.

EDIT: Addressed in 4362c99

@warcholjakub warcholjakub added the needs-squashing PR whose commits should be squashed by the author or via the "Squash and Merge" button label Aug 12, 2026
@warcholjakub
warcholjakub force-pushed the feat/repl/toolkit-directive branch from 6808a4e to df61878 Compare August 12, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-squashing PR whose commits should be squashed by the author or via the "Squash and Merge" button

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REPL: add support for //> using toolkit directive

2 participants