scalameta / nvim-metals

A Metals plugin for Neovim
https://scalameta.org/metals/
Apache License 2.0
455 stars 74 forks source link

Unable to import mtags when importing builds for a scala project using bazel #660

Closed SuyogSoti closed 3 months ago

SuyogSoti commented 3 months ago

Describe the bug

Hey Team,

For work, I have to write code in scala with bazel as the build system. In order to continue using vim, I have to be able to set up metals so that I get

These are the parts of LSP that I must have in order to be able to continue using vim. The problems I face is that when I import build, some files are generated and I don't get auto-complete/go-to-def/help-hover for imported files.

They can be in the same bazel target or different. When I look at the logs for metals, I see this error right after trying to import the build.

2024.04.03 18:02:33 INFO  Bloop uses /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home defined at /Users/$USER/.bloop/bloop.json
2024.04.03 18:02:33 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /Users/$USER/code/universe/project/.metals/bsp.trace.js
on or /Users/$USER/Library/Caches/org.scalameta.metals/bsp.trace.json
2024.04.03 18:02:33 INFO  time: Connected to build server in 0.29s
2024.04.03 18:02:33 INFO  Connected to Build server: Bloop v1.5.15
2024.04.03 18:02:34 INFO  Failed to resolve mtags for 2.12.7
2024.04.03 18:02:34 ERROR Failed to fetch mtags for 2.12.7
Error downloading org.scalameta:mtags_2.12.7:1.2.2
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://repo1.maven.org/maven2/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://oss.sonatype.org/content/repositories/public/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: https://oss.sonatype.org/content/repositories/snapshots/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
2024.04.03 18:02:34 INFO  Failed to resolve mtags for 2.12.7
2024.04.03 18:02:34 ERROR Failed to fetch mtags for 2.12.7
Error downloading org.scalameta:mtags_2.12.7:1.2.2
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://repo1.maven.org/maven2/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://oss.sonatype.org/content/repositories/public/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: https://oss.sonatype.org/content/repositories/snapshots/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
2024.04.03 18:02:36 INFO  Failed to resolve mtags for 2.12.7
2024.04.03 18:02:36 ERROR Failed to fetch mtags for 2.12.7
Error downloading org.scalameta:mtags_2.12.7:1.2.2
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://repo1.maven.org/maven2/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://oss.sonatype.org/content/repositories/public/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: https://oss.sonatype.org/content/repositories/snapshots/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
2024.04.03 18:02:36 ERROR Failed to fetch mtags for 2.12.7
Error downloading org.scalameta:mtags_2.12.7:1.2.2
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://repo1.maven.org/maven2/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://oss.sonatype.org/content/repositories/public/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: https://oss.sonatype.org/content/repositories/snapshots/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
2024.04.03 18:02:36 ERROR Failed to fetch mtags for 2.12.7
Error downloading org.scalameta:mtags_2.12.7:1.2.2
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://repo1.maven.org/maven2/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: /Users/$USER/.ivy2/local/org.scalameta/mtags_2.12.7/1.2.2/ivys/ivy.xml
  not found: https://oss.sonatype.org/content/repositories/public/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
  not found: https://oss.sonatype.org/content/repositories/snapshots/org/scalameta/mtags_2.12.7/1.2.2/mtags_2.12.7-1.2.2.pom
2024.04.03 18:02:37 INFO  time: indexed workspace in 3.76s
2024.04.03 18:02:37 WARN  no build target for: /Users/$USER/code/universe/ratelimit-v2/sidecar/src/SidecarBackend.scala

My config (I still use packer):

  use {
    "scalameta/nvim-metals",
    requires = {
      "nvim-lua/plenary.nvim",
    },
    config = function()
      local metals_config = require("metals").bare_config()
      metals_config.on_attach = function(client, bufnr)
        client.server_capabilities.semanticTokensProvider = nil
      end
      metals_config.useGlobalExecutable = true
      local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
      vim.api.nvim_create_autocmd("FileType", {
        pattern = { "scala", "sbt", "java" },
        callback = function()
          require("metals").initialize_or_attach(metals_config)
        end,
        group = nvim_metals_group,
      })
    end
  }

Expected behavior

I expect auto-complete/go-to-def/hover-help to work for imported files (both same and different bazel targets). It would be good to make it work for external dependencies (like when we import guava cache etc) but I am building my config incrementally and haven't gotten there yet.

Operating system

macOS

Version of Metals

1.2.2

Commit of nvim-metals

4f9bf0c821092f20dd34c1a4ea5b07b0500ff089

ckipp01 commented 3 months ago

So the issue here is that 2.12.7 is very old. You'll want to update your Scala version to a newer 2.12 version. For example the latest is 2.12.19. This should be an easy version bump.

SuyogSoti commented 3 months ago

Unfortunately, I am in a corporate environment where this is not easy and requires a large organizational effort. Are there any good work arounds?

ckipp01 commented 3 months ago

I'm sorry to hear that, but not really. In order for Metals navigation to work, it needs semanticdb to be produced. In order for that to work, you need scalameta to be available and for you old version Scalameta isn't even published anymore. Meaning that all newer versions of Metals won't work. You could maybe try an old version of Metals that uses an older version of scalameta.