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
My working setup is specific:
- macOS HIgh Sierra
- Sublime 3 on Dev channel build 3160
- using sbt 1.1.2
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 thesemanticdbEnable
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"
]
}
- 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
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.
features marked with a [-]
are not enabled because I have to figure out how to send extensions flags using the sublime LSP package
[-] scalac diagnostic (presentation compiler)
[-] sbt server
[ ] scalafix linting (don't know how to do it from sublime)
[√] 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
[-] scala presentation compiler completion
[ ] auto-import
[ ] auto-expand abstract methods
[√] 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
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