From 8adf0c1b3a7a2173c80a86da5d435288bab456de Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 1 Apr 2022 11:20:41 +0900 Subject: lsp: Implement support for workspace_folders (currently just one) Refs #1898 --- helix-term/src/application.rs | 65 +++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 36 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 09b1ff61..ddf9e8d6 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -601,7 +601,7 @@ impl Application { } }; - match call { + let reply = match call { MethodCall::WorkDoneProgressCreate(params) => { self.lsp_progress.create(server_id, params.token); @@ -613,16 +613,8 @@ impl Application { if spinner.is_stopped() { spinner.start(); } - let language_server = - match self.editor.language_servers.get_by_id(server_id) { - Some(language_server) => language_server, - None => { - warn!("can't find language server with id `{}`", server_id); - return; - } - }; - tokio::spawn(language_server.reply(id, Ok(serde_json::Value::Null))); + Ok(serde_json::Value::Null) } MethodCall::ApplyWorkspaceEdit(params) => { apply_workspace_edit( @@ -631,33 +623,19 @@ impl Application { ¶ms.edit, ); + Ok(json!(lsp::ApplyWorkspaceEditResponse { + applied: true, + failure_reason: None, + failed_change: None, + })) + } + MethodCall::WorkspaceFolders => { let language_server = - match self.editor.language_servers.get_by_id(server_id) { - Some(language_server) => language_server, - None => { - warn!("can't find language server with id `{}`", server_id); - return; - } - }; + self.editor.language_servers.get_by_id(server_id).unwrap(); - tokio::spawn(language_server.reply( - id, - Ok(json!(lsp::ApplyWorkspaceEditResponse { - applied: true, - failure_reason: None, - failed_change: None, - })), - )); + Ok(json!(language_server.workspace_folders())) } MethodCall::WorkspaceConfiguration(params) => { - let language_server = - match self.editor.language_servers.get_by_id(server_id) { - Some(language_server) => language_server, - None => { - warn!("can't find language server with id `{}`", server_id); - return; - } - }; let result: Vec<_> = params .items .iter() @@ -668,7 +646,12 @@ impl Application { let doc = self.editor.document_by_path(path)?; doc.language_config()?.config.as_ref()? } - None => language_server.config()?, + None => self + .editor + .language_servers + .get_by_id(server_id) + .unwrap() + .config()?, }; if let Some(section) = item.section.as_ref() { for part in section.split('.') { @@ -678,9 +661,19 @@ impl Application { Some(config) }) .collect(); - tokio::spawn(language_server.reply(id, Ok(json!(result)))); + Ok(json!(result)) } - } + }; + + let language_server = match self.editor.language_servers.get_by_id(server_id) { + Some(language_server) => language_server, + None => { + warn!("can't find language server with id `{}`", server_id); + return; + } + }; + + tokio::spawn(language_server.reply(id, reply)); } Call::Invalid { id } => log::error!("LSP invalid method call id={:?}", id), } -- cgit v1.2.3-70-g09d2