scalameta / nvim-metals

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

metals root detected in a subfolder #671

Closed gersonsosa closed 2 months ago

gersonsosa commented 2 months ago

Describe the bug

Today while importing my scala project I noticed it failed with the latest version of nvim-metals, I think this commit https://github.com/scalameta/nvim-metals/commit/72f47336a4515c75b123611ee1fa6070543a69bf now makes it detect the root of the project deeper than before.

I have a setup similar to the one in the docs https://github.com/scalameta/nvim-metals/blob/72f47336a4515c75b123611ee1fa6070543a69bf/doc/metals.txt#L945-L965

build.gradle.kts <- this is the desired root
    a/
        build.gradle.kts <- subproject, not the desired root (detected as root by the current version)
        b/
           build.gradle.kts <- subproject, not the desired root
           src/main/scala/Main.scala

by reading the docs and the code I guess I could try to use find_root_dir_max_project_nesting setting, but if I try to pass find_root_dir_max_project_nesting it's reported as an invalid option, am I missing something?

As a workaround I set this https://github.com/scalameta/nvim-metals/blob/72f47336a4515c75b123611ee1fa6070543a69bf/lua/metals/config.lua#L328 to 2

What would be the right way to fix this? I don't see why adding build.gradle.kts detect my root in a nested folder rather than the root.

Expected behavior

The root of the project to be detected

build.gradle.kts <- this is the desired root
    a/
        build.gradle.kts <- subproject, not the desired root
        b/
           build.gradle.kts <- subproject, not the desired root
           src/main/scala/Main.scala

or the ability to use the find_root_dir_max_project_nesting setting

Operating system

macOS

Version of Metals

v1.3.0

Commit of nvim-metals

72f47336a4515c75b123611ee1fa6070543a69bf

gersonsosa commented 2 months ago

this issue can be closed, after the suggestion by @ckipp01 I set the setting find_root_dir_max_project_nesting directly under the config object rather than under config.settings and that works

antonpaule commented 3 weeks ago

If you have a unique project build setup with subprojects, etc., you can also set the config.find_root_dir function. Here is a little example to set the root to the current working directory:

local metals_config = require("metals").bare_config()
metals_config.find_root_dir = function ()
  return vim.fn.getcwd()
end