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

How to set cwd on formatter? #588

Closed
marcinjahn opened this issue Nov 28, 2024 · 5 comments
Closed

How to set cwd on formatter? #588

marcinjahn opened this issue Nov 28, 2024 · 5 comments

Comments

@marcinjahn
Copy link

marcinjahn commented Nov 28, 2024

I'm struggling with providing a valid config for csharpier:

return {
  "stevearc/conform.nvim",
  optional = true,
  opts = {
    formatters_by_ft = {
      cs = { "csharpier" },
    },
    formatters = {
      csharpier = {
        cwd = require("conform.util").root_file(".csproj"),
        command = "dotnet csharpier",
        args = { "--write-stdout" },
      },
    },
  },
}

By default, conform uses csharpier from mason, but I'd rather want to use the version configured in a project that I'm working on, therefore I want to invoke dotnet csharpier from the directory where my project is located (.csproj).
What am I doing wrong?

:ConformInfo shows:

Formatters for this buffer:
LSP: roslyn
csharpier unavailable: Command not found
@stevearc
Copy link
Owner

stevearc commented Dec 3, 2024

The built-in formatter for csharpier uses the command dotnet-csharpier

command = "dotnet-csharpier",
args = { "--write-stdout" },
stdin = true,

It's actually important that the command is a single word, the name of the executable to be run. If this is actually invoked via dotnet csharpier (I'm not familiar with this tool), then you should change the configuration to be

command = "dotnet",
args = { "csharpier", "--write-stdout" },

@stevearc stevearc added the question Further information is requested label Dec 3, 2024
@marcinjahn
Copy link
Author

Right, it’s actually the same tool, the difference is that dotnet-csharpier invokes the version installed by mason(which for some reason is rather old), while ‚dotnet csharpier’ runs the version installed locally for a given project (via ‚dotnet tool’ utility).

to invoke the proper version of csharpier I need to invoke ‚dotnet tool’ from within the same directory where my .csproj is located.

@github-actions github-actions bot removed the question Further information is requested label Dec 3, 2024
@stevearc
Copy link
Owner

stevearc commented Dec 3, 2024

Did you try my suggestion?

@stevearc stevearc added the question Further information is requested label Dec 3, 2024
@marcinjahn
Copy link
Author

It seems to work fine after applying your suggested config. I did not set any cwd. What is the command's directory by default?

@github-actions github-actions bot removed the question Further information is requested label Dec 13, 2024
@stevearc
Copy link
Owner

If the cwd is not specified in the formatter config, it will default to Neovim's cwd (:echo getcwd())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants