From 594ead9898cc0723353773970499761c5f93a30e Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 18 Mar 2025 11:45:00 -0500 Subject: [PATCH] separate config into files --- config/cmp.nix | 43 +++++ config/dap.nix | 115 +++++++++++++ config/default.nix | 409 +------------------------------------------- config/keybinds.nix | 101 +++++++++++ config/lsp.nix | 124 ++++++++++++++ config/plugins.nix | 36 ++++ 6 files changed, 428 insertions(+), 400 deletions(-) create mode 100644 config/cmp.nix create mode 100644 config/dap.nix create mode 100644 config/keybinds.nix create mode 100644 config/lsp.nix create mode 100644 config/plugins.nix diff --git a/config/cmp.nix b/config/cmp.nix new file mode 100644 index 0000000..751bd98 --- /dev/null +++ b/config/cmp.nix @@ -0,0 +1,43 @@ +{ ... }: { + + plugins = { + + cmp-nvim-lsp.enable = true; + + cmp = { + enable = true; + autoEnableSources = true; + settings = { + sources = [ + { name = "nvim_lsp"; } + { name = "path"; } + { name = "buffer"; } + { name = "luasnip"; } +# { name = "cmdline"; } + ]; + + completion = { + completeopt = "menu,menuone,noinsert"; + }; + + mapping = { + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.select_prev_item()"; + "" = "cmp.mapping.confirm({ select = true })"; + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.abort()"; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + }; + + snippet.expand = '' + function(args) + require("luasnip").lsp_expand(args.body) + end + ''; + }; + + }; + + }; +} diff --git a/config/dap.nix b/config/dap.nix new file mode 100644 index 0000000..5498763 --- /dev/null +++ b/config/dap.nix @@ -0,0 +1,115 @@ +{ lib, pkgs, ... }: { + + plugins = { + + dap = { + enable = true; + + adapters = { + executables = { + lldb = { + command = lib.getExe' pkgs.lldb "lldb-vscode"; + }; + }; + + servers = { + codelldb = { + port = 13000; + executable = { + command = "${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb"; + args = [ + "--port" + "13000" + ]; + }; + }; + }; + }; + + configurations = let + codelldb-config = { + name = "Launch (CodeLLDB)"; + type = "codelldb"; + request = "launch"; + program.__raw = '' + function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. '/', "file") + end + ''; + cwd = ''''${workspaceFolder}''; + stopOnEntry = false; + }; + + lldb-config = { + name = "Launch (LLDB)"; + type = "lldb"; + request = "launch"; + program.__raw = '' + function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. '/', "file") + end''; + cwd = ''''${workspaceFolder}''; + stopOnEntry = false; + }; + in { + c = [ lldb-config ]; + + cpp = + [ lldb-config ] + ++ lib.optionals pkgs.stdenv.isLinux [ + codelldb-config + ]; + + rust = + [ lldb-config ] + ++ lib.optionals pkgs.stdenv.isLinux [ + codelldb-config + ]; + }; + + }; + + dap-ui = { + enable = true; + + # Set icons to characters that are more likely to work in every terminal. + # Feel free to remove or use ones that you like more! :) + # Don't feel like these are good choices. + settings = { + icons = { + expanded = "▾"; + collapsed = "▸"; + current_frame = "*"; + }; + + controls = { + icons = { + pause = "⏸"; + play = "▶"; + step_into = "⏎"; + step_over = "⏭"; + step_out = "⏮"; + step_back = "b"; + run_last = "▶▶"; + terminate = "⏹"; + disconnect = "⏏"; + }; + }; + }; + }; + + dap-virtual-text.enable = true; + + # Add debuggers here + dap-python = { + enable = true; + }; + + + dap-lldb = { + enable = true; + settings.codelldb_path = "${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb"; + }; + + }; +} diff --git a/config/default.nix b/config/default.nix index ee6775d..7ce9921 100644 --- a/config/default.nix +++ b/config/default.nix @@ -1,318 +1,19 @@ -{ lib, pkgs, opts, ... }: { +{ pkgs, opts, ... }: { # Import all your configuration modules here - imports = [ ./bufferline.nix ]; + imports = [ + ./bufferline.nix + ./cmp.nix + ./dap.nix + ./lsp.nix + ./plugins.nix + ./keybinds.nix + ]; extraPackages = with pkgs; [ coreutils lldb_18 ]; - plugins = { - - lualine.enable = true; - - luasnip.enable = true; - - barbar.enable = true; - - nvim-tree.enable = true; - - noice.enable = true; - - mini.enable = true; - - notify.enable = true; - - telescope.enable = true; - - treesitter = { - enable = true; - settings = { - highlight.enable = true; - grammarPackages = pkgs.vimPlugins.nvim-treesitter.passthru.allGrammars ++ [ - pkgs.vimPlugins.nvim-treesitter-parsers.glsl - ]; - }; - }; - - render-markdown.enable = true; - - web-devicons.enable = true; - - cmp-nvim-lsp.enable = true; - - lsp = { - enable = true; - servers = { - #js/typescript - ts_ls.enable = true; - #c/c++ - ccls.enable = true; - #nix - nil_ls.enable = true; - #python - pyright.enable = true; - #bash - bashls.enable = true; - #css - cssls.enable = true; - #glsl - glsl_analyzer.enable = true; - - }; - - keymaps = { - # Diagnostic keymaps - diagnostic = { - "q" = { - #mode = "n"; - action = "setloclist"; - desc = "Open diagnostic [Q]uickfix list"; - }; - }; - - extra = [ - # Jump to the definition of the word under your cusor. - # This is where a variable was first declared, or where a function is defined, etc. - # To jump back, press . - { - mode = "n"; - key = "gd"; - action.__raw = "require('telescope.builtin').lsp_definitions"; - options = { - desc = "LSP: [G]oto [D]efinition"; - }; - } - # Find references for the word under your cursor. - { - mode = "n"; - key = "gr"; - action.__raw = "require('telescope.builtin').lsp_references"; - options = { - desc = "LSP: [G]oto [R]eferences"; - }; - } - # Jump to the implementation of the word under your cursor. - # Useful when your language has ways of declaring types without an actual implementation. - { - mode = "n"; - key = "gI"; - action.__raw = "require('telescope.builtin').lsp_implementations"; - options = { - desc = "LSP: [G]oto [I]mplementation"; - }; - } - # Jump to the type of the word under your cursor. - # Useful when you're not sure what type a variable is and you want to see - # the definition of its *type*, not where it was *defined*. - { - mode = "n"; - key = "D"; - action.__raw = "require('telescope.builtin').lsp_type_definitions"; - options = { - desc = "LSP: Type [D]efinition"; - }; - } - # Fuzzy find all the symbols in your current document. - # Symbols are things like variables, functions, types, etc. - { - mode = "n"; - key = "ds"; - action.__raw = "require('telescope.builtin').lsp_document_symbols"; - options = { - desc = "LSP: [D]ocument [S]ymbols"; - }; - } - # Fuzzy find all the symbols in your current workspace. - # Similar to document symbols, except searches over your entire project. - { - mode = "n"; - key = "ws"; - action.__raw = "require('telescope.builtin').lsp_dynamic_workspace_symbols"; - options = { - desc = "LSP: [W]orkspace [S]ymbols"; - }; - } - ]; - - lspBuf = { - # Rename the variable under your cursor. - # Most Language Servers support renaming across files, etc. - "rn" = { - action = "rename"; - desc = "LSP: [R]e[n]ame"; - }; - # Execute a code action, usually your cursor needs to be on top of an error - # or a suggestion from your LSP for this to activate. - "ca" = { - #mode = "n"; - action = "code_action"; - desc = "LSP: [C]ode [A]ction"; - }; - # WARN: This is not Goto Definition, this is Goto Declaration. - # For example, in C this would take you to the header. - "gD" = { - action = "declaration"; - desc = "LSP: [G]oto [D]eclaration"; - }; - }; - }; - }; - - #dap-ui.enable = true; - - #dap-virtual-text.enable = true; - - dap = { - enable = true; - - adapters = { - executables = { - lldb = { - command = lib.getExe' pkgs.lldb "lldb-vscode"; - }; - }; - - servers = { - codelldb = { - port = 13000; - executable = { - command = "${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb"; - args = [ - "--port" - "13000" - ]; - }; - }; - }; - }; - - configurations = let - codelldb-config = { - name = "Launch (CodeLLDB)"; - type = "codelldb"; - request = "launch"; - program.__raw = '' - function() - return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. '/', "file") - end - ''; - cwd = ''''${workspaceFolder}''; - stopOnEntry = false; - }; - - lldb-config = { - name = "Launch (LLDB)"; - type = "lldb"; - request = "launch"; - program.__raw = '' - function() - return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. '/', "file") - end''; - cwd = ''''${workspaceFolder}''; - stopOnEntry = false; - }; - in { - c = [ lldb-config ]; - - cpp = - [ lldb-config ] - ++ lib.optionals pkgs.stdenv.isLinux [ - codelldb-config - ]; - - rust = - [ lldb-config ] - ++ lib.optionals pkgs.stdenv.isLinux [ - codelldb-config - ]; - }; - - }; - - dap-ui = { - enable = true; - - # Set icons to characters that are more likely to work in every terminal. - # Feel free to remove or use ones that you like more! :) - # Don't feel like these are good choices. - settings = { - icons = { - expanded = "▾"; - collapsed = "▸"; - current_frame = "*"; - }; - - controls = { - icons = { - pause = "⏸"; - play = "▶"; - step_into = "⏎"; - step_over = "⏭"; - step_out = "⏮"; - step_back = "b"; - run_last = "▶▶"; - terminate = "⏹"; - disconnect = "⏏"; - }; - }; - }; - }; - - dap-virtual-text.enable = true; - - # Add debuggers here - dap-python = { - enable = true; - }; - - - dap-lldb = { - enable = true; - settings.codelldb_path = "${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb"; - }; - - cmp = { - enable = true; - autoEnableSources = true; - settings = { - sources = [ - { name = "nvim_lsp"; } - { name = "path"; } - { name = "buffer"; } - { name = "luasnip"; } -# { name = "cmdline"; } - ]; - - completion = { - completeopt = "menu,menuone,noinsert"; - }; - - mapping = { - "" = "cmp.mapping.select_next_item()"; - "" = "cmp.mapping.select_prev_item()"; - "" = "cmp.mapping.confirm({ select = true })"; - "" = "cmp.mapping.complete()"; - "" = "cmp.mapping.abort()"; - "" = "cmp.mapping.scroll_docs(-4)"; - "" = "cmp.mapping.scroll_docs(4)"; - }; - - snippet.expand = '' - function(args) - require("luasnip").lsp_expand(args.body) - end - ''; - }; - - }; - }; - - globals = { - mapleader = " "; - maplocalleader = " "; - }; - opts = { nu = true; rnu = true; @@ -332,98 +33,6 @@ incsearch = true; }; - keymaps = [ - { - mode = "n"; - key = "ff"; - action = "Telescope find_files hidden=true"; - } - - { - mode = "n"; - key = "fc"; - action = "Telescope treesitter"; - } - - { - mode = "n"; - key = "t"; - action = "NvimTreeToggle"; - } - - { - mode = "n"; - key = ""; - action = "BufferNext"; - } - - { - mode = "n"; - key = ""; - action = "BufferPrevious"; - } - - { - mode = "n"; - key = ""; - action = "wincmd h"; - } - - { - mode = "n"; - key = ""; - action = "wincmd j"; - } - - { - mode = "n"; - key = ""; - action = "wincmd k"; - } - - { - mode = "n"; - key = ""; - action = "wincmd l"; - } - - { - mode = "n"; - key = "Q"; - action = ""; - } - - { - mode = "v"; - key = "J"; - action = ":m '>+1gv=gv"; - } - - { - mode = "v"; - key = "K"; - action = ":m '<-2gv=gv"; - } - - { - mode = "n"; - key = "y"; - action = "\"+y"; - } - - { - mode = "v"; - key = "y"; - action = "\"+y"; - } - - { - mode = "n"; - key = "s"; - action = ":%s/\\<\\>//gI"; - } - ]; - extraConfigLua = '' vim.filetype.add({ pattern = { [".*/hypr/.*%.conf"] = "hyprlang" }, diff --git a/config/keybinds.nix b/config/keybinds.nix new file mode 100644 index 0000000..3ac4ae1 --- /dev/null +++ b/config/keybinds.nix @@ -0,0 +1,101 @@ +{ ... }: { + + globals = { + mapleader = " "; + maplocalleader = " "; + }; + + keymaps = [ + { + mode = "n"; + key = "ff"; + action = "Telescope find_files hidden=true"; + } + + { + mode = "n"; + key = "fc"; + action = "Telescope treesitter"; + } + + { + mode = "n"; + key = "t"; + action = "NvimTreeToggle"; + } + + { + mode = "n"; + key = ""; + action = "BufferNext"; + } + + { + mode = "n"; + key = ""; + action = "BufferPrevious"; + } + + { + mode = "n"; + key = ""; + action = "wincmd h"; + } + + { + mode = "n"; + key = ""; + action = "wincmd j"; + } + + { + mode = "n"; + key = ""; + action = "wincmd k"; + } + + { + mode = "n"; + key = ""; + action = "wincmd l"; + } + + { + mode = "n"; + key = "Q"; + action = ""; + } + + { + mode = "v"; + key = "J"; + action = ":m '>+1gv=gv"; + } + + { + mode = "v"; + key = "K"; + action = ":m '<-2gv=gv"; + } + + { + mode = "n"; + key = "y"; + action = "\"+y"; + } + + { + mode = "v"; + key = "y"; + action = "\"+y"; + } + + { + mode = "n"; + key = "s"; + action = ":%s/\\<\\>//gI"; + } + ]; + + +} diff --git a/config/lsp.nix b/config/lsp.nix new file mode 100644 index 0000000..664e672 --- /dev/null +++ b/config/lsp.nix @@ -0,0 +1,124 @@ +{ pkgs, ... }: { + + plugins = { + lsp = { + enable = true; + servers = { +#js/typescript + ts_ls.enable = true; +#c/c++ + ccls.enable = true; +#nix + nil_ls.enable = true; +#python + pyright.enable = true; +#bash + bashls.enable = true; +#css + cssls.enable = true; +#glsl + glsl_analyzer.enable = true; + + }; + + keymaps = { +# Diagnostic keymaps + diagnostic = { + "q" = { +#mode = "n"; + action = "setloclist"; + desc = "Open diagnostic [Q]uickfix list"; + }; + }; + + extra = [ +# Jump to the definition of the word under your cusor. +# This is where a variable was first declared, or where a function is defined, etc. +# To jump back, press . + { + mode = "n"; + key = "gd"; + action.__raw = "require('telescope.builtin').lsp_definitions"; + options = { + desc = "LSP: [G]oto [D]efinition"; + }; + } +# Find references for the word under your cursor. + { + mode = "n"; + key = "gr"; + action.__raw = "require('telescope.builtin').lsp_references"; + options = { + desc = "LSP: [G]oto [R]eferences"; + }; + } +# Jump to the implementation of the word under your cursor. +# Useful when your language has ways of declaring types without an actual implementation. + { + mode = "n"; + key = "gI"; + action.__raw = "require('telescope.builtin').lsp_implementations"; + options = { + desc = "LSP: [G]oto [I]mplementation"; + }; + } +# Jump to the type of the word under your cursor. +# Useful when you're not sure what type a variable is and you want to see +# the definition of its *type*, not where it was *defined*. + { + mode = "n"; + key = "D"; + action.__raw = "require('telescope.builtin').lsp_type_definitions"; + options = { + desc = "LSP: Type [D]efinition"; + }; + } +# Fuzzy find all the symbols in your current document. +# Symbols are things like variables, functions, types, etc. + { + mode = "n"; + key = "ds"; + action.__raw = "require('telescope.builtin').lsp_document_symbols"; + options = { + desc = "LSP: [D]ocument [S]ymbols"; + }; + } +# Fuzzy find all the symbols in your current workspace. +# Similar to document symbols, except searches over your entire project. + { + mode = "n"; + key = "ws"; + action.__raw = "require('telescope.builtin').lsp_dynamic_workspace_symbols"; + options = { + desc = "LSP: [W]orkspace [S]ymbols"; + }; + } + ]; + + lspBuf = { +# Rename the variable under your cursor. +# Most Language Servers support renaming across files, etc. + "rn" = { + action = "rename"; + desc = "LSP: [R]e[n]ame"; + }; +# Execute a code action, usually your cursor needs to be on top of an error +# or a suggestion from your LSP for this to activate. + "ca" = { +#mode = "n"; + action = "code_action"; + desc = "LSP: [C]ode [A]ction"; + }; +# WARN: This is not Goto Definition, this is Goto Declaration. +# For example, in C this would take you to the header. + "gD" = { + action = "declaration"; + desc = "LSP: [G]oto [D]eclaration"; + }; + }; + }; + }; + + }; + +} diff --git a/config/plugins.nix b/config/plugins.nix new file mode 100644 index 0000000..036d2e4 --- /dev/null +++ b/config/plugins.nix @@ -0,0 +1,36 @@ +{ pkgs, ... }: { + + plugins = { + + lualine.enable = true; + + luasnip.enable = true; + + barbar.enable = true; + + nvim-tree.enable = true; + + noice.enable = true; + + mini.enable = true; + + notify.enable = true; + + telescope.enable = true; + + treesitter = { + enable = true; + settings = { + highlight.enable = true; + grammarPackages = pkgs.vimPlugins.nvim-treesitter.passthru.allGrammars ++ [ + pkgs.vimPlugins.nvim-treesitter-parsers.glsl + ]; + }; + }; + + render-markdown.enable = true; + + web-devicons.enable = true; + }; + +}