diff --git a/metals/src/main/scala/scala/meta/internal/metals/GithubNewIssue.scala b/metals/src/main/scala/scala/meta/internal/metals/GithubNewIssue.scala new file mode 100644 index 00000000000..60944f5b725 --- /dev/null +++ b/metals/src/main/scala/scala/meta/internal/metals/GithubNewIssue.scala @@ -0,0 +1,50 @@ +package scala.meta.internal.metals + +import java.net.URLEncoder + +import scala.util.Properties + +import org.eclipse.lsp4j.ClientInfo + +object GithubNewIssue { + def buildUrl(clientInfo: ClientInfo): String = { + val clientVersion = + if (clientInfo.getVersion() == null) "" + else s" ${clientInfo.getVersion()}" + val body = + s"""| + | + |### Expected behaviour: + | + | + | + |**Operating system:** + |${Properties.osName} + | + |**Java version:** + |${Properties.javaVersion} + | + |**Editor/extension:** + |${clientInfo.getName()}$clientVersion + | + |**Metals version:** + |${BuildInfo.metalsVersion} + | + |### Extra context or search terms: + | + |""".stripMargin + val encodedBody = URLEncoder.encode(body) + s"https://github.com/scalameta/metals/issues/new?body=$encodedBody" + } +} diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala index b8810ab4e67..6dcee6c7ad4 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -40,6 +40,7 @@ import scala.meta.internal.implementation.ImplementationProvider import scala.meta.internal.implementation.Supermethods import scala.meta.internal.io.FileIO import scala.meta.internal.metals.BuildInfo +import scala.meta.internal.metals.GithubNewIssue import scala.meta.internal.metals.Messages.AmmoniteJvmParametersChange import scala.meta.internal.metals.Messages.IncompatibleBloopVersion import scala.meta.internal.metals.MetalsEnrichments._ @@ -1871,6 +1872,14 @@ class MetalsLspService( else Future.successful(()) } } yield ()).asJavaObject + case ServerCommands.OpenIssue() => + Future + .successful( + Urls.openBrowser( + GithubNewIssue.buildUrl(initializeParams.getClientInfo()) + ) + ) + .asJavaObject case OpenBrowserCommand(url) => Future.successful(Urls.openBrowser(url)).asJavaObject case ServerCommands.CascadeCompile() => diff --git a/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala b/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala index fcadd896237..a0255708a40 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala @@ -590,10 +590,10 @@ object ServerCommands { "Open the Metals logs to troubleshoot issues.", ) - val OpenIssue = new OpenBrowserCommand( - "https://github.com/scalameta/metals/issues/new/choose", + val OpenIssue = new Command( + "open-new-github-issue", "Open issue on GitHub", - "Open the Metals repository on GitHub to ask a question, report a bug or request a new feature.", + "Open the Metals repository on GitHub to ask a question or report a bug.", ) val MetalsGithub = new OpenBrowserCommand(