Limit the extension tasks in the modal to current language only (#10207)

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2024-04-05 23:18:32 +02:00 committed by GitHub
parent c851e6edba
commit 7b636d9774
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 128 additions and 186 deletions

View file

@ -55,9 +55,7 @@ use std::{
},
};
use syntax_map::SyntaxSnapshot;
pub use task_context::{
ContextProvider, ContextProviderWithTasks, LanguageSource, SymbolContextProvider,
};
pub use task_context::{ContextProvider, ContextProviderWithTasks, SymbolContextProvider};
use theme::SyntaxTheme;
use tree_sitter::{self, wasmtime, Query, WasmStore};
use util::http::HttpClient;

View file

@ -1,12 +1,8 @@
use crate::{LanguageRegistry, Location};
use crate::Location;
use anyhow::Result;
use gpui::{AppContext, Context, Model};
use std::sync::Arc;
use task::{
static_source::{tasks_for, TaskDefinitions},
TaskSource, TaskVariables, VariableName,
};
use gpui::AppContext;
use task::{static_source::TaskDefinitions, TaskVariables, VariableName};
/// Language Contexts are used by Zed tasks to extract information about source file.
pub trait ContextProvider: Send + Sync {
@ -67,45 +63,3 @@ impl ContextProvider for ContextProviderWithTasks {
SymbolContextProvider.build_context(location, cx)
}
}
/// A source that pulls in the tasks from language registry.
pub struct LanguageSource {
languages: Arc<LanguageRegistry>,
}
impl LanguageSource {
pub fn new(
languages: Arc<LanguageRegistry>,
cx: &mut AppContext,
) -> Model<Box<dyn TaskSource>> {
cx.new_model(|_| Box::new(Self { languages }) as Box<_>)
}
}
impl TaskSource for LanguageSource {
fn as_any(&mut self) -> &mut dyn std::any::Any {
self
}
fn tasks_for_path(
&mut self,
_: Option<&std::path::Path>,
_: &mut gpui::ModelContext<Box<dyn TaskSource>>,
) -> Vec<Arc<dyn task::Task>> {
self.languages
.to_vec()
.into_iter()
.filter_map(|language| {
language
.context_provider()?
.associated_tasks()
.map(|tasks| (tasks, language))
})
.flat_map(|(tasks, language)| {
let language_name = language.name();
let id_base = format!("buffer_source_{language_name}");
tasks_for(tasks, &id_base)
})
.collect()
}
}