Check for user installed clangd (#9605)

Ezekiel Warren created

Release Notes:

- Improved C/C++ support using user installed clangd when available

Change summary

crates/languages/src/c.rs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

Detailed changes

crates/languages/src/c.rs 🔗

@@ -1,6 +1,7 @@
 use anyhow::{anyhow, bail, Context, Result};
 use async_trait::async_trait;
 use futures::StreamExt;
+use gpui::AsyncAppContext;
 pub use language::*;
 use lsp::LanguageServerBinary;
 use smol::fs::{self, File};
@@ -29,6 +30,7 @@ impl super::LspAdapter for CLspAdapter {
         let os_suffix = match consts::OS {
             "macos" => "mac",
             "linux" => "linux",
+            "windows" => "windows",
             other => bail!("Running on unsupported os: {other}"),
         };
         let asset_name = format!("clangd-{}-{}.zip", os_suffix, release.tag_name);
@@ -44,6 +46,20 @@ impl super::LspAdapter for CLspAdapter {
         Ok(Box::new(version) as Box<_>)
     }
 
+    async fn check_if_user_installed(
+        &self,
+        delegate: &dyn LspAdapterDelegate,
+        _: &AsyncAppContext,
+    ) -> Option<LanguageServerBinary> {
+        let env = delegate.shell_env().await;
+        let path = delegate.which("clangd".as_ref()).await?;
+        Some(LanguageServerBinary {
+            path,
+            arguments: vec![],
+            env: Some(env),
+        })
+    }
+
     async fn fetch_server_binary(
         &self,
         version: Box<dyn 'static + Send + Any>,