diff --git a/src/solidlsp/language_servers/clangd_language_server.py b/src/solidlsp/language_servers/clangd_language_server.py index 6f1426be..2a1f9e8e 100644 --- a/src/solidlsp/language_servers/clangd_language_server.py +++ b/src/solidlsp/language_servers/clangd_language_server.py @@ -51,6 +51,8 @@ class ClangdLanguageServer(SolidLanguageServer): """ Setup runtime dependencies for ClangdLanguageServer and return the command to start the server. """ + import shutil + deps = RuntimeDependencyCollection( [ RuntimeDependency( @@ -89,21 +91,40 @@ class ClangdLanguageServer(SolidLanguageServer): ) clangd_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), "clangd") - dep = deps.get_single_dep_for_current_platform() - clangd_executable_path = deps.binary_path(clangd_ls_dir) - if not os.path.exists(clangd_executable_path): - logger.log( - f"Clangd executable not found at {clangd_executable_path}. Downloading from {dep.url}", - logging.INFO, - ) - deps.install(logger, clangd_ls_dir) - if not os.path.exists(clangd_executable_path): - raise FileNotFoundError( - f"Clangd executable not found at {clangd_executable_path}.\n" - "Make sure you have installed clangd. See https://clangd.llvm.org/installation" - ) - os.chmod(clangd_executable_path, 0o755) + try: + dep = deps.get_single_dep_for_current_platform() + except RuntimeError: + dep = None + + if dep is None: + # No prebuilt binary available, look for system-installed clangd + clangd_executable_path = shutil.which("clangd") + if not clangd_executable_path: + raise FileNotFoundError( + "Clangd is not installed on your system.\n" + + "Please install clangd using your system package manager:\n" + + " Ubuntu/Debian: sudo apt-get install clangd\n" + + " Fedora/RHEL: sudo dnf install clang-tools-extra\n" + + " Arch Linux: sudo pacman -S clang\n" + + "See https://clangd.llvm.org/installation for more details." + ) + logger.log(f"Using system-installed clangd at {clangd_executable_path}", logging.INFO) + else: + # Standard download and install for platforms with prebuilt binaries + clangd_executable_path = deps.binary_path(clangd_ls_dir) + if not os.path.exists(clangd_executable_path): + logger.log( + f"Clangd executable not found at {clangd_executable_path}. Downloading from {dep.url}", + logging.INFO, + ) + _ = deps.install(logger, clangd_ls_dir) + if not os.path.exists(clangd_executable_path): + raise FileNotFoundError( + f"Clangd executable not found at {clangd_executable_path}.\n" + + "Make sure you have installed clangd. See https://clangd.llvm.org/installation" + ) + os.chmod(clangd_executable_path, 0o755) return clangd_executable_path @staticmethod