Add separate JSONC language (#12655)
Resolves https://github.com/zed-industries/extensions/issues/860 and https://github.com/zed-industries/zed/issues/10921, also https://github.com/biomejs/biome-zed/issues/11. ### Problem: When opening .json files, zed allows comments by default in the JSON language, which can cause some problems. For example, language-servers also get "json" as the language, which may show errors for those comments. <img width="935" alt="image" src="https://github.com/zed-industries/zed/assets/10381895/fed3d83d-abc0-44b5-9982-eb249bb04c3b"> ### Solution: This PR adds a JSONC language. <img width="816" alt="image" src="https://github.com/zed-industries/zed/assets/10381895/8b40e671-d4f0-4e8d-80cb-82ee7c0ec490"> This allows for more specific configuration for language servers. Also any json file can be set explicitly to be JSONC using the file_types setting: ```jsonc { "file_types": { // set all .json files to be seen as JSONC "JSONC": ["*.json"] } } ``` Release Notes: - N/A
This commit is contained in:
parent
e71b642f44
commit
fb3ef0d140
13 changed files with 98 additions and 3 deletions
|
@ -662,6 +662,17 @@ impl settings::Settings for AllLanguageSettings {
|
|||
.ok_or_else(Self::missing_default)?;
|
||||
|
||||
let mut file_types: HashMap<Arc<str>, GlobSet> = HashMap::default();
|
||||
|
||||
for (language, suffixes) in &default_value.file_types {
|
||||
let mut builder = GlobSetBuilder::new();
|
||||
|
||||
for suffix in suffixes {
|
||||
builder.add(Glob::new(suffix)?);
|
||||
}
|
||||
|
||||
file_types.insert(language.clone(), builder.build()?);
|
||||
}
|
||||
|
||||
for user_settings in sources.customizations() {
|
||||
if let Some(copilot) = user_settings.features.as_ref().and_then(|f| f.copilot) {
|
||||
copilot_enabled = Some(copilot);
|
||||
|
@ -701,6 +712,15 @@ impl settings::Settings for AllLanguageSettings {
|
|||
for (language, suffixes) in &user_settings.file_types {
|
||||
let mut builder = GlobSetBuilder::new();
|
||||
|
||||
let default_value = default_value.file_types.get(&language.clone());
|
||||
|
||||
// Merge the default value with the user's value.
|
||||
if let Some(suffixes) = default_value {
|
||||
for suffix in suffixes {
|
||||
builder.add(Glob::new(suffix)?);
|
||||
}
|
||||
}
|
||||
|
||||
for suffix in suffixes {
|
||||
builder.add(Glob::new(suffix)?);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue