Expand tilde paths in edit prediction settings (#31235)

Release Notes:

- edit_prediction: Handle `~` in paths in `disabled_globs` setting
This commit is contained in:
clauses3 2025-06-03 08:32:23 +00:00 committed by GitHub
parent 657c8b1084
commit b798392050
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 5 deletions

1
Cargo.lock generated
View file

@ -8762,6 +8762,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"settings", "settings",
"shellexpand 2.1.2",
"smallvec", "smallvec",
"smol", "smol",
"streaming-iterator", "streaming-iterator",

View file

@ -51,6 +51,7 @@ schemars.workspace = true
serde.workspace = true serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
settings.workspace = true settings.workspace = true
shellexpand.workspace = true
smallvec.workspace = true smallvec.workspace = true
smol.workspace = true smol.workspace = true
streaming-iterator.workspace = true streaming-iterator.workspace = true

View file

@ -23,6 +23,7 @@ use serde_json::Value;
use settings::{ use settings::{
Settings, SettingsLocation, SettingsSources, SettingsStore, add_references_to_properties, Settings, SettingsLocation, SettingsSources, SettingsStore, add_references_to_properties,
}; };
use shellexpand;
use std::{borrow::Cow, num::NonZeroU32, path::Path, sync::Arc}; use std::{borrow::Cow, num::NonZeroU32, path::Path, sync::Arc};
use util::serde::default_true; use util::serde::default_true;
@ -1331,9 +1332,10 @@ impl settings::Settings for AllLanguageSettings {
disabled_globs: completion_globs disabled_globs: completion_globs
.iter() .iter()
.filter_map(|g| { .filter_map(|g| {
let expanded_g = shellexpand::tilde(g).into_owned();
Some(DisabledGlob { Some(DisabledGlob {
matcher: globset::Glob::new(g).ok()?.compile_matcher(), matcher: globset::Glob::new(&expanded_g).ok()?.compile_matcher(),
is_absolute: Path::new(g).is_absolute(), is_absolute: Path::new(&expanded_g).is_absolute(),
}) })
}) })
.collect(), .collect(),
@ -1712,10 +1714,12 @@ mod tests {
}; };
#[cfg(windows)] #[cfg(windows)]
let glob_str = glob_str.as_str(); let glob_str = glob_str.as_str();
let expanded_glob_str = shellexpand::tilde(glob_str).into_owned();
DisabledGlob { DisabledGlob {
matcher: globset::Glob::new(glob_str).unwrap().compile_matcher(), matcher: globset::Glob::new(&expanded_glob_str)
is_absolute: Path::new(glob_str).is_absolute(), .unwrap()
.compile_matcher(),
is_absolute: Path::new(&expanded_glob_str).is_absolute(),
} }
}) })
.collect(), .collect(),
@ -1811,6 +1815,12 @@ mod tests {
let dot_env_file = make_test_file(&[".env"]); let dot_env_file = make_test_file(&[".env"]);
let settings = build_settings(&[".env"]); let settings = build_settings(&[".env"]);
assert!(!settings.enabled_for_file(&dot_env_file, &cx)); assert!(!settings.enabled_for_file(&dot_env_file, &cx));
// Test tilde expansion
let home = shellexpand::tilde("~").into_owned().to_string();
let home_file = make_test_file(&[&home, "test.rs"]);
let settings = build_settings(&["~/test.rs"]);
assert!(!settings.enabled_for_file(&home_file, &cx));
} }
#[test] #[test]

View file

@ -231,6 +231,18 @@ To not have predictions appear automatically as you type when working with a spe
} }
``` ```
### In Specific Directories
To disable edit predictions for specific directories or files, set this within `settings.json`:
```json
{
"edit_predictions": {
"disabled_globs": ["~/.config/zed/settings.json"]
}
}
```
### Turning Off Completely ### Turning Off Completely
To completely turn off edit prediction across all providers, explicitly set the settings to `none`, like so: To completely turn off edit prediction across all providers, explicitly set the settings to `none`, like so: