<#17895 Publish a JSON schema for pants.toml file ...
# github-notifications
q
#17895 Publish a JSON schema for pants.toml file to be used in IDEs Issue created by AlexTereshenkov Is your feature request related to a problem? Please describe. When editing the
pants.toml
in an IDE such as VSCode or PyCharm, there's no context shown (as hover hints) and no help about available sections and options. One has to consult the online docs to see what type an option is and what are the valid values. It's not terrible, but could be improved. For tools that provide some sort of configuration via YAML or JSON, it's fairly common to use JSON schemas to provide extra context for the person editing the configuration file and instant validation feedback. The JSON Schema Store is serving many schemas that IDEs can pick up: see Using schemas from JSON Schema Store in PyCharm and JSON schemas and settings in VSCode. VSCode users should be able to use any plugin that is capable of using the schema for TOML files, e.g. Even Better TOML and PyCharm comes with support for JSON schema OOTB. Describe the solution you'd like We shall build such a JSON schema, and publish it to the store so that it becomes available for every Pants user. Schema should be created programmatically; it looks like running
./pants help-all
should give us all the information we need in JSON format, so that the schemas could be updated between Pants version. It looks like it's common to have multiple schema files, one for each version. It's necessary to see what will be more convenient -- parsing the JSON output from the
help-all
or creating a new subcommand to get the schema constructed conveniently in Python code instead. Describe alternatives you've considered This seems to be a standard approach to providing a universal way to facilitate editing and validate configuration files. At some point, we are likely to add LSP support to improve the UX working with
BUILD
files and
pants.toml
and being able to generate a schema is a precursor to the LSP work. See this issue. Additional context An example JSON schema:
Copy code
{
  "$schema": "<http://json-schema.org/draft-07/schema#>",
  "description": "<https://www.pantsbuild.org/>",
  "properties": {
    "GLOBAL": {
      "description": "Options to control the overall behavior of Pants.",
      "type": "object",
      "properties": {
        "pants_version": {
          "description": "Use this Pants version.",
          "type": "string"
        },
        "level": {
          "description": "Set the logging level.",
          "type": "string",
          "enum": [
            "trace",
            "debug",
            "info",
            "warn",
            "error"
          ]
        },
        "pantsd": {
          "description": "Enables use of the Pants daemon (pantsd).",
          "type": "boolean"
        }
      }
    },
    "apache-thrift": {
      "description": "Apache Thrift IDL compiler.",
      "type": "object",
      "properties": {
        "thrift_search_paths": {
          "description": "A list of paths to search for Thrift.",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  },
  "required": [
    "GLOBAL"
  ],
  "title": "Schema for Pantsbuild pants.toml configuration file.",
  "type": "object",
  "x-taplo-info": {
    "authors": [
      "Pantsbuild (<https://www.pantsbuild.org/>)"
    ]
  }
}
A simple demo to exercise that schema in VSCode:

pants-schema

Using PyCharm:

image

pantsbuild/pants
❤️ 2