From f93bad12f1b4feeeee007ceab4a350eb1aa26c1e Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Wed, 25 Aug 2021 23:27:45 +0200 Subject: Updates from lvim, remove legacy --- .config/nvim/lua/config/defaults.lua | 1168 +++++++++++++++++++++++ .config/nvim/lua/config/init.lua | 36 + .config/nvim/lua/config/settings.lua | 76 ++ .config/nvim/lua/core/autocmds.lua | 3 +- .config/nvim/lua/core/autopairs.lua | 98 +- .config/nvim/lua/core/bufferline.lua | 5 + .config/nvim/lua/core/builtins/init.lua | 29 + .config/nvim/lua/core/commands.lua | 1 + .config/nvim/lua/core/comment.lua | 31 + .config/nvim/lua/core/compe.lua | 29 +- .config/nvim/lua/core/dap.lua | 30 +- .config/nvim/lua/core/dashboard.lua | 39 +- .config/nvim/lua/core/galaxyline.lua | 311 ------ .config/nvim/lua/core/gitsigns.lua | 1 + .config/nvim/lua/core/log.lua | 8 +- .config/nvim/lua/core/lspinstall.lua | 19 + .config/nvim/lua/core/lualine/colors.lua | 19 + .config/nvim/lua/core/lualine/components.lua | 180 ++++ .config/nvim/lua/core/lualine/conditions.lua | 17 + .config/nvim/lua/core/lualine/init.lua | 47 + .config/nvim/lua/core/lualine/styles.lua | 186 ++++ .config/nvim/lua/core/lualine/utils.lua | 27 + .config/nvim/lua/core/nvimtree.lua | 95 +- .config/nvim/lua/core/project.lua | 51 + .config/nvim/lua/core/status_colors.lua | 19 - .config/nvim/lua/core/telescope.lua | 32 +- .config/nvim/lua/core/terminal.lua | 24 +- .config/nvim/lua/core/treesitter.lua | 7 + .config/nvim/lua/core/which-key.lua | 59 +- .config/nvim/lua/dark/highlights.lua | 6 +- .config/nvim/lua/default-config.lua | 1308 -------------------------- .config/nvim/lua/interface/popup.lua | 62 ++ .config/nvim/lua/interface/text.lua | 79 ++ .config/nvim/lua/keymappings.lua | 23 +- .config/nvim/lua/lsp/init.lua | 43 +- .config/nvim/lua/lsp/null-ls/formatters.lua | 2 +- .config/nvim/lua/lsp/null-ls/linters.lua | 2 +- .config/nvim/lua/lsp/null-ls/services.lua | 24 +- .config/nvim/lua/lsp/utils.lua | 3 +- .config/nvim/lua/plugins.lua | 113 +-- .config/nvim/lua/settings.lua | 78 -- .config/nvim/lua/utils/init.lua | 13 +- 42 files changed, 2356 insertions(+), 2047 deletions(-) create mode 100644 .config/nvim/lua/config/defaults.lua create mode 100644 .config/nvim/lua/config/init.lua create mode 100644 .config/nvim/lua/config/settings.lua create mode 100644 .config/nvim/lua/core/builtins/init.lua create mode 100644 .config/nvim/lua/core/comment.lua delete mode 100644 .config/nvim/lua/core/galaxyline.lua create mode 100644 .config/nvim/lua/core/lspinstall.lua create mode 100644 .config/nvim/lua/core/lualine/colors.lua create mode 100644 .config/nvim/lua/core/lualine/components.lua create mode 100644 .config/nvim/lua/core/lualine/conditions.lua create mode 100644 .config/nvim/lua/core/lualine/init.lua create mode 100644 .config/nvim/lua/core/lualine/styles.lua create mode 100644 .config/nvim/lua/core/lualine/utils.lua create mode 100644 .config/nvim/lua/core/project.lua delete mode 100644 .config/nvim/lua/core/status_colors.lua delete mode 100644 .config/nvim/lua/default-config.lua create mode 100644 .config/nvim/lua/interface/popup.lua create mode 100644 .config/nvim/lua/interface/text.lua delete mode 100644 .config/nvim/lua/settings.lua (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/config/defaults.lua b/.config/nvim/lua/config/defaults.lua new file mode 100644 index 0000000..82c08a4 --- /dev/null +++ b/.config/nvim/lua/config/defaults.lua @@ -0,0 +1,1168 @@ +CONFIG_PATH = vim.fn.stdpath "config" +DATA_PATH = vim.fn.stdpath "data" +CACHE_PATH = vim.fn.stdpath "cache" +TERMINAL = vim.fn.expand "$TERMINAL" +USER = vim.fn.expand "$USER" +vim.cmd [[ set spellfile=~/.config/nvim/spell/en.utf-8.add ]] + +options = { + leader_key = "space", + colorscheme = "dark", + line_wrap_cursor_movement = true, + transparent_window = false, + format_on_save = true, + vsnip_dir = os.getenv "HOME" .. "/.config/snippets", + database = { save_location = "~/.config/nvim_db", auto_execute = 1 }, + keys = {}, + + -- TODO: might remove later + builtin = {}, + + log = { + ---@usage can be { "trace", "debug", "info", "warn", "error", "fatal" }, + level = "warn", + viewer = { + ---@usage this will fallback on "less +F" if not found + cmd = "lnav", + layout_config = { + ---@usage direction = 'vertical' | 'horizontal' | 'window' | 'float', + direction = "horizontal", + open_mapping = "", + size = 40, + float_opts = {}, + }, + }, + }, + + lsp = { + completion = { + item_kind = { + "  (text) ", + "  (method)", + "  (function)", + "  (constructor)", + " ﴲ (field)", + "[] (variable)", + "  (class)", + " ﰮ (interface)", + "  (module)", + " 襁 (property)", + "  (unit)", + "  (value)", + " 練 (enum)", + "  (keyword)", + "  (snippet)", + "  (color)", + "  (file)", + "  (reference)", + "  (folder)", + "  (enummember)", + " ﲀ (constant)", + " ﳤ (struct)", + "  (event)", + "  (operator)", + "  (typeparameter)", + }, + }, + diagnostics = { + signs = { + active = true, + values = { + { name = "LspDiagnosticsSignError", text = "" }, + { name = "LspDiagnosticsSignWarning", text = "" }, + { name = "LspDiagnosticsSignHint", text = "" }, + { name = "LspDiagnosticsSignInformation", text = "" }, + }, + }, + virtual_text = { + prefix = "", + spacing = 0, + }, + underline = true, + severity_sort = true, + }, + override = {}, + document_highlight = true, + popup_border = "single", + on_attach_callback = nil, + on_init_callback = nil, + null_ls = { + setup = {}, + }, + }, + + plugins = { + -- use config.lua for this not put here + }, + + autocommands = {}, +} + +local schemas = nil +local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") +if status_ok then + schemas = jsonls_settings.get_default_schemas() +end + +-- TODO move all of this into lang specific files, only require when using +options.lang = { + asm = { + formatters = { + -- { + -- exe = "asmfmt", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "", + setup = {}, + }, + }, + beancount = { + formatters = { + -- { + -- exe = "bean_format", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "beancount", + setup = { + cmd = { "beancount-langserver" }, + }, + }, + }, + c = { + formatters = { + -- { + -- exe = "clang_format", + -- args = {}, + -- }, + -- { + -- exe = "uncrustify", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "clangd", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd", + "--background-index", + "--header-insertion=never", + "--cross-file-rename", + "--clang-tidy", + "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", + }, + }, + }, + }, + cpp = { + formatters = { + -- { + -- exe = "clang_format", + -- args = {}, + -- }, + -- { + -- exe = "uncrustify", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "clangd", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd", + "--background-index", + "--header-insertion=never", + "--cross-file-rename", + "--clang-tidy", + "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", + }, + }, + }, + }, + crystal = { + formatters = { + -- { + -- exe = "crystal_format", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "crystalline", + setup = { + cmd = { "crystalline" }, + }, + }, + }, + cs = { + formatters = { + -- { + -- exe = "clang_format ", + -- args = {}, + -- }, + -- { + -- exe = "uncrustify", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "omnisharp", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/csharp/omnisharp/run", + "--languageserver", + "--hostPID", + tostring(vim.fn.getpid()), + }, + }, + }, + }, + cmake = { + formatters = { + -- { + -- exe = "cmake_format", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "cmake", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/cmake/venv/bin/cmake-language-server", + }, + }, + }, + }, + clojure = { + formatters = {}, + linters = {}, + lsp = { + provider = "clojure_lsp", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/clojure/clojure-lsp", + }, + }, + }, + }, + css = { + formatters = { + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "cssls", + setup = { + cmd = { + "node", + DATA_PATH + .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", + "--stdio", + }, + }, + }, + }, + less = { + formatters = { + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "cssls", + setup = { + cmd = { + "node", + DATA_PATH + .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", + "--stdio", + }, + }, + }, + }, + d = { + formatters = { + -- { + -- exe = "dfmt", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "serve_d", + setup = { + cmd = { "serve-d" }, + }, + }, + }, + dart = { + formatters = { + -- { + -- exe = "dart_format", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "dartls", + setup = { + cmd = { + "dart", + "/usr/lib/dart/bin/snapshots/analysis_server.dart.snapshot", + "--lsp", + }, + }, + }, + }, + docker = { + formatters = {}, + linters = {}, + lsp = { + provider = "dockerls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/dockerfile/node_modules/.bin/docker-langserver", + "--stdio", + }, + }, + }, + }, + elixir = { + formatters = { + -- { + -- exe = "mix", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "elixirls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/elixir/elixir-ls/language_server.sh", + }, + }, + }, + }, + elm = { + formatters = { + -- { + -- exe = "elm_format", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "elmls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-language-server", + }, + -- init_options = { + -- elmAnalyseTrigger = "change", + -- elmFormatPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-format", + -- elmPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/", + -- elmTestPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-test", + -- }, + }, + }, + }, + erlang = { + formatters = { + -- { + -- exe = "erlfmt", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "erlangls", + setup = { + cmd = { + "erlang_ls", + }, + }, + }, + }, + emmet = { active = false }, + fish = { + formatters = { + -- { + -- exe = "fish_indent", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "", + setup = {}, + }, + }, + fortran = { + formatters = {}, + linters = {}, + lsp = { + provider = "fortls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/fortran/venv/bin/fortls", + }, + }, + }, + }, + go = { + formatters = { + -- { + -- exe = "gofmt", + -- args = {}, + -- }, + -- { + -- exe = "goimports", + -- args = {}, + -- }, + -- { + -- exe = "gofumpt", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "gopls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/go/gopls", + }, + }, + }, + }, + graphql = { + formatters = {}, + linters = {}, + lsp = { + provider = "graphql", + setup = { + cmd = { + "graphql-lsp", + "server", + "-m", + "stream", + }, + }, + }, + }, + haskell = { + formatters = {}, + linters = {}, + lsp = { + provider = "hls", + setup = { + cmd = { DATA_PATH .. "/lspinstall/haskell/hls" }, + }, + }, + }, + html = { + formatters = { + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "html", + setup = { + cmd = { + "node", + DATA_PATH + .. "/lspinstall/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js", + "--stdio", + }, + }, + }, + }, + java = { + formatters = { + -- { + -- exe = "clang_format", + -- args = {}, + -- }, + -- { + -- exe = "uncrustify", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "jdtls", + setup = { + cmd = { DATA_PATH .. "/lspinstall/java/jdtls.sh" }, + }, + }, + }, + json = { + formatters = { + -- { + -- exe = "json_tool", + -- args = {}, + -- }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "jsonls", + setup = { + cmd = { + "node", + DATA_PATH + .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js", + "--stdio", + }, + settings = { + json = { + schemas = schemas, + -- = { + -- { + -- fileMatch = { "package.json" }, + -- url = "https://json.schemastore.org/package.json", + -- }, + -- }, + }, + }, + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) + end, + }, + }, + }, + }, + }, + julia = { + formatters = {}, + linters = {}, + lsp = { + provider = "julials", + setup = { + { + "julia", + "--startup-file=no", + "--history-file=no", + -- vim.fn.expand "~/.config/nvim/lua/lsp/julia/run.jl", + CONFIG_PATH .. "/utils/julia/run.jl", + }, + }, + }, + }, + kotlin = { + formatters = {}, + linters = {}, + lsp = { + provider = "kotlin_language_server", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/kotlin/server/bin/kotlin-language-server", + }, + root_dir = function(fname) + local util = require "lspconfig/util" + + local root_files = { + "settings.gradle", -- Gradle (multi-project) + "settings.gradle.kts", -- Gradle (multi-project) + "build.xml", -- Ant + "pom.xml", -- Maven + } + + local fallback_root_files = { + "build.gradle", -- Gradle + "build.gradle.kts", -- Gradle + } + return util.root_pattern(unpack(root_files))(fname) + or util.root_pattern(unpack(fallback_root_files))(fname) + end, + }, + }, + }, + lua = { + formatters = { + -- { + -- exe = "stylua", + -- args = {}, + -- }, + -- { + -- exe = "lua_format", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "sumneko_lua", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/lua/sumneko-lua-language-server", + "-E", + DATA_PATH .. "/lspinstall/lua/main.lua", + }, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + -- Setup your lua path + path = vim.split(package.path, ";"), + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim", "lvim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = { + [vim.fn.expand "~/.local/share/lunarvim/lvim/lua"] = true, + [vim.fn.expand "$VIMRUNTIME/lua"] = true, + [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, + }, + maxPreload = 100000, + preloadFileSize = 1000, + }, + }, + }, + }, + }, + }, + nginx = { + formatters = { + -- { + -- exe = "nginx_beautifier", + -- args = { + -- provider = "", + -- setup = {}, + -- }, + -- }, + }, + linters = {}, + lsp = {}, + }, + perl = { + formatters = { + -- { + -- exe = "perltidy", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "", + setup = {}, + }, + }, + sql = { + formatters = { + -- { + -- exe = "sqlformat", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "sqls", + setup = { + cmd = { "sqls" }, + }, + }, + }, + php = { + formatters = { + -- { + -- exe = "phpcbf", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "intelephense", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense", + "--stdio", + }, + filetypes = { "php", "phtml" }, + settings = { + intelephense = { + environment = { + phpVersion = "7.4", + }, + }, + }, + }, + }, + }, + puppet = { + formatters = {}, + linters = {}, + lsp = { + provider = "puppet", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/puppet/puppet-editor-services/puppet-languageserver", + "--stdio", + }, + }, + }, + }, + javascript = { + formatters = { + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + }, + -- @usage can be {"eslint"} or {"eslint_d"} + linters = {}, + lsp = { + provider = "tsserver", + setup = { + cmd = { + -- TODO: + DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio", + }, + }, + }, + }, + javascriptreact = { + formatters = { + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "tsserver", + setup = { + cmd = { + -- TODO: + DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio", + }, + }, + }, + }, + python = { + formatters = { + -- { + -- exe = "yapf", + -- args = {}, + -- }, + -- { + -- exe = "isort", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "pyright", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", + "--stdio", + }, + }, + }, + }, + -- R -e 'install.packages("formatR",repos = "http://cran.us.r-project.org")' + -- R -e 'install.packages("readr",repos = "http://cran.us.r-project.org")' + r = { + formatters = { + -- { + -- exe = "format_r", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "r_language_server", + setup = { + cmd = { + "R", + "--slave", + "-e", + "languageserver::run()", + }, + }, + }, + }, + ruby = { + formatters = { + -- { + -- exe = "rufo", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "solargraph", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", + "stdio", + }, + filetypes = { "ruby" }, + init_options = { + formatting = true, + }, + root_dir = function(fname) + local util = require("lspconfig").util + return util.root_pattern("Gemfile", ".git")(fname) + end, + settings = { + solargraph = { + diagnostics = true, + }, + }, + }, + }, + }, + rust = { + formatters = { + -- { + -- exe = "rustfmt", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "rust_analyzer", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/rust/rust-analyzer", + }, + }, + }, + }, + scala = { + formatters = { + -- { + -- exe = "scalafmt", + -- args = {}, + -- }, + }, + linters = { "" }, + lsp = { + provider = "metals", + setup = {}, + }, + }, + sh = { + formatters = { + -- { + -- exe = "shfmt", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "bashls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", + "start", + }, + }, + }, + }, + svelte = { + formatters = {}, + linters = {}, + lsp = { + provider = "svelte", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver", + "--stdio", + }, + }, + }, + }, + swift = { + formatters = { + -- { + -- exe = "swiftformat", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "sourcekit", + setup = { + cmd = { + "xcrun", + "sourcekit-lsp", + }, + }, + }, + }, + tailwindcss = { + active = false, + filetypes = { + "html", + "css", + "scss", + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + }, + }, + terraform = { + formatters = { + -- { + -- exe = "terraform_fmt", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "terraformls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/terraform/terraform-ls", + "serve", + }, + }, + }, + }, + tex = { + formatters = {}, + linters = {}, + lsp = { + provider = "texlab", + setup = { + cmd = { DATA_PATH .. "/lspinstall/latex/texlab" }, + }, + }, + }, + typescript = { + formatters = { + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "tsserver", + setup = { + cmd = { + -- TODO: + DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio", + }, + }, + }, + }, + typescriptreact = { + formatters = { + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, + }, + -- @usage can be {"eslint"} or {"eslint_d"} + linters = {}, + lsp = { + provider = "tsserver", + setup = { + cmd = { + -- TODO: + DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio", + }, + }, + }, + }, + vim = { + formatters = {}, + linters = {}, + lsp = { + provider = "vimls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/vim/node_modules/.bin/vim-language-server", + "--stdio", + }, + }, + }, + }, + vue = { + formatters = { + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "vuels", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls", + }, + }, + }, + }, + yaml = { + formatters = { + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "yamlls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/yaml/node_modules/.bin/yaml-language-server", + "--stdio", + }, + }, + }, + }, + zig = { + formatters = {}, + linters = {}, + lsp = { + provider = "zls", + setup = { + cmd = { + "zls", + }, + }, + }, + }, + gdscript = { + formatters = {}, + linters = {}, + lsp = { + provider = "gdscript", + setup = { + cmd = { + "nc", + "localhost", + "6008", + }, + }, + }, + }, + ps1 = { + formatters = {}, + linters = {}, + lsp = { + provider = "powershell_es", + setup = { + bundle_path = "", + }, + }, + }, + nix = { + formatters = { + -- { + -- exe = "nixfmt", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "rnix", + setup = { + cmd = { "rnix-lsp" }, + filetypes = { "nix" }, + init_options = {}, + settings = {}, + root_dir = function(fname) + local util = require "lspconfig/util" + return util.root_pattern ".git"(fname) or vim.fn.getcwd() + end, + }, + }, + }, +} diff --git a/.config/nvim/lua/config/init.lua b/.config/nvim/lua/config/init.lua new file mode 100644 index 0000000..e6d6389 --- /dev/null +++ b/.config/nvim/lua/config/init.lua @@ -0,0 +1,36 @@ +local M = { + path = string.format("%s/.config/nvim/config.lua", os.getenv "HOME"), +} + +--- Initialize nvim default configuration +-- Define nvim global variable +function M:init() + local utils = require "utils" + + require "config.defaults" + + local builtins = require "core.builtins" + builtins.config(self) + + local settings = require "config.settings" + settings.load_options() +end + +--- Override the configuration with a user provided one +-- @param config_path The path to the configuration overrides +function M:load(config_path) + config_path = config_path or self.path + local ok, err = pcall(vim.cmd, "luafile " .. config_path) + if not ok then + print("Invalid configuration", config_path) + print(err) + return + end + + self.path = config_path + + local settings = require "config.settings" + settings.load_commands() +end + +return M diff --git a/.config/nvim/lua/config/settings.lua b/.config/nvim/lua/config/settings.lua new file mode 100644 index 0000000..82d7f48 --- /dev/null +++ b/.config/nvim/lua/config/settings.lua @@ -0,0 +1,76 @@ +local M = {} + +M.load_options = function() + local default_options = { + backup = false, -- creates a backup file + clipboard = "unnamedplus", -- allows neovim to access the system clipboard + cmdheight = 2, -- more space in the neovim command line for displaying messages + colorcolumn = "99999", -- fixes indentline for now + completeopt = { "menuone", "noselect" }, + conceallevel = 0, -- so that `` is visible in markdown files + fileencoding = "utf-8", -- the encoding written to a file + foldmethod = "manual", -- folding, set to "expr" for treesitter based folding + foldexpr = "", -- set to "nvim_treesitter#foldexpr()" for treesitter based folding + guifont = "monospace:h17", -- the font used in graphical neovim applications + hidden = true, -- required to keep multiple buffers and open multiple buffers + hlsearch = true, -- highlight all matches on previous search pattern + ignorecase = true, -- ignore case in search patterns + mouse = "a", -- allow the mouse to be used in neovim + pumheight = 10, -- pop up menu height + showmode = false, -- we don't need to see things like -- INSERT -- anymore + showtabline = 2, -- always show tabs + smartcase = true, -- smart case + smartindent = true, -- make indenting smarter again + splitbelow = true, -- force all horizontal splits to go below current window + splitright = true, -- force all vertical splits to go to the right of current window + swapfile = false, -- creates a swapfile + termguicolors = true, -- set term gui colors (most terminals support this) + timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) + title = true, -- set the title of window to the value of the titlestring + -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to + undodir = CACHE_PATH .. "/undo", -- set an undo directory + undofile = true, -- enable persistent undo + updatetime = 300, -- faster completion + writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited + expandtab = true, -- convert tabs to spaces + shiftwidth = 2, -- the number of spaces inserted for each indentation + tabstop = 2, -- insert 2 spaces for a tab + cursorline = true, -- highlight the current line + number = true, -- set numbered lines + relativenumber = true, -- set relative numbered lines + numberwidth = 4, -- set number column width to 2 {default 4} + signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time + wrap = false, -- display lines as one long line + spell = false, + spelllang = "en", + scrolloff = 8, -- is one of my fav + sidescrolloff = 8, + } --- VIM ONLY COMMANDS ---cmd "filetype plugin on"cmd('let &titleold="' .. TERMINAL .. '"')cmd "set inccommand=split"cmd "set iskeyword+=-" + + --- SETTINGS --- + + vim.opt.shortmess:append "c" + + for k, v in pairs(default_options) do + vim.opt[k] = v + end +end + +M.load_commands = function() + local cmd = vim.cmd + if options.line_wrap_cursor_movement then + cmd "set whichwrap+=<,>,[,],h,l" + end + + if options.transparent_window then + cmd "au ColorScheme * hi Normal ctermbg=none guibg=none" + cmd "au ColorScheme * hi SignColumn ctermbg=none guibg=none" + cmd "au ColorScheme * hi NormalNC ctermbg=none guibg=none" + cmd "au ColorScheme * hi MsgArea ctermbg=none guibg=none" + cmd "au ColorScheme * hi TelescopeBorder ctermbg=none guibg=none" + cmd "au ColorScheme * hi NvimTreeNormal ctermbg=none guibg=none" + cmd "let &fcs='eob: '" + end +end + +return M diff --git a/.config/nvim/lua/core/autocmds.lua b/.config/nvim/lua/core/autocmds.lua index 33dea53..036cc80 100644 --- a/.config/nvim/lua/core/autocmds.lua +++ b/.config/nvim/lua/core/autocmds.lua @@ -1,4 +1,5 @@ local autocommands = {} +local config = require "config" options.autocommands = { _general_settings = { @@ -32,7 +33,7 @@ options.autocommands = { "*", "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", }, - { "BufWritePost", USER_CONFIG_PATH, "lua require('utils').reload_config()" }, + { "BufWritePost", config.path, "lua require('utils').reload_config()" }, { "FileType", "qf", diff --git a/.config/nvim/lua/core/autopairs.lua b/.config/nvim/lua/core/autopairs.lua index afd6e28..f8bdfd1 100644 --- a/.config/nvim/lua/core/autopairs.lua +++ b/.config/nvim/lua/core/autopairs.lua @@ -1,53 +1,69 @@ --- if not package.loaded['nvim-autopairs'] then --- return --- end -local Log = require "core.log" -local status_ok, _ = pcall(require, "nvim-autopairs") -if not status_ok then - Log:get_default().error "Failed to load autopairs" - return +local M = {} + +function M.config() + options.builtin.autopairs = { + active = true, + on_config_done = nil, + ---@usage map on insert mode + map_cr = true, + ---@usage auto insert after select function or method item + -- NOTE: This should be wrapped into a function so that it is re-evaluated when opening new files + map_complete = vim.bo.filetype ~= "tex", + ---@usage check treesitter + check_ts = true, + ts_config = { + lua = { "string" }, + javascript = { "template_string" }, + java = false, + }, + } end -local npairs = require "nvim-autopairs" -local Rule = require "nvim-autopairs.rule" --- skip it, if you use another global object -_G.MUtils = {} +M.setup = function() + -- skip it, if you use another global object + _G.MUtils = {} + local autopairs = require "nvim-autopairs" + local Rule = require "nvim-autopairs.rule" -vim.g.completion_confirm_key = "" -MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"](npairs.esc "") + vim.g.completion_confirm_key = "" + MUtils.completion_confirm = function() + if vim.fn.pumvisible() ~= 0 then + if vim.fn.complete_info()["selected"] ~= -1 then + return vim.fn["compe#confirm"](autopairs.esc "") + else + return autopairs.esc "" + end else - return npairs.esc "" + return autopairs.autopairs_cr() end - else - return npairs.autopairs_cr() end -end -if package.loaded["compe"] then - require("nvim-autopairs.completion.compe").setup { - map_cr = true, -- map on insert mode - map_complete = true, -- it will auto insert `(` after select function or method item + if package.loaded["compe"] then + require("nvim-autopairs.completion.compe").setup { + map_cr = options.builtin.autopairs.map_cr, + map_complete = options.builtin.autopairs.map_complete, + } + end + + autopairs.setup { + check_ts = options.builtin.autopairs.check_ts, + ts_config = options.builtin.autopairs.ts_config, } -end -npairs.setup { - check_ts = true, - ts_config = { - lua = { "string" }, -- it will not add pair on that treesitter node - javascript = { "template_string" }, - java = false, -- don't check treesitter on java - }, -} + require("nvim-treesitter.configs").setup { autopairs = { enable = true } } + + local ts_conds = require "nvim-autopairs.ts-conds" -require("nvim-treesitter.configs").setup { autopairs = { enable = true } } + -- TODO: can these rules be safely added from "config.lua" ? + -- press % => %% is only inside comment or string + autopairs.add_rules { + Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), + Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), + } -local ts_conds = require "nvim-autopairs.ts-conds" + if options.builtin.autopairs.on_config_done then + options.builtin.autopairs.on_config_done(autopairs) + end +end --- press % => %% is only inside comment or string -npairs.add_rules { - Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), - Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), -} +return M diff --git a/.config/nvim/lua/core/bufferline.lua b/.config/nvim/lua/core/bufferline.lua index 6306614..68b08ce 100644 --- a/.config/nvim/lua/core/bufferline.lua +++ b/.config/nvim/lua/core/bufferline.lua @@ -3,6 +3,7 @@ local M = {} M.config = function() options.builtin.bufferline = { active = true, + on_config_done = nil, keymap = { normal_mode = { [""] = ":BufferNext", @@ -15,6 +16,10 @@ end M.setup = function() local keymap = require "keymappings" keymap.append_to_defaults(options.builtin.bufferline.keymap) + + if options.builtin.bufferline.on_config_done then + options.builtin.bufferline.on_config_done() + end end return M diff --git a/.config/nvim/lua/core/builtins/init.lua b/.config/nvim/lua/core/builtins/init.lua new file mode 100644 index 0000000..32f96af --- /dev/null +++ b/.config/nvim/lua/core/builtins/init.lua @@ -0,0 +1,29 @@ +local M = {} + +local builtins = { + "keymappings", + "core.which-key", + "core.gitsigns", + "core.compe", + "core.dashboard", + "core.dap", + "core.terminal", + "core.telescope", + "core.treesitter", + "core.nvimtree", + "core.project", + "core.bufferline", + "core.autopairs", + "core.comment", + "core.lspinstall", + "core.lualine", +} + +function M.config(config) + for _, builtin_path in ipairs(builtins) do + local builtin = require(builtin_path) + builtin.config(config) + end +end + +return M diff --git a/.config/nvim/lua/core/commands.lua b/.config/nvim/lua/core/commands.lua index c42b385..403194e 100644 --- a/.config/nvim/lua/core/commands.lua +++ b/.config/nvim/lua/core/commands.lua @@ -10,6 +10,7 @@ M.defaults = { endif endfunction ]], + [[command! LvimInfo lua require('core.info').toggle_popup(vim.bo.filetype)]], } M.load = function(commands) diff --git a/.config/nvim/lua/core/comment.lua b/.config/nvim/lua/core/comment.lua new file mode 100644 index 0000000..a97018d --- /dev/null +++ b/.config/nvim/lua/core/comment.lua @@ -0,0 +1,31 @@ +local M = {} + +function M.config() + options.builtin.comment = { + active = true, + on_config_done = nil, + -- Linters prefer comment and line to have a space in between markers + marker_padding = true, + -- should comment out empty or whitespace only lines + comment_empty = false, + -- Should key mappings be created + create_mappings = true, + -- Normal mode mapping left hand side + line_mapping = "gcc", + -- Visual/Operator mapping left hand side + operator_mapping = "gc", + -- Hook function to call before commenting takes place + hook = nil, + } +end + +function M.setup() + local nvim_comment = require "nvim_comment" + + nvim_comment.setup(options.builtin.comment) + if options.builtin.comment.on_config_done then + options.builtin.comment.on_config_done(nvim_comment) + end +end + +return M diff --git a/.config/nvim/lua/core/compe.lua b/.config/nvim/lua/core/compe.lua index 14fba1a..19e49e0 100644 --- a/.config/nvim/lua/core/compe.lua +++ b/.config/nvim/lua/core/compe.lua @@ -1,8 +1,9 @@ local M = {} -local Log = require "core.log" + M.config = function() options.builtin.compe = { - enabled = true, + active = true, + on_config_done = nil, autocomplete = true, debug = false, min_length = 1, @@ -73,11 +74,7 @@ end M.setup = function() vim.g.vsnip_snippet_dir = options.vsnip_dir - local status_ok, compe = pcall(require, "compe") - if not status_ok then - Log:get_default().error "Failed to load compe" - return - end + local compe = require "compe" compe.setup(options.builtin.compe) @@ -94,6 +91,17 @@ M.setup = function() end end + local is_emmet_active = function() + local clients = vim.lsp.buf_get_clients() + + for _, client in pairs(clients) do + if client.name == "emmet_ls" then + return true + end + end + return false + end + -- Use (s-)tab to: --- move to prev/next item in completion menuone --- jump to prev/next snippet's placeholder @@ -104,8 +112,9 @@ M.setup = function() return t "(vsnip-jump-next)" elseif check_back_space() then return t "" + elseif is_emmet_active() then + return vim.fn["compe#complete"]() else - -- return vim.fn["compe#complete"]() -- < use this if you want to always offer completion return t "" end end @@ -127,6 +136,10 @@ M.setup = function() vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) + + if options.builtin.compe.on_config_done then + options.builtin.compe.on_config_done(compe) + end end return M diff --git a/.config/nvim/lua/core/dap.lua b/.config/nvim/lua/core/dap.lua index a325c7c..6179ea3 100644 --- a/.config/nvim/lua/core/dap.lua +++ b/.config/nvim/lua/core/dap.lua @@ -1,8 +1,9 @@ local M = {} -local Log = require "core.log" + M.config = function() options.builtin.dap = { active = false, + on_config_done = nil, breakpoint = { text = "", texthl = "LspDiagnosticsSignError", @@ -13,11 +14,7 @@ M.config = function() end M.setup = function() - local status_ok, dap = pcall(require, "dap") - if not status_ok then - Log:get_default().error "Failed to load dap" - return - end + local dap = require "dap" vim.fn.sign_define("DapBreakpoint", options.builtin.dap.breakpoint) dap.defaults.fallback.terminal_win_cmd = "50vsplit new" @@ -38,6 +35,27 @@ M.setup = function() s = { "lua require'dap'.continue()", "Start" }, q = { "lua require'dap'.close()", "Quit" }, } + + if options.builtin.dap.on_config_done then + options.builtin.dap.on_config_done(dap) + end end +-- TODO put this up there ^^^ call in ftplugin + +-- M.dap = function() +-- if options.plugin.dap.active then +-- local dap_install = require "dap-install" +-- dap_install.config("python_dbg", {}) +-- end +-- end +-- +-- M.dap = function() +-- -- gem install readapt ruby-debug-ide +-- if options.plugin.dap.active then +-- local dap_install = require "dap-install" +-- dap_install.config("ruby_vsc_dbg", {}) +-- end +-- end + return M diff --git a/.config/nvim/lua/core/dashboard.lua b/.config/nvim/lua/core/dashboard.lua index efbb790..f9eec22 100644 --- a/.config/nvim/lua/core/dashboard.lua +++ b/.config/nvim/lua/core/dashboard.lua @@ -1,8 +1,12 @@ local M = {} -M.config = function() + +M.config = function(config) options.builtin.dashboard = { active = false, + on_config_done = nil, search_handler = "telescope", + disable_at_vim_enter = 0, + session_directory = os.getenv "HOME" .. "/.cache/options/sessions", custom_header = { " ##############..... ############## ", " ##############......############## ", @@ -30,23 +34,27 @@ M.config = function() command = "Telescope find_files", }, b = { + description = { " Recent Projects " }, + command = "Telescope projects", + }, + c = { description = { " Recently Used Files" }, command = "Telescope oldfiles", }, - c = { + d = { description = { " Find Word " }, command = "Telescope live_grep", }, - d = { - description = { " Settings " }, - command = ":e ~/.config/nvim/config.lua", + e = { + description = { " Configuration " }, + command = ":e " .. config.path, }, }, } end M.setup = function() - vim.g.dashboard_disable_at_vimenter = 0 + vim.g.dashboard_disable_at_vimenter = options.builtin.dashboard.disable_at_vim_enter vim.g.dashboard_custom_header = options.builtin.dashboard.custom_header @@ -56,26 +64,17 @@ M.setup = function() options.builtin.which_key.mappings[";"] = { "Dashboard", "Dashboard" } - -- f = { - -- description = { " Neovim Config Files" }, - -- command = "Telescope find_files cwd=" .. CoptionsFIG_PATH, - -- }, - -- e = {description = {' Marks '}, command = 'Telescope marks'} + vim.g.dashboard_session_directory = options.builtin.dashboard.session_directory - vim.cmd "let g:dashboard_session_directory = $HoptionsE..'/.config/nvim/.sessions'" - vim.cmd "let packages = len(globpath('~/.local/share/nvim/site/pack/packer/start', '*', 0, 1))" + vim.cmd "let packages = len(globpath('~/.local/share/lunarvim/site/pack/packer/start', '*', 0, 1))" vim.api.nvim_exec( [[ - let g:dashboard_custom_footer = ['LuaJIT loaded '..packages..' builtins'] + let g:dashboard_custom_footer = ['LunarVim loaded '..packages..' plugins  '] ]], false ) - -- file_browser = {description = {' File Browser'}, command = 'Telescope find_files'}, - - -- vim.g.dashboard_session_directory = CACHE_PATH..'/session' - -- vim.g.dashboard_custom_footer = optionsdashboard.footer require("core.autocmds").define_augroups { _dashboard = { -- seems to be nobuflisted that makes my stuff disappear will do more testing @@ -93,6 +92,10 @@ M.setup = function() { "FileType", "dashboard", "nnoremap q :q" }, }, } + + if options.builtin.dashboard.on_config_done then + options.builtin.dashboard.on_config_done() + end end return M diff --git a/.config/nvim/lua/core/galaxyline.lua b/.config/nvim/lua/core/galaxyline.lua deleted file mode 100644 index f7fa8c9..0000000 --- a/.config/nvim/lua/core/galaxyline.lua +++ /dev/null @@ -1,311 +0,0 @@ --- if not package.loaded['galaxyline'] then --- return --- end -local Log = require "core.log" -local status_ok, gl = pcall(require, "galaxyline") -if not status_ok then - Log:get_default().error "Failed to load galaxyline" - return -end - --- NOTE: if someone defines colors but doesn't have them then this will break -local palette_status_ok, colors = pcall(require, options.colorscheme .. ".palette") -if not palette_status_ok then - colors = options.builtin.galaxyline.colors -end - -local condition = require "galaxyline.condition" -local gls = gl.section -gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" } - -table.insert(gls.left, { - ViMode = { - provider = function() - local alias = { - n = "NORMAL", - i = "INSERT", - c = "COMMAND", - V = "VISUAL", - [""] = "VISUAL", - v = "VISUAL", - R = "REPLACE", - } - local alias_mode = alias[vim.fn.mode()] - if alias_mode == nil then - alias_mode = vim.fn.mode() - end - return alias_mode .. " " - end, - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -vim.fn.getbufvar(0, "ts") - -table.insert(gls.left, { - GitIcon = { - provider = function() - return " " - end, - condition = condition.check_git_workspace, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.orange, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - GitBranch = { - provider = "GitBranch", - condition = condition.check_git_workspace, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - DiffAdd = { - provider = "DiffAdd", - condition = condition.hide_in_width, - icon = "  ", - highlight = { colors.green, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - DiffModified = { - provider = "DiffModified", - condition = condition.hide_in_width, - icon = " 柳", - highlight = { colors.blue, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - DiffRemove = { - provider = "DiffRemove", - condition = condition.hide_in_width, - icon = "  ", - highlight = { colors.red, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - Filler = { - provider = function() - return " " - end, - highlight = { colors.grey, colors.alt_bg }, - }, -}) --- get output from shell command -function os.capture(cmd, raw) - local f = assert(io.popen(cmd, "r")) - local s = assert(f:read "*a") - f:close() - if raw then - return s - end - s = string.gsub(s, "^%s+", "") - s = string.gsub(s, "%s+$", "") - s = string.gsub(s, "[\n\r]+", " ") - return s -end --- cleanup virtual env -local function env_cleanup(venv) - if string.find(venv, "/") then - local final_venv = venv - for w in venv:gmatch "([^/]+)" do - final_venv = w - end - venv = final_venv - end - return venv -end -local PythonEnv = function() - if vim.bo.filetype == "python" then - local venv = os.getenv "CONDA_DEFAULT_ENV" - if venv ~= nil then - return "  (" .. env_cleanup(venv) .. ")" - end - venv = os.getenv "VIRTUAL_ENV" - if venv ~= nil then - return "  (" .. env_cleanup(venv) .. ")" - end - return "" - end - return "" -end -table.insert(gls.left, { - VirtualEnv = { - provider = PythonEnv, - event = "BufEnter", - highlight = { colors.green, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - DiagnosticError = { - provider = "DiagnosticError", - icon = "  ", - highlight = { colors.red, colors.alt_bg }, - }, -}) -table.insert(gls.right, { - DiagnosticWarn = { - provider = "DiagnosticWarn", - icon = "  ", - highlight = { colors.orange, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - DiagnosticInfo = { - provider = "DiagnosticInfo", - icon = "  ", - highlight = { colors.yellow, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - DiagnosticHint = { - provider = "DiagnosticHint", - icon = "  ", - highlight = { colors.blue, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - TreesitterIcon = { - provider = function() - if next(vim.treesitter.highlighter.active) ~= nil then - return " " - end - return "" - end, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.green, colors.alt_bg }, - }, -}) - -local function get_attached_provider_name(msg) - msg = msg or "LSP Inactive" - - local buf_clients = vim.lsp.buf_get_clients() - if next(buf_clients) == nil then - return msg - end - - local buf_client_names = {} - for _, client in pairs(buf_clients) do - if client.name ~= "null-ls" then - table.insert(buf_client_names, client.name) - end - end - - local null_ls = require "lsp.null-ls" - local null_ls_providers = null_ls.list_supported_provider_names(vim.bo.filetype) - vim.list_extend(buf_client_names, null_ls_providers) - - return table.concat(buf_client_names, ", ") -end - -table.insert(gls.right, { - ShowLspClient = { - provider = get_attached_provider_name, - condition = function() - local tbl = { ["dashboard"] = true, [" "] = true } - if tbl[vim.bo.filetype] then - return false - end - return true - end, - icon = " ", - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - LineInfo = { - provider = "LineColumn", - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - PerCent = { - provider = "LinePercent", - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - Tabstop = { - provider = function() - local label = "Spaces: " - if not vim.api.nvim_buf_get_option(0, "expandtab") then - label = "Tab size: " - end - return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " - end, - condition = condition.hide_in_width, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - BufferType = { - provider = "FileTypeName", - condition = condition.hide_in_width, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - FileEncode = { - provider = "FileEncode", - condition = condition.hide_in_width, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - Space = { - provider = function() - return " " - end, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.short_line_left, { - BufferType = { - provider = "FileTypeName", - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.alt_bg, colors.alt_bg }, - }, -}) - -table.insert(gls.short_line_left, { - SFileName = { - provider = "SFileName", - condition = condition.buffer_not_empty, - highlight = { colors.alt_bg, colors.alt_bg }, - }, -}) diff --git a/.config/nvim/lua/core/gitsigns.lua b/.config/nvim/lua/core/gitsigns.lua index 0b72689..d9c9187 100644 --- a/.config/nvim/lua/core/gitsigns.lua +++ b/.config/nvim/lua/core/gitsigns.lua @@ -1,5 +1,6 @@ local M = {} local Log = require "core.log" + M.config = function() options.builtin.gitsigns = { signs = { diff --git a/.config/nvim/lua/core/log.lua b/.config/nvim/lua/core/log.lua index e6f7afe..35ba4be 100644 --- a/.config/nvim/lua/core/log.lua +++ b/.config/nvim/lua/core/log.lua @@ -10,11 +10,7 @@ function Log:new(opts) end local obj = require("plenary.log").new(opts) - local path = string.format( - "%s/%s.log", - vim.api.nvim_call_function("stdpath", { "cache" }), - opts.plugin - ) + local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin) obj.get_path = function() return path @@ -27,7 +23,7 @@ end --- based on Plenary.log ---@return log handle function Log:get_default() - return Log:new { plugin = "nvim", level = options.log.level } + return Log:new { plugin = "lunarvim", level = options.log.level } end return Log diff --git a/.config/nvim/lua/core/lspinstall.lua b/.config/nvim/lua/core/lspinstall.lua new file mode 100644 index 0000000..79c7502 --- /dev/null +++ b/.config/nvim/lua/core/lspinstall.lua @@ -0,0 +1,19 @@ +local M = {} + +M.config = function() + options.builtin.lspinstall = { + active = true, + on_config_done = nil, + } +end + +M.setup = function() + local lspinstall = require "lspinstall" + lspinstall.setup() + + if options.builtin.lspinstall.on_config_done then + options.builtin.lspinstall.on_config_done(lspinstall) + end +end + +return M diff --git a/.config/nvim/lua/core/lualine/colors.lua b/.config/nvim/lua/core/lualine/colors.lua new file mode 100644 index 0000000..92e37ce --- /dev/null +++ b/.config/nvim/lua/core/lualine/colors.lua @@ -0,0 +1,19 @@ +local colors = { + bg = "#0D0D0D", + fg = "#D0D0D0", + grey = "#D0D0D0", + blue = "#569CD6", + green = "#608B4E", + yellow = "#DCDCAA", + orange = "#FF8800", + purple = "#C586C0", + magenta = "#D16D9E", + cyan = "#4EC9B0", + red = "#D16969", + error_red = "#F44747", + warning_orange = "#FF8800", + info_yellow = "#FFCC66", + hint_blue = "#9CDCFE", +} + +return colors diff --git a/.config/nvim/lua/core/lualine/components.lua b/.config/nvim/lua/core/lualine/components.lua new file mode 100644 index 0000000..4777392 --- /dev/null +++ b/.config/nvim/lua/core/lualine/components.lua @@ -0,0 +1,180 @@ +local conditions = require "core.lualine.conditions" +local colors = require "core.lualine.colors" + +return { + mode = { + function() + local alias = { + n = "NORMAL", + i = "INSERT", + c = "COMMAND", + V = "VISUAL", + [""] = "VISUAL", + v = "VISUAL", + R = "REPLACE", + } + local alias_mode = alias[vim.fn.mode()] + if alias_mode == nil then + alias_mode = vim.fn.mode() + end + return alias_mode .. " " + -- return " " + end, + left_padding = 0, + right_padding = 0, + condition = function() + return true + end, + color = { fg = colors.fg, bg = colors.bg }, + }, + branch = { + "branch", + icon = " ", + condition = function() + return conditions.hide_in_width() and conditions.check_git_workspace() + end, + color = { gui = "bold", fg = colors.fg, bg = colors.bg }, + }, + filename = { + "filename", + condition = function() + return true + end, + color = { fg = colors.fg, bg = colors.bg }, + }, + diff = { + "diff", + symbols = { added = "  ", modified = "柳", removed = " " }, + color_added = { fg = colors.green }, + color_modified = { fg = colors.yellow }, + color_removed = { fg = colors.red }, + condition = conditions.hide_in_width, + color = {}, + }, + python_env = { + function() + local utils = require "core.lualine.utils" + if vim.bo.filetype == "python" then + local venv = os.getenv "CONDA_DEFAULT_ENV" + if venv then + return string.format("  (%s)", utils.env_cleanup(venv)) + end + venv = os.getenv "VIRTUAL_ENV" + if venv then + return string.format("  (%s)", utils.env_cleanup(venv)) + end + return "" + end + return "" + end, + condition = conditions.hide_in_width, + color = { fg = colors.green }, + }, + diagnostics = { + "diagnostics", + sources = { "nvim_lsp" }, + symbols = { error = " ", warn = " ", info = " ", hint = " " }, + condition = conditions.hide_in_width, + color = {}, + }, + treesitter = { + function() + if next(vim.treesitter.highlighter.active) then + return "  " + end + return "" + end, + condition = conditions.hide_in_width, + color = { fg = colors.green }, + }, + lsp = { + function(msg) + msg = msg or "LSP Inactive" + local buf_clients = vim.lsp.buf_get_clients() + if next(buf_clients) == nil then + return msg + end + local buf_ft = vim.bo.filetype + local buf_client_names = {} + + -- add client + local utils = require "lsp.utils" + local active_client = utils.get_active_client_by_ft(buf_ft) + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" then + table.insert(buf_client_names, client.name) + end + end + vim.list_extend(buf_client_names, active_client or {}) + + -- add formatter + local formatters = require "lsp.null-ls.formatters" + local supported_formatters = formatters.list_supported_names(buf_ft) + vim.list_extend(buf_client_names, supported_formatters) + + -- add linter + local linters = require "lsp.null-ls.linters" + local supported_linters = linters.list_supported_names(buf_ft) + vim.list_extend(buf_client_names, supported_linters) + + return table.concat(buf_client_names, ", ") + end, + icon = " ", + condition = conditions.hide_in_width, + color = { fg = colors.fg, bg = colors.bg }, + }, + location = { + "location", + condition = conditions.hide_in_width, + color = { fg = colors.fg, bg = colors.bg }, + }, + progress = { + "progress", + condition = conditions.hide_in_width, + color = { fg = colors.fg, bg = colors.bg }, + }, + spaces = { + function() + local label = "Spaces: " + if not vim.api.nvim_buf_get_option(0, "expandtab") then + label = "Tab size: " + end + return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " + end, + condition = conditions.hide_in_width, + color = {}, + }, + encoding = { + "o:encoding", + upper = true, + condition = conditions.hide_in_width, + color = { fg = colors.fg, bg = colors.bg }, + }, + filetype = { "filetype", condition = conditions.hide_in_width, color = {} }, + scrollbar = { + function() + local current_line = vim.fn.line "." + local total_lines = vim.fn.line "$" + local chars = { + "__", + "▁▁", + "▂▂", + "▃▃", + "▄▄", + "▅▅", + "▆▆", + "▇▇", + "██", + } + local line_ratio = current_line / total_lines + local index = math.ceil(line_ratio * #chars) + return chars[index] + end, + left_padding = 0, + right_padding = 0, + condition = function() + return true + end, + color = { fg = colors.yellow, bg = colors.bg }, + }, +} diff --git a/.config/nvim/lua/core/lualine/conditions.lua b/.config/nvim/lua/core/lualine/conditions.lua new file mode 100644 index 0000000..2d2d81e --- /dev/null +++ b/.config/nvim/lua/core/lualine/conditions.lua @@ -0,0 +1,17 @@ +local window_width_limit = 80 + +local conditions = { + buffer_not_empty = function() + return vim.fn.empty(vim.fn.expand "%:t") ~= 1 + end, + hide_in_width = function() + return vim.fn.winwidth(0) > window_width_limit + end, + check_git_workspace = function() + local filepath = vim.fn.expand "%:p:h" + local gitdir = vim.fn.finddir(".git", filepath .. ";") + return gitdir and #gitdir > 0 and #gitdir < #filepath + end, +} + +return conditions diff --git a/.config/nvim/lua/core/lualine/init.lua b/.config/nvim/lua/core/lualine/init.lua new file mode 100644 index 0000000..7d67559 --- /dev/null +++ b/.config/nvim/lua/core/lualine/init.lua @@ -0,0 +1,47 @@ +local M = {} +M.config = function() + options.builtin.lualine = { + active = true, + style = "options", + options = { + icons_enabled = nil, + component_separators = nil, + section_separators = nil, + theme = nil, + disabled_filetypes = nil, + }, + sections = { + lualine_a = nil, + lualine_b = nil, + lualine_c = nil, + lualine_x = nil, + lualine_y = nil, + lualine_z = nil, + }, + inactive_sections = { + lualine_a = nil, + lualine_b = nil, + lualine_c = nil, + lualine_x = nil, + lualine_y = nil, + lualine_z = nil, + }, + tabline = nil, + extensions = nil, + on_config_done = nil, + } +end + +M.setup = function() + require("core.lualine.styles").update() + require("core.lualine.utils").validate_theme() + + local lualine = require "lualine" + lualine.setup(options.builtin.lualine) + + if options.builtin.lualine.on_config_done then + options.builtin.lualine.on_config_done(lualine) + end +end + +return M diff --git a/.config/nvim/lua/core/lualine/styles.lua b/.config/nvim/lua/core/lualine/styles.lua new file mode 100644 index 0000000..014ba81 --- /dev/null +++ b/.config/nvim/lua/core/lualine/styles.lua @@ -0,0 +1,186 @@ +local M = {} +local components = require "core.lualine.components" + +local styles = { + lvim = nil, + default = nil, + none = nil, + clean = nil, +} + +styles.clean = { + style = "lvim", + options = { + icons_enabled = true, + component_separators = "", + section_separators = "", + disabled_filetypes = { "dashboard" }, + }, + sections = { + lualine_a = { + components.mode, + }, + lualine_b = { + components.branch, + components.filename, + }, + lualine_c = { + components.diff, + components.python_env, + }, + lualine_x = { + components.diagnostics, + components.treesitter, + components.lsp, + components.filetype, + }, + lualine_y = {}, + lualine_z = { + components.location, + components.progress, + components.encoding, + }, + }, + inactive_sections = { + lualine_a = { + "filename", + }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = { "nvim-tree" }, +} + +styles.none = { + style = "none", + options = { + icons_enabled = true, + component_separators = "", + section_separators = "", + disabled_filetypes = {}, + }, + sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +} + +styles.default = { + style = "default", + options = { + icons_enabled = true, + component_separators = { "", "" }, + section_separators = { "", "" }, + disabled_filetypes = {}, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch" }, + lualine_c = { "filename" }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +} + +styles.lvim = { + style = "lvim", + options = { + icons_enabled = true, + component_separators = "", + section_separators = "", + disabled_filetypes = { "dashboard" }, + }, + sections = { + lualine_a = { + components.mode, + }, + lualine_b = { + components.branch, + components.filename, + }, + lualine_c = { + components.diff, + components.python_env, + }, + lualine_x = { + components.diagnostics, + components.treesitter, + components.lsp, + components.filetype, + }, + lualine_y = {}, + lualine_z = { + components.scrollbar, + }, + }, + inactive_sections = { + lualine_a = { + "filename", + }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = { "nvim-tree" }, +} + +function M.get_style(style) + local style_keys = vim.tbl_keys(styles) + if not vim.tbl_contains(style_keys, style) then + local Log = require "core.log" + local logger = Log:get_default() + logger.error( + "Invalid lualine style", + string.format('"%s"', style), + "options are: ", + string.format('"%s"', table.concat(style_keys, '", "')) + ) + logger.info '"lvim" style is applied.' + style = "lvim" + end + + return vim.deepcopy(styles[style]) +end + +function M.update() + local style = M.get_style(options.builtin.lualine.style) + if options.builtin.lualine.options.theme == nil then + options.builtin.lualine.options.theme = options.colorscheme + end + + options.builtin.lualine = vim.tbl_deep_extend("keep", options.builtin.lualine, style) +end + +return M diff --git a/.config/nvim/lua/core/lualine/utils.lua b/.config/nvim/lua/core/lualine/utils.lua new file mode 100644 index 0000000..48756a7 --- /dev/null +++ b/.config/nvim/lua/core/lualine/utils.lua @@ -0,0 +1,27 @@ +local M = {} + +function M.validate_theme() + local theme = options.builtin.lualine.options.theme + if type(theme) == "table" then + return + end + + local lualine_loader = require "lualine.utils.loader" + local ok = pcall(lualine_loader.load_theme, theme) + if not ok then + options.builtin.lualine.options.theme = "auto" + end +end + +function M.env_cleanup(venv) + if string.find(venv, "/") then + local final_venv = venv + for w in venv:gmatch "([^/]+)" do + final_venv = w + end + venv = final_venv + end + return venv +end + +return M diff --git a/.config/nvim/lua/core/nvimtree.lua b/.config/nvim/lua/core/nvimtree.lua index 376ae56..c640583 100644 --- a/.config/nvim/lua/core/nvimtree.lua +++ b/.config/nvim/lua/core/nvimtree.lua @@ -1,8 +1,10 @@ local M = {} local Log = require "core.log" --- -M.config = function() + +function M.config() options.builtin.nvimtree = { + active = true, + on_config_done = nil, side = "left", width = 30, show_icons = { @@ -46,8 +48,8 @@ M.config = function() }, } end --- -M.setup = function() + +function M.setup() local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") if not status_ok then Log:get_default().error "Failed to load nvim-tree.config" @@ -59,6 +61,12 @@ M.setup = function() g["nvim_tree_" .. opt] = val end + -- Implicitly update nvim-tree when project module is active + if options.builtin.project.active then + vim.g.nvim_tree_update_cwd = 1 + vim.g.nvim_tree_respect_buf_cwd = 1 + end + local tree_cb = nvim_tree_config.nvim_tree_callback if not g.nvim_tree_bindings then @@ -66,67 +74,46 @@ M.setup = function() { key = { "l", "", "o" }, cb = tree_cb "edit" }, { key = "h", cb = tree_cb "close_node" }, { key = "v", cb = tree_cb "vsplit" }, - - { key = "q", cb = ":lua require('core.nvimtree').toggle_tree()" }, } end -end --- -M.focus_or_close = function() - local view_status_ok, view = pcall(require, "nvim-tree.view") - if not view_status_ok then - return + + options.builtin.which_key.mappings["e"] = { "NvimTreeToggle", "Explorer" } + + local tree_view = require "nvim-tree.view" + + -- Add nvim_tree open callback + local open = tree_view.open + tree_view.open = function() + M.on_open() + open() end - local a = vim.api - local curwin = a.nvim_get_current_win() - local curbuf = a.nvim_win_get_buf(curwin) - local bufnr = view.View.bufnr - local winnr = view.get_winnr() + vim.cmd "au WinClosed * lua require('core.nvimtree').on_close()" - if view.win_open() then - if curwin == winnr and curbuf == bufnr then - view.close() - if package.loaded["bufferline.state"] then - require("bufferline.state").set_offset(0) - end - else - view.focus() - end - else - view.open() - if - package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left" - then - require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "") - end + if options.builtin.nvimtree.on_config_done then + options.builtin.nvimtree.on_config_done(nvim_tree_config) end end --- -M.toggle_tree = function() - local view_status_ok, view = pcall(require, "nvim-tree.view") - if not view_status_ok then - return + +function M.on_open() + if package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left" then + require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "") end - if view.win_open() then - require("nvim-tree").close() - if package.loaded["bufferline.state"] then - require("bufferline.state").set_offset(0) - end - else - if - package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left" - then - require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "") - end - require("nvim-tree").toggle() +end + +function M.on_close() + local buf = tonumber(vim.fn.expand "") + local ft = vim.api.nvim_buf_get_option(buf, "filetype") + if ft == "NvimTree" and package.loaded["bufferline.state"] then + require("bufferline.state").set_offset(0) end end --- + function M.change_tree_dir(dir) - if vim.g.loaded_tree then - require("nvim-tree.lib").change_dir(dir) + local lib_status_ok, lib = pcall(require, "nvim-tree.lib") + if lib_status_ok then + lib.change_dir(dir) end end --- + return M diff --git a/.config/nvim/lua/core/project.lua b/.config/nvim/lua/core/project.lua new file mode 100644 index 0000000..c7eacde --- /dev/null +++ b/.config/nvim/lua/core/project.lua @@ -0,0 +1,51 @@ +local M = {} + +function M.config() + options.builtin.project = { + ---@usage set to false to disable project.nvim. + --- This is on by default since it's currently the expected behavior. + active = true, + + on_config_done = nil, + + ---@usage set to true to disable setting the current-woriking directory + --- Manual mode doesn't automatically change your root directory, so you have + --- the option to manually do so using `:ProjectRoot` command. + manual_mode = false, + + ---@usage Methods of detecting the root directory + --- Allowed values: **"lsp"** uses the native neovim lsp + --- **"pattern"** uses vim-rooter like glob pattern matching. Here + --- order matters: if one is not detected, the other is used as fallback. You + --- can also delete or rearangne the detection methods. + detection_methods = { "lsp", "pattern" }, + + ---@usage patterns used to detect root dir, when **"pattern"** is in detection_methods + patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, + + ---@ Show hidden files in telescope when searching for files in a project + show_hidden = false, + + ---@usage When set to false, you will get a message when project.nvim changes your directory. + -- When set to false, you will get a message when project.nvim changes your directory. + silent_chdir = true, + + ---@usage list of lsp client names to ignore when using **lsp** detection. eg: { "efm", ... } + ignore_lsp = {}, + + ---@type string + ---@usage path to store the project history for use in telescope + datapath = CACHE_PATH, + } +end + +function M.setup() + local project = require "project_nvim" + + project.setup(options.builtin.project) + if options.builtin.project.on_config_done then + options.builtin.project.on_config_done(project) + end +end + +return M diff --git a/.config/nvim/lua/core/status_colors.lua b/.config/nvim/lua/core/status_colors.lua deleted file mode 100644 index 71b6277..0000000 --- a/.config/nvim/lua/core/status_colors.lua +++ /dev/null @@ -1,19 +0,0 @@ -options.builtin.galaxyline = { - active = true, - colors = { - alt_bg = "#0A0A0A", - grey = "#D0D0D0", - blue = "#569CD6", - green = "#608B4E", - yellow = "#DCDCAA", - orange = "#FF8800", - purple = "#C586C0", - magenta = "#D16D9E", - cyan = "#4EC9B0", - red = "#D16969", - error_red = "#F44747", - warning_orange = "#FF8800", - info_yellow = "#FFCC66", - hint_blue = "#9CDCFE", - }, -} diff --git a/.config/nvim/lua/core/telescope.lua b/.config/nvim/lua/core/telescope.lua index 513665e..d394884 100644 --- a/.config/nvim/lua/core/telescope.lua +++ b/.config/nvim/lua/core/telescope.lua @@ -1,13 +1,19 @@ local M = {} -local Log = require "core.log" -M.config = function() + +function M.config() + -- Define this minimal config so that it's available if telescope is not yet available. + options.builtin.telescope = { + ---@usage disable telescope completely [not recommeded] + active = true, + on_config_done = nil, + } + local status_ok, actions = pcall(require, "telescope.actions") if not status_ok then return end - options.builtin.telescope = { - active = false, + options.builtin.telescope = vim.tbl_extend("force", options.builtin.telescope, { defaults = { find_command = { "rg", @@ -82,16 +88,20 @@ M.config = function() override_file_sorter = true, }, }, - } + }) end -M.setup = function() - local status_ok, telescope = pcall(require, "telescope") - if not status_ok then - Log:get_default().error "Failed to load telescope" - return - end +function M.setup() + local telescope = require "telescope" + telescope.setup(options.builtin.telescope) + if options.builtin.project.active then + telescope.load_extension "projects" + end + + if options.builtin.telescope.on_config_done then + options.builtin.telescope.on_config_done(telescope) + end end return M diff --git a/.config/nvim/lua/core/terminal.lua b/.config/nvim/lua/core/terminal.lua index ff3f95e..80dc9d0 100644 --- a/.config/nvim/lua/core/terminal.lua +++ b/.config/nvim/lua/core/terminal.lua @@ -1,9 +1,9 @@ local M = {} -local Log = require "core.log" local utils = require "utils" M.config = function() options.builtin["terminal"] = { + on_config_done = nil, -- size can be a number or function which is passed the current terminal size = 20, -- open_mapping = [[]], @@ -46,20 +46,15 @@ M.config = function() end M.setup = function() - local status_ok, terminal = pcall(require, "toggleterm") - if not status_ok then - Log:get_default().error "Failed to load toggleterm" - print(terminal) - return - end + local terminal = require "toggleterm" for _, exec in pairs(options.builtin.terminal.execs) do require("core.terminal").add_exec(exec[1], exec[2], exec[3]) end terminal.setup(options.builtin.terminal) -end -local function is_installed(exe) - return vim.fn.executable(exe) == 1 + if options.builtin.terminal.on_config_done then + options.builtin.terminal.on_config_done(terminal) + end end M.add_exec = function(exec, keymap, name) @@ -85,12 +80,9 @@ end M._exec_toggle = function(exec) local binary = M._split(exec)[1] - if is_installed(binary) ~= true then - print( - "Please install executable " - .. binary - .. ". Check documentation for more information" - ) + if vim.fn.executable(binary) ~= 1 then + local Log = require "core.log" + Log:get_default().error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") return end local Terminal = require("toggleterm.terminal").Terminal diff --git a/.config/nvim/lua/core/treesitter.lua b/.config/nvim/lua/core/treesitter.lua index ba70b70..59adda4 100644 --- a/.config/nvim/lua/core/treesitter.lua +++ b/.config/nvim/lua/core/treesitter.lua @@ -1,7 +1,10 @@ + local M = {} local Log = require "core.log" + M.config = function() options.builtin.treesitter = { + on_config_done = nil, ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages ignore_install = {}, matchup = { @@ -70,6 +73,10 @@ M.setup = function() end treesitter_configs.setup(options.builtin.treesitter) + + if options.builtin.treesitter.on_config_done then + options.builtin.treesitter.on_config_done(treesitter_configs) + end end return M diff --git a/.config/nvim/lua/core/which-key.lua b/.config/nvim/lua/core/which-key.lua index 775ea67..7ea86a8 100644 --- a/.config/nvim/lua/core/which-key.lua +++ b/.config/nvim/lua/core/which-key.lua @@ -1,8 +1,10 @@ local M = {} -local Log = require "core.log" + M.config = function() options.builtin.which_key = { - active = false, + ---@usage disable which-key completely [not recommeded] + active = true, + on_config_done = nil, setup = { plugins = { marks = true, -- shows a list of your marks on ' and ` @@ -66,9 +68,8 @@ M.config = function() ["q"] = { "q!", "Quit" }, ["k"] = { "CommentToggle", "Comment" }, ["c"] = { "BufferClose!", "Close Buffer" }, - ["e"] = { "lua require'core.nvimtree'.toggle_tree()", "Explorer" }, ["f"] = { "Telescope find_files", "Find File" }, - ["n"] = { 'let @/=""', "No Highlight" }, + ["n"] = { "nohlsearch", "No Highlight" }, b = { name = "Buffers", j = { "BufferPick", "jump to buffer" }, @@ -156,14 +157,8 @@ M.config = function() p = { name = "Peek", d = { "lua require('lsp.peek').Peek('definition')", "Definition" }, - t = { - "lua require('lsp.peek').Peek('typeDefinition')", - "Type Definition", - }, - i = { - "lua require('lsp.peek').Peek('implementation')", - "Implementation", - }, + t = { "lua require('lsp.peek').Peek('typeDefinition')", "Type Definition" }, + i = { "lua require('lsp.peek').Peek('implementation')", "Implementation" }, }, q = { "lua vim.lsp.diagnostic.set_loclist()", "Quickfix" }, r = { "lua vim.lsp.buf.rename()", "Rename" }, @@ -173,18 +168,31 @@ M.config = function() "Workspace Symbols", }, }, - I = { + i = { name = "+nvim", - k = { - "lua require('keymappings').print()", - "View nvim's default keymappings", + c = { + "edit ~/.config/nvim/config.lua", + "Edit config.lua", }, + k = { "lua require('keymappings').print()", "View LunarVim's default keymappings" }, i = { "lua require('core.info').toggle_popup(vim.bo.filetype)", "Toggle nvim Info", }, + l = { + name = "+logs", + D = { "edit ~/.cache/nvim/lunarvim.log", "Open the default logfile" }, + n = { "lua require('core.terminal').toggle_log_view('lsp')", "view lsp log" }, + N = { "edit ~/.cache/nvim/log", "Open the Neovim logfile" }, + l = { "lua require('core.terminal').toggle_log_view('nvim')", "view neovim log" }, + L = { "edit ~/.cache/nvim/lsp.log", "Open the LSP logfile" }, + p = { + "lua require('core.terminal').toggle_log_view('packer.nvim')", + "view packer log", + }, + P = { "edit ~/.cache/nvim/packer.nvim.log", "Open the Packer logfile" }, + }, }, - s = { name = "Search", b = { "Telescope git_branches", "Checkout branch" }, @@ -211,14 +219,7 @@ M.config = function() end M.setup = function() - -- if not package.loaded['which-key'] then - -- return - -- end - local status_ok, which_key = pcall(require, "which-key") - if not status_ok then - Log:get_default "Failed to load whichkey" - return - end + local which_key = require "which-key" which_key.setup(options.builtin.which_key.setup) @@ -228,10 +229,12 @@ M.setup = function() local mappings = options.builtin.which_key.mappings local vmappings = options.builtin.which_key.vmappings - local wk = require "which-key" + which_key.register(mappings, opts) + which_key.register(vmappings, vopts) - wk.register(mappings, opts) - wk.register(vmappings, vopts) + if options.builtin.which_key.on_config_done then + options.builtin.which_key.on_config_done(which_key) + end end return M diff --git a/.config/nvim/lua/dark/highlights.lua b/.config/nvim/lua/dark/highlights.lua index a974cae..d24f53f 100644 --- a/.config/nvim/lua/dark/highlights.lua +++ b/.config/nvim/lua/dark/highlights.lua @@ -10,8 +10,8 @@ local highlights = { SpellRare = { fg = C.purple, style = "underline" }, NormalNC = { fg = C.fg, bg = C.bg }, Pmenu = { fg = C.white, bg = C.accent }, - PmenuSel = { fg = C.alt_bg, bg = C.blue }, - WildMenu = { fg = C.alt_bg, bg = C.blue }, + PmenuSel = { fg = C.blue, bg = C.alt_bg }, + WildMenu = { fg = C.blue, bg = C.alt_bg }, CursorLineNr = { fg = C.light_gray, style = "bold" }, Comment = { fg = C.blue, style = "italic" }, Folded = { fg = C.accent, bg = C.alt_bg }, @@ -24,7 +24,7 @@ local highlights = { CursorColumn = { bg = C.alt_bg }, ColorColumn = { bg = C.alt_bg }, NormalFloat = { bg = C.alt_bg }, - Visual = { bg = C.accent }, + Visual = { bg = C.gray }, VisualNOS = { bg = C.alt_bg }, WarningMsg = { fg = C.error_red, bg = C.bg }, DiffAdd = { fg = C.alt_bg, bg = C.sign_add }, diff --git a/.config/nvim/lua/default-config.lua b/.config/nvim/lua/default-config.lua deleted file mode 100644 index 6f396ba..0000000 --- a/.config/nvim/lua/default-config.lua +++ /dev/null @@ -1,1308 +0,0 @@ -CONFIG_PATH = vim.fn.stdpath "config" -DATA_PATH = vim.fn.stdpath "data" -CACHE_PATH = vim.fn.stdpath "cache" -TERMINAL = vim.fn.expand "$TERMINAL" -USER = vim.fn.expand "$USER" -vim.cmd [[ set spellfile=~/.config/nvim/spell/en.utf-8.add ]] - -options = { - leader_key = "space", - colorscheme = "dark", - line_wrap_cursor_movement = true, - transparent_window = false, - format_on_save = true, - vsnip_dir = os.getenv "HOME" .. "/.config/snippets", - database = { save_location = "~/.config/nvim_db", auto_execute = 1 }, - keys = {}, - - -- TODO: might remove later - builtin = { - lspinstall = {}, - telescope = {}, - compe = {}, - autopairs = {}, - treesitter = {}, - nvimtree = {}, - gitsigns = {}, - which_key = {}, - comment = {}, - galaxyline = {}, - bufferline = {}, - dap = {}, - dashboard = {}, - terminal = {}, - rooter = {}, - }, - - log = { - ---@usage can be { "trace", "debug", "info", "warn", "error", "fatal" }, - level = "warn", - viewer = { - ---@usage this will fallback on "less +F" if not found - cmd = "lnav", - layout_config = { - ---@usage direction = 'vertical' | 'horizontal' | 'window' | 'float', - direction = "horizontal", - open_mapping = "", - size = 40, - float_opts = {}, - }, - }, - }, - - lsp = { - completion = { - item_kind = { - "  (Text) ", - "  (Method)", - "  (Function)", - "  (Constructor)", - " ﴲ (Field)", - "[] (Variable)", - "  (Class)", - " ﰮ (Interface)", - "  (Module)", - " 襁 (Property)", - "  (Unit)", - "  (Value)", - " 練 (Enum)", - "  (Keyword)", - "  (Snippet)", - "  (Color)", - "  (File)", - "  (Reference)", - "  (Folder)", - "  (EnumMember)", - " ﲀ (Constant)", - " ﳤ (Struct)", - "  (Event)", - "  (Operator)", - "  (TypeParameter)", - }, - }, - diagnostics = { - signs = { - active = true, - values = { - { name = "LspDiagnosticsSignError", text = "" }, - { name = "LspDiagnosticsSignWarning", text = "" }, - { name = "LspDiagnosticsSignHint", text = "" }, - { name = "LspDiagnosticsSignInformation", text = "" }, - }, - }, - virtual_text = { - prefix = "", - spacing = 0, - }, - underline = true, - severity_sort = true, - }, - override = {}, - document_highlight = true, - popup_border = "single", - on_attach_callback = nil, - on_init_callback = nil, - ---@usage query the project directory from the language server and use it to set the CWD - smart_cwd = true, - }, - - plugins = { - -- use config.lua for this not put here - }, - - autocommands = {}, -} - -local schemas = nil -local lsp = require "lsp" -local common_on_attach = lsp.common_on_attach -local common_capabilities = lsp.common_capabilities() -local common_on_init = lsp.common_on_init -local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") -if status_ok then - schemas = jsonls_settings.get_default_schemas() -end - --- TODO move all of this into lang specific files, only require when using -options.lang = { - asm = { - formatters = { - -- { - -- exe = "asmfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "", - setup = {}, - }, - }, - beancount = { - formatters = { - -- { - -- exe = "bean_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "beancount", - setup = { - cmd = { "beancount-langserver" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - c = { - formatters = { - -- { - -- exe = "clang_format", - -- args = {}, - -- }, - -- { - -- exe = "uncrustify", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "clangd", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd", - "--background-index", - "--header-insertion=never", - "--cross-file-rename", - "--clang-tidy", - "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - cpp = { - formatters = { - -- { - -- exe = "clang_format", - -- args = {}, - -- }, - -- { - -- exe = "uncrustify", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "clangd", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd", - "--background-index", - "--header-insertion=never", - "--cross-file-rename", - "--clang-tidy", - "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - crystal = { - formatters = { - -- { - -- exe = "crystal_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "crystalline", - setup = { - cmd = { "crystalline" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - cs = { - formatters = { - -- { - -- exe = "clang_format ", - -- args = {}, - -- }, - -- { - -- exe = "uncrustify", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "omnisharp", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/csharp/omnisharp/run", - "--languageserver", - "--hostPID", - tostring(vim.fn.getpid()), - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - cmake = { - formatters = { - -- { - -- exe = "cmake_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "cmake", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/cmake/venv/bin/cmake-language-server", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - clojure = { - formatters = {}, - linters = {}, - lsp = { - provider = "clojure_lsp", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/clojure/clojure-lsp", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - css = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "cssls", - setup = { - cmd = { - "node", - DATA_PATH - .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - less = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "cssls", - setup = { - cmd = { - "node", - DATA_PATH - .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - d = { - formatters = { - -- { - -- exe = "dfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "serve_d", - setup = { - cmd = { "serve-d" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - dart = { - formatters = { - -- { - -- exe = "dart_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "dartls", - setup = { - cmd = { - "dart", - "/usr/lib/dart/bin/snapshots/analysis_server.dart.snapshot", - "--lsp", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - docker = { - formatters = {}, - linters = {}, - lsp = { - provider = "dockerls", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/dockerfile/node_modules/.bin/docker-langserver", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - elixir = { - formatters = { - -- { - -- exe = "mix", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "elixirls", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/elixir/elixir-ls/language_server.sh", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - elm = { - formatters = { - -- { - -- exe = "elm_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "elmls", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-language-server", - }, - on_attach = common_on_attach, - on_init = common_on_init, - -- init_options = { - -- elmAnalyseTrigger = "change", - -- elmFormatPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-format", - -- elmPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/", - -- elmTestPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-test", - -- }, - }, - }, - }, - erlang = { - formatters = { - -- { - -- exe = "erlfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "erlangls", - setup = { - cmd = { - "erlang_ls", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - emmet = { active = false }, - fish = { - formatters = { - -- { - -- exe = "fish_indent", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "", - setup = { - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - go = { - formatters = { - -- { - -- exe = "gofmt", - -- args = {}, - -- }, - -- { - -- exe = "goimports", - -- args = {}, - -- }, - -- { - -- exe = "gofumpt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "gopls", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/go/gopls", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - graphql = { - formatters = {}, - linters = {}, - lsp = { - provider = "graphql", - setup = { - cmd = { - "graphql-lsp", - "server", - "-m", - "stream", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - haskell = { - formatters = {}, - linters = {}, - lsp = { - provider = "hls", - setup = { - cmd = { DATA_PATH .. "/lspinstall/haskell/hls" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - html = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "html", - setup = { - cmd = { - "node", - DATA_PATH - .. "/lspinstall/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - java = { - formatters = { - -- { - -- exe = "clang_format", - -- args = {}, - -- }, - -- { - -- exe = "uncrustify", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "jdtls", - setup = { - cmd = { DATA_PATH .. "/lspinstall/java/jdtls.sh" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - json = { - formatters = { - -- { - -- exe = "json_tool", - -- args = {}, - -- }, - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "jsonls", - setup = { - cmd = { - "node", - DATA_PATH - .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - settings = { - json = { - schemas = schemas, - -- = { - -- { - -- fileMatch = { "package.json" }, - -- url = "https://json.schemastore.org/package.json", - -- }, - -- }, - }, - }, - commands = { - Format = { - function() - vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) - end, - }, - }, - }, - }, - }, - julia = { - formatters = {}, - linters = {}, - lsp = { - provider = "julials", - setup = { - { - "julia", - "--startup-file=no", - "--history-file=no", - -- vim.fn.expand "~/.config/nvim/lua/lsp/julia/run.jl", - CONFIG_PATH .. "/utils/julia/run.jl", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - kotlin = { - formatters = {}, - linters = {}, - lsp = { - provider = "kotlin_language_server", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/kotlin/server/bin/kotlin-language-server", - }, - on_attach = common_on_attach, - on_init = common_on_init, - root_dir = function(fname) - local util = require "lspconfig/util" - - local root_files = { - "settings.gradle", -- Gradle (multi-project) - "settings.gradle.kts", -- Gradle (multi-project) - "build.xml", -- Ant - "pom.xml", -- Maven - } - - local fallback_root_files = { - "build.gradle", -- Gradle - "build.gradle.kts", -- Gradle - } - return util.root_pattern(unpack(root_files))(fname) - or util.root_pattern(unpack(fallback_root_files))(fname) - end, - }, - }, - }, - lua = { - formatters = { - -- { - -- exe = "stylua", - -- args = {}, - -- }, - -- { - -- exe = "lua_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "sumneko_lua", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/lua/sumneko-lua-language-server", - "-E", - DATA_PATH .. "/lspinstall/lua/main.lua", - }, - capabilities = common_capabilities, - on_attach = common_on_attach, - on_init = common_on_init, - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - -- Setup your lua path - path = vim.split(package.path, ";"), - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim", "nvim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - -- library = { - -- [vim.fn.expand "~/.local/share/lunarvim/options/lua"] = true, - -- [vim.fn.expand "$VIMRUNTIME/lua"] = true, - -- [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, - --}, - maxPreload = 100000, - preloadFileSize = 1000, - }, - }, - }, - }, - }, - }, - nginx = { - formatters = { - -- { - -- exe = "nginx_beautifier", - -- args = { - -- provider = "", - -- setup = {}, - -- }, - -- }, - }, - linters = {}, - lsp = {}, - }, - perl = { - formatters = { - -- { - -- exe = "perltidy", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "", - setup = {}, - }, - }, - sql = { - formatters = { - -- { - -- exe = "sqlformat", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "sqls", - setup = { - cmd = { "sqls" }, - }, - }, - }, - php = { - formatters = { - -- { - -- exe = "phpcbf", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "intelephense", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - filetypes = { "php", "phtml" }, - settings = { - intelephense = { - environment = { - phpVersion = "7.4", - }, - }, - }, - }, - }, - }, - puppet = { - formatters = {}, - linters = {}, - lsp = { - provider = "puppet", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/puppet/puppet-editor-services/puppet-languageserver", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - javascript = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - -- @usage can be {"eslint"} or {"eslint_d"} - linters = {}, - lsp = { - provider = "tsserver", - setup = { - cmd = { - -- TODO: - DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - javascriptreact = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "tsserver", - setup = { - cmd = { - -- TODO: - DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - python = { - formatters = { - -- { - -- exe = "yapf", - -- args = {}, - -- }, - -- { - -- exe = "isort", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "pyright", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - -- R -e 'install.packages("formatR",repos = "http://cran.us.r-project.org")' - -- R -e 'install.packages("readr",repos = "http://cran.us.r-project.org")' - r = { - formatters = { - -- { - -- exe = "format_r", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "r_language_server", - setup = { - cmd = { - "R", - "--slave", - "-e", - "languageserver::run()", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - ruby = { - formatters = { - -- { - -- exe = "rufo", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "solargraph", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", - "stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - filetypes = { "ruby" }, - init_options = { - formatting = true, - }, - root_dir = function(fname) - local util = require("lspconfig").util - return util.root_pattern("Gemfile", ".git")(fname) - end, - settings = { - solargraph = { - diagnostics = true, - }, - }, - }, - }, - }, - rust = { - formatters = { - -- { - -- exe = "rustfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "rust_analyzer", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/rust/rust-analyzer", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - scala = { - formatters = { - -- { - -- exe = "scalafmt", - -- args = {}, - -- }, - }, - linters = { "" }, - lsp = { - provider = "metals", - setup = { - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - sh = { - formatters = { - -- { - -- exe = "shfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "bashls", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", - "start", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - svelte = { - formatters = {}, - linters = {}, - lsp = { - provider = "svelte", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - swift = { - formatters = { - -- { - -- exe = "swiftformat", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "sourcekit", - setup = { - cmd = { - "xcrun", - "sourcekit-lsp", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - tailwindcss = { - active = false, - filetypes = { - "html", - "css", - "scss", - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - }, - }, - terraform = { - formatters = { - -- { - -- exe = "terraform_fmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "terraformls", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/terraform/terraform-ls", - "serve", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - tex = { - formatters = {}, - linters = {}, - lsp = { - provider = "texlab", - setup = { - cmd = { DATA_PATH .. "/lspinstall/latex/texlab" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - typescript = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "tsserver", - setup = { - cmd = { - -- TODO: - DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - typescriptreact = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - }, - -- @usage can be {"eslint"} or {"eslint_d"} - linters = {}, - lsp = { - provider = "tsserver", - setup = { - cmd = { - -- TODO: - DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - vim = { - formatters = {}, - linters = { "" }, - lsp = { - provider = "vimls", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/vim/node_modules/.bin/vim-language-server", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - vue = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "vuels", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - yaml = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "yamlls", - setup = { - cmd = { - DATA_PATH .. "/lspinstall/yaml/node_modules/.bin/yaml-language-server", - "--stdio", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - zig = { - formatters = {}, - linters = {}, - lsp = { - provider = "zls", - setup = { - cmd = { - "zls", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - gdscript = { - formatters = {}, - linters = {}, - lsp = { - provider = "gdscript", - setup = { - cmd = { - "nc", - "localhost", - "6008", - }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, - ps1 = { - formatters = {}, - linters = {}, - lsp = { - provider = "powershell_es", - setup = { - bundle_path = "", - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, - }, - }, -} - -require("keymappings").config() -require("core.which-key").config() -require "core.status_colors" -require("core.gitsigns").config() -require("core.compe").config() -require("core.dashboard").config() -require("core.dap").config() -require("core.terminal").config() -require("core.telescope").config() -require("core.treesitter").config() -require("core.nvimtree").config() --- require("core.rooter").config() -require("core.bufferline").config() diff --git a/.config/nvim/lua/interface/popup.lua b/.config/nvim/lua/interface/popup.lua new file mode 100644 index 0000000..b628125 --- /dev/null +++ b/.config/nvim/lua/interface/popup.lua @@ -0,0 +1,62 @@ +local Popup = {} + +--- Create a new floating window +-- @param config The configuration passed to vim.api.nvim_open_win +-- @param win_opts The options registered with vim.api.nvim_win_set_option +-- @param buf_opts The options registered with vim.api.nvim_buf_set_option +-- @return A new popup +function Popup:new(opts) + opts = opts or {} + opts.layout = opts.layout or {} + opts.win_opts = opts.win_opts or {} + opts.buf_opts = opts.buf_opts or {} + + Popup.__index = Popup + + local editor_layout = { + height = vim.o.lines - vim.o.cmdheight - 2, -- Add margin for status and buffer line + width = vim.o.columns, + } + local popup_layout = { + relative = "editor", + height = math.floor(editor_layout.height * 0.9), + width = math.floor(editor_layout.width * 0.8), + style = "minimal", + border = "rounded", + } + popup_layout.row = math.floor((editor_layout.height - popup_layout.height) / 2) + popup_layout.col = math.floor((editor_layout.width - popup_layout.width) / 2) + + local obj = { + buffer = vim.api.nvim_create_buf(false, true), + layout = vim.tbl_deep_extend("force", popup_layout, opts.layout), + win_opts = opts.win_opts, + buf_opts = opts.buf_opts, + } + + setmetatable(obj, Popup) + + return obj +end + +--- Display the popup with the provided content +-- @param content_provider A function accepting the popup's layout and returning the content to display +function Popup:display(content_provider) + self.win_id = vim.api.nvim_open_win(self.buffer, true, self.layout) + vim.lsp.util.close_preview_autocmd({ "BufHidden", "BufLeave" }, self.win_id) + + local lines = content_provider(self.layout) + vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, lines) + + -- window options + for key, value in pairs(self.win_opts) do + vim.api.nvim_win_set_option(self.win_id, key, value) + end + + -- buffer options + for key, value in pairs(self.buf_opts) do + vim.api.nvim_buf_set_option(self.buffer, key, value) + end +end + +return Popup diff --git a/.config/nvim/lua/interface/text.lua b/.config/nvim/lua/interface/text.lua new file mode 100644 index 0000000..f68cc49 --- /dev/null +++ b/.config/nvim/lua/interface/text.lua @@ -0,0 +1,79 @@ +local M = {} + +local function max_len_line(lines) + local max_len = 0 + + for _, line in ipairs(lines) do + local line_len = line:len() + if line_len > max_len then + max_len = line_len + end + end + + return max_len +end + +--- Center align lines relatively to the parent container +-- @param container The container where lines will be displayed +-- @param lines The text to align +-- @param alignment The alignment value, range: [0-1] +function M.align(container, lines, alignment) + local max_len = max_len_line(lines) + local indent_amount = math.ceil(math.max(container.width - max_len, 0) * alignment) + return M.shift_left(lines, indent_amount) +end + +--- Shift lines by a given amount +-- @params lines The lines the shift +-- @param amount The amount of spaces to add +function M.shift_left(lines, amount) + local output = {} + local padding = string.rep(" ", amount) + + for _, line in ipairs(lines) do + table.insert(output, padding .. line) + end + + return output +end + +--- Pretty format tables +-- @param entries The table to format +-- @param col_count The number of column to span the table on +-- @param col_sep The separator between each colummn, default: " " +function M.format_table(entries, col_count, col_sep) + col_sep = col_sep or " " + + local col_rows = math.ceil(vim.tbl_count(entries) / col_count) + local cols = {} + local count = 0 + + for i, entry in ipairs(entries) do + if ((i - 1) % col_rows) == 0 then + table.insert(cols, {}) + count = count + 1 + end + table.insert(cols[count], entry) + end + + local col_max_len = {} + for _, col in ipairs(cols) do + table.insert(col_max_len, max_len_line(col)) + end + + local output = {} + for i, col in ipairs(cols) do + for j, entry in ipairs(col) do + if not output[j] then + output[j] = entry + else + local padding = string.rep(" ", col_max_len[i - 1] - cols[i - 1][j]:len()) + output[j] = output[j] .. padding .. col_sep .. entry + end + end + end + + return output +end + +return M diff --git a/.config/nvim/lua/keymappings.lua b/.config/nvim/lua/keymappings.lua index 60069d8..f7d91d8 100644 --- a/.config/nvim/lua/keymappings.lua +++ b/.config/nvim/lua/keymappings.lua @@ -1,4 +1,5 @@ local M = {} +local Log = require "core.log" local generic_opts_any = { noremap = true, silent = true } @@ -7,6 +8,7 @@ local generic_opts = { normal_mode = generic_opts_any, visual_mode = generic_opts_any, visual_block_mode = generic_opts_any, + command_mode = generic_opts_any, term_mode = { silent = true }, } @@ -81,14 +83,8 @@ function M.config() [""] = "l", -- navigate tab completion with and -- runs conditionally - [""] = { - 'pumvisible() ? "\\" : "\\"', - { expr = true, noremap = true }, - }, - [""] = { - 'pumvisible() ? "\\" : "\\"', - { expr = true, noremap = true }, - }, + [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, + [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, }, ---@usage change or add keymappings for normal mode @@ -148,18 +144,13 @@ function M.config() [""] = ":m '>+1gv-gv", [""] = ":m '<-2gv-gv", }, + ---@usage change or add keymappings for command mode command_mode = { -- navigate tab completion with and -- runs conditionally - [""] = { - 'pumvisible() ? "\\" : "\\"', - { expr = true, noremap = true }, - }, - [""] = { - 'pumvisible() ? "\\" : "\\"', - { expr = true, noremap = true }, - }, + [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, + [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, }, } diff --git a/.config/nvim/lua/lsp/init.lua b/.config/nvim/lua/lsp/init.lua index 067375f..b693dec 100644 --- a/.config/nvim/lua/lsp/init.lua +++ b/.config/nvim/lua/lsp/init.lua @@ -5,10 +5,7 @@ function M.config() vim.lsp.protocol.CompletionItemKind = options.lsp.completion.item_kind for _, sign in ipairs(options.lsp.diagnostics.signs.values) do - vim.fn.sign_define( - sign.name, - { texthl = sign.name, text = sign.text, numhl = sign.name } - ) + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) end require("lsp.handlers").setup() @@ -37,7 +34,11 @@ local function lsp_highlight_document(client) end local function add_lsp_buffer_keybindings(bufnr) - local wk = require "which-key" + local status_ok, wk = pcall(require, "which-key") + if not status_ok then + return + end + local keys = { ["K"] = { "lua vim.lsp.buf.hover()", "Show hover" }, ["gd"] = { "lua vim.lsp.buf.definition()", "Goto Definition" }, @@ -54,14 +55,6 @@ local function add_lsp_buffer_keybindings(bufnr) wk.register(keys, { mode = "n", buffer = bufnr }) end -local function set_smart_cwd(client) - local proj_dir = client.config.root_dir - if options.lsp.smart_cwd and proj_dir ~= "/" then - vim.api.nvim_set_current_dir(proj_dir) - require("core.nvimtree").change_tree_dir(proj_dir) - end -end - function M.common_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true @@ -111,18 +104,10 @@ function M.common_on_init(client, bufnr) end local formatters = options.lang[vim.bo.filetype].formatters - if - not vim.tbl_isempty(formatters) - and formatters[1]["exe"] ~= nil - and formatters[1].exe ~= "" - then + if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then client.resolved_capabilities.document_formatting = false Log:get_default().info( - string.format( - "Overriding language server [%s] with format provider [%s]", - client.name, - formatters[1].exe - ) + string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe) ) end end @@ -134,7 +119,6 @@ function M.common_on_attach(client, bufnr) end lsp_highlight_document(client) add_lsp_buffer_keybindings(bufnr) - set_smart_cwd(client) require("lsp.null-ls").setup(vim.bo.filetype) end @@ -154,6 +138,17 @@ function M.setup(lang) if lsp.provider ~= nil and lsp.provider ~= "" then local lspconfig = require "lspconfig" + + if not lsp.setup.on_attach then + lsp.setup.on_attach = M.common_on_attach + end + if not lsp.setup.on_init then + lsp.setup.on_init = M.common_on_init + end + if not lsp.setup.capabilities then + lsp.setup.capabilities = M.common_capabilities() + end + lspconfig[lsp.provider].setup(lsp.setup) end end diff --git a/.config/nvim/lua/lsp/null-ls/formatters.lua b/.config/nvim/lua/lsp/null-ls/formatters.lua index e69c824..cf62615 100644 --- a/.config/nvim/lua/lsp/null-ls/formatters.lua +++ b/.config/nvim/lua/lsp/null-ls/formatters.lua @@ -66,7 +66,7 @@ function M.list_configured(formatter_configs) end function M.setup(filetype, option) - if formatters_by_ft[filetype] and not option.force_reload then + if not options.lang[filetype] or (formatters_by_ft[filetype] and not option.force_reload) then return end diff --git a/.config/nvim/lua/lsp/null-ls/linters.lua b/.config/nvim/lua/lsp/null-ls/linters.lua index a0675a7..a4eaa89 100644 --- a/.config/nvim/lua/lsp/null-ls/linters.lua +++ b/.config/nvim/lua/lsp/null-ls/linters.lua @@ -66,7 +66,7 @@ function M.list_configured(linter_configs) end function M.setup(filetype, option) - if linters_by_ft[filetype] and not option.force_reload then + if not options.lang[filetype] or (linters_by_ft[filetype] and not option.force_reload) then return end diff --git a/.config/nvim/lua/lsp/null-ls/services.lua b/.config/nvim/lua/lsp/null-ls/services.lua index 80bf66e..a1e3a06 100644 --- a/.config/nvim/lua/lsp/null-ls/services.lua +++ b/.config/nvim/lua/lsp/null-ls/services.lua @@ -1,28 +1,20 @@ local M = {} -local logger = require("core.log"):get_default() - local function find_root_dir() - if options.builtin.rooter.active then - --- use vim-rooter to set root_dir - vim.cmd "let root_dir = FindRootDirectory()" - return vim.api.nvim_get_var "root_dir" - end - - -- TODO: Rework this to not make it javascript specific - --- use LSP to set root_dir + local util = require "lspconfig/util" local lsp_utils = require "lsp.utils" - local ts_client = lsp_utils.get_active_client_by_ft "typescript" - if ts_client == nil then - logger.error "Unable to determine root directory since tsserver didn't start correctly" - return nil - end - return ts_client.config.root_dir + local status_ok, ts_client = lsp_utils.is_client_active "typescript" + if status_ok then + return ts_client.config.root_dir + end + local dirname = vim.fn.expand "%:p:h" + return util.root_pattern "package.json"(dirname) end local function from_node_modules(command) local root_dir = find_root_dir() + if not root_dir then return nil end diff --git a/.config/nvim/lua/lsp/utils.lua b/.config/nvim/lua/lsp/utils.lua index af265de..e024a0c 100644 --- a/.config/nvim/lua/lsp/utils.lua +++ b/.config/nvim/lua/lsp/utils.lua @@ -4,12 +4,13 @@ function M.is_client_active(name) local clients = vim.lsp.get_active_clients() for _, client in pairs(clients) do if client.name == name then - return true + return true, client end end return false end +-- FIXME: this should return a list instead function M.get_active_client_by_ft(filetype) if not options.lang[filetype] or not options.lang[filetype].lsp then return nil diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index ded8fe6..4effcb1 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -8,14 +8,12 @@ return { "kabouzeid/nvim-lspinstall", event = "VimEnter", config = function() - local lspinstall = require "lspinstall" + local lspinstall = require "core.lspinstall" lspinstall.setup() - if options.builtin.lspinstall.on_config_done then - options.builtin.lspinstall.on_config_done(lspinstall) - end end, }, + { "nvim-lua/popup.nvim" }, { "nvim-lua/plenary.nvim" }, @@ -24,49 +22,40 @@ return { "nvim-telescope/telescope.nvim", config = function() require("core.telescope").setup() - if options.builtin.telescope.on_config_done then - options.builtin.telescope.on_config_done(require "telescope") - end end, + disable = not options.builtin.telescope.active, }, - -- Autocomplete { - "hrsh7th/nvim-compe", - -- event = "InsertEnter", - config = function() - require("core.compe").setup() - if options.builtin.compe.on_config_done then - options.builtin.compe.on_config_done(require "compe") - end - end, + "hrsh7th/vim-vsnip", + -- wants = "friendly-snippets", + event = "InsertEnter", + disable = not options.builtin.compe.active, + }, + { + "rafamadriz/friendly-snippets", + event = "InsertCharPre", + disable = not options.builtin.compe.active, }, -- Autopairs { "windwp/nvim-autopairs", -- event = "InsertEnter", + after = "nvim-compe", config = function() - require "core.autopairs" - if options.builtin.autopairs.on_config_done then - options.builtin.autopairs.on_config_done(require "nvim-autopairs") - end + require("core.autopairs").setup() end, + disable = not options.builtin.autopairs.active or not options.builtin.compe.active, }, - -- Snippets - - { "hrsh7th/vim-vsnip", event = "InsertEnter" }, - { "rafamadriz/friendly-snippets", event = "InsertEnter" }, - -- Treesitter { "nvim-treesitter/nvim-treesitter", + branch = "0.5-compat", + -- run = ":TSUpdate", config = function() require("core.treesitter").setup() - if options.builtin.treesitter.on_config_done then - options.builtin.treesitter.on_config_done(require "nvim-treesitter.configs") - end end, }, @@ -78,33 +67,27 @@ return { -- commit = "fd7f60e242205ea9efc9649101c81a07d5f458bb", config = function() require("core.nvimtree").setup() - if options.builtin.nvimtree.on_config_done then - options.builtin.nvimtree.on_config_done(require "nvim-tree.config") - end end, + disable = not options.builtin.nvimtree.active, }, - { "lewis6991/gitsigns.nvim", + config = function() require("core.gitsigns").setup() - if options.builtin.gitsigns.on_config_done then - options.builtin.gitsigns.on_config_done(require "gitsigns") - end end, event = "BufRead", + disable = not options.builtin.gitsigns.active, }, - -- whichkey + -- Whichkey { "folke/which-key.nvim", config = function() require("core.which-key").setup() - if options.builtin.which_key.on_config_done then - options.builtin.which_key.on_config_done(require "which-key") - end end, event = "BufWinEnter", + disable = not options.builtin.which_key.active, }, -- Comments @@ -112,26 +95,18 @@ return { "terrortylor/nvim-comment", event = "BufRead", config = function() - local status_ok, nvim_comment = pcall(require, "nvim_comment") - if not status_ok then - local Log = require "core.log" - Log:get_default().error "Failed to load nvim-comment" - return - end - nvim_comment.setup() - if options.builtin.comment.on_config_done then - options.builtin.comment.on_config_done(nvim_comment) - end + require("nvim_comment").setup() end, + disable = not options.builtin.comment.active, }, + -- project.nvim { - "ahmedkhalf/lsp-rooter.nvim", + "ahmedkhalf/project.nvim", config = function() - if options.builtin.rooter.on_config_done then - options.builtin.rooter.on_config_done() - end + require("core.project").setup() end, + disable = not options.builtin.project.active, }, -- Icons @@ -139,26 +114,22 @@ return { -- Status Line and Bufferline { - "glepnir/galaxyline.nvim", + -- "hoob3rt/lualine.nvim", + "shadmansaleh/lualine.nvim", + -- "Lunarvim/lualine.nvim", config = function() - require "core.galaxyline" - if options.builtin.galaxyline.on_config_done then - options.builtin.galaxyline.on_config_done(require "galaxyline") - end + require("core.lualine").setup() end, - event = "BufWinEnter", - disable = not options.builtin.galaxyline.active, + disable = not options.builtin.lualine.active, }, { "romgrk/barbar.nvim", config = function() - require "core.bufferline" - if options.builtin.bufferline.on_config_done then - options.builtin.bufferline.on_config_done() - end + require("core.bufferline").setup() end, event = "BufWinEnter", + disable = not options.builtin.bufferline.active, }, -- Debugging @@ -167,9 +138,6 @@ return { -- event = "BufWinEnter", config = function() require("core.dap").setup() - if options.builtin.dap.on_config_done then - options.builtin.dap.on_config_done(require "dap") - end end, disable = not options.builtin.dap.active, }, @@ -182,30 +150,23 @@ return { disable = not options.builtin.dap.active, }, - -- Builtins, these do not load by default - -- Dashboard { "ChristianChiarulli/dashboard-nvim", event = "BufWinEnter", config = function() require("core.dashboard").setup() - if options.builtin.dashboard.on_config_done then - options.builtin.dashboard.on_config_done(require "dashboard") - end end, disable = not options.builtin.dashboard.active, }, + -- Terminal { "akinsho/nvim-toggleterm.lua", event = "BufWinEnter", config = function() require("core.terminal").setup() - if options.builtin.terminal.on_config_done then - options.builtin.terminal.on_config_done(require "toggleterm") - end end, disable = not options.builtin.terminal.active, }, -} + } diff --git a/.config/nvim/lua/settings.lua b/.config/nvim/lua/settings.lua deleted file mode 100644 index 9295999..0000000 --- a/.config/nvim/lua/settings.lua +++ /dev/null @@ -1,78 +0,0 @@ -local M = {} - -M.load_options = function() - local opt = vim.opt - - local default_options = { - backup = false, -- creates a backup file - clipboard = "unnamedplus", -- allows neovim to access the system clipboard - cmdheight = 2, -- more space in the neovim command line for displaying messages - colorcolumn = "99999", -- fixes indentline for now - completeopt = { "menuone", "noselect" }, - conceallevel = 0, -- so that `` is visible in markdown files - fileencoding = "utf-8", -- the encoding written to a file - foldmethod = "manual", -- folding, set to "expr" for treesitter based folding - foldexpr = "", -- set to "nvim_treesitter#foldexpr()" for treesitter based folding - guifont = "monospace:h17", -- the font used in graphical neovim applications - hidden = true, -- required to keep multiple buffers and open multiple buffers - hlsearch = true, -- highlight all matches on previous search pattern - ignorecase = true, -- ignore case in search patterns - mouse = "a", -- allow the mouse to be used in neovim - pumheight = 10, -- pop up menu height - showmode = false, -- we don't need to see things like -- INSERT -- anymore - showtabline = 2, -- always show tabs - smartcase = true, -- smart case - smartindent = true, -- make indenting smarter again - splitbelow = true, -- force all horizontal splits to go below current window - splitright = true, -- force all vertical splits to go to the right of current window - swapfile = false, -- creates a swapfile - termguicolors = true, -- set term gui colors (most terminals support this) - timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) - title = true, -- set the title of window to the value of the titlestring - -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to - undodir = CACHE_PATH .. "/undo", -- set an undo directory - undofile = true, -- enable persistent undo - updatetime = 300, -- faster completion - writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited - expandtab = true, -- convert tabs to spaces - shiftwidth = 2, -- the number of spaces inserted for each indentation - tabstop = 2, -- insert 2 spaces for a tab - cursorline = true, -- highlight the current line - number = true, -- set numbered lines - relativenumber = true, -- set relative numbered lines - numberwidth = 4, -- set number column width to 2 {default 4} - signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time - wrap = false, -- display lines as one long line - spell = false, - spelllang = "en", - scrolloff = 8, -- is one of my fav - sidescrolloff = 8, - } --- VIM ONLY COMMANDS ---cmd "filetype plugin on"cmd('let &titleold="' .. TERMINAL .. '"')cmd "set inccommand=split"cmd "set iskeyword+=-" - - --- SETTINGS --- - - opt.shortmess:append "c" - - for k, v in pairs(default_options) do - vim.opt[k] = v - end -end - -M.load_commands = function() - local cmd = vim.cmd - if options.line_wrap_cursor_movement then - cmd "set whichwrap+=<,>,[,],h,l" - end - - if options.transparent_window then - cmd "au ColorScheme * hi Normal ctermbg=none guibg=none" - cmd "au ColorScheme * hi SignColumn ctermbg=none guibg=none" - cmd "au ColorScheme * hi NormalNC ctermbg=none guibg=none" - cmd "au ColorScheme * hi MsgArea ctermbg=none guibg=none" - cmd "au ColorScheme * hi TelescopeBorder ctermbg=none guibg=none" - cmd "au ColorScheme * hi NvimTreeNormal ctermbg=none guibg=none" - cmd "let &fcs='eob: '" - end -end - -return M diff --git a/.config/nvim/lua/utils/init.lua b/.config/nvim/lua/utils/init.lua index 3cea053..65bc6f5 100644 --- a/.config/nvim/lua/utils/init.lua +++ b/.config/nvim/lua/utils/init.lua @@ -46,7 +46,7 @@ end function utils.generate_settings() -- Opens a file in append mode - local file = io.open("settings.lua", "w") + local file = io.open("lv-settings.lua", "w") -- sets the default output file as test.lua io.output(file) @@ -88,9 +88,12 @@ function utils.toggle_autoformat() end function utils.reload_config() - vim.cmd "source ~/.config/nvim/lua/settings.lua" - vim.cmd("source " .. USER_CONFIG_PATH) - require("keymappings").setup() + require("core.lualine").config() + + local config = require "config" + config:load() + + require("keymappings").setup() -- this should be done before loading the plugins vim.cmd "source ~/.config/nvim/lua/plugins.lua" local plugins = require "plugins" local plugin_loader = require("plugin-loader").init() @@ -129,3 +132,5 @@ function utils.is_file(filename) end return utils + +-- TODO: find a new home for these autocommands -- cgit v1.2.3-70-g09d2