diff --git a/README.md b/README.md index 26ba428..5bbf749 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,15 @@ nix run .# Option 2: Run directly ```bash -nix run github:fred-drake/neovim#. +nix run github:fred-drake/neovim# ``` +### Configurations + +The default configuration performs editing without settings for any particular language or technology. The following configurations allow for CMP, LSP, Tree-Sitter and DAP in their respective language or technology stack: + +- Rust `nix run github:fred-drake/neovim#rust` + ## Things To Do - TODO: Implement DAP for debugging diff --git a/config/dap.nix b/config/dap.nix index 4833453..2e8ad82 100644 --- a/config/dap.nix +++ b/config/dap.nix @@ -4,10 +4,207 @@ dap = { enable = true; extensions = { - dap-go.enable = true; - dap-python.enable = true; - dap-ui.enable = true; + dap-ui = { + enable = true; + floating.mappings = { close = [ "" "q" ]; }; + }; + dap-virtual-text = { enable = true; }; + }; + signs = { + dapBreakpoint = { + text = "●"; + texthl = "DapBreakpoint"; + }; + dapBreakpointCondition = { + text = "●"; + texthl = "DapBreakpointCondition"; + }; + dapLogPoint = { + text = "◆"; + texthl = "DapLogPoint"; + }; }; }; }; + + keymaps = [ + { + mode = "n"; + key = "dB"; + action = + "\n lua require('dap').set_breakpoint(vim.fn.input('Breakpoint condition: '))\n "; + options = { + silent = true; + desc = "Breakpoint Condition"; + }; + } + { + mode = "n"; + key = "db"; + action = ":DapToggleBreakpoint"; + options = { + silent = true; + desc = "Toggle Breakpoint"; + }; + } + { + mode = "n"; + key = "dc"; + action = ":DapContinue"; + options = { + silent = true; + desc = "Continue"; + }; + } + { + mode = "n"; + key = "da"; + action = "lua require('dap').continue({ before = get_args })"; + options = { + silent = true; + desc = "Run with Args"; + }; + } + { + mode = "n"; + key = "dC"; + action = "lua require('dap').run_to_cursor()"; + options = { + silent = true; + desc = "Run to cursor"; + }; + } + { + mode = "n"; + key = "dg"; + action = "lua require('dap').goto_()"; + options = { + silent = true; + desc = "Go to line (no execute)"; + }; + } + { + mode = "n"; + key = "di"; + action = ":DapStepInto"; + options = { + silent = true; + desc = "Step into"; + }; + } + { + mode = "n"; + key = "dj"; + action = "\n lua require('dap').down()\n "; + options = { + silent = true; + desc = "Down"; + }; + } + { + mode = "n"; + key = "dk"; + action = "lua require('dap').up()"; + options = { + silent = true; + desc = "Up"; + }; + } + { + mode = "n"; + key = "dl"; + action = "lua require('dap').run_last()"; + options = { + silent = true; + desc = "Run Last"; + }; + } + { + mode = "n"; + key = "do"; + action = ":DapStepOut"; + options = { + silent = true; + desc = "Step Out"; + }; + } + { + mode = "n"; + key = "dO"; + action = ":DapStepOver"; + options = { + silent = true; + desc = "Step Over"; + }; + } + { + mode = "n"; + key = "dp"; + action = "lua require('dap').pause()"; + options = { + silent = true; + desc = "Pause"; + }; + } + { + mode = "n"; + key = "dr"; + action = ":DapToggleRepl"; + options = { + silent = true; + desc = "Toggle REPL"; + }; + } + { + mode = "n"; + key = "ds"; + action = "lua require('dap').session()"; + options = { + silent = true; + desc = "Session"; + }; + } + { + mode = "n"; + key = "dt"; + action = ":DapTerminate"; + options = { + silent = true; + desc = "Terminate"; + }; + } + { + mode = "n"; + key = "du"; + action = "lua require('dapui').toggle()"; + options = { + silent = true; + desc = "Dap UI"; + }; + } + { + mode = "n"; + key = "dw"; + action = "lua require('dap.ui.widgets').hover()"; + options = { + silent = true; + desc = "Widgets"; + }; + } + { + mode = [ "n" "v" ]; + key = "de"; + action = "lua require('dapui').eval()"; + options = { + silent = true; + desc = "Eval"; + }; + } + ]; + + extraConfigLua = '' + require('dap').listeners.after.event_initialized['dapui_config'] = require('dapui').open + require('dap').listeners.before.event_terminated['dapui_config'] = require('dapui').close + require('dap').listeners.before.event_exited['dapui_config'] = require('dapui').close + ''; } diff --git a/config/keys.nix b/config/keys.nix index 70f365e..7a49808 100644 --- a/config/keys.nix +++ b/config/keys.nix @@ -34,6 +34,11 @@ group = "SOPS"; icon = ""; } + { + __unkeyed-1 = "d"; + group = "Debug"; + icon = ""; + } ]; }; }; diff --git a/config/lsp.nix b/config/lsp.nix index 633bae8..83acde1 100644 --- a/config/lsp.nix +++ b/config/lsp.nix @@ -176,7 +176,6 @@ in { pkgs, ... }: { nix = [ "nixfmt" ]; python = [ "black" ]; ruby = [ "rubyfmt" ]; - rust = [ "rustfmt" ]; terraform = [ "tofu_fmt" ]; tf = [ "tofu_fmt" ]; typescript = [ "prettier" ]; @@ -243,11 +242,5 @@ in { pkgs, ... }: { omnisharp.enable = true; }; }; - - rustaceanvim = { - enable = true; - settings = { tools.enable_clippy = true; }; - }; - # rust-tools.enable = true; }; } diff --git a/config/rust/dap.nix b/config/rust/dap.nix new file mode 100644 index 0000000..d39005f --- /dev/null +++ b/config/rust/dap.nix @@ -0,0 +1,13 @@ +{ pkgs, ... }: { + plugins.dap = { + enable = true; + extensions = { + dap-ui.enable = true; + dap-virtual-text.enable = true; + }; + + adapters = { + executables = { lldb = { command = "${pkgs.lldb_19}/bin/lldb-dap"; }; }; + }; + }; +} diff --git a/config/rust/default.nix b/config/rust/default.nix new file mode 100644 index 0000000..3d7eebc --- /dev/null +++ b/config/rust/default.nix @@ -0,0 +1,16 @@ +let + # Read all files in the current directory + files = builtins.readDir ./.; + + # Filter out default.nix and non-.nix files + nixFiles = builtins.filter + (name: name != "default.nix" && builtins.match ".*\\.nix" name != null) + (builtins.attrNames files); + + # Create a list of import statements + imports = map (name: ./. + "/${name}") nixFiles; +in { + # Import all configuration modules automatically + imports = imports; +} + diff --git a/config/rust/lsp.nix b/config/rust/lsp.nix new file mode 100644 index 0000000..022df58 --- /dev/null +++ b/config/rust/lsp.nix @@ -0,0 +1,28 @@ +{ pkgs, ... }: { + plugins = { + conform-nvim = { + enable = true; + settings = { formatters_by_ft.rust = [ "rustfmt" ]; }; + }; + rustaceanvim = { + enable = true; + settings = { + dap.adapter = { + command = "${pkgs.lldb_19}/bin/lldb-dap"; + type = "executable"; + }; + tools.enable_clippy = true; + server = { + default_settings = { + inlayHints = { lifetimeElisionHints = { enable = "always"; }; }; + rust-analyzer = { + cargo = { allFeatures = true; }; + check = { command = "clippy"; }; + }; + }; + }; + }; + }; + + }; +} diff --git a/flake.nix b/flake.nix index 2ea67cb..09d1edd 100644 --- a/flake.nix +++ b/flake.nix @@ -1,52 +1,56 @@ { description = "A nixvim configuration"; - inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixvim.url = "github:nix-community/nixvim"; flake-parts.url = "github:hercules-ci/flake-parts"; rust-overlay.url = "github:oxalica/rust-overlay"; }; - outputs = { nixvim, flake-parts, rust-overlay, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - perSystem = { system, ... }: let overlays = [ (import rust-overlay) ]; nixvimLib = nixvim.lib.${system}; nixvim' = nixvim.legacyPackages.${system}; - nixvimModule = { + baseNixvimModule = { inherit pkgs; module = { pkgs, ... }: { imports = [ ./config ]; + extraPackages = with pkgs; [ sops ]; + }; + extraSpecialArgs = { }; + }; + rustNixvimModule = { + inherit pkgs; + module = { pkgs, ... }: { + imports = [ ./config ./config/rust ]; extraPackages = with pkgs; [ sops rust-bin.stable.latest.default ]; }; - # You can use `extraSpecialArgs` to pass additional arguments to your module files - extraSpecialArgs = { - # inherit (inputs) foo; - }; + extraSpecialArgs = { }; }; pkgs = import inputs.nixpkgs { inherit system overlays; config.allowUnfree = true; }; - nvim = nixvim'.makeNixvimWithModule nixvimModule; + baseNvim = nixvim'.makeNixvimWithModule baseNixvimModule; + rustNvim = nixvim'.makeNixvimWithModule rustNixvimModule; in { checks = { # Run `nix flake check .` to verify that your config is not broken default = - nixvimLib.check.mkTestDerivationFromNixvimModule nixvimModule; + nixvimLib.check.mkTestDerivationFromNixvimModule baseNixvimModule; }; - packages = { # Lets you run `nix run .` to start nixvim - default = nvim; + default = baseNvim; + # Lets you run `nix run .#rust` to start nixvim with Rust configuration + rust = rustNvim; }; }; };