Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collab: Fix project sharing between Windows and Unix #23680

Merged
merged 64 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3817aad
init
JunkuiZhang Jan 26, 2025
ffa222d
fix `collab`
JunkuiZhang Jan 26, 2025
813d11d
remove proto change
JunkuiZhang Jan 27, 2025
ed3031e
remove unused clone
JunkuiZhang Jan 27, 2025
0a0c5cf
use new `CrossPlatformPathBuf`
JunkuiZhang Jan 28, 2025
08344aa
new helper function
JunkuiZhang Jan 28, 2025
88430e4
fix projects
JunkuiZhang Jan 28, 2025
c0f9d37
fix `projects`
JunkuiZhang Jan 28, 2025
403c2ef
update more
JunkuiZhang Jan 28, 2025
2edd153
try fix all
JunkuiZhang Jan 28, 2025
3af17b9
use `String` for path in db
JunkuiZhang Jan 29, 2025
42cf985
fix collab
JunkuiZhang Jan 29, 2025
cd6d979
fix `remote_server`
JunkuiZhang Jan 29, 2025
3c4524c
clippy
JunkuiZhang Jan 29, 2025
efb4d91
fix
JunkuiZhang Jan 31, 2025
f9e631f
Introduce backward compatibility
JunkuiZhang Feb 5, 2025
7ce3556
fix
JunkuiZhang Feb 5, 2025
d1178d9
update proto
JunkuiZhang Feb 5, 2025
c1e6c98
fix
JunkuiZhang Feb 5, 2025
794b448
fix all
JunkuiZhang Feb 5, 2025
8a82746
fix headless
JunkuiZhang Feb 5, 2025
bee29c2
fix merge conflicts
JunkuiZhang Feb 5, 2025
297b978
simplify some function
JunkuiZhang Feb 5, 2025
dc7b359
fix
JunkuiZhang Feb 5, 2025
fa81e4c
fix `worktree_store`
JunkuiZhang Feb 5, 2025
ff5cc16
fix `headless_project`
JunkuiZhang Feb 5, 2025
83e6302
fix `worktree`
JunkuiZhang Feb 5, 2025
c469c8b
fix `db`
JunkuiZhang Feb 5, 2025
1eab622
fix `collab/project`
JunkuiZhang Feb 5, 2025
6b84b6b
fix collab
JunkuiZhang Feb 5, 2025
e845bd6
clippy
JunkuiZhang Feb 5, 2025
6398ca0
clippy
JunkuiZhang Feb 5, 2025
25a475f
clippy
JunkuiZhang Feb 5, 2025
98289e1
remove unused
JunkuiZhang Feb 5, 2025
5bae8e2
revert proto changes
JunkuiZhang Feb 6, 2025
be33b4f
add comments
JunkuiZhang Feb 6, 2025
f676588
more comments
JunkuiZhang Feb 6, 2025
2b0b34c
more commetns
JunkuiZhang Feb 6, 2025
8433ba8
fix proto
JunkuiZhang Feb 6, 2025
5bba73f
fix `worktree.rs`
JunkuiZhang Feb 6, 2025
8df0b1e
fix `worktree/worktree.rs`
JunkuiZhang Feb 6, 2025
83cd5ad
fix `project/buffer_store.rs`
JunkuiZhang Feb 6, 2025
0425e19
fix `project/git.rs`
JunkuiZhang Feb 6, 2025
da8df64
fix `project/lsp_store.rs`
JunkuiZhang Feb 6, 2025
e2ec823
fix `project/project.rs`
JunkuiZhang Feb 6, 2025
3ac7979
fix `project/project_settings.rs`
JunkuiZhang Feb 6, 2025
0d83719
fix `project/toolchain_store.rs`
JunkuiZhang Feb 6, 2025
1ffb0e3
fix `project/worktree_store.rs`
JunkuiZhang Feb 6, 2025
fc4dbd4
clippy
JunkuiZhang Feb 6, 2025
7fc1914
clippy
JunkuiZhang Feb 6, 2025
60dab48
fix remote server
JunkuiZhang Feb 6, 2025
b4462a6
fix rename
JunkuiZhang Feb 6, 2025
acbd846
add comments
JunkuiZhang Feb 6, 2025
cf8e304
fix `db/room.rs`
JunkuiZhang Feb 6, 2025
b07a961
fix `db/queries/project.rs`
JunkuiZhang Feb 6, 2025
462684b
fix `collab/db.rs`
JunkuiZhang Feb 6, 2025
5646bcb
fix typo
JunkuiZhang Feb 6, 2025
2119a7c
fix merge conflicts
JunkuiZhang Feb 6, 2025
4bbd286
clippy
JunkuiZhang Feb 6, 2025
068c1c6
try fix
JunkuiZhang Feb 6, 2025
92987db
fix `test_remote_resolve_abs_path`
JunkuiZhang Feb 6, 2025
71239d8
fix
JunkuiZhang Feb 6, 2025
856e6ab
remove `NOTE` from `.rs`
JunkuiZhang Feb 8, 2025
828b1d6
remove `// path` from proto file
JunkuiZhang Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/file_finder/src/open_path_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ impl PickerDelegate for OpenPathDelegate {
cx.notify();
}

// todo(windows)
// Is this method woring correctly on Windows? This method uses `/` for path separator.
fn update_matches(
&mut self,
query: String,
Expand Down
4 changes: 0 additions & 4 deletions crates/git/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,6 @@ impl RepoPath {

RepoPath(path.into())
}

pub fn to_proto(&self) -> String {
self.0.to_string_lossy().to_string()
}
}

impl std::fmt::Display for RepoPath {
Expand Down
8 changes: 5 additions & 3 deletions crates/project/src/buffer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ use language::{
},
Buffer, BufferEvent, Capability, DiskState, File as _, Language, LanguageRegistry, Operation,
};
use rpc::{proto, AnyProtoClient, ErrorExt as _, TypedEnvelope};
use rpc::{
proto::{self, ToProto},
AnyProtoClient, ErrorExt as _, TypedEnvelope,
};
use serde::Deserialize;
use smol::channel::Receiver;
use std::{
Expand Down Expand Up @@ -629,13 +632,12 @@ impl RemoteBufferStore {
let worktree_id = worktree.read(cx).id().to_proto();
let project_id = self.project_id;
let client = self.upstream_client.clone();
let path_string = path.clone().to_string_lossy().to_string();
cx.spawn(move |this, mut cx| async move {
let response = client
.request(proto::OpenBufferByPath {
project_id,
worktree_id,
path: path_string,
path: path.to_proto(),
})
.await?;
let buffer_id = BufferId::new(response.buffer_id)?;
Expand Down
5 changes: 3 additions & 2 deletions crates/project/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use gpui::{
App, AppContext, Context, Entity, EventEmitter, SharedString, Subscription, Task, WeakEntity,
};
use language::{Buffer, LanguageRegistry};
use rpc::proto::ToProto;
use rpc::{proto, AnyProtoClient};
use settings::WorktreeId;
use std::path::Path;
Expand Down Expand Up @@ -222,7 +223,7 @@ impl GitState {
work_directory_id: work_directory_id.to_proto(),
paths: paths
.into_iter()
.map(|repo_path| repo_path.to_proto())
.map(|repo_path| repo_path.as_ref().to_proto())
.collect(),
})
.await
Expand All @@ -247,7 +248,7 @@ impl GitState {
work_directory_id: work_directory_id.to_proto(),
paths: paths
.into_iter()
.map(|repo_path| repo_path.to_proto())
.map(|repo_path| repo_path.as_ref().to_proto())
.collect(),
})
.await
Expand Down
25 changes: 13 additions & 12 deletions crates/project/src/lsp_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ use parking_lot::Mutex;
use postage::watch;
use rand::prelude::*;

use rpc::AnyProtoClient;
use rpc::{
proto::{FromProto, ToProto},
AnyProtoClient,
};
use serde::Serialize;
use settings::{Settings, SettingsLocation, SettingsStore};
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -5466,7 +5469,7 @@ impl LspStore {
project_id: *project_id,
worktree_id: worktree_id.to_proto(),
summary: Some(proto::DiagnosticSummary {
path: worktree_path.to_string_lossy().to_string(),
path: worktree_path.to_proto(),
language_server_id: server_id.0 as u64,
error_count: new_summary.error_count as u32,
warning_count: new_summary.warning_count as u32,
Expand Down Expand Up @@ -5954,10 +5957,8 @@ impl LspStore {
.ok_or_else(|| anyhow!("worktree not found"))?;
let (old_abs_path, new_abs_path) = {
let root_path = worktree.update(&mut cx, |this, _| this.abs_path())?;
(
root_path.join(&old_path),
root_path.join(&envelope.payload.new_path),
)
let new_path = PathBuf::from_proto(envelope.payload.new_path.clone());
(root_path.join(&old_path), root_path.join(&new_path))
};

Self::will_rename_entry(
Expand Down Expand Up @@ -5987,7 +5988,7 @@ impl LspStore {
if let Some(message) = envelope.payload.summary {
let project_path = ProjectPath {
worktree_id,
path: Path::new(&message.path).into(),
path: Arc::<Path>::from_proto(message.path),
};
let path = project_path.path.clone();
let server_id = LanguageServerId(message.language_server_id as usize);
Expand Down Expand Up @@ -6021,7 +6022,7 @@ impl LspStore {
project_id: *project_id,
worktree_id: worktree_id.to_proto(),
summary: Some(proto::DiagnosticSummary {
path: project_path.path.to_string_lossy().to_string(),
path: project_path.path.as_ref().to_proto(),
language_server_id: server_id.0 as u64,
error_count: summary.error_count as u32,
warning_count: summary.warning_count as u32,
Expand Down Expand Up @@ -7211,7 +7212,7 @@ impl LspStore {
project_id,
worktree_id: worktree_id.to_proto(),
summary: Some(proto::DiagnosticSummary {
path: path.to_string_lossy().to_string(),
path: path.as_ref().to_proto(),
language_server_id: server_id.0 as u64,
error_count: 0,
warning_count: 0,
Expand Down Expand Up @@ -7865,7 +7866,7 @@ impl LspStore {
language_server_name: symbol.language_server_name.0.to_string(),
source_worktree_id: symbol.source_worktree_id.to_proto(),
worktree_id: symbol.path.worktree_id.to_proto(),
path: symbol.path.path.to_string_lossy().to_string(),
path: symbol.path.path.as_ref().to_proto(),
name: symbol.name.clone(),
kind: unsafe { mem::transmute::<lsp::SymbolKind, i32>(symbol.kind) },
start: Some(proto::PointUtf16 {
Expand All @@ -7886,7 +7887,7 @@ impl LspStore {
let kind = unsafe { mem::transmute::<i32, lsp::SymbolKind>(serialized_symbol.kind) };
let path = ProjectPath {
worktree_id,
path: PathBuf::from(serialized_symbol.path).into(),
path: Arc::<Path>::from_proto(serialized_symbol.path),
};

let start = serialized_symbol
Expand Down Expand Up @@ -8360,7 +8361,7 @@ impl DiagnosticSummary {
path: &Path,
) -> proto::DiagnosticSummary {
proto::DiagnosticSummary {
path: path.to_string_lossy().to_string(),
path: path.to_proto(),
language_server_id: language_server_id.0 as u64,
error_count: self.error_count as u32,
warning_count: self.warning_count as u32,
Expand Down
16 changes: 9 additions & 7 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub use prettier_store::PrettierStore;
use project_settings::{ProjectSettings, SettingsObserver, SettingsObserverEvent};
use remote::{SshConnectionOptions, SshRemoteClient};
use rpc::{
proto::{LanguageServerPromptResponse, SSH_PROJECT_ID},
proto::{FromProto, LanguageServerPromptResponse, ToProto, SSH_PROJECT_ID},
AnyProtoClient, ErrorCode,
};
use search::{SearchInputKind, SearchQuery, SearchResult};
Expand Down Expand Up @@ -296,14 +296,14 @@ impl ProjectPath {
pub fn from_proto(p: proto::ProjectPath) -> Self {
Self {
worktree_id: WorktreeId::from_proto(p.worktree_id),
path: Arc::from(PathBuf::from(p.path)),
path: Arc::<Path>::from_proto(p.path),
}
}

pub fn to_proto(&self) -> proto::ProjectPath {
proto::ProjectPath {
worktree_id: self.worktree_id.to_proto(),
path: self.path.to_string_lossy().to_string(),
path: self.path.as_ref().to_proto(),
}
}

Expand Down Expand Up @@ -3332,18 +3332,19 @@ impl Project {
})
})
} else if let Some(ssh_client) = self.ssh_client.as_ref() {
let request_path = Path::new(path);
let request = ssh_client
.read(cx)
.proto_client()
.request(proto::GetPathMetadata {
project_id: SSH_PROJECT_ID,
path: path.to_string(),
path: request_path.to_proto(),
});
cx.background_executor().spawn(async move {
let response = request.await.log_err()?;
if response.exists {
Some(ResolvedPath::AbsPath {
path: PathBuf::from(response.path),
path: PathBuf::from_proto(response.path),
is_dir: response.is_dir,
})
} else {
Expand Down Expand Up @@ -3413,9 +3414,10 @@ impl Project {
if self.is_local() {
DirectoryLister::Local(self.fs.clone()).list_directory(query, cx)
} else if let Some(session) = self.ssh_client.as_ref() {
let path_buf = PathBuf::from(query);
let request = proto::ListRemoteDirectory {
dev_server_id: SSH_PROJECT_ID,
path: query,
path: path_buf.to_proto(),
};

let response = session.read(cx).proto_client().request(request);
Expand Down Expand Up @@ -3966,7 +3968,7 @@ impl Project {
this.open_buffer(
ProjectPath {
worktree_id,
path: PathBuf::from(envelope.payload.path).into(),
path: Arc::<Path>::from_proto(envelope.payload.path),
},
cx,
)
Expand Down
19 changes: 9 additions & 10 deletions crates/project/src/project_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ use paths::{
local_settings_file_relative_path, local_tasks_file_relative_path,
local_vscode_tasks_file_relative_path, EDITORCONFIG_NAME,
};
use rpc::{proto, AnyProtoClient, TypedEnvelope};
use rpc::{
proto::{self, FromProto, ToProto},
AnyProtoClient, TypedEnvelope,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{
parse_json_with_comments, InvalidSettingsError, LocalSettingsKind, Settings, SettingsLocation,
SettingsSources, SettingsStore,
};
use std::{
path::{Path, PathBuf},
sync::Arc,
time::Duration,
};
use std::{path::Path, sync::Arc, time::Duration};
use task::{TaskTemplates, VsCodeTaskFile};
use util::ResultExt;
use worktree::{PathChange, UpdatedEntriesSet, Worktree, WorktreeId};
Expand Down Expand Up @@ -292,7 +291,7 @@ impl SettingsObserver {
.send(proto::UpdateWorktreeSettings {
project_id,
worktree_id,
path: path.to_string_lossy().into(),
path: path.to_proto(),
content: Some(content),
kind: Some(
local_settings_kind_to_proto(LocalSettingsKind::Settings).into(),
Expand All @@ -305,7 +304,7 @@ impl SettingsObserver {
.send(proto::UpdateWorktreeSettings {
project_id,
worktree_id,
path: path.to_string_lossy().into(),
path: path.to_proto(),
content: Some(content),
kind: Some(
local_settings_kind_to_proto(LocalSettingsKind::Editorconfig).into(),
Expand Down Expand Up @@ -343,7 +342,7 @@ impl SettingsObserver {
this.update_settings(
worktree,
[(
PathBuf::from(&envelope.payload.path).into(),
Arc::<Path>::from_proto(envelope.payload.path.clone()),
local_settings_kind_from_proto(kind),
envelope.payload.content,
)],
Expand Down Expand Up @@ -551,7 +550,7 @@ impl SettingsObserver {
.send(proto::UpdateWorktreeSettings {
project_id: self.project_id,
worktree_id: remote_worktree_id.to_proto(),
path: directory.to_string_lossy().into_owned(),
path: directory.to_proto(),
content: file_content,
kind: Some(local_settings_kind_to_proto(kind).into()),
})
Expand Down
50 changes: 36 additions & 14 deletions crates/project/src/toolchain_store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{str::FromStr, sync::Arc};
use std::{path::PathBuf, str::FromStr, sync::Arc};

use anyhow::{bail, Result};

Expand All @@ -8,7 +8,10 @@ use gpui::{
App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, Subscription, Task, WeakEntity,
};
use language::{LanguageName, LanguageRegistry, LanguageToolchainStore, Toolchain, ToolchainList};
use rpc::{proto, AnyProtoClient, TypedEnvelope};
use rpc::{
proto::{self, FromProto, ToProto},
AnyProtoClient, TypedEnvelope,
};
use settings::WorktreeId;
use util::ResultExt as _;

Expand Down Expand Up @@ -120,7 +123,9 @@ impl ToolchainStore {
};
let toolchain = Toolchain {
name: toolchain.name.into(),
path: toolchain.path.into(),
// todo(windows)
// Do we need to convert path to native string?
path: PathBuf::from(toolchain.path).to_proto().into(),
as_json: serde_json::Value::from_str(&toolchain.raw_json)?,
language_name,
};
Expand All @@ -144,10 +149,13 @@ impl ToolchainStore {
.await;

Ok(proto::ActiveToolchainResponse {
toolchain: toolchain.map(|toolchain| proto::Toolchain {
name: toolchain.name.into(),
path: toolchain.path.into(),
raw_json: toolchain.as_json.to_string(),
toolchain: toolchain.map(|toolchain| {
let path = PathBuf::from(toolchain.path.to_string());
proto::Toolchain {
name: toolchain.name.into(),
path: path.to_proto(),
raw_json: toolchain.as_json.to_string(),
}
}),
})
}
Expand Down Expand Up @@ -183,10 +191,13 @@ impl ToolchainStore {
toolchains
.toolchains
.into_iter()
.map(|toolchain| proto::Toolchain {
name: toolchain.name.to_string(),
path: toolchain.path.to_string(),
raw_json: toolchain.as_json.to_string(),
.map(|toolchain| {
let path = PathBuf::from(toolchain.path.to_string());
proto::Toolchain {
name: toolchain.name.to_string(),
path: path.to_proto(),
raw_json: toolchain.as_json.to_string(),
}
})
.collect::<Vec<_>>()
} else {
Expand Down Expand Up @@ -354,14 +365,15 @@ impl RemoteToolchainStore {
let project_id = self.project_id;
let client = self.client.clone();
cx.spawn(move |_| async move {
let path = PathBuf::from(toolchain.path.to_string());
let _ = client
.request(proto::ActivateToolchain {
project_id,
worktree_id: worktree_id.to_proto(),
language_name: toolchain.language_name.into(),
toolchain: Some(proto::Toolchain {
name: toolchain.name.into(),
path: toolchain.path.into(),
path: path.to_proto(),
raw_json: toolchain.as_json.to_string(),
}),
})
Expand Down Expand Up @@ -398,7 +410,12 @@ impl RemoteToolchainStore {
Some(Toolchain {
language_name: language_name.clone(),
name: toolchain.name.into(),
path: toolchain.path.into(),
// todo(windows)
// Do we need to convert path to native string?
path: PathBuf::from_proto(toolchain.path)
.to_string_lossy()
.to_string()
.into(),
as_json: serde_json::Value::from_str(&toolchain.raw_json).ok()?,
})
})
Expand Down Expand Up @@ -439,7 +456,12 @@ impl RemoteToolchainStore {
Some(Toolchain {
language_name: language_name.clone(),
name: toolchain.name.into(),
path: toolchain.path.into(),
// todo(windows)
// Do we need to convert path to native string?
path: PathBuf::from_proto(toolchain.path)
.to_string_lossy()
.to_string()
.into(),
as_json: serde_json::Value::from_str(&toolchain.raw_json).ok()?,
})
})
Expand Down
Loading
Loading