scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.1k stars 332 forks source link

VSCode Scala Metals on Traditional Play Project Structure - no build target #849

Closed suriyanto closed 4 years ago

suriyanto commented 5 years ago

Question I'm trying out Scala Metals with VSCode and so far everything works great. However when I load a traditional Play project that uses the directory structure of

app
  org
    myname
      controllers
      models
      ...
test
   org
      ....

In this structure, during import, Metals gives warning: no build target and code navigation does not work. When I try to use Go To Definition, it gives this warning in the log.

WARN code navigation does not work for the file ...

Is there any special settings need to be done for this project structure?

Installation:

Search terms Play Framework, Code Navigation

tgodzik commented 5 years ago

Hi, this should work as long as the build is correctly imported to Bloop by sbt. I will check later with some sample projects.

suriyanto commented 5 years ago

Thanks, @tgodzik . Did you get a chance to verify this on Bloop?

tgodzik commented 5 years ago

Sorry, I didn't have enough time this week. Will try to look at it as soon as possible, probably after the weekend. It's the single item in my inbox that I didn't get to, which is a sore point for me :sweat_smile:

tgodzik commented 5 years ago

Managed to check on a sample project and it seems to work. Does a sample application work for you? I created one using sbt new playframework/play-scala-seed.g8

tgodzik commented 5 years ago

@suriyanto are you able to reproduce the issue on a sample play project? It would be nice to figure out a minimal reproduction if this is really an issue.

It's running fine on the sample one for me though.

tgodzik commented 5 years ago

Closing this until we can get a proper reproduction. This works on play projects so most likely not the issue.

kostafey commented 4 years ago

Reproduced for Emacs. Version: org.scalameta:metals_2.12:0.7.6 Scala 2.13.1 sbt 1.3.3

Steps to reproduce: 1 Run sbt new playframework/play-scala-seed.g8

  1. Open Scala file (e.g. C:\Workspace\play-scala-seed\app\controllers\HomeController.scala)
  2. Accept import project (confirm import project proposal). Output:
    Command "metals-emacs" is present on the path.
    Found the following clients for c:/Workspace/play-scala-seed/app/controllers/HomeController.scala: (server-id metals, priority -1)
    The following clients were selected based on priority: (server-id metals, priority -1)
    logging to file C:\Workspace\play-scala-seed\.metals\metals.log
    time: initialize in 0.33s
    Creating watch for c:/Workspace/play-scala-seed
    Creating watch for c:/Workspace/play-scala-seed/.g8
    Creating watch for c:/Workspace/play-scala-seed/.g8/form
    Creating watch for c:/Workspace/play-scala-seed/.g8/form/app
    Creating watch for c:/Workspace/play-scala-seed/.g8/form/app/controllers
    Creating watch for c:/Workspace/play-scala-seed/.g8/form/app/views
    Creating watch for c:/Workspace/play-scala-seed/.g8/form/app/views/$model__camel$
    Creating watch for c:/Workspace/play-scala-seed/.g8/form/test
    Creating watch for c:/Workspace/play-scala-seed/.g8/form/test/controllers
    Creating watch for c:/Workspace/play-scala-seed/app
    Creating watch for c:/Workspace/play-scala-seed/app/controllers
    Creating watch for c:/Workspace/play-scala-seed/app/views
    Creating watch for c:/Workspace/play-scala-seed/conf
    Creating watch for c:/Workspace/play-scala-seed/project
    Creating watch for c:/Workspace/play-scala-seed/project/project
    Creating watch for c:/Workspace/play-scala-seed/public
    Creating watch for c:/Workspace/play-scala-seed/public/images
    Creating watch for c:/Workspace/play-scala-seed/public/javascripts
    Creating watch for c:/Workspace/play-scala-seed/public/stylesheets
    Creating watch for c:/Workspace/play-scala-seed/test
    Creating watch for c:/Workspace/play-scala-seed/test/controllers
    no build target: C:\Workspace\play-scala-seed\app\controllers\HomeController.scala
    no build target: using presentation compiler with only scala-library
    Buffer switched - ignoring response. Method textDocument/hover
    Buffer switched - ignoring response. Method textDocument/signatureHelp
    code navigation does not work for the file 'C:\Workspace\play-scala-seed\app\controllers\HomeController.scala' because it doesn't belong to a build target.

This fixes by import project manually: M-x lsp-metals-build-import.

Not sure whether it's an Emacs only related issue or not. But looks similar to the original VSCode issue. Should I create a new issue for it?

tgodzik commented 4 years ago

@kostafey I think with the reproduction we can reopen this one. Thanks for adding it!

olafurpg commented 4 years ago

This fixes by import project manually:

Can you clarify? It is expected that you get "no build target" errors before running the "import build" command.

kostafey commented 4 years ago

@olafurpg Once again step by step.

  1. Open new Scala project (e.g. open some Scala file), I see the following message: New sbt workspace detected, would you like to import the build?
  2. Confirm it.
  3. I see no build target message in *lsp-log* buffer (full output in the comment below https://github.com/scalameta/metals/issues/849#issuecomment-557918511). LSP doesn't work at this moment. But looks like it should.
  4. When I run M-x lsp-metals-build-import it fixes the problem.

Probably it's a client error.

olafurpg commented 4 years ago

@kostafey in step 2, what happens after you confirm? Does .metals/metals.log produce output after you confirm? The "import build" step takes a while to run

olafurpg commented 4 years ago

If step 4 fixes the problem, then then this is unrelated to the Play app structure so I'll close this issue but feel free to report a separate issue on step 3.

kostafey commented 4 years ago

@olafurpg I've found the problem. It's the wrong usage and misunderstanding the docs. Here is a Metals doc for Emacs:

The first time you open Metals in a new workspace it prompts you to import the build. Click "Import build" to start the installation step.

So, in Emacs when I see New sbt workspace detected, would you like to import the build? I don't see any items to select. I simply typed [RET]. Looks like there is no default item to select, and no import actually happens. Instead, I should type Import build manually or press [Tab] to see the possible items to select. Probably it's worth to update docs a little bit to remove future users' possible misunderstanding.

tgodzik commented 4 years ago

I think that's a good idea - would you be willing to add that to the docs? You can find the file here: https://github.com/scalameta/metals/blob/master/docs/editors/emacs.md