Add allow_rewrap
setting to control editor::Rewrap
behavior for a given language (#25173)
This PR adds a new `allow_rewrap` setting to control how `editor::Rewrap` behaves for a given language. This is a language setting, so it can either be configured globally or within the context of an individual language. For example: ```json { "allow_rewrap": "in_selections", "languages": { "Typst": { "allow_rewrap": "anywhere" } } } ``` There are three different values: - `in_comment`: Only perform rewrapping within comments. - `in_selections`: Only perform rewrapping within the current selection(s). - `anywhere`: Allow rewrapping anywhere. The global default is `in_comment`, as it is the most conservative option and allows rewrapping comments without risking breaking other syntax. The `Markdown` and `Plain Text` languages default to `anywhere`, which mirrors the previous behavior for those language that was hard-coded into the rewrap implementation. This setting does not have any effect in Vim mode, as Vim mode already allowed rewrapping anywhere. Closes https://github.com/zed-industries/zed/issues/24242. Release Notes: - Added an `allow_rewrap` setting to control the `editor::Rewrap` behavior for a given language.
This commit is contained in:
parent
1ce8a51712
commit
d17c6b392e
4 changed files with 79 additions and 14 deletions
|
@ -109,6 +109,11 @@ pub struct LanguageSettings {
|
|||
/// - `"!<language_server_id>"` - A language server ID prefixed with a `!` will be disabled.
|
||||
/// - `"..."` - A placeholder to refer to the **rest** of the registered language servers for this language.
|
||||
pub language_servers: Vec<String>,
|
||||
/// Controls where the `editor::Rewrap` action is allowed for this language.
|
||||
///
|
||||
/// Note: This setting has no effect in Vim mode, as rewrap is already
|
||||
/// allowed everywhere.
|
||||
pub allow_rewrap: RewrapBehavior,
|
||||
/// Controls whether edit predictions are shown immediately (true)
|
||||
/// or manually by triggering `editor::ShowEditPrediction` (false).
|
||||
pub show_edit_predictions: bool,
|
||||
|
@ -349,6 +354,14 @@ pub struct LanguageSettingsContent {
|
|||
/// Default: ["..."]
|
||||
#[serde(default)]
|
||||
pub language_servers: Option<Vec<String>>,
|
||||
/// Controls where the `editor::Rewrap` action is allowed for this language.
|
||||
///
|
||||
/// Note: This setting has no effect in Vim mode, as rewrap is already
|
||||
/// allowed everywhere.
|
||||
///
|
||||
/// Default: "in_comments"
|
||||
#[serde(default)]
|
||||
pub allow_rewrap: Option<RewrapBehavior>,
|
||||
/// Controls whether edit predictions are shown immediately (true)
|
||||
/// or manually by triggering `editor::ShowEditPrediction` (false).
|
||||
///
|
||||
|
@ -427,6 +440,19 @@ pub struct LanguageSettingsContent {
|
|||
pub show_completion_documentation: Option<bool>,
|
||||
}
|
||||
|
||||
/// The behavior of `editor::Rewrap`.
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RewrapBehavior {
|
||||
/// Only rewrap within comments.
|
||||
#[default]
|
||||
InComments,
|
||||
/// Only rewrap within the current selection(s).
|
||||
InSelections,
|
||||
/// Allow rewrapping anywhere.
|
||||
Anywhere,
|
||||
}
|
||||
|
||||
/// The contents of the edit prediction settings.
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
pub struct EditPredictionSettingsContent {
|
||||
|
@ -1224,6 +1250,7 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
|
|||
src.enable_language_server,
|
||||
);
|
||||
merge(&mut settings.language_servers, src.language_servers.clone());
|
||||
merge(&mut settings.allow_rewrap, src.allow_rewrap);
|
||||
merge(
|
||||
&mut settings.show_edit_predictions,
|
||||
src.show_edit_predictions,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue