Added test covering this feature
This commit is contained in:
parent
88202a567c
commit
8a6605c090
3 changed files with 49 additions and 11 deletions
|
@ -84,7 +84,8 @@
|
||||||
"shell": "system",
|
"shell": "system",
|
||||||
// What working directory to use when launching the terminal.
|
// What working directory to use when launching the terminal.
|
||||||
// May take 4 values:
|
// May take 4 values:
|
||||||
// 1. Use the current file's project directory.
|
// 1. Use the current file's project directory. Will Fallback to the
|
||||||
|
// first project directory strategy if unsuccessful
|
||||||
// "working_directory": "current_project_directory"
|
// "working_directory": "current_project_directory"
|
||||||
// 2. Use the first project in this workspace's directory
|
// 2. Use the first project in this workspace's directory
|
||||||
// "working_directory": "first_project_directory"
|
// "working_directory": "first_project_directory"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use gpui::{ModelHandle, ViewContext};
|
use gpui::{ModelHandle, ViewContext};
|
||||||
|
use settings::{Settings, WorkingDirectory};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -27,7 +28,14 @@ pub fn deploy_modal(workspace: &mut Workspace, _: &DeployModal, cx: &mut ViewCon
|
||||||
// No connection was stored, create a new terminal
|
// No connection was stored, create a new terminal
|
||||||
if let Some(closed_terminal_handle) = workspace.toggle_modal(cx, |workspace, cx| {
|
if let Some(closed_terminal_handle) = workspace.toggle_modal(cx, |workspace, cx| {
|
||||||
// No terminal modal visible, construct a new one.
|
// No terminal modal visible, construct a new one.
|
||||||
let working_directory = get_working_directory(workspace, cx);
|
let wd_strategy = cx
|
||||||
|
.global::<Settings>()
|
||||||
|
.terminal_overrides
|
||||||
|
.working_directory
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(WorkingDirectory::CurrentProjectDirectory);
|
||||||
|
|
||||||
|
let working_directory = get_working_directory(workspace, cx, wd_strategy);
|
||||||
|
|
||||||
let this = cx.add_view(|cx| TerminalView::new(working_directory, true, cx));
|
let this = cx.add_view(|cx| TerminalView::new(working_directory, true, cx));
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,14 @@ impl Entity for ErrorView {
|
||||||
impl TerminalView {
|
impl TerminalView {
|
||||||
///Create a new Terminal in the current working directory or the user's home directory
|
///Create a new Terminal in the current working directory or the user's home directory
|
||||||
fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) {
|
fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) {
|
||||||
let working_directory = get_working_directory(workspace, cx);
|
let wd_strategy = cx
|
||||||
|
.global::<Settings>()
|
||||||
|
.terminal_overrides
|
||||||
|
.working_directory
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(WorkingDirectory::CurrentProjectDirectory);
|
||||||
|
|
||||||
|
let working_directory = get_working_directory(workspace, cx, wd_strategy);
|
||||||
let view = cx.add_view(|cx| TerminalView::new(working_directory, false, cx));
|
let view = cx.add_view(|cx| TerminalView::new(working_directory, false, cx));
|
||||||
workspace.add_item(Box::new(view), cx);
|
workspace.add_item(Box::new(view), cx);
|
||||||
}
|
}
|
||||||
|
@ -327,14 +334,12 @@ impl Item for TerminalView {
|
||||||
}
|
}
|
||||||
|
|
||||||
///Get's the working directory for the given workspace, respecting the user's settings.
|
///Get's the working directory for the given workspace, respecting the user's settings.
|
||||||
fn get_working_directory(workspace: &Workspace, cx: &AppContext) -> Option<PathBuf> {
|
fn get_working_directory(
|
||||||
let wd_setting = cx
|
workspace: &Workspace,
|
||||||
.global::<Settings>()
|
cx: &AppContext,
|
||||||
.terminal_overrides
|
strategy: WorkingDirectory,
|
||||||
.working_directory
|
) -> Option<PathBuf> {
|
||||||
.clone()
|
let res = match strategy {
|
||||||
.unwrap_or(WorkingDirectory::CurrentProjectDirectory);
|
|
||||||
let res = match wd_setting {
|
|
||||||
WorkingDirectory::CurrentProjectDirectory => current_project_directory(workspace, cx)
|
WorkingDirectory::CurrentProjectDirectory => current_project_directory(workspace, cx)
|
||||||
.or_else(|| first_project_directory(workspace, cx)),
|
.or_else(|| first_project_directory(workspace, cx)),
|
||||||
WorkingDirectory::FirstProjectDirectory => first_project_directory(workspace, cx),
|
WorkingDirectory::FirstProjectDirectory => first_project_directory(workspace, cx),
|
||||||
|
@ -520,4 +525,28 @@ mod tests {
|
||||||
assert_eq!(res, Some((Path::new("/root1/")).to_path_buf()));
|
assert_eq!(res, Some((Path::new("/root1/")).to_path_buf()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Active entry with a work tree, worktree is a file, integration test with the strategy interface
|
||||||
|
#[gpui::test]
|
||||||
|
async fn active_entry_worktree_is_file_int(cx: &mut TestAppContext) {
|
||||||
|
//Setup variables
|
||||||
|
let mut cx = TerminalTestContext::new(cx, true);
|
||||||
|
let (project, workspace) = cx.blank_workspace().await;
|
||||||
|
let (_wt, _entry) = cx.create_folder_wt(project.clone(), "/root1/").await;
|
||||||
|
let (wt2, entry2) = cx.create_file_wt(project.clone(), "/root2.txt").await;
|
||||||
|
cx.insert_active_entry_for(wt2, entry2, project.clone());
|
||||||
|
|
||||||
|
//Test
|
||||||
|
cx.cx.update(|cx| {
|
||||||
|
let workspace = workspace.read(cx);
|
||||||
|
let active_entry = project.read(cx).active_entry();
|
||||||
|
|
||||||
|
assert!(active_entry.is_some());
|
||||||
|
|
||||||
|
let res =
|
||||||
|
get_working_directory(workspace, cx, WorkingDirectory::CurrentProjectDirectory);
|
||||||
|
let first = first_project_directory(workspace, cx);
|
||||||
|
assert_eq!(res, first);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue