Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #71 from laughedelic/0.8.0-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
laughedelic authored Dec 2, 2018
2 parents d4b61ea + ab9d1a8 commit 0de1815
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
60 changes: 40 additions & 20 deletions src/main/scala/ScalaLanguageClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ class ScalaLanguageClient extends AutoLanguageClient { client =>
case Nil => {
val default = ScalaLanguageServer.fromConfig
Atom.notifications.addInfo(
"Project is not setup, using default language server: **${default.name.capitalize}**",
s"Project is not setup, using default language server: **${default.name.capitalize}**",
new NotificationOptions(
description = "To learn how to setup new projects, follow the [documentation](https://github.com/laughedelic/atom-ide-scala#usage)",
detail = projectPath,
dismissable = true,
dismissable = false,
icon = "plug",
)
)
Expand Down Expand Up @@ -113,28 +112,49 @@ class ScalaLanguageClient extends AutoLanguageClient { client =>
}

private def addServerCommands(activeServer: ActiveServer): Unit = {
activeServer
def capitalizeWords(str: String): String =
str.split("\\s+").map(_.capitalize).mkString(" ")

def displayName(category: String, name: String): String =
s"${capitalizeWords(category)}: ${capitalizeWords(name)}"

// What we got from the server on initialization
val declaredCommands = activeServer
.capabilities
.executeCommandProvider
.map(_.commands).getOrElse(js.Array())
.foreach { cmd =>
server.commands.get(cmd).foreach { handler =>
Atom.commands.add(
"atom-workspace",
s"${server.name}:${cmd}",
{ node =>
handler(activeServer)(node)
}: js.Function1[js.Any, Unit]
)
}
}

// What we are aware of
val knownCommands = server.commands

for {
cmd <- declaredCommands
title <- knownCommands.get(cmd)
} yield {
Atom.commands.add(
target = "atom-workspace",
commandName = s"${server.name}:${cmd}",
new CommandListener(
displayName = displayName(server.name, title)
)({ node =>
activeServer.connection.executeCommand(
new ExecuteCommandParams(command = cmd)
)
}: js.Function1[js.Any, Unit]
)
)
}

// An additional command implemented through the atom-languageclient API
Atom.commands.add(
"atom-workspace",
s"ide-scala:restart-all-language-servers",
{ _ =>
client.restartAllServers()
}: js.Function1[js.Any, Unit]
target = "atom-workspace",
commandName = s"${server.name}:restart-server",
new CommandListener(
displayName = displayName(server.name, "Restart Server")
)({ _ =>
client.restartAllServers()
}: js.Function1[js.Any, Unit]
)
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ScalaLanguageServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait ScalaLanguageServer {
)
}

val commands: Map[String, ActiveServer => js.Any => Any]
val commands: Map[String, String]

def postInitialization(
client: ScalaLanguageClient,
Expand Down
24 changes: 9 additions & 15 deletions src/main/scala/servers/Metals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scala.scalajs.js, js.annotation._
import org.scalajs.dom, dom.raw.Element
import laughedelic.atom.Atom
import laughedelic.atom.config._
import laughedelic.atom.languageclient.{ ActiveServer, ExecuteCommandParams }
import laughedelic.atom.languageclient.ActiveServer

// For matching glob patterns
@js.native @JSImport("minimatch", JSImport.Namespace)
Expand All @@ -27,7 +27,7 @@ class HtmlView(title: String, html: String) extends js.Object {
object Metals extends ScalaLanguageServer { server =>
val name: String = "metals"
val description: String = "Metals"
val defaultVersion: String = "0.2.5"
val defaultVersion: String = "0.2.11"

def trigger(projectPath: String): Boolean = {
(projectPath / ".metals").isDirectory
Expand All @@ -54,18 +54,12 @@ object Metals extends ScalaLanguageServer { server =>
"--main", "scala.meta.metals.Main"
)

val commands = Seq(
"build-import",
"build-connect",
"sources-scan",
"doctor-run",
).map { cmd =>
cmd -> { activeServer: ActiveServer => _: js.Any =>
activeServer.connection.executeCommand(
new ExecuteCommandParams(command = cmd)
)
}
}.toMap
val commands = Map(
"build-import" -> "Import build",
"build-connect" -> "Connect to build server",
"sources-scan" -> "Rescan sources",
"doctor-run" -> "Run doctor",
)

override def postInitialization(client: ScalaLanguageClient, activeServer: ActiveServer): Unit = {
activeServer
Expand All @@ -84,7 +78,7 @@ object Metals extends ScalaLanguageServer { server =>
dispatchAtomCommand("console:toggle")
case "metals-diagnostics-focus" =>
dispatchAtomCommand("diagnostics:toggle-table")
case "metals-run-doctor" => {
case "metals-doctor-run" => {
val html = params.arguments.toString
Atom.asInstanceOf[js.Dynamic]
.views
Expand Down

0 comments on commit 0de1815

Please sign in to comment.