2023-04-17 20:27:27 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib;
|
|
|
|
with builtins; let
|
|
|
|
cfg = config.vim.languages.clang;
|
|
|
|
|
|
|
|
defaultServer = "ccls";
|
|
|
|
servers = {
|
|
|
|
ccls = {
|
|
|
|
package = pkgs.ccls;
|
|
|
|
lspConfig = ''
|
|
|
|
lspconfig.ccls.setup{
|
|
|
|
capabilities = capabilities;
|
|
|
|
on_attach=default_on_attach;
|
2023-04-23 13:36:53 +00:00
|
|
|
cmd = {"${cfg.lsp.package}/bin/ccls"};
|
|
|
|
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
|
2023-04-17 20:27:27 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-04-23 13:46:05 +00:00
|
|
|
clangd = {
|
2023-09-17 17:07:01 +00:00
|
|
|
package = pkgs.clang-tools_16;
|
2023-04-23 13:46:05 +00:00
|
|
|
lspConfig = ''
|
2023-06-11 23:12:05 +00:00
|
|
|
local clangd_cap = capabilities
|
|
|
|
-- use same offsetEncoding as null-ls
|
|
|
|
clangd_cap.offsetEncoding = {"utf-16"}
|
2023-04-23 13:46:05 +00:00
|
|
|
lspconfig.clangd.setup{
|
2023-06-11 23:12:05 +00:00
|
|
|
capabilities = clangd_cap;
|
2023-04-23 13:46:05 +00:00
|
|
|
on_attach=default_on_attach;
|
|
|
|
cmd = {"${cfg.lsp.package}/bin/clangd"};
|
|
|
|
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
2023-05-20 11:46:19 +00:00
|
|
|
|
|
|
|
defaultDebugger = "lldb-vscode";
|
|
|
|
debuggers = {
|
|
|
|
lldb-vscode = {
|
|
|
|
package = pkgs.lldb;
|
|
|
|
dapConfig = ''
|
|
|
|
dap.adapters.lldb = {
|
|
|
|
type = 'executable',
|
|
|
|
command = '${cfg.dap.package}/bin/lldb-vscode',
|
|
|
|
name = 'lldb'
|
|
|
|
}
|
|
|
|
dap.configurations.cpp = {
|
|
|
|
{
|
|
|
|
name = 'Launch',
|
|
|
|
type = 'lldb',
|
|
|
|
request = 'launch',
|
|
|
|
program = function()
|
|
|
|
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
|
|
|
|
end,
|
|
|
|
cwd = "''${workspaceFolder}",
|
|
|
|
stopOnEntry = false,
|
|
|
|
args = {},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
dap.configurations.c = dap.configurations.cpp
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2023-04-17 20:27:27 +00:00
|
|
|
in {
|
|
|
|
options.vim.languages.clang = {
|
|
|
|
enable = mkEnableOption "C/C++ language support";
|
|
|
|
|
|
|
|
cHeader = mkOption {
|
|
|
|
description = ''
|
|
|
|
C syntax for headers. Can fix treesitter errors, see:
|
|
|
|
https://www.reddit.com/r/neovim/comments/orfpcd/question_does_the_c_parser_from_nvimtreesitter/
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
treesitter = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "C/C++ treesitter" // {default = config.vim.languages.enableTreesitter;};
|
2023-04-17 21:55:27 +00:00
|
|
|
cPackage = nvim.types.mkGrammarOption pkgs "c";
|
|
|
|
cppPackage = nvim.types.mkGrammarOption pkgs "cpp";
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
lsp = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable clang LSP support" // {default = config.vim.languages.enableLSP;};
|
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
server = mkOption {
|
|
|
|
description = "The clang LSP server to use";
|
|
|
|
type = with types; enum (attrNames servers);
|
|
|
|
default = defaultServer;
|
|
|
|
};
|
2023-06-05 20:10:25 +00:00
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
package = mkOption {
|
|
|
|
description = "clang LSP server package";
|
|
|
|
type = types.package;
|
|
|
|
default = servers.${cfg.lsp.server}.package;
|
|
|
|
};
|
2023-06-05 20:10:25 +00:00
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
opts = mkOption {
|
|
|
|
description = "Options to pass to clang LSP server";
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
};
|
2023-05-20 11:46:19 +00:00
|
|
|
|
|
|
|
dap = {
|
|
|
|
enable = mkOption {
|
|
|
|
description = "Enable clang Debug Adapter";
|
|
|
|
type = types.bool;
|
|
|
|
default = config.vim.languages.enableDAP;
|
|
|
|
};
|
|
|
|
debugger = mkOption {
|
|
|
|
description = "clang debugger to use";
|
|
|
|
type = with types; enum (attrNames debuggers);
|
|
|
|
default = defaultDebugger;
|
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
description = "clang debugger package.";
|
|
|
|
type = types.package;
|
|
|
|
default = debuggers.${cfg.dap.debugger}.package;
|
|
|
|
};
|
|
|
|
};
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf cfg.cHeader {
|
|
|
|
vim.configRC.c-header = nvim.dag.entryAnywhere "let g:c_syntax_for_h = 1";
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.treesitter.enable {
|
|
|
|
vim.treesitter.enable = true;
|
|
|
|
vim.treesitter.grammars = [cfg.treesitter.cPackage cfg.treesitter.cppPackage];
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.lsp.enable {
|
|
|
|
vim.lsp.lspconfig.enable = true;
|
|
|
|
|
|
|
|
vim.lsp.lspconfig.sources.clang-lsp = servers.${cfg.lsp.server}.lspConfig;
|
|
|
|
})
|
2023-05-20 11:46:19 +00:00
|
|
|
|
|
|
|
(mkIf cfg.dap.enable {
|
|
|
|
vim.debugger.nvim-dap.enable = true;
|
|
|
|
vim.debugger.nvim-dap.sources.clang-debugger = debuggers.${cfg.dap.debugger}.dapConfig;
|
|
|
|
})
|
2023-04-17 20:27:27 +00:00
|
|
|
]);
|
|
|
|
}
|