-
Notifications
You must be signed in to change notification settings - Fork 214
feature request: Support calling formatters with any callable binary path such as a container command #669
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
Comments
You are passing in the string I've made the ConformInfo more explicit to help make this issue more obvious |
Thanks, but that also fails. Here's what I put in: return {
{
"stevearc/conform.nvim",
opts = {
formatters_by_ft = {
python = { "black" },
},
formatters = {
black = {
command = "docker",
args = { "compose", "exec", "web", "black" },
},
},
},
},
} Here's the error:
It says it's not running but it is running. Here's what happens when I run the command from my terminal: $ docker compose exec web black .
reformatted /app/hello/app.py
All done!
1 file reformatted, 20 files left unchanged. As for the syntax I used, I took it from this example in the docs: require("conform").formatters.shfmt = {
inherit = false,
command = "shfmt",
args = { "-i", "2", "-filename", "$FILENAME" },
} |
Also if I use this: return {
{
"stevearc/conform.nvim",
opts = {
formatters_by_ft = {
python = { "black" },
},
formatters = {
black = {
command = "docker",
args = { "compose", "exec", "web", "black", "$FILENAME" },
},
},
},
},
} Which throws: Error: Invalid value for 'SRC ...': Path '/home/nick/src/github/docker-flask-example/hello/app.py' does not exist. Which makes sense because the absolute path doesn't exist in Docker. Is there a way to pass in the relative path, such as |
Yes, you will note that the built-in black formatter passes some args conform.nvim/lua/conform/formatters/black.lua Lines 9 to 14 in 09d4fba
You will need to replicate those args to get the formatter to work properly. You can use |
Thanks, that is working. I didn't find The last piece of the puzzle (if you don't mind), would be having Black inherit the root directory's Black's documentation says it should walk back directories until it finds one. In this case the file is available in the container but it never finds it when called this way. |
If you're open for it, I'd be happy to contribute a PR to document Maybe in the readme file to replace: -- A list of strings, or a function that returns a list of strings
-- Return a single string instead of a list to run the command in a shell
args = { "--stdin-from-filename", "$FILENAME" }, With: -- A list of strings, or a function that returns a list of strings
-- Return a single string instead of a list to run the command in a shell
-- $FILENAME contains the absolute path, $RELATIVE_FILENAME contains the relative path
args = { "--stdin-from-filename", "$FILENAME" }, The way I scanned the docs was by CTRL+f'ing it for "relative" and coming up empty. |
That would be the conform.nvim/lua/conform/formatters/black.lua Lines 15 to 18 in f005611
This is probably calculating an absolute path, so you'll need to figure out what path makes sense to pass to the docker command. I hadn't added docs about the magic strings thus far because I didn't really have a good place to put them, and most people don't need to interact with them. I think I can just stick them in a section in the README. |
I believe Yesterday when I reported that, I had only tested it with a docstring comment. |
Uh oh!
There was an error while loading. Please reload this page.
Did you check existing requests?
Describe the feature
I run all of my applications in Docker. That means tools like Black, Flake8, isort, Rubocop and friends are all inside of a container. They are not callable directly on my host machine where Neovim is installed.
I'd love to be able to do something like this (I'm using LazyVim):
Which would run Black in a container and pickup the custom
pyproject.toml
file in the root of the project with config settings for Black. If the container isn't running then it would silently fail.When I use the above configuration
:ConformInfo
saysblack unavailable: command not found
. Here is the full details:As a sanity check, I did install Black locally just to confirm my config is active and it does work, although it didn't pick up the
pyproject.toml
file in the project because it formatted my code with what I think are default Black settings but that's a separate concern.On the command line I would run
docker compose exec web black .
to run the formatter in an already running container, such as a web application. It works great and I have used this pattern for years for all types of formatters but I'd love to be able integrate these formatters in Neovim.What is the significance of this feature?
Cannot use this plugin without it.
The text was updated successfully, but these errors were encountered: