-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[WIP] Add option documentation to :set-option, :get-option. #6174
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why store the options in runtime/
as TOML? We know all options at compilation time so it should be possible to describe them using types and/or constants
I had the same question (listed above), any tradeoffs to consider here? I look at something like If not, I'll move it into a constant -- seems a lot easier to work with (e.g., not having to worry about whether it loads). |
The configuration in A large binary size was a problem in the past but that was mostly about tree-sitter parsers being built in to the Helix binary (see #432). I don't think the binary size change would be very noticeable from adding option docs |
While I like the general direction of providing a better user experience I would prefer if we could auto generate the data from doc comments (and update those to match the documentation once). I have been thinking that we could use the use schemars::gen::SchemaGenerator;
use schemars::JsonSchema;
#[derive(JsonSchema)]
/// Hello Foo
struct Foo {
/// Hello Bar
pub bar: String,
}
#[test]
fn test_schmema() {
let mut schema = Foo::json_schema(&mut SchemaGenerator::default()).into_object();
assert_eq!(schema.metadata().description.as_deref(), Some("Hello Foo"));
assert_eq!(
schema.object().properties["bar"]
.clone()
.into_object()
.metadata()
.description
.as_deref(),
Some("Hello Bar")
);
} Just like serde |
Yeah! I was looking for something to simply give me the doc comments but it all seemed really complicated. Didn't consider extracting a schema first and traversing that. I really like this idea, let me spend some time on it over the coming days/weeks. |
@pascalkuthe I managed to get it working using the JsonSchema trait -- it's very cool. The code is super rough right now, and doesn't hit a ton of cases, but works for all top level booleans and numerics, as well as enums with simple variants (e.g.,
Overall I'm a bit torn, I love the code being the source of truth, but I wouldn't want it to be harder to expand the configuration structures in the future, especially if someone tries to do that and then has to look at all the struct->JsonSchema->magic->runtime_options::Options heroics I may have to do to get this to where I want it. |
I would want to keep it simple too so we shouldn't write some complex magic to extract the description. That being said, I think
If I understand what you mean here correctly than I think unwrapping is fine since the schema is essentially hardcoded. That said you shouldn't need unwrap for the mostpar. |
Ah, good idea. I haven't looked to see what annotations they support but you're right I could implement JsonSchema myself rather than juggle the bits on the scanning side. I'll find some time in the coming days to keep poking at this, thanks for the thoughts. 👍🏼 |
2893dde
to
f61ef53
Compare
@pascalkuthe I spent a bit more time on this trying to adapt JsonSchema to some of the special-case config options that exist in the project and I'm about ready to give up and pivot to something more structured (such as a trait implementation we can create for each runtime-configurable pile of settings). These edge cases (like auto-pairs accepting boolean values, but not really being a bool) are really rough to work with within the JsonSchema hierarchies and produce piles of code as a result. I'm curious for your thoughts here on whether something simpler is a good interim step until someone with more stamina wants to chase this down? This branch can export the full JSON schema of the config object, I'm not sure if that's useful for #3901 or if it has all the same edge cases. |
I'm going to close this out for now. IMO, the JsonSchema stuff, while interesting, is a ton of work and potentially breaks some of the config modeling. I'm going to pivot this to a statically defined approach (as @the-mikedavis mentioned) when I have some cycles to work on it. |
@askreet did u continue this in some other pr? |
@goyalyashpal I haven't. Feel free to pick it up if interested, there's some generally useful bits here for either approach. |
Closes #5938.Oops, I mean closes #5939.Looking for some early feedback on approach here. The idea is that we move the options from
configuration.md
into a structured format that can be used both by docgen and the help built into the editor.When combined with #5966 (which suppresses autocomplete for the second argument) this is the user experience:
If this general direction gets a few 👍, I would do the following before merge:
configuration.md
to be some sort of template that can pull sections of options fromruntime_options::Options
and build the tables dynamically.Some open questions I have:
doc_fn: Option<Fn...>
to TypedCommand?===
line, instead of replacing it?Lazy<Result<...>>
for the reference toruntime_options::Options
is defensive against the runtime directory not havinghelp/options.toml
. Is this a good approach? Alternatives?Potential future roadmap: