Skip to content

Support stdin + stdout formatting with external formatters #15393

Description

@kevinushey

From discussion with @DavisVaughan, we should:

  • Require formatters to receive code on stdin, and produce output on stdout;
  • Use <formatter> - when attempting to format some code selection, or code not associated with any file;
  • Use <formatter> --stdin-filepath <path> when formatting a file / code associated with a file.

Activity

  1. added
    new
    on Nov 1, 2024
  2. DavisVaughan commented on Nov 1, 2024

    @DavisVaughan

    Few more thoughts:

    • Possibly give {file_path} as an optional injection that the external command could use, like the user would set the command to be thing format --stdin-filepath {file_path}
    • Think about where the command is run from - the project directory or the file path directory? This is relevant for lookup of a configuration file. I think if --stdin-filepath {file_path} is provided then configuration file lookup would start from {file_path} and look upwards from there. But if just thing format - is provided then we'd start from the current directory that the formatter is launched from
    • Its possible that range formatting could "just work" with this stdin/stdout approach, where RStudio only streams a segment of the file over stdin (not sure if that would conflict with line length configuration settings though, its possible that the right way to do it is to provide both the entire file and a range within that file to format, so the formatter has access to everything)

    Zed has a nice section on external formatters to pull ideas like these from https://zed.dev/docs/configuring-zed#formatter

    Screenshot 2024-11-01 at 11 50 11 AM
  3. added this to the Mariposa Orchid milestone on Nov 15, 2024
  4. removed
    new
    on Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions