debugger/extensions: Revert changes to extension store related to language config (#30225)
Revert #29945 Release Notes: - N/A --------- Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
parent
20387f24aa
commit
b091581e4b
9 changed files with 159 additions and 218 deletions
|
@ -34,7 +34,8 @@ use gpui::{
|
|||
};
|
||||
use http_client::{AsyncBody, HttpClient, HttpClientWithUrl};
|
||||
use language::{
|
||||
LanguageConfig, LanguageName, LanguageQueries, LoadedLanguage, QUERY_FILENAME_PREFIXES, Rope,
|
||||
LanguageConfig, LanguageMatcher, LanguageName, LanguageQueries, LoadedLanguage,
|
||||
QUERY_FILENAME_PREFIXES, Rope,
|
||||
};
|
||||
use node_runtime::NodeRuntime;
|
||||
use project::ContextProviderWithTasks;
|
||||
|
@ -139,7 +140,7 @@ struct GlobalExtensionStore(Entity<ExtensionStore>);
|
|||
|
||||
impl Global for GlobalExtensionStore {}
|
||||
|
||||
#[derive(Deserialize, Serialize, Default)]
|
||||
#[derive(Debug, Deserialize, Serialize, Default, PartialEq, Eq)]
|
||||
pub struct ExtensionIndex {
|
||||
pub extensions: BTreeMap<Arc<str>, ExtensionIndexEntry>,
|
||||
pub themes: BTreeMap<Arc<str>, ExtensionIndexThemeEntry>,
|
||||
|
@ -166,12 +167,13 @@ pub struct ExtensionIndexIconThemeEntry {
|
|||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Deserialize, Serialize)]
|
||||
pub struct ExtensionIndexLanguageEntry {
|
||||
pub extension: Arc<str>,
|
||||
pub path: PathBuf,
|
||||
#[serde(skip)]
|
||||
pub config: LanguageConfig,
|
||||
pub matcher: LanguageMatcher,
|
||||
pub hidden: bool,
|
||||
pub grammar: Option<Arc<str>>,
|
||||
}
|
||||
|
||||
actions!(zed, [ReloadExtensions]);
|
||||
|
@ -1181,8 +1183,44 @@ impl ExtensionStore {
|
|||
}
|
||||
|
||||
self.proxy.register_grammars(grammars_to_add);
|
||||
let languages_to_add = new_index
|
||||
.languages
|
||||
.iter_mut()
|
||||
.filter(|(_, entry)| extensions_to_load.contains(&entry.extension))
|
||||
.collect::<Vec<_>>();
|
||||
for (language_name, language) in languages_to_add {
|
||||
let mut language_path = self.installed_dir.clone();
|
||||
language_path.extend([
|
||||
Path::new(language.extension.as_ref()),
|
||||
language.path.as_path(),
|
||||
]);
|
||||
self.proxy.register_language(
|
||||
language_name.clone(),
|
||||
language.grammar.clone(),
|
||||
language.matcher.clone(),
|
||||
language.hidden,
|
||||
Arc::new(move || {
|
||||
let config = std::fs::read_to_string(language_path.join("config.toml"))?;
|
||||
let config: LanguageConfig = ::toml::from_str(&config)?;
|
||||
let queries = load_plugin_queries(&language_path);
|
||||
let context_provider =
|
||||
std::fs::read_to_string(language_path.join("tasks.json"))
|
||||
.ok()
|
||||
.and_then(|contents| {
|
||||
let definitions =
|
||||
serde_json_lenient::from_str(&contents).log_err()?;
|
||||
Some(Arc::new(ContextProviderWithTasks::new(definitions)) as Arc<_>)
|
||||
});
|
||||
|
||||
let installed_dir = self.installed_dir.clone();
|
||||
Ok(LoadedLanguage {
|
||||
config,
|
||||
queries,
|
||||
context_provider,
|
||||
toolchain_provider: None,
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
let fs = self.fs.clone();
|
||||
let wasm_host = self.wasm_host.clone();
|
||||
|
@ -1192,60 +1230,11 @@ impl ExtensionStore {
|
|||
.iter()
|
||||
.filter_map(|name| new_index.extensions.get(name).cloned())
|
||||
.collect::<Vec<_>>();
|
||||
self.extension_index = new_index;
|
||||
cx.notify();
|
||||
cx.emit(Event::ExtensionsUpdated);
|
||||
|
||||
cx.spawn(async move |this, cx| {
|
||||
let languages_to_add = new_index
|
||||
.languages
|
||||
.iter_mut()
|
||||
.filter(|(_, entry)| extensions_to_load.contains(&entry.extension))
|
||||
.collect::<Vec<_>>();
|
||||
for (_, language) in languages_to_add {
|
||||
let mut language_path = installed_dir.clone();
|
||||
language_path.extend([
|
||||
Path::new(language.extension.as_ref()),
|
||||
language.path.as_path(),
|
||||
]);
|
||||
let Some(config) = fs.load(&language_path.join("config.toml")).await.ok() else {
|
||||
log::error!("Could not load config.toml in {:?}", language_path);
|
||||
continue;
|
||||
};
|
||||
let Some(config) = ::toml::from_str::<LanguageConfig>(&config).ok() else {
|
||||
log::error!(
|
||||
"Could not parse language config.toml in {:?}",
|
||||
language_path
|
||||
);
|
||||
continue;
|
||||
};
|
||||
language.config = config.clone();
|
||||
proxy.register_language(
|
||||
language.config.clone(),
|
||||
Arc::new(move || {
|
||||
let queries = load_plugin_queries(&language_path);
|
||||
let context_provider =
|
||||
std::fs::read_to_string(language_path.join("tasks.json"))
|
||||
.ok()
|
||||
.and_then(|contents| {
|
||||
let definitions =
|
||||
serde_json_lenient::from_str(&contents).log_err()?;
|
||||
Some(Arc::new(ContextProviderWithTasks::new(definitions))
|
||||
as Arc<_>)
|
||||
});
|
||||
|
||||
Ok(LoadedLanguage {
|
||||
config: config.clone(),
|
||||
queries,
|
||||
context_provider,
|
||||
toolchain_provider: None,
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
this.update(cx, |this, cx| {
|
||||
this.extension_index = new_index;
|
||||
cx.notify();
|
||||
cx.emit(Event::ExtensionsUpdated);
|
||||
})
|
||||
.ok();
|
||||
cx.background_spawn({
|
||||
let fs = fs.clone();
|
||||
async move {
|
||||
|
@ -1448,7 +1437,9 @@ impl ExtensionStore {
|
|||
ExtensionIndexLanguageEntry {
|
||||
extension: extension_id.clone(),
|
||||
path: relative_path,
|
||||
config,
|
||||
matcher: config.matcher,
|
||||
hidden: config.hidden,
|
||||
grammar: config.grammar,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue