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

Use coursier completions to handle backpublished mtags #4606

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

keynmol
Copy link
Contributor

@keynmol keynmol commented Nov 4, 2022

Users often refer to the output of metals --version (in vim/emacs and may be others) to ensure their version of Scala is supported.

With mtags being backpublished, that output is often out of date.

This PR is to start a conversation about may be detecting backpublished mtags and showing the user the full set of supported version?

Copy link
Member

@jkciesluk jkciesluk left a comment

Choose a reason for hiding this comment

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

Looks good, I just have some minor questions

else Some(scalaVer)
}.toOption.flatten
}
.toParArray
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.toParArray
.distinct
.toParArray

We can have duplicates here, maybe it's worth doing distinct before next api calls

Comment on lines +69 to +70
_.startsWith("2.")
)).distinct
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_.startsWith("2.")
)).distinct
_.startsWith("2.")
))

Comment on lines +79 to +80
_.startsWith("3.")
)).sorted.distinct.mkString(", ")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_.startsWith("3.")
)).sorted.distinct.mkString(", ")
_.startsWith("3.")
)).sorted.mkString(", ")


import scala.collection.parallel._

val additional =
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can wrap it in Future and do something like

val additional = 
  try Await.result(additionalFuture, 10.seconds)
  catch {
    case _: Throwable => Nil
  }

So when we don't get response from coursier we still show other supported versions?

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

I think this is an improvement for sure, thanks for looking into this! I left some comments.

.flatMap { case artif =>
Try {
val scalaVer = artif.stripPrefix("mtags_")
val List(epoch, major, rest) = scalaVer.split("\\.", 3).toList
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use SemVer to parse the version.

import org.eclipse.lsp4j.jsonrpc.Launcher

object Main {
def main(args: Array[String]): Unit = {
if (args.exists(Set("-v", "--version", "-version"))) {
val api: Complete = coursierapi.Complete
.create()
.withInput("org.scalameta:mtags")
Copy link
Contributor

Choose a reason for hiding this comment

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

One problem I see is that it will not work for snapshot versions of Metals. The alternative would be something similar to my super fun workaround here: https://github.com/scalameta/metals/blob/main/metals/src/main/scala/scala/meta/internal/metals/MtagsResolver.scala#L119

@ckipp01
Copy link
Member

ckipp01 commented Jan 2, 2023

This has been inactive for a while so I'm going to mark as a draft. @keynmol if you dive back into please do ping us for another review.

@ckipp01 ckipp01 marked this pull request as draft January 2, 2023 14:07
@ckipp01 ckipp01 added the improvement Not a bug or a feature, but something general we can improve label Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Not a bug or a feature, but something general we can improve
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants