Skip to content

Extend file formatters #174

@diegoiast

Description

@diegoiast

We have a POC, that calls clang-format. Lets make this extendable. Lets have the formaters in a config file. This could be updated independently of the IDE. Code for formatting now sits on the project manager, but could be moved to a new plugin.

Further updates:

  1. When formatting - stream the new formatted code from the indenter, modify in memory representation and then save.
  2. A new command to format the the current document on demand
  3. Download new definitions from github (?). We need to first use the built in, and then the ones in local config.
  4. User should be able to modify the config locally and add new indenters.
  5. Some GUI to at least see the configuration.
[
  {
    "name": "clang-format",
    "exts": ["c", "h", "cpp", "hpp", "cc", "cxx"],
    "binary": "clang-format",
    "standalone": false,
    "toolchain": "LLVM / Clang",
    "args": ["-style=file", "-fallback-style=none", "-i", "$filepath"]
  },

  {
    "name": "dotnet-format",
    "exts": ["cs"],
    "binary": "dotnet",
    "standalone": false,
    "toolchain": ".NET SDK",
    "args": ["format", "$filepath"]
  },

  {
    "name": "gofmt",
    "exts": ["go"],
    "binary": "gofmt",
    "standalone": false,
    "toolchain": "Go toolchain",
    "args": ["-w", "$filepath"]
  },

  {
    "name": "rustfmt",
    "exts": ["rs"],
    "binary": "cargo",
    "standalone": false,
    "toolchain": "Rust toolchain",
    "args": ["fmt", "--", "$filepath"]
  },

  {
    "name": "black",
    "exts": ["py"],
    "binary": "black",
    "standalone": false,
    "toolchain": "Python (pip package)",
    "args": ["$filepath"]
  },

  {
    "name": "google-java-format",
    "exts": ["java"],
    "binary": "google-java-format",
    "standalone": true,
    "args": ["-i", "$filepath"],
    "downloads": {
      "linux-amd64": "https://github.com/google/google-java-format/releases/latest/download/google-java-format_linux-x86_64",
      "windows-amd64": "https://github.com/google/google-java-format/releases/latest/download/google-java-format_windows-x86_64.exe",
      "macos-amd64": "https://github.com/google/google-java-format/releases/latest/download/google-java-format_osx-x86_64"
    }
  },

  {
    "name": "prettier",
    "exts": ["js", "jsx", "ts", "tsx", "json", "css", "html"],
    "binary": "prettier",
    "standalone": false,
    "toolchain": "Node.js (npm package)",
    "args": ["--write", "$filepath"]
  },

  {
    "name": "shfmt",
    "exts": ["sh", "bash"],
    "binary": "shfmt",
    "standalone": true,
    "args": ["-w", "$filepath"],
    "downloads": {
      "linux-amd64": "https://github.com/mvdan/sh/releases/latest/download/shfmt_linux_amd64",
      "windows-amd64": "https://github.com/mvdan/sh/releases/latest/download/shfmt_windows_amd64.exe",
      "macos-amd64": "https://github.com/mvdan/sh/releases/latest/download/shfmt_darwin_amd64"
    }
  },

  {
    "name": "ktlint",
    "exts": ["kt", "kts"],
    "binary": "ktlint",
    "standalone": true,
    "args": ["-F", "$filepath"],
    "downloads": {
      "linux-amd64": "https://github.com/pinterest/ktlint/releases/latest/download/ktlint",
      "windows-amd64": "https://github.com/pinterest/ktlint/releases/latest/download/ktlint.exe",
      "macos-amd64": "https://github.com/pinterest/ktlint/releases/latest/download/ktlint"
    }
  },

  {
    "name": "dart format",
    "exts": ["dart"],
    "binary": "dart",
    "standalone": false,
    "toolchain": "Dart SDK",
    "args": ["format", "$filepath"]
  },

  {
    "name": "swift-format",
    "exts": ["swift"],
    "binary": "swift-format",
    "standalone": true,
    "args": ["-i", "$filepath"],
    "downloads": {
      "linux-amd64": "https://github.com/apple/swift-format/releases/latest/download/swift-format-linux",
      "macos-amd64": "https://github.com/apple/swift-format/releases/latest/download/swift-format-macos"
    }
  },

  {
    "name": "cmake-format",
    "exts": ["cmake"],
    "binary": "cmake-format",
    "standalone": false,
    "toolchain": "Python (pip package)",
    "args": ["-i", "$filepath"]
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Text editorIssues related to the text editor pluginenhancementNew feature or requestgood first issueGood for newcomers

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions