Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dap): auto-detect codelldb if installed using mason.nvim #80

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 16 additions & 1 deletion lua/rustaceanvim/config/internal.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local types = require('rustaceanvim.types.internal')
local compat = require('rustaceanvim.compat')

local RustaceanConfig

Expand Down Expand Up @@ -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',
Expand Down