Add code_actions
as formatter
type (#10121)
This fixes #8992 and solves a problem that ESLint/Prettier/... users have been running into: They want to format _only_ with ESLint, which is *not* a primary language server (so `formatter: language server` does not help) and it is not a formatter. What they want to use is what they get when they have configured something like this: ```json { "languages": { "JavaScript": { "code_actions_on_format": { "source.fixAll.eslint": true } } } } ``` BUT they don't want to run the formatter. So what this PR does is to add a new formatter type: `code_actions`. With that, users can only use code actions to format: ```json { "languages": { "JavaScript": { "formatter": { "code_actions": { "source.fixAll.eslint": true } } } } } ``` This means that when formatting (via `editor: format` or on-save) only the code actions that are specified are being executed, no formatter. Release Notes: - Added a new `formatter`/`format_on_save` option: `code_actions`. When configured, this uses language server code actions to format a buffer. This can be used if one wants to, for example, format a buffer with ESLint and *not* run prettier or another formatter afterwards. Example configuration: `{"languages": {"JavaScript": {"formatter": {"code_actions": {"source.fixAll.eslint": true}}}}}` ([#8992](https://github.com/zed-industries/zed/issues/8992)). --------- Co-authored-by: JH Chabran <jh@chabran.fr> Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
654504d5ee
commit
eb231d0449
3 changed files with 131 additions and 85 deletions
|
@ -241,7 +241,8 @@ pub struct LanguageSettingsContent {
|
|||
///
|
||||
/// Default: false
|
||||
pub always_treat_brackets_as_autoclosed: Option<bool>,
|
||||
/// Which code actions to run on save
|
||||
/// Which code actions to run on save after the formatter.
|
||||
/// These are not run if formatting is off.
|
||||
///
|
||||
/// Default: {} (or {"source.organizeImports": true} for Go).
|
||||
pub code_actions_on_format: Option<HashMap<String, bool>>,
|
||||
|
@ -292,6 +293,8 @@ pub enum FormatOnSave {
|
|||
/// The arguments to pass to the program.
|
||||
arguments: Arc<[String]>,
|
||||
},
|
||||
/// Files should be formatted using code actions executed by language servers.
|
||||
CodeActions(HashMap<String, bool>),
|
||||
}
|
||||
|
||||
/// Controls how whitespace should be displayedin the editor.
|
||||
|
@ -325,6 +328,8 @@ pub enum Formatter {
|
|||
/// The arguments to pass to the program.
|
||||
arguments: Arc<[String]>,
|
||||
},
|
||||
/// Files should be formatted using code actions executed by language servers.
|
||||
CodeActions(HashMap<String, bool>),
|
||||
}
|
||||
|
||||
/// The settings for inlay hints.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue