lukas-reineke / lsp-format.nvim

A wrapper around Neovims native LSP formatting.
564 stars 27 forks source link

temporary file directory #2

Closed elianiva closed 3 years ago

elianiva commented 3 years ago

Is it possible to specify a directory for the temporary file? Currently it saves it on the same directory of the file that gets formatted then delete it. This causes issue with an SPA framework that uses filesystem routing (Sapper in my case) and watching for file change. So when the temporary files created, it throws an error because it's not a valid file extension for Sapper and it refresh the page several times (when the tmp files got created and deleted).

I'd like to be able to set the directory for the tmp files, e.g ~/.config/nvim/tmp/ so it doesn't cause this issue. Maybe let user specify it in the setup? Thanks!

lukas-reineke commented 3 years ago

:+1: makes sense. Pushed to master now, you can add tempfile_dir as an option.

elianiva commented 3 years ago

Thankss!

elianiva commented 3 years ago

Welp, turns out this caused another issue. Prettier will not pick up the .prettierrc file because the formatting is done on a place where .prettierrc is not present (basically tempfile_dir). Guess I'll stick with current directory for tempfile even though it causes multiple refreshes. I don't know how hard is it to fix this.

lukas-reineke commented 3 years ago

You can configure the config path for prettier This should work if your working path is set up correctly.

require "format".setup {
    typescript = {
        {
            cmd = {
                function(file)
                    return string.format("prettier -w --config %s/.prettierrc %s", vim.fn.getcwd(), file)
                end
            },
            tempfile_dir = "/tmp"
        }
    }
}
elianiva commented 3 years ago

Oh, I forgot if prettier can specify a path to prettierrc. Thanks! It works like a charm.