Load python venv for tasks
This commit is contained in:
parent
d2f2142127
commit
333354024d
8 changed files with 236 additions and 115 deletions
|
@ -141,18 +141,28 @@ impl AgentTool for TerminalTool {
|
||||||
|
|
||||||
let program = program.await;
|
let program = program.await;
|
||||||
let env = env.await;
|
let env = env.await;
|
||||||
let terminal = self.project.update(cx, |project, cx| {
|
let terminal = self
|
||||||
project.create_terminal_task(
|
.project
|
||||||
task::SpawnInTerminal {
|
.update(cx, |project, cx| {
|
||||||
command: Some(program),
|
project.create_terminal_task(
|
||||||
args,
|
task::SpawnInTerminal {
|
||||||
cwd: working_dir.clone(),
|
command: Some(program),
|
||||||
env,
|
args,
|
||||||
..Default::default()
|
cwd: working_dir.clone(),
|
||||||
},
|
env,
|
||||||
cx,
|
..Default::default()
|
||||||
)
|
},
|
||||||
})??;
|
cx,
|
||||||
|
project
|
||||||
|
.active_entry()
|
||||||
|
.and_then(|entry_id| project.worktree_id_for_entry(entry_id, cx))
|
||||||
|
.map(|worktree_id| project::ProjectPath {
|
||||||
|
worktree_id,
|
||||||
|
path: Arc::from(Path::new("")),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})?
|
||||||
|
.await?;
|
||||||
let acp_terminal = cx.new(|cx| {
|
let acp_terminal = cx.new(|cx| {
|
||||||
acp_thread::Terminal::new(
|
acp_thread::Terminal::new(
|
||||||
input.command.clone(),
|
input.command.clone(),
|
||||||
|
|
|
@ -213,18 +213,27 @@ impl Tool for TerminalTool {
|
||||||
async move |cx| {
|
async move |cx| {
|
||||||
let program = program.await;
|
let program = program.await;
|
||||||
let env = env.await;
|
let env = env.await;
|
||||||
project.update(cx, |project, cx| {
|
project
|
||||||
project.create_terminal_task(
|
.update(cx, |project, cx| {
|
||||||
task::SpawnInTerminal {
|
project.create_terminal_task(
|
||||||
command: Some(program),
|
task::SpawnInTerminal {
|
||||||
args,
|
command: Some(program),
|
||||||
cwd,
|
args,
|
||||||
env,
|
cwd,
|
||||||
..Default::default()
|
env,
|
||||||
},
|
..Default::default()
|
||||||
cx,
|
},
|
||||||
)
|
cx,
|
||||||
})?
|
project
|
||||||
|
.active_entry()
|
||||||
|
.and_then(|entry_id| project.worktree_id_for_entry(entry_id, cx))
|
||||||
|
.map(|worktree_id| project::ProjectPath {
|
||||||
|
worktree_id,
|
||||||
|
path: Arc::from(Path::new("")),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})?
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1018,8 +1018,15 @@ impl RunningState {
|
||||||
project.create_terminal_task(
|
project.create_terminal_task(
|
||||||
task_with_shell.clone(),
|
task_with_shell.clone(),
|
||||||
cx,
|
cx,
|
||||||
|
project
|
||||||
|
.active_entry()
|
||||||
|
.and_then(|entry_id| project.worktree_id_for_entry(entry_id, cx))
|
||||||
|
.map(|worktree_id| project::ProjectPath {
|
||||||
|
worktree_id,
|
||||||
|
path: Arc::from(std::path::Path::new("")),
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
})??;
|
})?.await?;
|
||||||
|
|
||||||
let terminal_view = cx.new_window_entity(|window, cx| {
|
let terminal_view = cx.new_window_entity(|window, cx| {
|
||||||
TerminalView::new(
|
TerminalView::new(
|
||||||
|
@ -1186,10 +1193,21 @@ impl RunningState {
|
||||||
let workspace = self.workspace.clone();
|
let workspace = self.workspace.clone();
|
||||||
let weak_project = project.downgrade();
|
let weak_project = project.downgrade();
|
||||||
|
|
||||||
let terminal_task =
|
let terminal_task = project.update(cx, |project, cx| {
|
||||||
project.update(cx, |project, cx| project.create_terminal_task(kind, cx));
|
project.create_terminal_task(
|
||||||
|
kind,
|
||||||
|
cx,
|
||||||
|
project
|
||||||
|
.active_entry()
|
||||||
|
.and_then(|entry_id| project.worktree_id_for_entry(entry_id, cx))
|
||||||
|
.map(|worktree_id| project::ProjectPath {
|
||||||
|
worktree_id,
|
||||||
|
path: Arc::from(std::path::Path::new("")),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
});
|
||||||
let terminal_task = cx.spawn_in(window, async move |_, cx| {
|
let terminal_task = cx.spawn_in(window, async move |_, cx| {
|
||||||
let terminal = terminal_task?;
|
let terminal = terminal_task.await?;
|
||||||
|
|
||||||
let terminal_view = cx.new_window_entity(|window, cx| {
|
let terminal_view = cx.new_window_entity(|window, cx| {
|
||||||
TerminalView::new(terminal.clone(), workspace, None, weak_project, window, cx)
|
TerminalView::new(terminal.clone(), workspace, None, weak_project, window, cx)
|
||||||
|
|
|
@ -28,6 +28,9 @@ pub struct Toolchain {
|
||||||
pub as_json: serde_json::Value,
|
pub as_json: serde_json::Value,
|
||||||
/// shell -> script
|
/// shell -> script
|
||||||
pub activation_script: FxHashMap<ShellKind, String>,
|
pub activation_script: FxHashMap<ShellKind, String>,
|
||||||
|
// Option<String>
|
||||||
|
// sh activate -c "user shell -l"
|
||||||
|
// check if this work with powershell
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::hash::Hash for Toolchain {
|
impl std::hash::Hash for Toolchain {
|
||||||
|
|
|
@ -94,7 +94,8 @@ impl Project {
|
||||||
&mut self,
|
&mut self,
|
||||||
spawn_task: SpawnInTerminal,
|
spawn_task: SpawnInTerminal,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Result<Entity<Terminal>> {
|
project_path_context: Option<ProjectPath>,
|
||||||
|
) -> Task<Result<Entity<Terminal>>> {
|
||||||
let this = &mut *self;
|
let this = &mut *self;
|
||||||
let ssh_details = this.ssh_details(cx);
|
let ssh_details = this.ssh_details(cx);
|
||||||
let path: Option<Arc<Path>> = if let Some(cwd) = &spawn_task.cwd {
|
let path: Option<Arc<Path>> = if let Some(cwd) = &spawn_task.cwd {
|
||||||
|
@ -135,8 +136,14 @@ impl Project {
|
||||||
env.extend(settings.env);
|
env.extend(settings.env);
|
||||||
|
|
||||||
let local_path = if is_ssh_terminal { None } else { path.clone() };
|
let local_path = if is_ssh_terminal { None } else { path.clone() };
|
||||||
|
let toolchain =
|
||||||
let (spawn_task, shell) = {
|
project_path_context.map(|p| self.active_toolchain(p, LanguageName::new("Python"), cx));
|
||||||
|
cx.spawn(async move |project, cx| {
|
||||||
|
let scripts = maybe!(async {
|
||||||
|
let toolchain = toolchain?.await?;
|
||||||
|
Some(toolchain.activation_script)
|
||||||
|
})
|
||||||
|
.await;
|
||||||
let task_state = Some(TaskState {
|
let task_state = Some(TaskState {
|
||||||
id: spawn_task.id,
|
id: spawn_task.id,
|
||||||
full_label: spawn_task.full_label,
|
full_label: spawn_task.full_label,
|
||||||
|
@ -150,94 +157,132 @@ impl Project {
|
||||||
completion_rx,
|
completion_rx,
|
||||||
});
|
});
|
||||||
|
|
||||||
env.extend(spawn_task.env);
|
let shell = {
|
||||||
|
env.extend(spawn_task.env);
|
||||||
|
// todo(lw): Use shell builder
|
||||||
|
let shell = match &ssh_details {
|
||||||
|
Some(ssh) => ssh.shell.clone(),
|
||||||
|
None => match &settings.shell {
|
||||||
|
Shell::Program(program) => program.clone(),
|
||||||
|
Shell::WithArguments {
|
||||||
|
program,
|
||||||
|
args: _,
|
||||||
|
title_override: _,
|
||||||
|
} => program.clone(),
|
||||||
|
Shell::System => get_system_shell(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let shell_kind = ShellKind::new(&shell);
|
||||||
|
let activation_script = scripts.as_ref().and_then(|it| it.get(&shell_kind));
|
||||||
|
|
||||||
match ssh_details {
|
match ssh_details {
|
||||||
Some(SshDetails {
|
Some(SshDetails {
|
||||||
host,
|
host,
|
||||||
ssh_command,
|
ssh_command,
|
||||||
envs,
|
envs,
|
||||||
path_style,
|
|
||||||
shell,
|
|
||||||
}) => {
|
|
||||||
log::debug!("Connecting to a remote server: {ssh_command:?}");
|
|
||||||
env.entry("TERM".to_string())
|
|
||||||
.or_insert_with(|| "xterm-256color".to_string());
|
|
||||||
let (program, args) = wrap_for_ssh(
|
|
||||||
&shell,
|
|
||||||
&ssh_command,
|
|
||||||
spawn_task
|
|
||||||
.command
|
|
||||||
.as_ref()
|
|
||||||
.map(|command| (command, &spawn_task.args)),
|
|
||||||
path.as_deref(),
|
|
||||||
env,
|
|
||||||
path_style,
|
path_style,
|
||||||
None,
|
shell,
|
||||||
);
|
}) => {
|
||||||
env = HashMap::default();
|
log::debug!("Connecting to a remote server: {ssh_command:?}");
|
||||||
if let Some(envs) = envs {
|
env.entry("TERM".to_string())
|
||||||
env.extend(envs);
|
.or_insert_with(|| "xterm-256color".to_string());
|
||||||
}
|
|
||||||
(
|
let (program, args) = wrap_for_ssh(
|
||||||
task_state,
|
&shell,
|
||||||
|
&ssh_command,
|
||||||
|
spawn_task
|
||||||
|
.command
|
||||||
|
.as_ref()
|
||||||
|
.map(|command| (command, &spawn_task.args)),
|
||||||
|
path.as_deref(),
|
||||||
|
env,
|
||||||
|
path_style,
|
||||||
|
activation_script.map(String::as_str),
|
||||||
|
);
|
||||||
|
env = HashMap::default();
|
||||||
|
if let Some(envs) = envs {
|
||||||
|
env.extend(envs);
|
||||||
|
}
|
||||||
Shell::WithArguments {
|
Shell::WithArguments {
|
||||||
program,
|
program,
|
||||||
args,
|
args,
|
||||||
title_override: Some(format!("{} — Terminal", host).into()),
|
title_override: Some(format!("{} — Terminal", host).into()),
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
let shell = if let Some(program) = spawn_task.command {
|
|
||||||
Shell::WithArguments {
|
|
||||||
program,
|
|
||||||
args: spawn_task.args,
|
|
||||||
title_override: None,
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
Shell::System
|
None => match activation_script {
|
||||||
};
|
Some(activation_script) => {
|
||||||
(task_state, shell)
|
let to_run = if let Some(command) = spawn_task.command {
|
||||||
|
let command: Option<Cow<str>> = shlex::try_quote(&command).ok();
|
||||||
|
let args = spawn_task
|
||||||
|
.args
|
||||||
|
.iter()
|
||||||
|
.filter_map(|arg| shlex::try_quote(arg).ok());
|
||||||
|
command.into_iter().chain(args).join(" ")
|
||||||
|
} else {
|
||||||
|
format!("exec {shell} -l")
|
||||||
|
};
|
||||||
|
Shell::WithArguments {
|
||||||
|
program: shell,
|
||||||
|
args: vec![
|
||||||
|
"-c".to_owned(),
|
||||||
|
format!("{activation_script}; {to_run}",),
|
||||||
|
],
|
||||||
|
title_override: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
if let Some(program) = spawn_task.command {
|
||||||
|
Shell::WithArguments {
|
||||||
|
program,
|
||||||
|
args: spawn_task.args,
|
||||||
|
title_override: None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Shell::System
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
project.update(cx, move |this, cx| {
|
||||||
TerminalBuilder::new(
|
TerminalBuilder::new(
|
||||||
local_path.map(|path| path.to_path_buf()),
|
local_path.map(|path| path.to_path_buf()),
|
||||||
spawn_task,
|
task_state,
|
||||||
shell,
|
shell,
|
||||||
env,
|
env,
|
||||||
settings.cursor_shape.unwrap_or_default(),
|
settings.cursor_shape.unwrap_or_default(),
|
||||||
settings.alternate_scroll,
|
settings.alternate_scroll,
|
||||||
settings.max_scroll_history_lines,
|
settings.max_scroll_history_lines,
|
||||||
is_ssh_terminal,
|
is_ssh_terminal,
|
||||||
cx.entity_id().as_u64(),
|
cx.entity_id().as_u64(),
|
||||||
Some(completion_tx),
|
Some(completion_tx),
|
||||||
cx,
|
cx,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.map(|builder| {
|
.map(|builder| {
|
||||||
let terminal_handle = cx.new(|cx| builder.subscribe(cx));
|
let terminal_handle = cx.new(|cx| builder.subscribe(cx));
|
||||||
|
|
||||||
this.terminals
|
this.terminals
|
||||||
.local_handles
|
.local_handles
|
||||||
.push(terminal_handle.downgrade());
|
.push(terminal_handle.downgrade());
|
||||||
|
|
||||||
let id = terminal_handle.entity_id();
|
let id = terminal_handle.entity_id();
|
||||||
cx.observe_release(&terminal_handle, move |project, _terminal, cx| {
|
cx.observe_release(&terminal_handle, move |project, _terminal, cx| {
|
||||||
let handles = &mut project.terminals.local_handles;
|
let handles = &mut project.terminals.local_handles;
|
||||||
|
|
||||||
if let Some(index) = handles
|
if let Some(index) = handles
|
||||||
.iter()
|
.iter()
|
||||||
.position(|terminal| terminal.entity_id() == id)
|
.position(|terminal| terminal.entity_id() == id)
|
||||||
{
|
{
|
||||||
handles.remove(index);
|
handles.remove(index);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
terminal_handle
|
terminal_handle
|
||||||
|
})
|
||||||
|
})?
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,6 +323,7 @@ impl Project {
|
||||||
let toolchain =
|
let toolchain =
|
||||||
project_path_context.map(|p| self.active_toolchain(p, LanguageName::new("Python"), cx));
|
project_path_context.map(|p| self.active_toolchain(p, LanguageName::new("Python"), cx));
|
||||||
cx.spawn(async move |project, cx| {
|
cx.spawn(async move |project, cx| {
|
||||||
|
// todo(lw): Use shell builder
|
||||||
let shell = match &ssh_details {
|
let shell = match &ssh_details {
|
||||||
Some(ssh) => ssh.shell.clone(),
|
Some(ssh) => ssh.shell.clone(),
|
||||||
None => match &settings.shell {
|
None => match &settings.shell {
|
||||||
|
|
|
@ -95,6 +95,7 @@ pub enum VenvSettings {
|
||||||
/// to the current working directory. We recommend overriding this
|
/// to the current working directory. We recommend overriding this
|
||||||
/// in your project's settings, rather than globally.
|
/// in your project's settings, rather than globally.
|
||||||
activate_script: Option<ActivateScript>,
|
activate_script: Option<ActivateScript>,
|
||||||
|
// deprecate but use
|
||||||
venv_name: Option<String>,
|
venv_name: Option<String>,
|
||||||
directories: Option<Vec<PathBuf>>,
|
directories: Option<Vec<PathBuf>>,
|
||||||
},
|
},
|
||||||
|
|
|
@ -592,7 +592,17 @@ impl TerminalPanel {
|
||||||
.workspace
|
.workspace
|
||||||
.update(cx, |workspace, cx| {
|
.update(cx, |workspace, cx| {
|
||||||
Self::add_center_terminal(workspace, window, cx, |project, cx| {
|
Self::add_center_terminal(workspace, window, cx, |project, cx| {
|
||||||
Task::ready(project.create_terminal_task(spawn_task, cx))
|
project.create_terminal_task(
|
||||||
|
spawn_task,
|
||||||
|
cx,
|
||||||
|
project
|
||||||
|
.active_entry()
|
||||||
|
.and_then(|entry_id| project.worktree_id_for_entry(entry_id, cx))
|
||||||
|
.map(|worktree_id| project::ProjectPath {
|
||||||
|
worktree_id,
|
||||||
|
path: Arc::from(Path::new("")),
|
||||||
|
}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|e| Task::ready(Err(e))),
|
.unwrap_or_else(|e| Task::ready(Err(e))),
|
||||||
|
@ -731,8 +741,21 @@ impl TerminalPanel {
|
||||||
terminal_panel.active_pane.clone()
|
terminal_panel.active_pane.clone()
|
||||||
})?;
|
})?;
|
||||||
let project = workspace.read_with(cx, |workspace, _| workspace.project().clone())?;
|
let project = workspace.read_with(cx, |workspace, _| workspace.project().clone())?;
|
||||||
let terminal =
|
let terminal = project
|
||||||
project.update(cx, |project, cx| project.create_terminal_task(task, cx))??;
|
.update(cx, |project, cx| {
|
||||||
|
project.create_terminal_task(
|
||||||
|
task,
|
||||||
|
cx,
|
||||||
|
project
|
||||||
|
.active_entry()
|
||||||
|
.and_then(|entry_id| project.worktree_id_for_entry(entry_id, cx))
|
||||||
|
.map(|worktree_id| project::ProjectPath {
|
||||||
|
worktree_id,
|
||||||
|
path: Arc::from(Path::new("")),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})?
|
||||||
|
.await?;
|
||||||
let result = workspace.update_in(cx, |workspace, window, cx| {
|
let result = workspace.update_in(cx, |workspace, window, cx| {
|
||||||
let terminal_view = Box::new(cx.new(|cx| {
|
let terminal_view = Box::new(cx.new(|cx| {
|
||||||
TerminalView::new(
|
TerminalView::new(
|
||||||
|
@ -909,9 +932,21 @@ impl TerminalPanel {
|
||||||
this.workspace
|
this.workspace
|
||||||
.update(cx, |workspace, _| workspace.project().clone())
|
.update(cx, |workspace, _| workspace.project().clone())
|
||||||
})??;
|
})??;
|
||||||
let new_terminal = project.update(cx, |project, cx| {
|
let new_terminal = project
|
||||||
project.create_terminal_task(spawn_task, cx)
|
.update(cx, |project, cx| {
|
||||||
})??;
|
project.create_terminal_task(
|
||||||
|
spawn_task,
|
||||||
|
cx,
|
||||||
|
project
|
||||||
|
.active_entry()
|
||||||
|
.and_then(|entry_id| project.worktree_id_for_entry(entry_id, cx))
|
||||||
|
.map(|worktree_id| project::ProjectPath {
|
||||||
|
worktree_id,
|
||||||
|
path: Arc::from(Path::new("")),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})?
|
||||||
|
.await?;
|
||||||
terminal_to_replace.update_in(cx, |terminal_to_replace, window, cx| {
|
terminal_to_replace.update_in(cx, |terminal_to_replace, window, cx| {
|
||||||
terminal_to_replace.set_terminal(new_terminal.clone(), window, cx);
|
terminal_to_replace.set_terminal(new_terminal.clone(), window, cx);
|
||||||
})?;
|
})?;
|
||||||
|
|
|
@ -1389,7 +1389,6 @@ impl WorkspaceDb {
|
||||||
relative_path: String,
|
relative_path: String,
|
||||||
language_name: LanguageName,
|
language_name: LanguageName,
|
||||||
) -> Result<Option<Toolchain>> {
|
) -> Result<Option<Toolchain>> {
|
||||||
return Ok(None);
|
|
||||||
self.write(move |this| {
|
self.write(move |this| {
|
||||||
let mut select = this
|
let mut select = this
|
||||||
.select_bound(sql!(
|
.select_bound(sql!(
|
||||||
|
@ -1415,7 +1414,6 @@ impl WorkspaceDb {
|
||||||
&self,
|
&self,
|
||||||
workspace_id: WorkspaceId,
|
workspace_id: WorkspaceId,
|
||||||
) -> Result<Vec<(Toolchain, WorktreeId, Arc<Path>)>> {
|
) -> Result<Vec<(Toolchain, WorktreeId, Arc<Path>)>> {
|
||||||
return Ok(vec![]);
|
|
||||||
self.write(move |this| {
|
self.write(move |this| {
|
||||||
let mut select = this
|
let mut select = this
|
||||||
.select_bound(sql!(
|
.select_bound(sql!(
|
||||||
|
@ -1426,6 +1424,7 @@ impl WorkspaceDb {
|
||||||
let toolchain: Vec<(String, String, u64, String, String, String)> =
|
let toolchain: Vec<(String, String, u64, String, String, String)> =
|
||||||
select(workspace_id)?;
|
select(workspace_id)?;
|
||||||
|
|
||||||
|
// todo look into re-serializing these if we fix up
|
||||||
Ok(toolchain.into_iter().filter_map(|(name, path, worktree_id, relative_worktree_path, language_name, raw_json)| Some((Toolchain {
|
Ok(toolchain.into_iter().filter_map(|(name, path, worktree_id, relative_worktree_path, language_name, raw_json)| Some((Toolchain {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
path: path.into(),
|
path: path.into(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue