Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metals root detected in a subfolder #671

Closed
gersonsosa opened this issue May 1, 2024 · 2 comments
Closed

metals root detected in a subfolder #671

gersonsosa opened this issue May 1, 2024 · 2 comments

Comments

@gersonsosa
Copy link

Describe the bug

Today while importing my scala project I noticed it failed with the latest version of nvim-metals, I think this commit 72f4733 now makes it detect the root of the project deeper than before.

I have a setup similar to the one in the docs

nvim-metals/doc/metals.txt

Lines 945 to 965 in 72f4733

By default, when Metals detects a valid root_dir,
it will check 1 folder up to see if there is a
valid "parent" project above it. If you have a
more complex project with multiple nested sub-
projects, set the `find_root_dir_max_project_nesting`
key to an integer greater than 1.
Ex: Set `find_root_dir_max_project_nesting` to 2 if
this is your project tree:
build.sbt <- this is the desired root
a/
b/
- build.sbt <- subproject, not the desired root
- src/main/scala/Main.scala
If you need even more fine-grained control over
finding your root-dir (in cases where you have very
uncommon build layouts) you can also use the
`find_root_dir` key in the config to provide your
own custom function to find the root dir given a
starting dir and root patterns. _You more than likely
shouldn't need to do this_.

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

local find_root_dir_max_project_nesting = config.find_root_dir_max_project_nesting or 1
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

72f4733

@gersonsosa
Copy link
Author

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants