Add support for auto-closing of JSX tags (#25681)

Closes #4271

Implemented by kicking of a task on the main thread at the end of
`Editor::handle_input` which waits for the buffer to be re-parsed before
checking if JSX tag completion possible based on the recent edits, and
if it is then it spawns a task on the background thread to generate the
edits to be auto-applied to the buffer

Release Notes:

- Added support for auto-closing of JSX tags

---------

Co-authored-by: Cole Miller <cole@zed.dev>
Co-authored-by: Max Brunsfeld <max@zed.dev>
Co-authored-by: Marshall Bowers <git@maxdeviant.com>
Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Peter Tripp <peter@zed.dev>
This commit is contained in:
Ben Kunkle 2025-03-06 08:36:10 -06:00 committed by GitHub
parent 05df3d1bd6
commit ff25fa24e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 1207 additions and 149 deletions

View file

@ -100,6 +100,8 @@ pub struct LanguageSettings {
pub formatter: SelectedFormatter,
/// Zed's Prettier integration settings.
pub prettier: PrettierSettings,
/// Whether to automatically close JSX tags.
pub jsx_tag_auto_close: JsxTagAutoCloseSettings,
/// Whether to use language servers to provide code intelligence.
pub enable_language_server: bool,
/// The list of language servers to use (or disable) for this language.
@ -374,6 +376,9 @@ pub struct LanguageSettingsContent {
/// Default: off
#[serde(default)]
pub prettier: Option<PrettierSettings>,
/// Whether to automatically close JSX tags.
#[serde(default)]
pub jsx_tag_auto_close: Option<JsxTagAutoCloseSettings>,
/// Whether to use language servers to provide code intelligence.
///
/// Default: true
@ -1335,6 +1340,10 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
);
merge(&mut settings.formatter, src.formatter.clone());
merge(&mut settings.prettier, src.prettier.clone());
merge(
&mut settings.jsx_tag_auto_close,
src.jsx_tag_auto_close.clone(),
);
merge(&mut settings.format_on_save, src.format_on_save.clone());
merge(
&mut settings.remove_trailing_whitespace_on_save,
@ -1398,6 +1407,13 @@ pub struct PrettierSettings {
pub options: HashMap<String, serde_json::Value>,
}
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct JsxTagAutoCloseSettings {
/// Enables or disables auto-closing of JSX tags.
#[serde(default)]
pub enabled: bool,
}
#[cfg(test)]
mod tests {
use gpui::TestAppContext;