SSH Remoting: Add the ability to resolve file paths on the remote host (#18250)
Release Notes: - N/A
This commit is contained in:
parent
d989183f94
commit
20c06545b6
5 changed files with 119 additions and 33 deletions
|
@ -108,6 +108,7 @@ impl HeadlessProject {
|
|||
session.subscribe_to_entity(SSH_PROJECT_ID, &settings_observer);
|
||||
|
||||
client.add_request_handler(cx.weak_model(), Self::handle_list_remote_directory);
|
||||
client.add_request_handler(cx.weak_model(), Self::handle_check_file_exists);
|
||||
|
||||
client.add_model_request_handler(Self::handle_add_worktree);
|
||||
client.add_model_request_handler(Self::handle_open_buffer_by_path);
|
||||
|
@ -298,4 +299,20 @@ impl HeadlessProject {
|
|||
}
|
||||
Ok(proto::ListRemoteDirectoryResponse { entries })
|
||||
}
|
||||
|
||||
pub async fn handle_check_file_exists(
|
||||
this: Model<Self>,
|
||||
envelope: TypedEnvelope<proto::CheckFileExists>,
|
||||
cx: AsyncAppContext,
|
||||
) -> Result<proto::CheckFileExistsResponse> {
|
||||
let fs = cx.read_model(&this, |this, _| this.fs.clone())?;
|
||||
let expanded = shellexpand::tilde(&envelope.payload.path).to_string();
|
||||
|
||||
let exists = fs.is_file(&PathBuf::from(expanded.clone())).await;
|
||||
|
||||
Ok(proto::CheckFileExistsResponse {
|
||||
exists,
|
||||
path: expanded,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use lsp::{CompletionContext, CompletionResponse, CompletionTriggerKind};
|
|||
use node_runtime::NodeRuntime;
|
||||
use project::{
|
||||
search::{SearchQuery, SearchResult},
|
||||
Project,
|
||||
Project, ProjectPath,
|
||||
};
|
||||
use remote::SshSession;
|
||||
use serde_json::json;
|
||||
|
@ -440,6 +440,49 @@ async fn test_remote_lsp(cx: &mut TestAppContext, server_cx: &mut TestAppContext
|
|||
})
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_remote_resolve_file_path(cx: &mut TestAppContext, server_cx: &mut TestAppContext) {
|
||||
let (project, _headless, _fs) = init_test(cx, server_cx).await;
|
||||
let (worktree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_worktree("/code/project1", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let worktree_id = cx.update(|cx| worktree.read(cx).id());
|
||||
|
||||
let buffer = project
|
||||
.update(cx, |project, cx| {
|
||||
project.open_buffer((worktree_id, Path::new("src/lib.rs")), cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let path = project
|
||||
.update(cx, |project, cx| {
|
||||
project.resolve_existing_file_path("/code/project1/README.md", &buffer, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
path.abs_path().unwrap().to_string_lossy(),
|
||||
"/code/project1/README.md"
|
||||
);
|
||||
|
||||
let path = project
|
||||
.update(cx, |project, cx| {
|
||||
project.resolve_existing_file_path("../README.md", &buffer, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
path.project_path().unwrap().clone(),
|
||||
ProjectPath::from((worktree_id, "README.md"))
|
||||
);
|
||||
}
|
||||
|
||||
fn init_logger() {
|
||||
if std::env::var("RUST_LOG").is_ok() {
|
||||
env_logger::try_init().ok();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue