lsp: Add support for dynamic registration of rename capability (#25610)

Piotr Osiewicz created

While looking at Biome LSP implementation I've noticed that they
register their rename capability dynamically, which we don't handle.

Release Notes:

- N/A

Change summary

crates/project/src/lsp_store.rs | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)

Detailed changes

crates/project/src/lsp_store.rs 🔗

@@ -663,6 +663,30 @@ impl LocalLspStore {
                                 "workspace/didChangeConfiguration" => {
                                     // Ignore payload since we notify clients of setting changes unconditionally, relying on them pulling the latest settings.
                                 }
+                                "textDocument/rename" => {
+                                    this.update(&mut cx, |this, _| {
+                                        if let Some(server) = this.language_server_for_id(server_id)
+                                        {
+                                            let options = reg
+                                                .register_options
+                                                .map(|options| {
+                                                    serde_json::from_value::<lsp::RenameOptions>(
+                                                        options,
+                                                    )
+                                                })
+                                                .transpose()?;
+                                            let options = match options {
+                                                None => OneOf::Left(true),
+                                                Some(options) => OneOf::Right(options),
+                                            };
+
+                                            server.update_capabilities(|capabilities| {
+                                                capabilities.rename_provider = Some(options);
+                                            })
+                                        }
+                                        anyhow::Ok(())
+                                    })??;
+                                }
                                 _ => log::warn!("unhandled capability registration: {reg:?}"),
                             }
                         }
@@ -689,6 +713,9 @@ impl LocalLspStore {
                                         Some(())
                                     })?;
                                 }
+                                "workspace/didChangeConfiguration" => {
+                                    // Ignore payload since we notify clients of setting changes unconditionally, relying on them pulling the latest settings.
+                                }
                                 "textDocument/rename" => {
                                     this.update(&mut cx, |this, _| {
                                         if let Some(server) = this.language_server_for_id(server_id)