Neovim + lsp + formatter (again)

This is a common topic, but I find quite hard to find up to date information online. Indeed, the official wiki is very old.
There are some information in this post and on lspconfig that can be adapted to nvim 0.11 and make it work. Great.

My question is how to configure Julia Formatter inside the LSP. Is this possible without external plugins (e.g. conform)?

I tried to put

    settings = {
        julia = {
            format = {
                enable = true,
                yas_style_nesting = true,
                indent = 4,
            },
        },
    }

in my julials.lua, but I don’t get the desired Yas Style behavior. Does anybody know how to add JuliaFormatter options for vim.lsp.buf.format()?

1 Like

Roughly, the pipeline is like this:


The depend arrow. Upon installing the julials server of nvim-lspconfig as instructed here, one should have a folder

~/.julia/environments/nvim-lspconfig

which looks like

.
├── Manifest.toml
└── Project.toml

and inside Manifest.toml, one can find an entry [[deps.JuliaFormatter]], which means that the language server depends on JuliaFormatter to do the LSP formatting.

So, to configure the formatting of this LSP, rather than controlling the behavior of some NeoVim plugin, one actually needs to configure the behavior of the JuliaFormatter.jl package.


The config arrow. In the docs of JuliaFormatting.jl, there is a section on how to use .JuliaFormatter.toml files to config the package. The project directory needs to have this dotfile and a Project.toml file (the latter is required!).

Note also that, once it sees a Project.toml, JuliaFormatter regards this as the root of its working directory, and stops searching for config files higher on the tree. See this issue, for example, and this post.

1 Like

This makes sense, but I mostly work with single files, so I don’t have any toml in my directories, usually. I tried to put a .JuliaFormatter.toml directly in the nvim-lspconfig with some non-standard configuration, but it seems that it is not read while I try to vim.lsp.buf.format()

I’ve actually realized that some options work, e.g. vim.lsp.buf.format({formatting_options={tabSize=2}}) is like passing indent=2. The available options are defined in src/protocol/formatting.jl. Does it make sense to make a PR to add other available options there? I think only such file and src/request/features.jl need to be updated. I’d love the be able to change the style option on the fly without resorting to project files.