From b4eaabea957cb2b3bde3e8076be67d797a72eddd Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 25 Jun 2023 14:09:12 +0200 Subject: [PATCH 01/15] fix(flutter-tools): bug where dart lsp is not found --- lib/types/plugins.nix | 1 + modules/default.nix | 22 +++++++++++------ modules/languages/dart/config.nix | 5 +++- modules/languages/dart/dart.nix | 10 ++++++++ patches/flutter-tools.patch | 41 +++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 patches/flutter-tools.patch diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 310fdaa..9515b04 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -73,6 +73,7 @@ with lib; let "diffview-nvim" "todo-comments" "flutter-tools" + "flutter-tools-patched" "hop-nvim" "leap-nvim" "modes-nvim" diff --git a/modules/default.nix b/modules/default.nix index f7abc9e..1e06398 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -25,13 +25,13 @@ inputs: { // extraSpecialArgs; }; - buildPlug = name: - buildVimPluginFrom2Nix rec { - pname = name; - version = "master"; - src = assert lib.asserts.assertMsg (name != "nvim-treesitter") "Use buildTreesitterPlug for building nvim-treesitter."; - getAttr pname inputs; - }; + buildPlug = {pname, ...} @ args: + assert lib.asserts.assertMsg (pname != "nvim-treesitter") "Use buildTreesitterPlug for building nvim-treesitter."; + buildVimPluginFrom2Nix (args + // { + version = "master"; + src = getAttr pname inputs; + }); buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars); @@ -45,7 +45,13 @@ inputs: { ( if (plug == "nvim-treesitter") then (buildTreesitterPlug vimOptions.treesitter.grammars) - else (buildPlug plug) + else if (plug == "flutter-tools-patched") + then + (buildPlug { + pname = "flutter-tools"; + patches = [../patches/flutter-tools.patch]; + }) + else (buildPlug {pname = plug;}) ) else plug )) diff --git a/modules/languages/dart/config.nix b/modules/languages/dart/config.nix index ff19ede..82b061d 100644 --- a/modules/languages/dart/config.nix +++ b/modules/languages/dart/config.nix @@ -35,7 +35,10 @@ in { }) (mkIf (ftcfg.enable) { - vim.startPlugins = ["flutter-tools"]; + vim.startPlugins = + if ftcfg.enableNoResolvePatch + then ["flutter-tools-patched"] + else ["flutter-tools"]; vim.luaConfigRC.flutter-tools = nvim.dag.entryAnywhere '' require('flutter-tools').setup { diff --git a/modules/languages/dart/dart.nix b/modules/languages/dart/dart.nix index 728e64d..f6694ad 100644 --- a/modules/languages/dart/dart.nix +++ b/modules/languages/dart/dart.nix @@ -56,6 +56,16 @@ in { default = config.vim.languages.enableLSP; }; + enableNoResolvePatch = mkOption { + description = '' + Patch flutter-tools so that it doesn't resolve symlinks when detecting flutter path. + This is required if you want to use a flutter package built with nix. + If you are using a flutter SDK installed from a different source and encounter the error "`dart` missing from PATH", disable this option. + ''; + type = types.bool; + default = true; + }; + color = { enable = mkEnableOption "Whether or mot to highlight color variables at all"; diff --git a/patches/flutter-tools.patch b/patches/flutter-tools.patch new file mode 100644 index 0000000..b8315fe --- /dev/null +++ b/patches/flutter-tools.patch @@ -0,0 +1,41 @@ +diff --git a/lua/flutter-tools/executable.lua b/lua/flutter-tools/executable.lua +index 3807a4f..3345760 100644 +--- a/lua/flutter-tools/executable.lua ++++ b/lua/flutter-tools/executable.lua +@@ -31,12 +31,12 @@ local function _dart_sdk_root(paths) + end + + if utils.executable("flutter") then +- local flutter_path = fn.resolve(fn.exepath("flutter")) ++ local flutter_path = fn.exepath("flutter") + local flutter_bin = fn.fnamemodify(flutter_path, ":h") + return path.join(flutter_bin, dart_sdk) + end + +- if utils.executable("dart") then return fn.resolve(fn.exepath("dart")) end ++ if utils.executable("dart") then return fn.exepath("dart") end + + return "" + end +@@ -50,10 +50,10 @@ end + ---Get paths for flutter and dart based on the binary locations + ---@return table + local function get_default_binaries() +- local flutter_bin = fn.resolve(fn.exepath("flutter")) ++ local flutter_bin = fn.exepath("flutter") + return { + flutter_bin = flutter_bin, +- dart_bin = fn.resolve(fn.exepath("dart")), ++ dart_bin = fn.exepath("dart"), + flutter_sdk = _flutter_sdk_root(flutter_bin), + } + end +@@ -119,7 +119,7 @@ function M.get(callback) + end + + if config.flutter_path then +- local flutter_path = fn.resolve(config.flutter_path) ++ local flutter_path = config.flutter_path + _paths = { flutter_bin = flutter_path, flutter_sdk = _flutter_sdk_root(flutter_path) } + _paths.dart_sdk = _dart_sdk_root(_paths) + _paths.dart_bin = _flutter_sdk_dart_bin(_paths.flutter_sdk) From e4c2c3dfe44ec68fd6179b0d5649298f6b5e82d4 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 25 Jun 2023 14:31:01 +0200 Subject: [PATCH 02/15] update docs --- docs/release-notes/rl-0.4.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/rl-0.4.adoc b/docs/release-notes/rl-0.4.adoc index c1e548c..14dcb78 100644 --- a/docs/release-notes/rl-0.4.adoc +++ b/docs/release-notes/rl-0.4.adoc @@ -1,6 +1,5 @@ [[sec-release-0.4]] == Release 0.4 - Following the release of v0.3, I have decided to release v0.4 with a massive new change: customizable keybinds. As of the 0.4 release, keybinds will no longer be hardcoded and instead provided by each module's own keybinds section. The old keybind system (`vim.keybinds = {}`) is now considered deprecated and the new lib functions are recommended to be used for adding keybinds for new plugins, or adding keybinds to existing plugins. Alongside customizable keybinds, there are a few quality of life updates, such as `lazygit` integration and the new experimental Lua loader of Neovim 0.9 thanks to our awesome contributors who made this update possible during my absence. @@ -34,6 +33,8 @@ https://github.com/horriblename[horriblename]: * Added new option `enableluaLoader` to enable neovim's experimental module loader for faster startup time. +* Fixed bug where flutter-tools can't find `dart` LSP + https://github.com/notashelf[notashelf]: * Made Copilot's Node package configurable. It is recommended to keep as default, but providing a different NodeJS version is now possible. From 640e37bd0803636cf0f3bfea403764c6332a277b Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 4 May 2023 18:41:11 +0300 Subject: [PATCH 03/15] dev: init nvim-dap setup --- extra.nix | 8 ++++++ flake.lock | 34 ++++++++++++++++++++++++++ flake.nix | 11 +++++++++ lib/types/plugins.nix | 2 ++ modules/debugger/default.nix | 5 ++++ modules/debugger/nvim-dap/config.nix | 23 +++++++++++++++++ modules/debugger/nvim-dap/default.nix | 6 +++++ modules/debugger/nvim-dap/nvim-dap.nix | 10 ++++++++ modules/modules.nix | 1 + 9 files changed, 100 insertions(+) create mode 100644 modules/debugger/default.nix create mode 100644 modules/debugger/nvim-dap/config.nix create mode 100644 modules/debugger/nvim-dap/default.nix create mode 100644 modules/debugger/nvim-dap/nvim-dap.nix diff --git a/extra.nix b/extra.nix index 70ccbfb..a38a2da 100644 --- a/extra.nix +++ b/extra.nix @@ -39,6 +39,13 @@ inputs: let lspSignature.enable = true; }; + vim.debugger = { + nvim-dap = { + enable = true; + ui.enable = true; + }; + }; + vim.languages = { enableLSP = true; enableFormat = true; @@ -217,6 +224,7 @@ inputs: let image_text = "The Superior Text Editor"; client_id = "793271441293967371"; main_image = "neovim"; + show_time = true; rich_presence = { editing_text = "Editing %s"; }; diff --git a/flake.lock b/flake.lock index f2b194b..bdde15f 100644 --- a/flake.lock +++ b/flake.lock @@ -1012,6 +1012,38 @@ "type": "github" } }, + "nvim-dap": { + "flake": false, + "locked": { + "lastModified": 1682077642, + "narHash": "sha256-l5sJ6PKW10CtOzSBKzWasWVMZq/mAkgpgWOecIVuV+0=", + "owner": "mfussenegger", + "repo": "nvim-dap", + "rev": "6cedcb527e264c8f25e86afa8dae74c6692dee51", + "type": "github" + }, + "original": { + "owner": "mfussenegger", + "repo": "nvim-dap", + "type": "github" + } + }, + "nvim-dap-ui": { + "flake": false, + "locked": { + "lastModified": 1683055722, + "narHash": "sha256-8TavZqkTCr2/jaO3C8fp+r7qfN6mCzVvidbHGtJGLfs=", + "owner": "rcarriga", + "repo": "nvim-dap-ui", + "rev": "749bfe12d1447703899fa823c1c075fbe2d42c24", + "type": "github" + }, + "original": { + "owner": "rcarriga", + "repo": "nvim-dap-ui", + "type": "github" + } + }, "nvim-lightbulb": { "flake": false, "locked": { @@ -1360,6 +1392,8 @@ "nvim-colorizer-lua": "nvim-colorizer-lua", "nvim-compe": "nvim-compe", "nvim-cursorline": "nvim-cursorline", + "nvim-dap": "nvim-dap", + "nvim-dap-ui": "nvim-dap-ui", "nvim-lightbulb": "nvim-lightbulb", "nvim-lspconfig": "nvim-lspconfig", "nvim-neoclip": "nvim-neoclip", diff --git a/flake.nix b/flake.nix index 0198f1e..61aa9c3 100644 --- a/flake.nix +++ b/flake.nix @@ -162,6 +162,17 @@ inputs.flake-utils.follows = "flake-utils"; }; + # Debuggers + nvim-dap = { + url = "github:mfussenegger/nvim-dap"; + flake = false; + }; + + nvim-dap-ui = { + url = "github:rcarriga/nvim-dap-ui"; + flake = false; + }; + # Filetrees nvim-tree-lua = { url = "github:nvim-tree/nvim-tree.lua"; diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 9515b04..111fd8c 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -85,6 +85,8 @@ with lib; let "nvim-colorizer-lua" "vim-illuminate" "nvim-surround" + "nvim-dap" + "nvim-dap-ui" ]; # You can either use the name of the plugin or a package. pluginsType = with types; diff --git a/modules/debugger/default.nix b/modules/debugger/default.nix new file mode 100644 index 0000000..f882196 --- /dev/null +++ b/modules/debugger/default.nix @@ -0,0 +1,5 @@ +_: { + imports = [ + ./nvim-dap + ]; +} diff --git a/modules/debugger/nvim-dap/config.nix b/modules/debugger/nvim-dap/config.nix new file mode 100644 index 0000000..60d8a92 --- /dev/null +++ b/modules/debugger/nvim-dap/config.nix @@ -0,0 +1,23 @@ +{ + config, + lib, + ... +}: +with lib; +with builtins; let + cfg = config.vim.debugger.nvim-dap; +in { + config = mkIf cfg.enable { + vim.startPlugins = + [ + "nvim-dap" + ] + ++ optionals cfg.ui.enable [ + "nvim-dap-ui" + ]; + + vim.luaConfigRC.nvim-dap-ui = nvim.dag.entryAnywhere '' + require("dapui").setup() + ''; + }; +} diff --git a/modules/debugger/nvim-dap/default.nix b/modules/debugger/nvim-dap/default.nix new file mode 100644 index 0000000..083220b --- /dev/null +++ b/modules/debugger/nvim-dap/default.nix @@ -0,0 +1,6 @@ +_: { + imports = [ + ./config.nix + ./nvim-dap.nix + ]; +} diff --git a/modules/debugger/nvim-dap/nvim-dap.nix b/modules/debugger/nvim-dap/nvim-dap.nix new file mode 100644 index 0000000..14eb359 --- /dev/null +++ b/modules/debugger/nvim-dap/nvim-dap.nix @@ -0,0 +1,10 @@ +{lib, ...}: +with lib; { + options.vim.debugger.nvim-dap = { + enable = mkEnableOption "Enable debugging via nvim-dap"; + + ui = { + enable = mkEnableOption "Enable UI extension for nvim-dap"; + }; + }; +} diff --git a/modules/modules.nix b/modules/modules.nix index a23241c..b3cb152 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -29,6 +29,7 @@ ./comments ./projects ./languages + ./debugger ]; pkgsModule = {config, ...}: { From 595e76ed2fd1a946f94bff9a989f89f640a2ba29 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 5 May 2023 15:31:55 +0200 Subject: [PATCH 04/15] feat: option to autostart debugger UI --- modules/debugger/nvim-dap/config.nix | 39 ++++++++++++++++++-------- modules/debugger/nvim-dap/nvim-dap.nix | 5 ++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/modules/debugger/nvim-dap/config.nix b/modules/debugger/nvim-dap/config.nix index 60d8a92..cf18897 100644 --- a/modules/debugger/nvim-dap/config.nix +++ b/modules/debugger/nvim-dap/config.nix @@ -7,17 +7,32 @@ with lib; with builtins; let cfg = config.vim.debugger.nvim-dap; in { - config = mkIf cfg.enable { - vim.startPlugins = - [ - "nvim-dap" - ] - ++ optionals cfg.ui.enable [ - "nvim-dap-ui" - ]; + config = mkMerge [ + (mkIf cfg.enable { + vim.startPlugins = ["nvim-dap"]; - vim.luaConfigRC.nvim-dap-ui = nvim.dag.entryAnywhere '' - require("dapui").setup() - ''; - }; + vim.luaConfigRC.nvim-dap = + nvim.dag.entryAnywhere '' + ''; + }) + (mkIf (cfg.enable && cfg.ui.enable) { + vim.startPlugins = ["nvim-dap-ui"]; + + vim.luaConfigRC.nvim-dap-ui = nvim.dag.entryAfter ["nvim-dap"] ('' + local dapui = require("dapui") + require("dapui").setup() + '' + + optionalString cfg.ui.autoStart '' + dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open() + end + dap.listeners.before.event_terminated["dapui_config"] = function() + dapui.close() + end + dap.listeners.before.event_exited["dapui_config"] = function() + dapui.close() + end + ''); + }) + ]; } diff --git a/modules/debugger/nvim-dap/nvim-dap.nix b/modules/debugger/nvim-dap/nvim-dap.nix index 14eb359..1a9f2fe 100644 --- a/modules/debugger/nvim-dap/nvim-dap.nix +++ b/modules/debugger/nvim-dap/nvim-dap.nix @@ -5,6 +5,11 @@ with lib; { ui = { enable = mkEnableOption "Enable UI extension for nvim-dap"; + autoStart = mkOption { + type = types.bool; + default = true; + description = "Automatically Opens and Closes DAP-UI upon starting/closing a debugging session"; + }; }; }; } From 1eceb04db99fad4412a7c0fa2871197203a3c5c8 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 5 May 2023 16:16:16 +0200 Subject: [PATCH 05/15] feat: new option enableDAP --- modules/languages/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/languages/default.nix b/modules/languages/default.nix index 0b1ac28..9a5135e 100644 --- a/modules/languages/default.nix +++ b/modules/languages/default.nix @@ -27,6 +27,7 @@ in { options.vim.languages = { enableLSP = mkEnable "LSP"; + enableDAP = mkEnable "Debug Adapter"; enableTreesitter = mkEnable "treesitter"; enableFormat = mkEnable "formatting"; enableExtraDiagnostics = mkEnable "extra diagnostics"; From 624782e1963c5c0c8c1cd83d5ea14134ab0d78c8 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 8 May 2023 13:01:42 +0200 Subject: [PATCH 06/15] feat: add option for debugger configs --- modules/debugger/nvim-dap/config.nix | 10 +++++++--- modules/debugger/nvim-dap/nvim-dap.nix | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/debugger/nvim-dap/config.nix b/modules/debugger/nvim-dap/config.nix index cf18897..b3d08f7 100644 --- a/modules/debugger/nvim-dap/config.nix +++ b/modules/debugger/nvim-dap/config.nix @@ -11,9 +11,13 @@ in { (mkIf cfg.enable { vim.startPlugins = ["nvim-dap"]; - vim.luaConfigRC.nvim-dap = - nvim.dag.entryAnywhere '' - ''; + vim.luaConfigRC = + { + nvim-dap = nvim.dag.entryAnywhere '' + local dap = require("dap") + ''; + } + // mapAttrs (_: v: (nvim.dag.entryAfter ["nvim-dap"] v)) cfg.sources; }) (mkIf (cfg.enable && cfg.ui.enable) { vim.startPlugins = ["nvim-dap-ui"]; diff --git a/modules/debugger/nvim-dap/nvim-dap.nix b/modules/debugger/nvim-dap/nvim-dap.nix index 1a9f2fe..159f88e 100644 --- a/modules/debugger/nvim-dap/nvim-dap.nix +++ b/modules/debugger/nvim-dap/nvim-dap.nix @@ -11,5 +11,11 @@ with lib; { description = "Automatically Opens and Closes DAP-UI upon starting/closing a debugging session"; }; }; + + sources = mkOption { + default = {}; + description = "List of debuggers to install"; + type = with types; attrsOf string; + }; }; } From bdf77593ee31347c6521aaf0ca244816af50e1e7 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 8 May 2023 13:03:03 +0200 Subject: [PATCH 07/15] feat: default dap keybinds --- modules/debugger/nvim-dap/config.nix | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/debugger/nvim-dap/config.nix b/modules/debugger/nvim-dap/config.nix index b3d08f7..805955a 100644 --- a/modules/debugger/nvim-dap/config.nix +++ b/modules/debugger/nvim-dap/config.nix @@ -13,8 +13,28 @@ in { vim.luaConfigRC = { + # TODO customizable keymaps nvim-dap = nvim.dag.entryAnywhere '' local dap = require("dap") + local opts = { noremap = true, silent = true } + + vim.keymap.set("n", "d.", "lua require'dap'.run_last()", opts) + vim.keymap.set("n", "dR", "lua require'dap'.restart()", opts) + vim.keymap.set("n", "dq", "lua require'dap'.terminate()", opts) + vim.keymap.set("n", "db", "lua require'dap'.toggle_breakpoint()", opts) + vim.keymap.set("n", "dc", "lua require'dap'.continue()", opts) + vim.keymap.set("n", "dl", "lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))", opts) + vim.keymap.set("n", "dgb", "lua require'dap'.continue()", opts) + vim.keymap.set("n", "dgc", "lua require'dap'.run_to_cursor()", opts) + vim.keymap.set("n", "dgi", "lua require'dap'.step_into()", opts) + vim.keymap.set("n", "dgo", "lua require'dap'.step_out()", opts) + vim.keymap.set("n", "dgI", "lua require'dap'.down()", opts) + vim.keymap.set("n", "dgO", "lua require'dap'.up()", opts) + vim.keymap.set("n", "dgj", "lua require'dap'.step_over()", opts) + vim.keymap.set("n", "dgk", "lua require'dap'.step_back()", opts) + vim.keymap.set("n", "dr", "lua require'dap'.repl.toggle()", opts) + vim.keymap.set("n", "dh", "lua require'dap.ui.widgets'.hover()", opts) + ''; } // mapAttrs (_: v: (nvim.dag.entryAfter ["nvim-dap"] v)) cfg.sources; @@ -25,6 +45,8 @@ in { vim.luaConfigRC.nvim-dap-ui = nvim.dag.entryAfter ["nvim-dap"] ('' local dapui = require("dapui") require("dapui").setup() + vim.keymap.set("n", "du", "lua require'dapui'.toggle()", opts) + vim.keymap.set({ "n", "v" }, "dd", "lua require'dapui'.eval()", opts) '' + optionalString cfg.ui.autoStart '' dap.listeners.after.event_initialized["dapui_config"] = function() From b029426d3444c5690c0e867afe45a2a072732991 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 8 May 2023 13:03:26 +0200 Subject: [PATCH 08/15] feat: add debugger for go --- modules/languages/go.nix | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/modules/languages/go.nix b/modules/languages/go.nix index 9944006..aae808b 100644 --- a/modules/languages/go.nix +++ b/modules/languages/go.nix @@ -21,6 +21,46 @@ with builtins; let ''; }; }; + defaultDebugger = "delve"; + debuggers = { + delve = { + package = pkgs.delve; + dapConfig = '' + dap.adapters.delve = { + type = "server", + port = "''${port}", + executable = { + command = "${getExe cfg.dap.package}", + args = { "dap", "-l", "127.0.0.1:''${port}" }, + }, + } + + dap.configurations.go = { + { + type = "delve", + name = "Debug", + request = "launch", + program = "''${file}", + }, + { + type = "delve", + name = "Debug test", -- configuration for debugging test files + request = "launch", + mode = "test", + program = "''${file}", + }, + -- works with go.mod packages and sub packages + { + type = "delve", + name = "Debug test (go.mod)", + request = "launch", + mode = "test", + program = "./''${relativeFileDirname}", + }, + } + ''; + }; + }; in { options.vim.languages.go = { enable = mkEnableOption "Go language support"; @@ -46,6 +86,24 @@ in { default = servers.${cfg.lsp.server}.package; }; }; + + dap = { + enable = mkOption { + description = "Enable Go Debug Adapter"; + type = types.bool; + default = config.vim.languages.enableDAP; + }; + debugger = mkOption { + description = "Go debugger to use"; + type = with types; enum (attrNames debuggers); + default = defaultDebugger; + }; + package = mkOption { + description = "Go debugger package."; + type = types.package; + default = debuggers.${cfg.dap.debugger}.package; + }; + }; }; config = mkIf cfg.enable (mkMerge [ @@ -58,5 +116,10 @@ in { vim.lsp.lspconfig.enable = true; vim.lsp.lspconfig.sources.go-lsp = servers.${cfg.lsp.server}.lspConfig; }) + + (mkIf cfg.dap.enable { + vim.debugger.nvim-dap.enable = true; + vim.debugger.nvim-dap.sources.go-debugger = debuggers.${cfg.dap.debugger}.dapConfig; + }) ]); } From b3b6f56fbc09240e768f126ea74d7c42906e3613 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 20 May 2023 12:29:55 +0200 Subject: [PATCH 09/15] feat: add dap support for python --- modules/languages/python.nix | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/modules/languages/python.nix b/modules/languages/python.nix index d25e7c1..daea5b8 100644 --- a/modules/languages/python.nix +++ b/modules/languages/python.nix @@ -36,6 +36,69 @@ with builtins; let ''; }; }; + + defaultDebugger = "debugpy"; + debuggers = { + debugpy = { + # idk if this is the best way to install/run debugpy + package = pkgs.python3.withPackages (ps: with ps; [debugpy]); + dapConfig = '' + dap.adapters.python = function(cb, config) + if config.request == 'attach' then + ---@diagnostic disable-next-line: undefined-field + local port = (config.connect or config).port + ---@diagnostic disable-next-line: undefined-field + local host = (config.connect or config).host or '127.0.0.1' + cb({ + type = 'server', + port = assert(port, '`connect.port` is required for a python `attach` configuration'), + host = host, + options = { + source_filetype = 'python', + }, + }) + else + cb({ + type = 'executable', + command = '${getExe cfg.dap.package}', + args = { '-m', 'debugpy.adapter' }, + options = { + source_filetype = 'python', + }, + }) + end + end + + dap.configurations.python = { + { + -- The first three options are required by nvim-dap + type = 'python'; -- the type here established the link to the adapter definition: `dap.adapters.python` + request = 'launch'; + name = "Launch file"; + + -- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options + + program = "''${file}"; -- This configuration will launch the current file if used. + pythonPath = function() + -- debugpy supports launching an application with a different interpreter then the one used to launch debugpy itself. + -- The code below looks for a `venv` or `.venv` folder in the current directly and uses the python within. + -- You could adapt this - to for example use the `VIRTUAL_ENV` environment variable. + local cwd = vim.fn.getcwd() + if vim.fn.executable(cwd .. '/venv/bin/python') == 1 then + return cwd .. '/venv/bin/python' + elseif vim.fn.executable(cwd .. '/.venv/bin/python') == 1 then + return cwd .. '/.venv/bin/python' + elseif vim.fn.executable("python") == 1 then + return vim.fn.exepath("python") + else -- WARNING cfg.dap.package probably has NO libraries other than builtins and debugpy + return '${getExe cfg.dap.package}' + end + end; + }, + } + ''; + }; + }; in { options.vim.languages.python = { enable = mkEnableOption "Python language support"; @@ -80,6 +143,29 @@ in { default = formats.${cfg.format.type}.package; }; }; + + # TODO this implementation is very bare bones, I don't know enough python to implement everything + dap = { + enable = mkOption { + description = "Enable Python Debug Adapter"; + type = types.bool; + default = config.vim.languages.enableDAP; + }; + debugger = mkOption { + description = "Python debugger to use"; + type = with types; enum (attrNames debuggers); + default = defaultDebugger; + }; + package = mkOption { + description = '' + Python debugger package. + This is a python package with debugpy installed, see https://nixos.wiki/wiki/Python#Install_Python_Packages. + ''; + example = literalExpression "with pkgs; python39.withPackages (ps: with ps; [debugpy])"; + type = types.package; + default = debuggers.${cfg.dap.debugger}.package; + }; + }; }; config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable { @@ -96,5 +182,10 @@ in { vim.lsp.null-ls.enable = true; vim.lsp.null-ls.sources.python-format = formats.${cfg.format.type}.nullConfig; }) + + (mkIf cfg.dap.enable { + vim.debugger.nvim-dap.enable = true; + vim.debugger.nvim-dap.sources.python-debugger = debuggers.${cfg.dap.debugger}.dapConfig; + }) ]); } From 3a8b614ea9b2d5bcbf6fd03111eb9aa228ac546b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 20 May 2023 13:46:19 +0200 Subject: [PATCH 10/15] feat: add dap support for clang --- modules/languages/clang.nix | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/modules/languages/clang.nix b/modules/languages/clang.nix index 32e02f9..7d201e4 100644 --- a/modules/languages/clang.nix +++ b/modules/languages/clang.nix @@ -36,6 +36,35 @@ with builtins; let ''; }; }; + + 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 + ''; + }; + }; in { options.vim.languages.clang = { enable = mkEnableOption "C/C++ language support"; @@ -76,6 +105,24 @@ in { default = null; }; }; + + 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; + }; + }; }; config = mkIf cfg.enable (mkMerge [ @@ -93,5 +140,10 @@ in { vim.lsp.lspconfig.sources.clang-lsp = servers.${cfg.lsp.server}.lspConfig; }) + + (mkIf cfg.dap.enable { + vim.debugger.nvim-dap.enable = true; + vim.debugger.nvim-dap.sources.clang-debugger = debuggers.${cfg.dap.debugger}.dapConfig; + }) ]); } From 588d348bd299a3a2040c7d3daddbd7603c028d46 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 22 May 2023 01:55:26 +0200 Subject: [PATCH 11/15] feat: add dap support for rust --- modules/languages/rust.nix | 44 +++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/modules/languages/rust.nix b/modules/languages/rust.nix index 1298c9f..21ab58d 100644 --- a/modules/languages/rust.nix +++ b/modules/languages/rust.nix @@ -40,6 +40,19 @@ in { default = ""; }; }; + + dap = { + enable = mkOption { + description = "Rust Debug Adapter support"; + type = types.bool; + default = config.vim.languages.enableDAP; + }; + package = mkOption { + description = "lldb pacakge"; + type = types.package; + default = pkgs.lldb; + }; + }; }; config = mkIf cfg.enable (mkMerge [ @@ -62,8 +75,8 @@ in { vim.treesitter.enable = true; vim.treesitter.grammars = [cfg.treesitter.package]; }) - (mkIf cfg.lsp.enable { - vim.startPlugins = ["rust-tools"]; + (mkIf (cfg.lsp.enable || cfg.dap.enable) { + vim.startPlugins = ["rust-tools"] ++ optionals cfg.dap.enable [cfg.dap.package]; vim.lsp.lspconfig.enable = true; vim.lsp.lspconfig.sources.rust-lsp = '' @@ -78,6 +91,21 @@ in { vim.keymap.set("n", "rm", rt.expand_macro.expand_macro, opts) vim.keymap.set("n", "rc", rt.open_cargo_toml.open_cargo_toml, opts) vim.keymap.set("n", "rg", function() rt.crate_graph.view_crate_graph("x11", nil) end, opts) + ${optionalString cfg.dap.enable '' + vim.keymap.set("n", "rd", ":RustDebuggables", opts) + vim.keymap.set( + "n", "${config.vim.debugger.nvim-dap.mappings.continue}", + function() + local dap = require("dap") + if dap.status() == "" then + vim.cmd "RustDebuggables" + else + dap.continue() + end + end, + opts + ) + ''} end local rustopts = { tools = { @@ -94,7 +122,17 @@ in { settings = { ${cfg.lsp.opts} } - } + }, + + ${optionalString cfg.dap.enable '' + dap = { + adapter = { + type = "executable", + command = "${cfg.dap.package}/bin/lldb-vscode", + name = "rt_lldb", + }, + }, + ''} } rt.setup(rustopts) ''; From fe9da14d85235cea756696fc17414d15efb848a0 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 12 Jun 2023 02:59:34 +0200 Subject: [PATCH 12/15] feat: add mapping options for nvim-dap --- modules/debugger/nvim-dap/config.nix | 49 ++++++++++++++------------ modules/debugger/nvim-dap/nvim-dap.nix | 22 ++++++++++++ 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/modules/debugger/nvim-dap/config.nix b/modules/debugger/nvim-dap/config.nix index 805955a..35610a8 100644 --- a/modules/debugger/nvim-dap/config.nix +++ b/modules/debugger/nvim-dap/config.nix @@ -6,6 +6,11 @@ with lib; with builtins; let cfg = config.vim.debugger.nvim-dap; + self = import ./nvim-dap.nix { + inherit lib; + }; + mappingDefinitions = self.options.vim.debugger.nvim-dap.mappings; + mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; in { config = mkMerge [ (mkIf cfg.enable { @@ -16,37 +21,36 @@ in { # TODO customizable keymaps nvim-dap = nvim.dag.entryAnywhere '' local dap = require("dap") - local opts = { noremap = true, silent = true } - - vim.keymap.set("n", "d.", "lua require'dap'.run_last()", opts) - vim.keymap.set("n", "dR", "lua require'dap'.restart()", opts) - vim.keymap.set("n", "dq", "lua require'dap'.terminate()", opts) - vim.keymap.set("n", "db", "lua require'dap'.toggle_breakpoint()", opts) - vim.keymap.set("n", "dc", "lua require'dap'.continue()", opts) - vim.keymap.set("n", "dl", "lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))", opts) - vim.keymap.set("n", "dgb", "lua require'dap'.continue()", opts) - vim.keymap.set("n", "dgc", "lua require'dap'.run_to_cursor()", opts) - vim.keymap.set("n", "dgi", "lua require'dap'.step_into()", opts) - vim.keymap.set("n", "dgo", "lua require'dap'.step_out()", opts) - vim.keymap.set("n", "dgI", "lua require'dap'.down()", opts) - vim.keymap.set("n", "dgO", "lua require'dap'.up()", opts) - vim.keymap.set("n", "dgj", "lua require'dap'.step_over()", opts) - vim.keymap.set("n", "dgk", "lua require'dap'.step_back()", opts) - vim.keymap.set("n", "dr", "lua require'dap'.repl.toggle()", opts) - vim.keymap.set("n", "dh", "lua require'dap.ui.widgets'.hover()", opts) - ''; } // mapAttrs (_: v: (nvim.dag.entryAfter ["nvim-dap"] v)) cfg.sources; + + vim.maps.normal = mkMerge [ + (mkSetLuaBinding mappings.continue "require('dap').continue") + (mkSetLuaBinding mappings.restart "require('dap').restart") + (mkSetLuaBinding mappings.terminate "require('dap').terminate") + (mkSetLuaBinding mappings.runLast "require('dap').run_last") + + (mkSetLuaBinding mappings.toggleRepl "require('dap').repl.toggle") + (mkSetLuaBinding mappings.hover "require('dap.ui.widgets').hover") + (mkSetLuaBinding mappings.toggleBreakpoint "require('dap').toggle_breakpoint") + + (mkSetLuaBinding mappings.runToCursor "require('dap').run_to_cursor") + (mkSetLuaBinding mappings.stepInto "require('dap').step_into") + (mkSetLuaBinding mappings.stepOut "require('dap').step_out") + (mkSetLuaBinding mappings.stepOver "require('dap').step_over") + (mkSetLuaBinding mappings.stepBack "require('dap').step_back") + + (mkSetLuaBinding mappings.goUp "require('dap').up") + (mkSetLuaBinding mappings.goDown "require('dap').down") + ]; }) (mkIf (cfg.enable && cfg.ui.enable) { vim.startPlugins = ["nvim-dap-ui"]; vim.luaConfigRC.nvim-dap-ui = nvim.dag.entryAfter ["nvim-dap"] ('' local dapui = require("dapui") - require("dapui").setup() - vim.keymap.set("n", "du", "lua require'dapui'.toggle()", opts) - vim.keymap.set({ "n", "v" }, "dd", "lua require'dapui'.eval()", opts) + dapui.setup() '' + optionalString cfg.ui.autoStart '' dap.listeners.after.event_initialized["dapui_config"] = function() @@ -59,6 +63,7 @@ in { dapui.close() end ''); + vim.maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle"; }) ]; } diff --git a/modules/debugger/nvim-dap/nvim-dap.nix b/modules/debugger/nvim-dap/nvim-dap.nix index 159f88e..b0fcb5e 100644 --- a/modules/debugger/nvim-dap/nvim-dap.nix +++ b/modules/debugger/nvim-dap/nvim-dap.nix @@ -17,5 +17,27 @@ with lib; { description = "List of debuggers to install"; type = with types; attrsOf string; }; + + mappings = { + continue = mkMappingOption "Contiue" "dc"; + restart = mkMappingOption "Restart" "dR"; + terminate = mkMappingOption "Terminate" "dq"; + runLast = mkMappingOption "Re-run Last Debug Session" "d."; + + toggleRepl = mkMappingOption "Toggle Repl" "dr"; + hover = mkMappingOption "Hover" "dh"; + toggleBreakpoint = mkMappingOption "Toggle breakpoint" "db"; + + runToCursor = mkMappingOption "Continue to the current cursor" "dgc"; + stepInto = mkMappingOption "Step into function" "dgi"; + stepOut = mkMappingOption "Step out of function" "dgo"; + stepOver = mkMappingOption "Next step" "dgj"; + stepBack = mkMappingOption "Step back" "dgk"; + + goUp = mkMappingOption "Go up stacktrace" "dvo"; + goDown = mkMappingOption "Go down stacktrace" "dvi"; + + toggleDapUI = mkMappingOption "Toggle DAP-UI" "du"; + }; }; } From ae0a2389ff1fca0d9dff29f2ccdc0baee9fc5f65 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Thu, 15 Jun 2023 18:17:13 +0200 Subject: [PATCH 13/15] feat(dap): add breakpoint icon --- modules/debugger/nvim-dap/config.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/debugger/nvim-dap/config.nix b/modules/debugger/nvim-dap/config.nix index 35610a8..874e1b6 100644 --- a/modules/debugger/nvim-dap/config.nix +++ b/modules/debugger/nvim-dap/config.nix @@ -21,6 +21,7 @@ in { # TODO customizable keymaps nvim-dap = nvim.dag.entryAnywhere '' local dap = require("dap") + vim.fn.sign_define("DapBreakpoint", { text = "🛑", texthl = "ErrorMsg", linehl = "", numhl = "" }) ''; } // mapAttrs (_: v: (nvim.dag.entryAfter ["nvim-dap"] v)) cfg.sources; From b5efd5cba7e2d0c740e70e09a217e9cbb66a7e30 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Tue, 27 Jun 2023 00:04:48 +0200 Subject: [PATCH 14/15] feat: add dap support for dart --- modules/languages/dart/config.nix | 6 +++++- modules/languages/dart/dart.nix | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/languages/dart/config.nix b/modules/languages/dart/config.nix index 82b061d..c4761cd 100644 --- a/modules/languages/dart/config.nix +++ b/modules/languages/dart/config.nix @@ -55,8 +55,12 @@ in { on_attach = default_on_attach; flags = lsp_flags, }, + ${optionalString cfg.dap.enable '' + debugger = { + enabled = true, + }, + ''} } - ''; }) ]); diff --git a/modules/languages/dart/dart.nix b/modules/languages/dart/dart.nix index f6694ad..b985224 100644 --- a/modules/languages/dart/dart.nix +++ b/modules/languages/dart/dart.nix @@ -49,6 +49,14 @@ in { }; }; + dap = { + enable = mkOption { + description = "Enable Dart DAP support via flutter-tools"; + type = types.bool; + default = config.vim.languages.enableDAP; + }; + }; + flutter-tools = { enable = mkOption { description = "Enable flutter-tools for flutter support"; From 18e95533d6727ccc35710b0e4c5b4ec2a7d10e19 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Tue, 27 Jun 2023 00:07:56 +0200 Subject: [PATCH 15/15] update docs --- docs/release-notes/rl-0.4.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/release-notes/rl-0.4.adoc b/docs/release-notes/rl-0.4.adoc index 14dcb78..389a19c 100644 --- a/docs/release-notes/rl-0.4.adoc +++ b/docs/release-notes/rl-0.4.adoc @@ -35,6 +35,8 @@ https://github.com/horriblename[horriblename]: * Fixed bug where flutter-tools can't find `dart` LSP +* Added Debug Adapter (DAP) support for clang, rust, go, python and dart. + https://github.com/notashelf[notashelf]: * Made Copilot's Node package configurable. It is recommended to keep as default, but providing a different NodeJS version is now possible.