Skip to content

Instantly share code, notes, and snippets.

@ivanopagano
Last active February 8, 2019 09:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanopagano/122291b6a3b55b069abd7b019b972b29 to your computer and use it in GitHub Desktop.
Save ivanopagano/122291b6a3b55b069abd7b019b972b29 to your computer and use it in GitHub Desktop.
Using Metals LSP with Sublime 3

Using with Sublime

I successfully enabled the metals lsp server to work with sublime text 3

I didn't actually need to write any lsp client, since I'm using the standard LSP Package

Setup

My working setup is specific:

  • macOS HIgh Sierra
  • Sublime 3 on Dev channel build 3160
  • using sbt 1.1.2

How-to

Instructions to enable the lsp communication follows the guidelines of metals, that is

  • add the MetalsPlugin.scala globally in the ~/.sbt/1.0/plugins
  • enable the semanticdb (I do this locally with the semanticdbEnable command)
  • run the metalsSetup command

On sublime

  • Add the Package Control extension (I expect anyone using sublime to have this installed, otherwise the editor is useless...)
  • Install the LSP Package
  • open the Preferences: LSP Settings in the command menu
  • add the following json object to the user settings under clients
"sbt":
{
  "command":
  [
    "<path-to-start-server-script>"
  ],
  "languageId": "scala",
  "scopes":
  [
    "source.scala",
    "source.sc"
  ],
  "syntaxes":
  [
    "Packages/Scala/Scala.sublime-syntax"
  ]
}

Notes to the json config:

  • I called the client sbt, but you're free to use any name you like, as long as it doesn't conflict with other configured lsp
  • the scala syntax is enabled by installing the appropriate package from the Package Control
  • the executable command is the shell script available in metals/bin/start-server.sh, place it somewhere locally and use the local path

server notes

To make the actual server available from coursier in the start-server.sh, I had to :

  • clone the metals repo locally
  • run the publishLocal task to have the latest snapshot on my local ivy cache

About the last point, I didn't try to fetch the latest published binary from some remote repo like bintray or sonatype or maven central.

Enabled features

features marked with a [-] are not enabled because I have to figure out how to send extensions flags using the sublime LSP package

diagnostics

[-] scalac diagnostic (presentation compiler)
[-] sbt server
[ ] scalafix linting (don't know how to do it from sublime)

navigation

[√] goto-definition
[√] find references
[-] highlight references to symbol
[√] goto-symbol
[ ] symbol outline in sidebar as-you-type
[ ] goto-impl
[ ] goto-type-def
[√] show symbol type on hover
[ ] show expression type on hover

completions

[-] scala presentation compiler completion
[ ] auto-import
[ ] auto-expand abstract methods

refactoring

[√] format whole file
[ ] format selection
[ ] format on-save
[ ] format as-you-type
[√] rename local symbol
[ ] rename global symbol
[ ] remove unused imports
[ ] organize imports
[ ] move class
[ ] insert type annotation

code actions

I actually couldn't manage to have any code action suggested when calling the contextual menu.

That is: the code actions menu is enabled but when opened is always empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment