Limit the extension tasks in the modal to current language only (#10207)
Release Notes: - N/A
This commit is contained in:
parent
c851e6edba
commit
7b636d9774
9 changed files with 128 additions and 186 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue