diff --git a/CHANGELOG.md b/CHANGELOG.md index a6f81273..02388e99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.9.0] - 2023-12-01 + +### Added + +- DAP: Auto-detect `codelldb` if it is installed via [mason.nvim](https://github.com/williamboman/mason.nvim). + ## [3.8.0] - 2023-12-01 ### Added diff --git a/README.md b/README.md index b1609d62..6761c625 100644 --- a/README.md +++ b/README.md @@ -434,6 +434,8 @@ Some examples: - NixOS: [`vscode-extensions.vadimcn.vscode-lldb.adapter`](https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/editors/vscode/extensions/vadimcn.vscode-lldb/default.nix#L134) - Arch Linux: [`codelldb-bin` (AUR)](https://aur.archlinux.org/packages/codelldb-bin) +- Using [`mason.nvim`](https://github.com/williamboman/mason.nvim): + `:MasonInstall codelldb` If your distribution does not have a `codelldb` package, you can configure it as follows: diff --git a/lua/rustaceanvim/config/internal.lua b/lua/rustaceanvim/config/internal.lua index 4f0fde62..76a3e777 100644 --- a/lua/rustaceanvim/config/internal.lua +++ b/lua/rustaceanvim/config/internal.lua @@ -1,4 +1,5 @@ local types = require('rustaceanvim.types.internal') +local compat = require('rustaceanvim.compat') local RustaceanConfig @@ -207,7 +208,21 @@ local RustaceanDefaultConfig = { adapter = function() --- @type DapExecutableConfig | DapServerConfig | disable local result = false - if vim.fn.executable('codelldb') == 1 then + local has_mason, mason_registry = pcall(require, 'mason-registry') + local mason_has_codelldb, codelldb = has_mason and pcall(mason_registry.get_package, 'codelldb') or false, nil + if mason_has_codelldb then + local mason_codelldb_path = compat.joinpath(codelldb:get_install_path(), 'extension') + local codelldb_path = compat.joinpath(mason_codelldb_path, 'adapter', 'codelldb') + local liblldb_path = compat.joinpath('lldb', 'lib', 'liblldb') + local shell = require('rustaceanvim.shell') + if shell.is_windows() then + codelldb_path = codelldb_path .. 'exe' + liblldb_path = compat.joinpath(mason_codelldb_path, 'lldb', 'bin', 'liblldb.dll') + else + liblldb_path = liblldb_path .. (shell.is_macos() and '.dylib' or '.so') + end + result = require('rustaceanvim.dap').get_codelldb_adapter(codelldb_path, liblldb_path) + elseif vim.fn.executable('codelldb') == 1 then ---@cast result DapServerConfig result = { type = 'server',