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

cli formatter can not get the source file name #4273

Closed
ttys3 opened this issue Oct 14, 2022 · 1 comment
Closed

cli formatter can not get the source file name #4273

ttys3 opened this issue Oct 14, 2022 · 1 comment
Labels
C-enhancement Category: Improvements

Comments

@ttys3
Copy link
Contributor

ttys3 commented Oct 14, 2022

this PR #2942 added cli formatter support, this is great.

but in some formatters need the file path to location a config in the project (stylua) or use it to determine the file type (prettier),

in neovim we can use vim.api.nvim_buf_get_name(0) to get the current buf file path, but in hexlix seems no way to do so.

for example:

style:

--stdin-filepath Specify the location of the file that is being passed into stdin. Ignored
if not taking in input from stdin. This option is only used to help
determine where to find the configuration file

require("formatter").setup {
	filetype = {
		javascript = {
			-- prettier
			function()
				return {
					exe = "prettier",
					args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
					stdin = true,
				}
			end,
		},
		lua = {
			-- stylua
			function()
				return {
					exe = "stylua",
					args = { "--search-parent-directories", "--stdin-filepath", vim.api.nvim_buf_get_name(0), "-" },
					stdin = true,
				}
			end,
		},
	}
}
@ttys3 ttys3 added the C-enhancement Category: Improvements label Oct 14, 2022
@ttys3
Copy link
Contributor Author

ttys3 commented Oct 14, 2022

close due to duplicated with #3596

@ttys3 ttys3 closed this as completed Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

1 participant