mhartington / formatter.nvim

MIT License
1.36k stars 142 forks source link

Python "isort" is ignoring the project configuration #233

Open exhuma opened 1 year ago

exhuma commented 1 year ago

Which configuration? Type (custom or builtin): builtin Filetype: python Formatter: isort

Configuration(s) (post all the variants you tried):

     require('formatter').setup(
         {
             logging = true,
             log_level = vim.log.levels.WARN,
             filetype = {
                 python = {
                     require("formatter.filetypes.python").black,
                     require("formatter.filetypes.python").isort,
                 },
                 ["*"] = {
                     require("formatter.filetypes.any").remove_trailing_whitespace
                 }
             }
         }
     )

Expected behavior

The formatter should run isort with the project configuration (this is the default isort behaviour)

Actual behaviour

Runs isort with the default config even if a configuration file exists in the project root.

Additional context /

JamesDevlin5 commented 1 year ago

Is vim in the project directory when you run the formatter; is the output of :pwd<CR> the project directory

JamesDevlin5 commented 1 year ago

Actually, this looks similar to #218

exhuma commented 1 year ago

I can confirm that :pwd shows the correct path. That is, the root of the project which contains the isort config.

JamesDevlin5 commented 1 year ago

Ok it's because the stdin option copies everything to a temp file first, so isort things the project directory is the temp dir or something.

If you change the line about requiring isort,

require("formatter.filetypes.python").isort,

to

function()
  local util = require("formatter.util")
  return {
    exe = "isort",
    args = {
      "--quiet",
      "--",
      util.escape_path(util.get_current_buffer_file_path())
    },
    stdin = false
  }
end,

that should fix it

exhuma commented 1 year ago

Unfortunately this still ignores the config :(