Skip to content

feat(init): plugin options, preferred plugins, and adding above existing plugins - #1356

Merged
dsherret merged 9 commits into
mainfrom
feat/init-options-and-preferences
Oct 18, 2026
Merged

dsherret merged 9 commits into
mainfrom
feat/init-options-and-preferences

Conversation

@dsherret

@dsherret dsherret commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Extends the interactive dprint init so plugins can be ordered and configured while selecting them, and so the plugins someone always wants can be remembered.

What changes for users

Plugin picker (dprint init)

  • Selected plugins are kept at the top in the order they'll be written to the config file. Selecting a plugin moves it up to its place; shift+↑/↓ reorders the selected ones.
  • Type to filter the list. Page up and page down work.
  • → opens a plugin to choose which of its file extensions and file names it formats, and to set its options. The options come from the plugin's schema, so the plugin is only downloaded the first time it's opened, and leaving before that finishes cancels the download. An option is written once it's given a value, even when that's its default, and del clears it again so the default applies. The options shown are those of the version that will be written, so --minimum-dependency-age holds them back too.
  • The prompts are drawn again when the terminal is resized (debounced). A terminal that's too small for a prompt says so until it's made bigger.

Existing config file

  • Running dprint init where a config file already exists offers the plugins it doesn't have yet. The file's plugins are listed first and can't be unselected, including ones that aren't in the plugin info file (ex. a local ./custom.wasm), so a new plugin can be moved above any of them.
  • A new plugin moved above an existing one is inserted before it in the file's plugins array instead of being appended.

Preferred plugins (dprint init --preferences)

  • Shows only a "plugins to prefer" screen and saves the selection, its order, and each plugin's files and options to init.json in the global config directory. Nothing is initialized.
  • From then on dprint init starts out with those choices for the preferred plugins and puts them ahead of the others that format the same files, in that order. A preferred plugin is pre-selected when one of its files is in the project (even if another plugin would otherwise claim it, or it's marked neverPreselect), but not otherwise. Preferred plugins are marked with ★ in the picker either way.
  • Plain dprint init never writes init.json, and remembered choices aren't applied to plugins a config file already has.
  • Conflicts with --yes and --global, and needs an interactive terminal.

Implementation notes

  • PromptTerminal is a new trait the multi-select and the new settings editor draw on and read keys from. A scripted implementation drives them in tests.
  • crates/dprint/tests/specs/init/*.txt are spec tests: each has a key script and the screen after every step, plus the files that were written. Regenerate with UPDATE=1 cargo test -p dprint --bin dprint -- init_specs.
  • read_terminal_key_press now returns a debounced Event::Resize as well as key presses, and returns read errors instead of retrying forever. This also makes the existing confirm and select prompts redraw on resize.

Known limitations

  • The default shown for an option doesn't account for the config file's top-level values (ex. a global lineWidth) or a plugin's scaffolded default config. Giving the option a value writes it either way.
  • A corrupt init.json is read as empty with a warning, and is replaced on the next save from --preferences.
  • --preferences silently ignores --config and --minimum-dependency-age.
  • On some Unix terminals alt+↑/↓ arrives as escape, which cancels; shift+↑/↓ works everywhere.
  • Narrowing the terminal can leave stray lines above the prompt, since the terminal re-wraps what was drawn before it's cleared.
  • The website docs don't cover the new flag yet.

- write an option that's set to its default and clear it with delete
- say when the terminal is too small for a prompt
- count rows instead of lines in the options editor's scroll indicators
- show the options of the version the minimum dependency age allows
- don't offer a plugin that an inherited config file already has
- only treat a schema enum as a boolean when it allows both values
- test the resize debounce
Also keeps an `associations` that's a single pattern when files are left out.
- add carriage returns to logs written while a key is read in raw mode
- read init.json without creating the global config directory
- show a config file's plugins the info file doesn't know about
- only look up a plugin's entry and options once while prompting
- read the config file once and share the warning for unresolved plugins
@dsherret
dsherret merged commit e28a6f6 into main Oct 18, 2026
22 of 23 checks passed
@dsherret
dsherret deleted the feat/init-options-and-preferences branch October 18, 2026 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant