Add a specific server id to a Copilot LSP
This commit is contained in:
parent
91fac2aa76
commit
5b0b2fe50b
3 changed files with 26 additions and 12 deletions
|
@ -41,10 +41,15 @@ actions!(
|
||||||
[Suggest, NextSuggestion, PreviousSuggestion, Reinstall]
|
[Suggest, NextSuggestion, PreviousSuggestion, Reinstall]
|
||||||
);
|
);
|
||||||
|
|
||||||
pub fn init(http: Arc<dyn HttpClient>, node_runtime: Arc<dyn NodeRuntime>, cx: &mut AppContext) {
|
pub fn init(
|
||||||
|
new_server_id: LanguageServerId,
|
||||||
|
http: Arc<dyn HttpClient>,
|
||||||
|
node_runtime: Arc<dyn NodeRuntime>,
|
||||||
|
cx: &mut AppContext,
|
||||||
|
) {
|
||||||
let copilot = cx.add_model({
|
let copilot = cx.add_model({
|
||||||
let node_runtime = node_runtime.clone();
|
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());
|
cx.set_global(copilot.clone());
|
||||||
|
|
||||||
|
@ -268,6 +273,7 @@ pub struct Copilot {
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: Arc<dyn NodeRuntime>,
|
||||||
server: CopilotServer,
|
server: CopilotServer,
|
||||||
buffers: HashSet<WeakModelHandle<Buffer>>,
|
buffers: HashSet<WeakModelHandle<Buffer>>,
|
||||||
|
server_id: LanguageServerId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity for Copilot {
|
impl Entity for Copilot {
|
||||||
|
@ -298,11 +304,13 @@ impl Copilot {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(
|
fn start(
|
||||||
|
new_server_id: LanguageServerId,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: Arc<dyn NodeRuntime>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
|
server_id: new_server_id,
|
||||||
http,
|
http,
|
||||||
node_runtime,
|
node_runtime,
|
||||||
server: CopilotServer::Disabled,
|
server: CopilotServer::Disabled,
|
||||||
|
@ -315,13 +323,16 @@ impl Copilot {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable_or_disable_copilot(&mut self, cx: &mut ModelContext<Copilot>) {
|
fn enable_or_disable_copilot(&mut self, cx: &mut ModelContext<Copilot>) {
|
||||||
|
let server_id = self.server_id;
|
||||||
let http = self.http.clone();
|
let http = self.http.clone();
|
||||||
let node_runtime = self.node_runtime.clone();
|
let node_runtime = self.node_runtime.clone();
|
||||||
if all_language_settings(None, cx).copilot_enabled(None, None) {
|
if all_language_settings(None, cx).copilot_enabled(None, None) {
|
||||||
if matches!(self.server, CopilotServer::Disabled) {
|
if matches!(self.server, CopilotServer::Disabled) {
|
||||||
let start_task = cx
|
let start_task = cx
|
||||||
.spawn({
|
.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();
|
.shared();
|
||||||
self.server = CopilotServer::Starting { task: start_task };
|
self.server = CopilotServer::Starting { task: start_task };
|
||||||
|
@ -342,6 +353,7 @@ impl Copilot {
|
||||||
let http = util::http::FakeHttpClient::create(|_| async { unreachable!() });
|
let http = util::http::FakeHttpClient::create(|_| async { unreachable!() });
|
||||||
let node_runtime = FakeNodeRuntime::new();
|
let node_runtime = FakeNodeRuntime::new();
|
||||||
let this = cx.add_model(|_| Self {
|
let this = cx.add_model(|_| Self {
|
||||||
|
server_id: LanguageServerId(0),
|
||||||
http: http.clone(),
|
http: http.clone(),
|
||||||
node_runtime,
|
node_runtime,
|
||||||
server: CopilotServer::Running(RunningCopilotServer {
|
server: CopilotServer::Running(RunningCopilotServer {
|
||||||
|
@ -355,6 +367,7 @@ impl Copilot {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_language_server(
|
fn start_language_server(
|
||||||
|
new_server_id: LanguageServerId,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: Arc<dyn NodeRuntime>,
|
||||||
this: ModelHandle<Self>,
|
this: ModelHandle<Self>,
|
||||||
|
@ -369,13 +382,8 @@ impl Copilot {
|
||||||
path: node_path,
|
path: node_path,
|
||||||
arguments,
|
arguments,
|
||||||
};
|
};
|
||||||
let server = LanguageServer::new(
|
let server =
|
||||||
LanguageServerId(0),
|
LanguageServer::new(new_server_id, binary, Path::new("/"), None, cx.clone())?;
|
||||||
binary,
|
|
||||||
Path::new("/"),
|
|
||||||
None,
|
|
||||||
cx.clone(),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
server
|
server
|
||||||
.on_notification::<LogMessage, _>(|params, _cx| {
|
.on_notification::<LogMessage, _>(|params, _cx| {
|
||||||
|
@ -547,9 +555,10 @@ impl Copilot {
|
||||||
.spawn({
|
.spawn({
|
||||||
let http = self.http.clone();
|
let http = self.http.clone();
|
||||||
let node_runtime = self.node_runtime.clone();
|
let node_runtime = self.node_runtime.clone();
|
||||||
|
let server_id = self.server_id;
|
||||||
move |this, cx| async move {
|
move |this, cx| async move {
|
||||||
clear_copilot_dir().await;
|
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();
|
.shared();
|
||||||
|
|
|
@ -1018,6 +1018,10 @@ impl LanguageRegistry {
|
||||||
.log_err();
|
.log_err();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn next_language_server_id(&self) -> LanguageServerId {
|
||||||
|
self.state.write().next_language_server_id()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LanguageRegistryState {
|
impl LanguageRegistryState {
|
||||||
|
|
|
@ -129,6 +129,7 @@ fn main() {
|
||||||
|
|
||||||
let client = client::Client::new(http.clone(), cx);
|
let client = client::Client::new(http.clone(), cx);
|
||||||
let mut languages = LanguageRegistry::new(login_shell_env_loaded);
|
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_executor(cx.background().clone());
|
||||||
languages.set_language_server_download_dir(paths::LANGUAGES_DIR.clone());
|
languages.set_language_server_download_dir(paths::LANGUAGES_DIR.clone());
|
||||||
let languages = Arc::new(languages);
|
let languages = Arc::new(languages);
|
||||||
|
@ -159,7 +160,7 @@ fn main() {
|
||||||
semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx);
|
semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx);
|
||||||
vim::init(cx);
|
vim::init(cx);
|
||||||
terminal_view::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);
|
ai::init(cx);
|
||||||
component_test::init(cx);
|
component_test::init(cx);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue