lukas-reineke / lsp-format.nvim

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

tempfile fails to open #4

Closed lukas-reineke closed 3 years ago

lukas-reineke commented 3 years ago

Same here. I got the error message: Format error: ...o/.config/nvim/plugged/format.nvim/lua/format/format.lua:35: attempt to index local 'tempfile' (a nil value)

Originally posted by @pulcinello in https://github.com/lukas-reineke/format.nvim/issues/3#issuecomment-717914995

elianiva commented 3 years ago

I also got this message if I use ~ as a shorthand for home directory. The solution is to replace it with os.getenv("HOME").."/rest/of/directory".

ndreas commented 3 years ago

You also get this error when the file is in the same directory as the buffer's current path. I stumbled upon this when I tried the plugin, and I use set autochdir. The result here: https://github.com/lukas-reineke/format.nvim/blob/master/lua/format/format.lua#L30 will in that case be an empty table, and the generated temporary filename will be located in the filesystem root.

lukas-reineke commented 3 years ago

Thanks for the debugging I pushed a fix

ndreas commented 3 years ago

Thanks for the debugging I pushed a fix

That was fast! I was just about to create a PR :smile_cat: It works for me, and I got a bonus debug print statement :stuck_out_tongue_closed_eyes: https://github.com/lukas-reineke/format.nvim/commit/d4a9f7eac93320503267b5b0c32b7291aa7286f8#diff-b05a6a67438ba15eb301bf4568205cbd072768999217c5f3b379e07fafb9de3fR37

lukas-reineke commented 3 years ago

and I got a bonus debug print statement

:facepalm: fixed