From 1f6654ba8ffe4ef01fc28b7d2900797087acb263 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Mon, 13 Feb 2023 11:44:04 +0100 Subject: [PATCH] Improvement: adds details to github issue --- .../metals/GithubNewIssueUrlCreator.scala | 98 +++++++++++++++++++ .../internal/metals/MetalsLspService.scala | 13 +++ .../meta/internal/metals/ServerCommands.scala | 16 ++- .../internal/tvp/MetalsTreeViewProvider.scala | 1 + 4 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 metals/src/main/scala/scala/meta/internal/metals/GithubNewIssueUrlCreator.scala diff --git a/metals/src/main/scala/scala/meta/internal/metals/GithubNewIssueUrlCreator.scala b/metals/src/main/scala/scala/meta/internal/metals/GithubNewIssueUrlCreator.scala new file mode 100644 index 00000000000..fd58693b866 --- /dev/null +++ b/metals/src/main/scala/scala/meta/internal/metals/GithubNewIssueUrlCreator.scala @@ -0,0 +1,98 @@ +package scala.meta.internal.metals + +import java.net.URLEncoder + +import scala.util.Properties + +import scala.meta.internal.bsp.BspResolvedResult +import scala.meta.internal.bsp.BspSession +import scala.meta.internal.bsp.ResolvedBloop +import scala.meta.internal.bsp.ResolvedBspOne +import scala.meta.internal.bsp.ResolvedMultiple +import scala.meta.internal.bsp.ResolvedNone +import scala.meta.internal.builds.BuildTools + +import org.eclipse.lsp4j.ClientInfo + +class GithubNewIssueUrlCreator( + tables: Tables, + buildTargets: BuildTargets, + currentBuildServer: () => Option[BspSession], + calculateNewBuildServer: () => BspResolvedResult, + clientInfo: ClientInfo, + buildTools: BuildTools, +) { + + def buildUrl(): String = { + val scalaVersions = + buildTargets.allScala.map(_.scalaVersion).toSet.mkString("; ") + val clientVersion = + Option(clientInfo.getVersion()).map(v => s" v$v").getOrElse("") + 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: + | + | + |### Workspace information: + | + | - **Scala versions:** $scalaVersions$selectedBuildTool$selectedBuildServer + | - **All build tools in workspace:** ${buildTools.all.mkString("; ")} + |""".stripMargin + s"https://github.com/scalameta/metals/issues/new?body=${URLEncoder.encode(body)}" + } + + private def selectedBuildTool(): String = { + tables.buildTool + .selectedBuildTool() + .map { value => + s"""| + | - **Build tool:** ${value}""".stripMargin + } + .getOrElse("") + } + + private def selectedBuildServer(): String = { + val buildServer = currentBuildServer() + .map(s => s"${s.main.name} v${s.main.version}") + .getOrElse { + calculateNewBuildServer() match { + case ResolvedBloop => "Disconnected: Bloop" + case ResolvedBspOne(details) => s"Disconnected: ${details.getName()}" + case ResolvedMultiple(_, details) => + s"Disconnected: Multiple Found ${details.map(_.getName()).mkString("; ")}" + case ResolvedNone => s"Disconnected: None Found" + } + } + + s"""| + | - **Build server:** $buildServer""".stripMargin + } +} 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..988404eac4a 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -716,6 +716,15 @@ class MetalsLspService( maybeJdkVersion, ) + private val githubNewIssueUrlCreator = new GithubNewIssueUrlCreator( + tables, + buildTargets, + () => bspSession, + () => bspConnector.resolve(), + initializeParams.getClientInfo(), + buildTools, + ) + private val fileDecoderProvider: FileDecoderProvider = new FileDecoderProvider( workspace, @@ -1871,6 +1880,10 @@ class MetalsLspService( else Future.successful(()) } } yield ()).asJavaObject + case ServerCommands.OpenIssue() => + Future + .successful(Urls.openBrowser(githubNewIssueUrlCreator.buildUrl())) + .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..05c022bcde1 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,16 @@ object ServerCommands { "Open the Metals logs to troubleshoot issues.", ) - val OpenIssue = new OpenBrowserCommand( - "https://github.com/scalameta/metals/issues/new/choose", - "Open issue on GitHub", - "Open the Metals repository on GitHub to ask a question, report a bug or request a new feature.", + val OpenIssue = new Command( + "open-new-github-issue", + "Open an issue on GitHub", + "Open the Metals repository on GitHub to ask a question or report a bug.", + ) + + val OpenFeatureRequest = new OpenBrowserCommand( + "https://github.com/scalameta/metals-feature-requests/issues/new?template=feature-request.yml", + "Open a feature request", + "Open the Metals repository on GitHub to open a feature request.", ) val MetalsGithub = new OpenBrowserCommand( @@ -700,6 +706,8 @@ object ServerCommands { SuperMethodHierarchy, StartScalaCliServer, StopScalaCliServer, + OpenIssue, + OpenFeatureRequest, ) val allIds: Set[String] = all.map(_.id).toSet diff --git a/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala b/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala index ac944e260d4..967216f8076 100644 --- a/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala @@ -205,6 +205,7 @@ class MetalsTreeViewProvider( echoCommand(ServerCommands.ReadBloopDocumentation, "book"), echoCommand(ServerCommands.ChatOnDiscord, "discord"), echoCommand(ServerCommands.OpenIssue, "issue-opened"), + echoCommand(ServerCommands.OpenFeatureRequest, "github"), echoCommand(ServerCommands.MetalsGithub, "github"), echoCommand(ServerCommands.BloopGithub, "github"), echoCommand(ServerCommands.ScalametaTwitter, "twitter"),