task: use full task label to distinguish a terminal (#10469)
Spotted by @SomeoneToIgnore, in #10468 I've used a shortened task label, which might lead to collisions. Release Notes: - N/A
This commit is contained in:
parent
298e9c9387
commit
a1cbc23fee
5 changed files with 12 additions and 5 deletions
|
@ -52,6 +52,7 @@ impl Project {
|
||||||
(
|
(
|
||||||
Some(TaskState {
|
Some(TaskState {
|
||||||
id: spawn_task.id,
|
id: spawn_task.id,
|
||||||
|
full_label: spawn_task.full_label,
|
||||||
label: spawn_task.label,
|
label: spawn_task.label,
|
||||||
status: TaskStatus::Running,
|
status: TaskStatus::Running,
|
||||||
completion_rx,
|
completion_rx,
|
||||||
|
|
|
@ -25,6 +25,8 @@ pub struct TaskId(pub String);
|
||||||
pub struct SpawnInTerminal {
|
pub struct SpawnInTerminal {
|
||||||
/// Id of the task to use when determining task tab affinity.
|
/// Id of the task to use when determining task tab affinity.
|
||||||
pub id: TaskId,
|
pub id: TaskId,
|
||||||
|
/// Full unshortened form of `label` field.
|
||||||
|
pub full_label: String,
|
||||||
/// Human readable name of the terminal tab.
|
/// Human readable name of the terminal tab.
|
||||||
pub label: String,
|
pub label: String,
|
||||||
/// Executable command to spawn.
|
/// Executable command to spawn.
|
||||||
|
|
|
@ -115,10 +115,11 @@ impl TaskTemplate {
|
||||||
Some(ResolvedTask {
|
Some(ResolvedTask {
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
original_task: self.clone(),
|
original_task: self.clone(),
|
||||||
resolved_label: full_label,
|
resolved_label: full_label.clone(),
|
||||||
resolved: Some(SpawnInTerminal {
|
resolved: Some(SpawnInTerminal {
|
||||||
id,
|
id,
|
||||||
cwd,
|
cwd,
|
||||||
|
full_label,
|
||||||
label: shortened_label,
|
label: shortened_label,
|
||||||
command,
|
command,
|
||||||
args,
|
args,
|
||||||
|
|
|
@ -288,6 +288,7 @@ impl Display for TerminalError {
|
||||||
|
|
||||||
pub struct SpawnTask {
|
pub struct SpawnTask {
|
||||||
pub id: TaskId,
|
pub id: TaskId,
|
||||||
|
pub full_label: String,
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub command: String,
|
pub command: String,
|
||||||
pub args: Vec<String>,
|
pub args: Vec<String>,
|
||||||
|
@ -594,6 +595,7 @@ pub struct Terminal {
|
||||||
|
|
||||||
pub struct TaskState {
|
pub struct TaskState {
|
||||||
pub id: TaskId,
|
pub id: TaskId,
|
||||||
|
pub full_label: String,
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub status: TaskStatus,
|
pub status: TaskStatus,
|
||||||
pub completion_rx: Receiver<()>,
|
pub completion_rx: Receiver<()>,
|
||||||
|
@ -1363,7 +1365,7 @@ impl Terminal {
|
||||||
if truncate {
|
if truncate {
|
||||||
truncate_and_trailoff(&task_state.label, MAX_CHARS)
|
truncate_and_trailoff(&task_state.label, MAX_CHARS)
|
||||||
} else {
|
} else {
|
||||||
task_state.label.clone()
|
task_state.full_label.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => self
|
None => self
|
||||||
|
|
|
@ -296,9 +296,10 @@ impl TerminalPanel {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_task(&mut self, spawn_in_terminal: &SpawnInTerminal, cx: &mut ViewContext<Self>) {
|
fn spawn_task(&mut self, spawn_in_terminal: &SpawnInTerminal, cx: &mut ViewContext<Self>) {
|
||||||
let mut spawn_task = SpawnTask {
|
let mut spawn_task = SpawnTask {
|
||||||
id: spawn_in_terminal.id.clone(),
|
id: spawn_in_terminal.id.clone(),
|
||||||
|
full_label: spawn_in_terminal.full_label.clone(),
|
||||||
label: spawn_in_terminal.label.clone(),
|
label: spawn_in_terminal.label.clone(),
|
||||||
command: spawn_in_terminal.command.clone(),
|
command: spawn_in_terminal.command.clone(),
|
||||||
args: spawn_in_terminal.args.clone(),
|
args: spawn_in_terminal.args.clone(),
|
||||||
|
@ -334,7 +335,7 @@ impl TerminalPanel {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let terminals_for_task = self.terminals_for_task(&spawn_in_terminal.label, cx);
|
let terminals_for_task = self.terminals_for_task(&spawn_in_terminal.full_label, cx);
|
||||||
if terminals_for_task.is_empty() {
|
if terminals_for_task.is_empty() {
|
||||||
self.spawn_in_new_terminal(spawn_task, working_directory, cx);
|
self.spawn_in_new_terminal(spawn_task, working_directory, cx);
|
||||||
return;
|
return;
|
||||||
|
@ -445,7 +446,7 @@ impl TerminalPanel {
|
||||||
.filter_map(|(index, item)| Some((index, item.act_as::<TerminalView>(cx)?)))
|
.filter_map(|(index, item)| Some((index, item.act_as::<TerminalView>(cx)?)))
|
||||||
.filter_map(|(index, terminal_view)| {
|
.filter_map(|(index, terminal_view)| {
|
||||||
let task_state = terminal_view.read(cx).terminal().read(cx).task()?;
|
let task_state = terminal_view.read(cx).terminal().read(cx).task()?;
|
||||||
if &task_state.label == label {
|
if &task_state.full_label == label {
|
||||||
Some((index, terminal_view))
|
Some((index, terminal_view))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue