scalameta / coc-metals

Deprecated in favor of scalameta/nvim-metals
http://scalameta.org/metals/
Apache License 2.0
167 stars 24 forks source link

Not being able to run Scala 3 in *.worksheet.sc #461

Closed sbushmanov closed 2 years ago

sbushmanov commented 2 years ago

In a project with a `build.sbt' like

ThisBuild / scalaVersion := "3.1.1"

lazy val root = (project in file("."))
  .settings(
    name := "myapp2"
  )

I'm running in a *.worksheet.sc:

scala.util.Properties.versionString -> : String = version 2.13.8

The following in metals config:

"metals.fallbackScalaVersion": "3.1.1",

gives a warning:

[json 1] [W] Value is not accepted. Valid values: "automatic", "2.13.4", "2.13.3", "2.13.2", "2.13.1", "2.13.0", "2.12.13", "2.12.12", "2.12.11", "2.12.10", "2.12.9", "2.12.8", "2.11.12", "3.0.0-M3", "3.0.0-M2", "3.0.0-M1".

even though specifying 3.0.0-M1 gives another warning this is not supported, and suggestion to upgrade to 3.1.1.

I'm using:

vim version: NVIM v0.7.0-dev
node version: v14.18.0
coc.nvim version: 0.0.80-93ed9c68 2022-03-20 00:49:33 +0800
coc.nvim directory: /home/sergey/.vimscala/plugged/coc.nvim
term: tmux
platform: linux

## Log of coc.nvim

2022-03-21T21:19:31.540 INFO (pid:18389) [services] - registered service "languageserver.bash"
2022-03-21T21:19:31.558 INFO (pid:18389) [services] - registered service "diagnostic-languageserver"
2022-03-21T21:19:31.765 INFO (pid:18389) [plugin] - coc.nvim initialized with node: v14.18.0 after 300ms
2022-03-21T21:19:31.773 WARN (pid:18389) [workspace] - workspace.createStatusBarItem is deprecated, please use window.createStatusBarItem instead. 
    at k (/home/sergey/.config/coc/extensions/node_modules/coc-metals/lib/index.js:28:2736)
    at /home/sergey/.config/coc/extensions/node_modules/coc-metals/lib/index.js:28:1666
2022-03-21T21:19:32.073 INFO (pid:18389) [attach] - receive notification: highlight []
2022-03-21T21:19:34.057 INFO (pid:18389) [language-client-index] - Language server "metals" started with 18436
2022-03-21T21:19:35.856 WARN (pid:18389) [workspace] - workspace.createStatusBarItem is deprecated, please use window.createStatusBarItem instead. 
    at /home/sergey/.config/coc/extensions/node_modules/coc-metals/lib/index.js:28:9127
2022-03-21T21:19:36.584 INFO (pid:18389) [attach] - receive notification: showInfo []

and

call plug#begin('/home/sergey/.vimscala/plugged')

    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    Plug 'ryanoasis/vim-devicons'
    Plug 'https://github.com/sainnhe/gruvbox-material'
    Plug 'lifepillar/vim-solarized8'
    Plug 'sainnhe/edge'
    Plug 'sbdchd/neoformat'
    Plug 'neomake/neomake' ", {'for':[]}
    Plug 'jiangmiao/auto-pairs'
    Plug 'cometsong/CommentFrame.vim'
    Plug 'psf/black', { 'rev': 'stable' }
    Plug 'nvim-treesitter/nvim-treesitter'
"   COC stuff
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
    "Plug 'scalameta/coc-metals', {'do': 'yarn install --frozen-lockfile'}
    Plug 'nvim-telescope/telescope.nvim'
    Plug 'nvim-lua/plenary.nvim'
    Plug 'nvim-lua/popup.nvim'
    Plug 'kevinhwang91/nvim-bqf'
    Plug 'junegunn/fzf'

call plug#end()

It seems to me there must be a conflict between perhaps some leftover installation, but I am not able to troubleshoot it.

Any help how to use Scala 3.1.1 in a worksheet is appreciated

PS Same happens in VS (2.13.8) and in Intellij (2.13.6)

ckipp01 commented 2 years ago

Hey @sbushmanov thanks for the report.

scala.util.Properties.versionString -> : String = version 2.13.8

So this is a little bit of a gotcha. This doesn't actually correspond to the version of Scala that you're using, but rather the version of the collections library which is being used. In Scala 3, this is the 2.13 Scala collections library. For example, you can see this in the REPL even.

❯ scala3-nightly-repl
Downloading JVM index
Welcome to Scala 3.2.0-RC1-bin-20220308-29073f1-NIGHTLY-git-29073f1 (11.0.12, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> scala.util.Properties.versionString
val res0: String = version 2.13.8

So it's not a good idea to rely on that. So if your sbt build is using 3.1.1 as long as your worksheet is next to your sources you should be able to have your worksheet in 3.1.1 just fine.

Regarding about the warning about an invalid value for the fallbackScalaVersion, that's due to this being out of date https://github.com/scalameta/coc-metals/blob/main/package.json#L271-L288. It hasn't been updated in a while. It should actually be updated to support the supported scala versions that are available. Feel free to shoot in a pr to update this.

Also, as a total aside, looking at your plugins, if you are only using coc-metals in the coc ecosystem, then I'd recommend switching to https://github.com/scalameta/nvim-metals. You can seed more context here: https://github.com/scalameta/coc-metals/issues/460

sbushmanov commented 2 years ago

@ckipp01 Thanks, as always!

Working as Scala 3, indeed!