diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index 28c20d95bb..4551fe0358 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -41,10 +41,15 @@ actions!( [Suggest, NextSuggestion, PreviousSuggestion, Reinstall] ); -pub fn init(http: Arc, node_runtime: Arc, cx: &mut AppContext) { +pub fn init( + new_server_id: LanguageServerId, + http: Arc, + node_runtime: Arc, + cx: &mut AppContext, +) { let copilot = cx.add_model({ let node_runtime = node_runtime.clone(); - move |cx| Copilot::start(http, node_runtime, cx) + move |cx| Copilot::start(new_server_id, http, node_runtime, cx) }); cx.set_global(copilot.clone()); @@ -268,6 +273,7 @@ pub struct Copilot { node_runtime: Arc, server: CopilotServer, buffers: HashSet>, + server_id: LanguageServerId, } impl Entity for Copilot { @@ -298,11 +304,13 @@ impl Copilot { } fn start( + new_server_id: LanguageServerId, http: Arc, node_runtime: Arc, cx: &mut ModelContext, ) -> Self { let mut this = Self { + server_id: new_server_id, http, node_runtime, server: CopilotServer::Disabled, @@ -315,13 +323,16 @@ impl Copilot { } fn enable_or_disable_copilot(&mut self, cx: &mut ModelContext) { + let server_id = self.server_id; let http = self.http.clone(); let node_runtime = self.node_runtime.clone(); if all_language_settings(None, cx).copilot_enabled(None, None) { if matches!(self.server, CopilotServer::Disabled) { let start_task = cx .spawn({ - move |this, cx| Self::start_language_server(http, node_runtime, this, cx) + move |this, cx| { + Self::start_language_server(server_id, http, node_runtime, this, cx) + } }) .shared(); self.server = CopilotServer::Starting { task: start_task }; @@ -342,6 +353,7 @@ impl Copilot { let http = util::http::FakeHttpClient::create(|_| async { unreachable!() }); let node_runtime = FakeNodeRuntime::new(); let this = cx.add_model(|_| Self { + server_id: LanguageServerId(0), http: http.clone(), node_runtime, server: CopilotServer::Running(RunningCopilotServer { @@ -355,6 +367,7 @@ impl Copilot { } fn start_language_server( + new_server_id: LanguageServerId, http: Arc, node_runtime: Arc, this: ModelHandle, @@ -369,13 +382,8 @@ impl Copilot { path: node_path, arguments, }; - let server = LanguageServer::new( - LanguageServerId(0), - binary, - Path::new("/"), - None, - cx.clone(), - )?; + let server = + LanguageServer::new(new_server_id, binary, Path::new("/"), None, cx.clone())?; server .on_notification::(|params, _cx| { @@ -547,9 +555,10 @@ impl Copilot { .spawn({ let http = self.http.clone(); let node_runtime = self.node_runtime.clone(); + let server_id = self.server_id; move |this, cx| async move { clear_copilot_dir().await; - Self::start_language_server(http, node_runtime, this, cx).await + Self::start_language_server(server_id, http, node_runtime, this, cx).await } }) .shared(); diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index 07bea434e0..7d113a88af 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -1018,6 +1018,10 @@ impl LanguageRegistry { .log_err(); }) } + + pub fn next_language_server_id(&self) -> LanguageServerId { + self.state.write().next_language_server_id() + } } impl LanguageRegistryState { diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index c800e4e110..d22e26c1f5 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -129,6 +129,7 @@ fn main() { let client = client::Client::new(http.clone(), cx); let mut languages = LanguageRegistry::new(login_shell_env_loaded); + let copilot_language_server_id = languages.next_language_server_id(); languages.set_executor(cx.background().clone()); languages.set_language_server_download_dir(paths::LANGUAGES_DIR.clone()); let languages = Arc::new(languages); @@ -159,7 +160,7 @@ fn main() { semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx); vim::init(cx); terminal_view::init(cx); - copilot::init(http.clone(), node_runtime, cx); + copilot::init(copilot_language_server_id, http.clone(), node_runtime, cx); ai::init(cx); component_test::init(cx);