parent
46ecd7d190
commit
0fd5030297
18 changed files with 84 additions and 85 deletions
|
@ -643,7 +643,7 @@ impl DirectoryLister {
|
|||
pub fn is_local(&self, cx: &AppContext) -> bool {
|
||||
match self {
|
||||
DirectoryLister::Local(_) => true,
|
||||
DirectoryLister::Project(project) => project.read(cx).is_local(),
|
||||
DirectoryLister::Project(project) => project.read(cx).is_local_or_ssh(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1419,7 +1419,7 @@ impl Project {
|
|||
}
|
||||
|
||||
pub fn ssh_connection_string(&self, cx: &ModelContext<Self>) -> Option<SharedString> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -1837,7 +1837,7 @@ impl Project {
|
|||
}
|
||||
|
||||
fn unshare_internal(&mut self, cx: &mut AppContext) -> Result<()> {
|
||||
if self.is_remote() {
|
||||
if self.is_via_collab() {
|
||||
if self.dev_server_project_id().is_some() {
|
||||
if let ProjectClientState::Remote { in_room, .. } = &mut self.client_state {
|
||||
*in_room = false
|
||||
|
@ -1939,28 +1939,21 @@ impl Project {
|
|||
self.is_disconnected() || self.capability() == Capability::ReadOnly
|
||||
}
|
||||
|
||||
pub fn is_local(&self) -> bool {
|
||||
pub fn is_local_or_ssh(&self) -> bool {
|
||||
match &self.client_state {
|
||||
ProjectClientState::Local | ProjectClientState::Shared { .. } => true,
|
||||
ProjectClientState::Remote { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_ssh(&self) -> bool {
|
||||
match &self.client_state {
|
||||
ProjectClientState::Local | ProjectClientState::Shared { .. } => true,
|
||||
ProjectClientState::Remote { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_remote(&self) -> bool {
|
||||
!self.is_local()
|
||||
pub fn is_via_collab(&self) -> bool {
|
||||
!self.is_local_or_ssh()
|
||||
}
|
||||
|
||||
pub fn create_buffer(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<Model<Buffer>>> {
|
||||
self.buffer_store.update(cx, |buffer_store, cx| {
|
||||
buffer_store.create_buffer(
|
||||
if self.is_remote() {
|
||||
if self.is_via_collab() {
|
||||
Some((self.client.clone().into(), self.remote_id().unwrap()))
|
||||
} else {
|
||||
None
|
||||
|
@ -1976,7 +1969,7 @@ impl Project {
|
|||
language: Option<Arc<Language>>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Model<Buffer> {
|
||||
if self.is_remote() {
|
||||
if self.is_via_collab() {
|
||||
panic!("called create_local_buffer on a remote project")
|
||||
}
|
||||
self.buffer_store.update(cx, |buffer_store, cx| {
|
||||
|
@ -2018,7 +2011,7 @@ impl Project {
|
|||
path: impl Into<ProjectPath>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Model<Buffer>>> {
|
||||
if self.is_remote() && self.is_disconnected() {
|
||||
if self.is_via_collab() && self.is_disconnected() {
|
||||
return Task::ready(Err(anyhow!(ErrorCode::Disconnected)));
|
||||
}
|
||||
|
||||
|
@ -2107,7 +2100,7 @@ impl Project {
|
|||
) -> Task<Result<Model<Buffer>>> {
|
||||
if let Some(buffer) = self.buffer_for_id(id, cx) {
|
||||
Task::ready(Ok(buffer))
|
||||
} else if self.is_local() {
|
||||
} else if self.is_local_or_ssh() {
|
||||
Task::ready(Err(anyhow!("buffer {} does not exist", id)))
|
||||
} else if let Some(project_id) = self.remote_id() {
|
||||
let request = self.client.request(proto::OpenBufferById {
|
||||
|
@ -2370,7 +2363,7 @@ impl Project {
|
|||
let mut changes = rx.ready_chunks(MAX_BATCH_SIZE);
|
||||
|
||||
while let Some(changes) = changes.next().await {
|
||||
let is_local = this.update(&mut cx, |this, _| this.is_local())?;
|
||||
let is_local = this.update(&mut cx, |this, _| this.is_local_or_ssh())?;
|
||||
|
||||
for change in changes {
|
||||
match change {
|
||||
|
@ -2512,7 +2505,7 @@ impl Project {
|
|||
}
|
||||
|
||||
BufferEvent::Reloaded => {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
if let Some(project_id) = self.remote_id() {
|
||||
let buffer = buffer.read(cx);
|
||||
self.client
|
||||
|
@ -4015,7 +4008,7 @@ impl Project {
|
|||
buffers: impl IntoIterator<Item = Model<Buffer>>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
if self.is_remote() {
|
||||
if self.is_via_collab() {
|
||||
let request = self.client.request(proto::RestartLanguageServers {
|
||||
project_id: self.remote_id().unwrap(),
|
||||
buffer_ids: buffers
|
||||
|
@ -4328,7 +4321,7 @@ impl Project {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
self.enqueue_buffer_ordered_message(BufferOrderedMessage::LanguageServerUpdate {
|
||||
language_server_id,
|
||||
message: proto::update_language_server::Variant::WorkStart(proto::LspWorkStart {
|
||||
|
@ -4393,7 +4386,7 @@ impl Project {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
self.enqueue_buffer_ordered_message(BufferOrderedMessage::LanguageServerUpdate {
|
||||
language_server_id,
|
||||
message: proto::update_language_server::Variant::WorkEnd(proto::LspWorkEnd {
|
||||
|
@ -4936,7 +4929,7 @@ impl Project {
|
|||
trigger: FormatTrigger,
|
||||
cx: &mut ModelContext<Project>,
|
||||
) -> Task<anyhow::Result<ProjectTransaction>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let buffers_with_paths = buffers
|
||||
.into_iter()
|
||||
.map(|buffer_handle| {
|
||||
|
@ -5664,7 +5657,7 @@ impl Project {
|
|||
pub fn symbols(&self, query: &str, cx: &mut ModelContext<Self>) -> Task<Result<Vec<Symbol>>> {
|
||||
let language_registry = self.languages.clone();
|
||||
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let mut requests = Vec::new();
|
||||
for ((worktree_id, _), server_id) in self.language_server_ids.iter() {
|
||||
let Some(worktree_handle) = self.worktree_for_id(*worktree_id, cx) else {
|
||||
|
@ -5821,7 +5814,7 @@ impl Project {
|
|||
symbol: &Symbol,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Model<Buffer>>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let language_server_id = if let Some(id) = self.language_server_ids.get(&(
|
||||
symbol.source_worktree_id,
|
||||
symbol.language_server_name.clone(),
|
||||
|
@ -5880,7 +5873,7 @@ impl Project {
|
|||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Vec<SignatureHelp>> {
|
||||
let position = position.to_point_utf16(buffer.read(cx));
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let all_actions_task = self.request_multiple_lsp_locally(
|
||||
buffer,
|
||||
Some(position),
|
||||
|
@ -5954,7 +5947,7 @@ impl Project {
|
|||
position: PointUtf16,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Vec<Hover>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let all_actions_task = self.request_multiple_lsp_locally(
|
||||
&buffer,
|
||||
Some(position),
|
||||
|
@ -6062,7 +6055,10 @@ impl Project {
|
|||
})
|
||||
.map(|(_, server)| LanguageServerToQuery::Other(server.server_id()))
|
||||
.next()
|
||||
.or_else(|| self.is_remote().then_some(LanguageServerToQuery::Primary))
|
||||
.or_else(|| {
|
||||
self.is_via_collab()
|
||||
.then_some(LanguageServerToQuery::Primary)
|
||||
})
|
||||
.filter(|_| {
|
||||
maybe!({
|
||||
let language_name = buffer.read(cx).language_at(position)?.name();
|
||||
|
@ -6104,7 +6100,7 @@ impl Project {
|
|||
) -> Task<Result<Vec<Completion>>> {
|
||||
let language_registry = self.languages.clone();
|
||||
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let snapshot = buffer.read(cx).snapshot();
|
||||
let offset = position.to_offset(&snapshot);
|
||||
let scope = snapshot.language_scope_at(offset);
|
||||
|
@ -6214,7 +6210,7 @@ impl Project {
|
|||
let client = self.client();
|
||||
let language_registry = self.languages().clone();
|
||||
|
||||
let is_remote = self.is_remote();
|
||||
let is_remote = self.is_via_collab();
|
||||
let project_id = self.remote_id();
|
||||
|
||||
let buffer_id = buffer.read(cx).remote_id();
|
||||
|
@ -6427,7 +6423,7 @@ impl Project {
|
|||
let buffer = buffer_handle.read(cx);
|
||||
let buffer_id = buffer.remote_id();
|
||||
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let server_id = completion.server_id;
|
||||
let lang_server = match self.language_server_for_buffer(buffer, server_id, cx) {
|
||||
Some((_, server)) => server.clone(),
|
||||
|
@ -6539,7 +6535,7 @@ impl Project {
|
|||
range: Range<Anchor>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Vec<CodeAction>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let all_actions_task = self.request_multiple_lsp_locally(
|
||||
&buffer_handle,
|
||||
Some(range.start),
|
||||
|
@ -6630,7 +6626,7 @@ impl Project {
|
|||
push_to_history: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<ProjectTransaction>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let buffer = buffer_handle.read(cx);
|
||||
let (lsp_adapter, lang_server) = if let Some((adapter, server)) =
|
||||
self.language_server_for_buffer(buffer, action.server_id, cx)
|
||||
|
@ -6712,7 +6708,7 @@ impl Project {
|
|||
trigger: String,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Option<Transaction>>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
// Do not allow multiple concurrent formatting requests for the
|
||||
// same buffer.
|
||||
|
@ -7138,7 +7134,7 @@ impl Project {
|
|||
let buffer_id = buffer.remote_id().into();
|
||||
let lsp_request = InlayHints { range };
|
||||
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let lsp_request_task = self.request_lsp(
|
||||
buffer_handle.clone(),
|
||||
LanguageServerToQuery::Primary,
|
||||
|
@ -7190,7 +7186,7 @@ impl Project {
|
|||
server_id: LanguageServerId,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<anyhow::Result<InlayHint>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let buffer = buffer_handle.read(cx);
|
||||
let (_, lang_server) = if let Some((adapter, server)) =
|
||||
self.language_server_for_buffer(buffer, server_id, cx)
|
||||
|
@ -7252,7 +7248,7 @@ impl Project {
|
|||
query: SearchQuery,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Receiver<SearchResult> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
self.search_local(query, cx)
|
||||
} else if let Some(project_id) = self.remote_id() {
|
||||
let (tx, rx) = smol::channel::unbounded();
|
||||
|
@ -7594,7 +7590,7 @@ impl Project {
|
|||
<R::LspRequest as lsp::request::Request>::Params: Send,
|
||||
{
|
||||
let buffer = buffer_handle.read(cx);
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let language_server = match server {
|
||||
LanguageServerToQuery::Primary => {
|
||||
match self.primary_language_server_for_buffer(buffer, cx) {
|
||||
|
@ -7696,7 +7692,7 @@ impl Project {
|
|||
<R::LspRequest as lsp::request::Request>::Result: Send,
|
||||
<R::LspRequest as lsp::request::Request>::Params: Send,
|
||||
{
|
||||
if !self.is_local() {
|
||||
if !self.is_local_or_ssh() {
|
||||
debug_panic!("Should not request multiple lsp commands in non-local project");
|
||||
return Task::ready(Vec::new());
|
||||
}
|
||||
|
@ -7834,7 +7830,7 @@ impl Project {
|
|||
return Task::ready(None);
|
||||
}
|
||||
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let expanded = PathBuf::from(shellexpand::tilde(&path).into_owned());
|
||||
|
||||
if expanded.is_absolute() {
|
||||
|
@ -7909,7 +7905,7 @@ impl Project {
|
|||
query: String,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Vec<PathBuf>>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
DirectoryLister::Local(self.fs.clone()).list_directory(query, cx)
|
||||
} else if let Some(dev_server) = self.dev_server_project_id().and_then(|id| {
|
||||
dev_server_projects::Store::global(cx)
|
||||
|
@ -7940,7 +7936,7 @@ impl Project {
|
|||
if !self.loading_worktrees.contains_key(&path) {
|
||||
let task = if self.ssh_session.is_some() {
|
||||
self.create_ssh_worktree(abs_path, visible, cx)
|
||||
} else if self.is_local() {
|
||||
} else if self.is_local_or_ssh() {
|
||||
self.create_local_worktree(abs_path, visible, cx)
|
||||
} else if self.dev_server_project_id.is_some() {
|
||||
self.create_dev_server_worktree(abs_path, cx)
|
||||
|
@ -8467,7 +8463,7 @@ impl Project {
|
|||
}
|
||||
|
||||
cx.emit(Event::DiskBasedDiagnosticsStarted { language_server_id });
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
self.enqueue_buffer_ordered_message(BufferOrderedMessage::LanguageServerUpdate {
|
||||
language_server_id,
|
||||
message: proto::update_language_server::Variant::DiskBasedDiagnosticsUpdating(
|
||||
|
@ -8491,7 +8487,7 @@ impl Project {
|
|||
|
||||
cx.emit(Event::DiskBasedDiagnosticsFinished { language_server_id });
|
||||
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
self.enqueue_buffer_ordered_message(BufferOrderedMessage::LanguageServerUpdate {
|
||||
language_server_id,
|
||||
message: proto::update_language_server::Variant::DiskBasedDiagnosticsUpdated(
|
||||
|
@ -8765,7 +8761,7 @@ impl Project {
|
|||
mut cx: AsyncAppContext,
|
||||
) -> Result<()> {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
if this.is_local() {
|
||||
if this.is_local_or_ssh() {
|
||||
this.unshare(cx)?;
|
||||
} else {
|
||||
this.disconnected_from_host(cx);
|
||||
|
@ -10482,7 +10478,7 @@ impl Project {
|
|||
location: Location,
|
||||
cx: &mut ModelContext<'_, Project>,
|
||||
) -> Task<Option<TaskContext>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let (worktree_id, cwd) = if let Some(worktree) = self.task_worktree(cx) {
|
||||
(
|
||||
Some(worktree.read(cx).id()),
|
||||
|
@ -10609,7 +10605,7 @@ impl Project {
|
|||
location: Option<Location>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Vec<(TaskSourceKind, TaskTemplate)>>> {
|
||||
if self.is_local() {
|
||||
if self.is_local_or_ssh() {
|
||||
let (file, language) = location
|
||||
.map(|location| {
|
||||
let buffer = location.buffer.read(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue