julia formatter ignores config file one folder out
Description
The documentation of the Julia formatter states that directories will be search up from the current directory for a configuration file. However, that does not seem to be happening with the neovim formatter. I'm using LazyVim based on neovim 0.11.1 on macOS with Julia's LanguageServer.jl v4.5.1.
I have
dir/.JuliaFormatter.toml
dir/subdir/file.jl
If I cd to dir/subdir and edit file.jl, formatting the file applies the default formatting options (e.g., indent with 4 spaces). If I copy file.jl to the parent directory, and repeat, the settings in .JuliaFormatter.toml are applied (e.g., indent with 2 spaces).
Formatting directly from Julia works as advertised:
julia> add Pkg
julia> using Pkg
julia> Pkg.add("JuliaFormatter")
julia> using JuliaFormatter
julia> format("file.jl") # applies settings in ../.JuliaFormatter.toml
Here are a .JuliaFormatter.toml
indent = 2
and file.jlto reproduce:
function f()
return 1 # default indent is 4
end
As far as I understand, LazyVim imports nvim-lspconfig, but does not pass any options. I did not change the default options either.
Wondering if I'm missing some configuration option or if others can reproduce.
Thank you in advance!
The config is a single file, you can inspect it:
https://github.com/neovim/nvim-lspconfig/blob/master/lsp/julials.lua
This repo is just a collection of user-provided configs. We don't provide support for the 1000s of configs here.
I've been helping @dpo figure out how the different pieces are working together to create this inconsistency. One conclusion is that, for Julia, I think the root marker search should proceed down from the working dir rather than up from the file dir. The reason is that it's fairly common to have nested Julia environments where the outermost one defines the project as a whole, and the nested ones are derivative in some way. By my interpretation of how workspaceFolders is meant to be used, they correspond to the outermost/global project root. (See https://code.visualstudio.com/docs/editing/workspaces/workspaces; the LSP notion of workspaces is closely tied to the VSCode one.)
If folks agree, I can make a PR to implement this logic via root_dir. Not sure how the decision-making works here?
sure, PR welcome. though I think @bfredl @clason use julia and maybe they can give a +1
I've been helping @dpo figure out how the different pieces are working together to create this inconsistency. One conclusion is that, for Julia, I think the root marker search should proceed down from the working dir rather than up from the file dir. The reason is that it's fairly common to have nested Julia environments where the outermost one defines the project as a whole, and the nested ones are derivative in some way. By my interpretation of how
workspaceFoldersis meant to be used, they correspond to the outermost/global project root. (See https://code.visualstudio.com/docs/editing/workspaces/workspaces; the LSP notion of workspaces is closely tied to the VSCode one.)If folks agree, I can make a PR to implement this logic via
root_dir. Not sure how the decision-making works here?
Did you get around to hashing this out @danielwe ? We talked about it on discourse and I'm right now manually just handling the language server. The main problem is now that my LS doesn't know anything about the project I'm working in. As such it would be be nice to tie this up in nvim-lspconfig as well since I am having issues understanding how the root_dir is supposed to work. Thanks for all the hints so far. It's been very helpful.
No, unfortunately, I've been doing less Julia and more just writing lately. Hope to get around to this eventually if no one else does so first, but not until after some upcoming deadlines. (Not that it would be a big thing, I just haven't thought about it in a while and right now isn't the best time to dive back in.)