I am thinking about improving UX working with `pan...
# development
f
I am thinking about improving UX working with
pants.toml
in VSCode and, potentially, in PyCharm (depends on the tooling available). ๐Ÿงต
when editing the file, there's no context and no help, so 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. I am vaguely familiar with JSON schemas and know there's a website with lots of schemas for various tools: JSON Schema Store. The idea is that when you work on a configuration file such as YAML or JSON for a tool, you get context help, suggestions, and immediate validation. I am hoping to build such a JSON schema, and publish it to the server so that it becomes available for everyone. Schema should ideally be created programmatically and 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. I attach a gif to illustrate the point and the schema file used to produce the demo.
pants-schema.gif
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/>)"
    ]
  }
}
b
I saw a toml LSP at some point. Presumably that took in a schema
In the new year, I'm hoping to slice time for a Pants LSP, which would include
pants.toml
and
BUILD
LSP-ing
f
b
https://taplo.tamasfe.dev/ yup thats what I was thinking
OK carry on ๐Ÿ˜›
f
written in Rust ๐Ÿ˜„
๐Ÿฆ€ 3
it would of course be fundamental work to get LSP / BSP thing, but how realistic is it that we'll have something rather soon. The schema file, in contrast, seems to be lightweight and cheap to maintain, I think? FWIW, it works OOTB with a JSON schema file in PyCharm:
b
Being able to generate a schema is a precursor, so please be my guest ๐Ÿ™‚
f
image.png
Being able to generate a schema is a precursor, so please be my guest
Oh I see, gotcha. I thought an LSP solution would eliminate the need for the JSON schema file
if that's a green light, let me experiment getting a minimal schema generated from the
help-all
JSON data (I'll likely need to extend the Python code used to generate the help) to produce a schema instead
b
CC @wide-midnight-78598 since this sounds like the bash autocomplete
Alternatively we could try and
export
it, but I suspect there's a reason that wouldn't work
h
./pants help-all
could spit out that schema, I reckon?
It has all the necessary information
f
./pants help-all could spit out that schema, I reckon?
yes, indeed! I'll see what will be more convenient -- parsing the JSON output or creating a new subcommand to get the schema constructed conveniently in Python code instead
๐Ÿ™Œ 1
I've created https://github.com/pantsbuild/pants/issues/17895 and signed up ๐Ÿ™‚
w
Woooooot!
For the bash completions, we hook into "something" (literally something, as I want to
export
, but that has no access to
help
, so it's a
BuiltInGoal
- and parsing is pretty simple.
Actually, that PR wasn't merged yet - so still in a build-support: https://github.com/pantsbuild/pants/blob/main/build-support/bin/generate_completions.py