Specify a schema to use when dealing with JSONC files (#44250)
Follow-up of https://github.com/zed-industries/zed/pull/43854 Closes https://github.com/zed-industries/zed/issues/40970 Seems that json language server does not distinguish between JSONC and JSON files in runtime, but there is a static schema, which accepts globs in its `fileMatch` fields. Use all glob overrides and file suffixes for JSONC inside those match fields, and provide a grammar for such matches, which accepts trailing commas. Release Notes: - Improved JSONC trailing comma handling
This commit is contained in:
@@ -745,7 +745,7 @@ impl LanguageRegistry {
|
||||
self: &Arc<Self>,
|
||||
path: &Path,
|
||||
content: Option<&Rope>,
|
||||
user_file_types: Option<&FxHashMap<Arc<str>, GlobSet>>,
|
||||
user_file_types: Option<&FxHashMap<Arc<str>, (GlobSet, Vec<String>)>>,
|
||||
) -> Option<AvailableLanguage> {
|
||||
let filename = path.file_name().and_then(|filename| filename.to_str());
|
||||
// `Path.extension()` returns None for files with a leading '.'
|
||||
@@ -788,7 +788,7 @@ impl LanguageRegistry {
|
||||
let path_matches_custom_suffix = || {
|
||||
user_file_types
|
||||
.and_then(|types| types.get(language_name.as_ref()))
|
||||
.map_or(None, |custom_suffixes| {
|
||||
.map_or(None, |(custom_suffixes, _)| {
|
||||
path_suffixes
|
||||
.iter()
|
||||
.find(|(_, candidate)| custom_suffixes.is_match_candidate(candidate))
|
||||
|
||||
@@ -51,7 +51,7 @@ pub struct AllLanguageSettings {
|
||||
pub edit_predictions: EditPredictionSettings,
|
||||
pub defaults: LanguageSettings,
|
||||
languages: HashMap<LanguageName, LanguageSettings>,
|
||||
pub(crate) file_types: FxHashMap<Arc<str>, GlobSet>,
|
||||
pub file_types: FxHashMap<Arc<str>, (GlobSet, Vec<String>)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -656,7 +656,7 @@ impl settings::Settings for AllLanguageSettings {
|
||||
|
||||
let enabled_in_text_threads = edit_predictions.enabled_in_text_threads.unwrap();
|
||||
|
||||
let mut file_types: FxHashMap<Arc<str>, GlobSet> = FxHashMap::default();
|
||||
let mut file_types: FxHashMap<Arc<str>, (GlobSet, Vec<String>)> = FxHashMap::default();
|
||||
|
||||
for (language, patterns) in all_languages.file_types.iter().flatten() {
|
||||
let mut builder = GlobSetBuilder::new();
|
||||
@@ -665,7 +665,10 @@ impl settings::Settings for AllLanguageSettings {
|
||||
builder.add(Glob::new(pattern).unwrap());
|
||||
}
|
||||
|
||||
file_types.insert(language.clone(), builder.build().unwrap());
|
||||
file_types.insert(
|
||||
language.clone(),
|
||||
(builder.build().unwrap(), patterns.0.clone()),
|
||||
);
|
||||
}
|
||||
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user