瀏覽代碼

feat: add an independent lvim namespace (#1699)

kylo252 3 年之前
父節點
當前提交
52b7455741
共有 63 個文件被更改,包括 391 次插入255 次删除
  1. 8 10
      init.lua
  2. 0 28
      lua/core/builtins/init.lua
  3. 12 9
      lua/lvim/bootstrap.lua
  4. 1 6
      lua/lvim/config/defaults.lua
  5. 60 28
      lua/lvim/config/init.lua
  6. 1 1
      lua/lvim/config/settings.lua
  7. 3 3
      lua/lvim/core/autocmds.lua
  8. 0 0
      lua/lvim/core/autopairs.lua
  9. 1 1
      lua/lvim/core/bufferline.lua
  10. 28 0
      lua/lvim/core/builtins/init.lua
  11. 0 0
      lua/lvim/core/cmp.lua
  12. 3 3
      lua/lvim/core/commands.lua
  13. 0 0
      lua/lvim/core/comment.lua
  14. 0 0
      lua/lvim/core/dap.lua
  15. 4 4
      lua/lvim/core/dashboard.lua
  16. 0 0
      lua/lvim/core/gitsigns.lua
  17. 12 13
      lua/lvim/core/info.lua
  18. 0 0
      lua/lvim/core/log.lua
  19. 0 0
      lua/lvim/core/lualine/colors.lua
  20. 5 5
      lua/lvim/core/lualine/components.lua
  21. 0 0
      lua/lvim/core/lualine/conditions.lua
  22. 2 2
      lua/lvim/core/lualine/init.lua
  23. 2 2
      lua/lvim/core/lualine/styles.lua
  24. 0 0
      lua/lvim/core/lualine/utils.lua
  25. 2 2
      lua/lvim/core/nvimtree.lua
  26. 0 0
      lua/lvim/core/project.lua
  27. 4 5
      lua/lvim/core/telescope.lua
  28. 3 3
      lua/lvim/core/terminal.lua
  29. 1 1
      lua/lvim/core/treesitter.lua
  30. 18 15
      lua/lvim/core/which-key.lua
  31. 2 2
      lua/lvim/impatient.lua
  32. 0 0
      lua/lvim/impatient/profile.lua
  33. 0 0
      lua/lvim/interface/popup.lua
  34. 0 0
      lua/lvim/interface/text.lua
  35. 1 1
      lua/lvim/keymappings.lua
  36. 2 2
      lua/lvim/lsp/config.lua
  37. 0 0
      lua/lvim/lsp/handlers.lua
  38. 6 6
      lua/lvim/lsp/init.lua
  39. 6 6
      lua/lvim/lsp/manager.lua
  40. 3 3
      lua/lvim/lsp/null-ls/formatters.lua
  41. 3 3
      lua/lvim/lsp/null-ls/init.lua
  42. 3 3
      lua/lvim/lsp/null-ls/linters.lua
  43. 1 1
      lua/lvim/lsp/null-ls/services.lua
  44. 1 1
      lua/lvim/lsp/peek.lua
  45. 0 0
      lua/lvim/lsp/providers/jsonls.lua
  46. 1 1
      lua/lvim/lsp/providers/sumneko_lua.lua
  47. 1 1
      lua/lvim/lsp/providers/vuels.lua
  48. 0 0
      lua/lvim/lsp/providers/yamlls.lua
  49. 4 4
      lua/lvim/lsp/templates.lua
  50. 1 1
      lua/lvim/lsp/utils.lua
  51. 0 0
      lua/lvim/lualine/themes/onedarker.lua
  52. 2 2
      lua/lvim/plugin-loader.lua
  53. 15 15
      lua/lvim/plugins.lua
  54. 0 0
      lua/lvim/utils/ft.lua
  55. 7 5
      lua/lvim/utils/hooks.lua
  56. 3 35
      lua/lvim/utils/init.lua
  57. 0 0
      lua/lvim/utils/table.lua
  58. 1 1
      tests/bootstrap_spec.lua
  59. 37 0
      tests/config_loader_spec.lua
  60. 11 11
      tests/lsp_spec.lua
  61. 1 5
      tests/minimal_init.lua
  62. 103 0
      tests/minimal_rtp.lua
  63. 6 5
      tests/plugins_load_spec.lua

+ 8 - 10
init.lua

@@ -3,24 +3,22 @@ if os.getenv "LUNARVIM_RUNTIME_DIR" then
   vim.opt.rtp:append(os.getenv "LUNARVIM_RUNTIME_DIR" .. path_sep .. "lvim")
 end
 
-require("bootstrap"):init()
+require("lvim.bootstrap"):init()
 
-local config = require "config"
--- config:init()
-config:load()
+require("lvim.config"):load()
 
-local plugins = require "plugins"
-require("plugin-loader"):load { plugins, lvim.plugins }
+local plugins = require "lvim.plugins"
+require("lvim.plugin-loader"):load { plugins, lvim.plugins }
 
-local Log = require "core.log"
+local Log = require "lvim.core.log"
 Log:debug "Starting LunarVim"
 
 vim.g.colors_name = lvim.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs.
 vim.cmd("colorscheme " .. lvim.colorscheme)
 
-local commands = require "core.commands"
+local commands = require "lvim.core.commands"
 commands.load(commands.defaults)
 
-require("keymappings").setup()
+require("lvim.keymappings").setup()
 
-require("lsp").setup()
+require("lvim.lsp").setup()

+ 0 - 28
lua/core/builtins/init.lua

@@ -1,28 +0,0 @@
-local M = {}
-
-local builtins = {
-  "keymappings",
-  "core.which-key",
-  "core.gitsigns",
-  "core.cmp",
-  "core.dashboard",
-  "core.dap",
-  "core.terminal",
-  "core.telescope",
-  "core.treesitter",
-  "core.nvimtree",
-  "core.project",
-  "core.bufferline",
-  "core.autopairs",
-  "core.comment",
-  "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

+ 12 - 9
lua/bootstrap.lua → lua/lvim/bootstrap.lua

@@ -1,7 +1,7 @@
 local M = {}
 
-package.loaded["utils.hooks"] = nil
-local _, hooks = pcall(require, "utils.hooks")
+package.loaded["lvim.utils.hooks"] = nil
+local _, hooks = pcall(require, "lvim.utils.hooks")
 
 ---Join path segments that were passed as input
 ---@return string
@@ -99,22 +99,25 @@ function M:init()
     vim.cmd("set spellfile=" .. join_paths(self.config_dir, "spell", "en.utf-8.add"))
   end
 
-  vim.fn.mkdir(vim.fn.stdpath "cache", "p")
+  vim.fn.mkdir(get_cache_dir(), "p")
 
   -- FIXME: currently unreliable in unit-tests
   if not os.getenv "LVIM_TEST_ENV" then
-    require("impatient").setup {
+    require("lvim.impatient").setup {
       path = vim.fn.stdpath "cache" .. "/lvim_cache",
       enable_profiling = true,
     }
   end
 
-  local config = require "config"
+  require("lvim.config"):init {
+    config_dir = self.config_dir,
+  }
+  local config = require "lvim.config"
   config:init {
-    path = join_paths(self.config_dir, "config.lua"),
+    user_config = join_paths(self.config_dir, "config.lua"),
   }
 
-  require("plugin-loader"):init {
+  require("lvim.plugin-loader"):init {
     package_root = self.pack_dir,
     install_path = self.packer_install_dir,
   }
@@ -132,7 +135,7 @@ end
 
 local function git_cmd(subcmd)
   local Job = require "plenary.job"
-  local Log = require "core.log"
+  local Log = require "lvim.core.log"
   local args = { "-C", get_install_path() }
   vim.list_extend(args, subcmd)
 
@@ -161,7 +164,7 @@ end
 
 ---pulls the latest changes from github
 function M:update_repo()
-  local Log = require "core.log"
+  local Log = require "lvim.core.log"
   local sub_commands = {
     fetch = { "fetch" },
     diff = { "diff", "--quiet", "@{upstream}" },

+ 1 - 6
lua/config/defaults.lua → lua/lvim/config/defaults.lua

@@ -1,14 +1,9 @@
-local home_dir = vim.loop.os_homedir()
-local utils = require "utils"
-
-lvim = {
+return {
   leader = "space",
   colorscheme = "onedarker",
   line_wrap_cursor_movement = true,
   transparent_window = false,
   format_on_save = true,
-  vsnip_dir = utils.join_paths(home_dir, ".config", "snippets"),
-  database = { save_location = utils.join_paths(home_dir, ".config", "lunarvim_db"), auto_execute = 1 },
   keys = {},
 
   builtin = {},

+ 60 - 28
lua/config/init.lua → lua/lvim/config/init.lua

@@ -1,29 +1,39 @@
+local utils = require "lvim.utils"
+local Log = require "lvim.core.log"
+
 local M = {}
 
---- Initialize lvim default configuration
--- Define lvim global variable
-function M:init(opts)
-  opts = opts or {}
-  self.path = opts.path
-  local utils = require "utils"
+local user_config_dir = get_config_dir()
+local user_config_file = utils.join_paths(user_config_dir, "config.lua")
 
-  require "config.defaults"
+-- Fallback config.lua to lv-config.lua
+if not utils.is_file(user_config_file) then
+  local lv_config = utils.join_paths(user_config_dir, "lv-config.lua")
+  Log:warn(string.format("[%s] not found, falling back to [%s]", user_config_file, lv_config))
+  user_config_file = lv_config
+end
 
-  -- Fallback config.lua to lv-config.lua
-  if not utils.is_file(self.path) then
-    local lv_config = self.path:gsub("config.lua$", "lv-config.lua")
-    print(self.path, "not found, falling back to", lv_config)
+function M:get_user_config_path()
+  return user_config_file
+end
 
-    self.path = lv_config
+--- Initialize lvim default configuration
+-- Define lvim global variable
+function M:init()
+  if vim.tbl_isempty(lvim or {}) then
+    lvim = require "lvim.config.defaults"
+    local home_dir = vim.loop.os_homedir()
+    lvim.vsnip_dir = utils.join_paths(home_dir, ".config", "snippets")
+    lvim.database = { save_location = utils.join_paths(home_dir, ".config", "lunarvim_db"), auto_execute = 1 }
   end
 
-  local builtins = require "core.builtins"
-  builtins.config(self)
+  local builtins = require "lvim.core.builtins"
+  builtins.config { user_config_file = user_config_file }
 
-  local settings = require "config.settings"
+  local settings = require "lvim.config.settings"
   settings.load_options()
 
-  local lvim_lsp_config = require "lsp.config"
+  local lvim_lsp_config = require "lvim.lsp.config"
   lvim.lsp = vim.deepcopy(lvim_lsp_config)
 
   local supported_languages = {
@@ -121,7 +131,7 @@ function M:init(opts)
     "zig",
   }
 
-  require("lsp.manager").init_defaults(supported_languages)
+  require("lvim.lsp.manager").init_defaults(supported_languages)
 end
 
 local function deprecation_notice()
@@ -131,7 +141,7 @@ local function deprecation_notice()
   end
 
   for lang, entry in pairs(lvim.lang) do
-    local deprecated_config = entry["lsp"] or {}
+    local deprecated_config = entry["lvim.lsp"] or {}
     if not vim.tbl_isempty(deprecated_config) then
       local msg = string.format(
         "Deprecation notice: [lvim.lang.%s.lsp] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
@@ -147,24 +157,46 @@ end
 --- Override the configuration with a user provided one
 -- @param config_path The path to the configuration overrides
 function M:load(config_path)
-  local autocmds = require "core.autocmds"
-
-  config_path = config_path or self.path
-  local ok, err = pcall(vim.cmd, "luafile " .. config_path)
+  config_path = config_path or self.get_user_config_path()
+  local ok, _ = pcall(dofile, config_path)
   if not ok then
-    print("Invalid configuration", config_path)
-    print(err)
-    return
+    Log:warn("Invalid configuration: " .. config_path)
   end
 
   deprecation_notice()
 
-  self.path = config_path
-
+  local autocmds = require "lvim.core.autocmds"
   autocmds.define_augroups(lvim.autocommands)
 
-  local settings = require "config.settings"
+  local settings = require "lvim.config.settings"
   settings.load_commands()
 end
 
+--- Override the configuration with a user provided one
+-- @param config_path The path to the configuration overrides
+function M:reload()
+  local lvim_modules = {}
+  for module, _ in pairs(package.loaded) do
+    if module:match "lvim" then
+      package.loaded.module = nil
+      table.insert(lvim_modules, module)
+    end
+  end
+
+  M:init()
+  M:load()
+
+  require("lvim.keymappings").setup() -- this should be done before loading the plugins
+  local plugins = require "lvim.plugins"
+  utils.toggle_autoformat()
+  local plugin_loader = require "lvim.plugin-loader"
+  plugin_loader:cache_reset()
+  plugin_loader:load { plugins, lvim.plugins }
+  vim.cmd ":PackerInstall"
+  vim.cmd ":PackerCompile"
+  -- vim.cmd ":PackerClean"
+  require("lvim.lsp").setup()
+  Log:info "Reloaded configuration"
+end
+
 return M

+ 1 - 1
lua/config/settings.lua → lua/lvim/config/settings.lua

@@ -1,5 +1,5 @@
 local M = {}
-local utils = require "utils"
+local utils = require "lvim.utils"
 M.load_options = function()
   local default_options = {
     backup = false, -- creates a backup file

+ 3 - 3
lua/core/autocmds.lua → lua/lvim/core/autocmds.lua

@@ -1,12 +1,12 @@
 local autocommands = {}
-local config = require "config"
+local user_config_file = require("lvim.config"):get_user_config_path()
 
 lvim.autocommands = {
   _general_settings = {
     {
       "Filetype",
       "*",
-      "lua require('utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))",
+      "lua require('lvim.utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))",
     },
     {
       "FileType",
@@ -43,7 +43,7 @@ lvim.autocommands = {
       "*",
       "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
     },
-    { "BufWritePost", config.path, "lua require('utils').reload_lv_config()" },
+    { "BufWritePost", user_config_file, "lua require('lvim.config'):reload()" },
     {
       "FileType",
       "qf",

+ 0 - 0
lua/core/autopairs.lua → lua/lvim/core/autopairs.lua


+ 1 - 1
lua/core/bufferline.lua → lua/lvim/core/bufferline.lua

@@ -14,7 +14,7 @@ M.config = function()
 end
 
 M.setup = function()
-  local keymap = require "keymappings"
+  local keymap = require "lvim.keymappings"
   keymap.append_to_defaults(lvim.builtin.bufferline.keymap)
 
   if lvim.builtin.bufferline.on_config_done then

+ 28 - 0
lua/lvim/core/builtins/init.lua

@@ -0,0 +1,28 @@
+local M = {}
+
+local builtins = {
+  "lvim.keymappings",
+  "lvim.core.which-key",
+  "lvim.core.gitsigns",
+  "lvim.core.cmp",
+  "lvim.core.dashboard",
+  "lvim.core.dap",
+  "lvim.core.terminal",
+  "lvim.core.telescope",
+  "lvim.core.treesitter",
+  "lvim.core.nvimtree",
+  "lvim.core.project",
+  "lvim.core.bufferline",
+  "lvim.core.autopairs",
+  "lvim.core.comment",
+  "lvim.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

+ 0 - 0
lua/core/cmp.lua → lua/lvim/core/cmp.lua


+ 3 - 3
lua/core/commands.lua → lua/lvim/core/commands.lua

@@ -11,9 +11,9 @@ M.defaults = {
   endfunction
   ]],
   -- :LvimInfo
-  [[ command! LvimInfo lua require('core.info').toggle_popup(vim.bo.filetype) ]],
-  [[ command! LvimCacheReset lua require('utils.hooks').reset_cache() ]],
-  [[ command! LvimUpdate lua require('bootstrap').update() ]],
+  [[ command! LvimInfo lua require('lvim.core.info').toggle_popup(vim.bo.filetype) ]],
+  [[ command! LvimCacheReset lua require('lvim.utils.hooks').reset_cache() ]],
+  [[ command! LvimUpdate lua require('lvim.bootstrap').update() ]],
 }
 
 M.load = function(commands)

+ 0 - 0
lua/core/comment.lua → lua/lvim/core/comment.lua


+ 0 - 0
lua/core/dap.lua → lua/lvim/core/dap.lua


+ 4 - 4
lua/core/dashboard.lua → lua/lvim/core/dashboard.lua

@@ -1,5 +1,5 @@
 local M = {}
-local utils = require "utils"
+local utils = require "lvim.utils"
 
 M.config = function(config)
   lvim.builtin.dashboard = {
@@ -48,7 +48,7 @@ M.config = function(config)
       },
       e = {
         description = { "  Configuration      " },
-        command = ":e " .. config.path,
+        command = ":e " .. config.user_config_file,
       },
     },
 
@@ -84,10 +84,10 @@ M.setup = function()
     table.insert(footer, 3, "v" .. lvim_version)
   end
 
-  local text = require "interface.text"
+  local text = require "lvim.interface.text"
   vim.g.dashboard_custom_footer = text.align_center({ width = 0 }, footer, 0.49) -- Use 0.49 as  counts for 2 characters
 
-  require("core.autocmds").define_augroups {
+  require("lvim.core.autocmds").define_augroups {
     _dashboard = {
       -- seems to be nobuflisted that makes my stuff disappear will do more testing
       {

+ 0 - 0
lua/core/gitsigns.lua → lua/lvim/core/gitsigns.lua


+ 12 - 13
lua/core/info.lua → lua/lvim/core/info.lua

@@ -10,16 +10,16 @@ local M = {
 }
 
 local fmt = string.format
-local text = require "interface.text"
-local lsp_utils = require "lsp.utils"
+local text = require "lvim.interface.text"
+local lsp_utils = require "lvim.lsp.utils"
+local user_config_file = require("lvim.config"):get_user_config_path()
 
 local function str_list(list)
   return fmt("[ %s ]", table.concat(list, ", "))
 end
 
 local function get_formatter_suggestion_msg(ft)
-  local config = require "config"
-  local null_formatters = require "lsp.null-ls.formatters"
+  local null_formatters = require "lvim.lsp.null-ls.formatters"
   local supported_formatters = null_formatters.list_available(ft)
   local section = {
     " HINT ",
@@ -30,7 +30,7 @@ local function get_formatter_suggestion_msg(ft)
   if not vim.tbl_isempty(supported_formatters) then
     vim.list_extend(section, {
       "* Configured formatter needs to be installed and executable.",
-      fmt("* Enable installed formatter(s) with following config in %s", config.path),
+      fmt("* Enable installed formatter(s) with following config in %s", user_config_file),
       "",
       fmt("  lvim.lang.%s.formatters = { { exe = '%s' } }", ft, table.concat(supported_formatters, "│")),
     })
@@ -40,8 +40,7 @@ local function get_formatter_suggestion_msg(ft)
 end
 
 local function get_linter_suggestion_msg(ft)
-  local config = require "config"
-  local null_linters = require "lsp.null-ls.linters"
+  local null_linters = require "lvim.lsp.null-ls.linters"
   local supported_linters = null_linters.list_available(ft)
   local section = {
     " HINT ",
@@ -52,7 +51,7 @@ local function get_linter_suggestion_msg(ft)
   if not vim.tbl_isempty(supported_linters) then
     vim.list_extend(section, {
       "* Configured linter needs to be installed and executable.",
-      fmt("* Enable installed linter(s) with following config in %s", config.path),
+      fmt("* Enable installed linter(s) with following config in %s", user_config_file),
       "",
       fmt("  lvim.lang.%s.linters = { { exe = '%s' } }", ft, table.concat(supported_linters, "│")),
     })
@@ -108,8 +107,8 @@ function M.toggle_popup(ft)
     table.insert(client_names, client.name)
   end
 
-  local null_formatters = require "lsp.null-ls.formatters"
-  local null_linters = require "lsp.null-ls.linters"
+  local null_formatters = require "lvim.lsp.null-ls.formatters"
+  local null_linters = require "lvim.lsp.null-ls.linters"
   local registered_formatters = null_formatters.list_supported_names(ft)
   local registered_linters = null_linters.list_supported_names(ft)
   local registered_providers = {}
@@ -159,11 +158,11 @@ function M.toggle_popup(ft)
     vim.cmd 'let m=matchadd("string", "true")'
     vim.cmd 'let m=matchadd("error", "false")'
     tbl_set_highlight(registered_providers, "LvimInfoIdentifier")
-    -- tbl_set_highlight(require("lsp.null-ls.formatters").list_available(ft), "LvimInfoIdentifier")
-    -- tbl_set_highlight(require("lsp.null-ls.linters").list_available(ft), "LvimInfoIdentifier")
+    -- tbl_set_highlight(require("lvim.lsp.null-ls.formatters").list_available(ft), "LvimInfoIdentifier")
+    -- tbl_set_highlight(require("lvim.lsp.null-ls.linters").list_available(ft), "LvimInfoIdentifier")
   end
 
-  local Popup = require("interface.popup"):new {
+  local Popup = require("lvim.interface.popup"):new {
     win_opts = { number = false },
     buf_opts = { modifiable = false, filetype = "lspinfo" },
   }

+ 0 - 0
lua/core/log.lua → lua/lvim/core/log.lua


+ 0 - 0
lua/core/lualine/colors.lua → lua/lvim/core/lualine/colors.lua


+ 5 - 5
lua/core/lualine/components.lua → lua/lvim/core/lualine/components.lua

@@ -1,5 +1,5 @@
-local conditions = require "core.lualine.conditions"
-local colors = require "core.lualine.colors"
+local conditions = require "lvim.core.lualine.conditions"
+local colors = require "lvim.core.lualine.colors"
 
 local function diff_source()
   local gitsigns = vim.b.gitsigns_status_dict
@@ -46,7 +46,7 @@ return {
   },
   python_env = {
     function()
-      local utils = require "core.lualine.utils"
+      local utils = require "lvim.core.lualine.utils"
       if vim.bo.filetype == "python" then
         local venv = os.getenv "CONDA_DEFAULT_ENV"
         if venv then
@@ -103,12 +103,12 @@ return {
       end
 
       -- add formatter
-      local formatters = require "lsp.null-ls.formatters"
+      local formatters = require "lvim.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 linters = require "lvim.lsp.null-ls.linters"
       local supported_linters = linters.list_supported_names(buf_ft)
       vim.list_extend(buf_client_names, supported_linters)
 

+ 0 - 0
lua/core/lualine/conditions.lua → lua/lvim/core/lualine/conditions.lua


+ 2 - 2
lua/core/lualine/init.lua → lua/lvim/core/lualine/init.lua

@@ -33,8 +33,8 @@ M.config = function()
 end
 
 M.setup = function()
-  require("core.lualine.styles").update()
-  require("core.lualine.utils").validate_theme()
+  require("lvim.core.lualine.styles").update()
+  require("lvim.core.lualine.utils").validate_theme()
 
   local lualine = require "lualine"
   lualine.setup(lvim.builtin.lualine)

+ 2 - 2
lua/core/lualine/styles.lua → lua/lvim/core/lualine/styles.lua

@@ -1,5 +1,5 @@
 local M = {}
-local components = require "core.lualine.components"
+local components = require "lvim.core.lualine.components"
 
 local styles = {
   lvim = nil,
@@ -111,7 +111,7 @@ styles.lvim = {
 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 Log = require "lvim.core.log"
     Log:error(
       "Invalid lualine style",
       string.format('"%s"', style),

+ 0 - 0
lua/core/lualine/utils.lua → lua/lvim/core/lualine/utils.lua


+ 2 - 2
lua/core/nvimtree.lua → lua/lvim/core/nvimtree.lua

@@ -1,5 +1,5 @@
 local M = {}
-local Log = require "core.log"
+local Log = require "lvim.core.log"
 
 function M.config()
   lvim.builtin.nvimtree = {
@@ -109,7 +109,7 @@ function M.setup()
     open()
   end
 
-  vim.cmd "au WinClosed * lua require('core.nvimtree').on_close()"
+  vim.cmd "au WinClosed * lua require('lvim.core.nvimtree').on_close()"
 
   if lvim.builtin.nvimtree.on_config_done then
     lvim.builtin.nvimtree.on_config_done(nvim_tree_config)

+ 0 - 0
lua/core/project.lua → lua/lvim/core/project.lua


+ 4 - 5
lua/core/telescope.lua → lua/lvim/core/telescope.lua

@@ -1,7 +1,5 @@
 local M = {}
 
-local utils = require "utils"
-
 function M.config()
   -- Define this minimal config so that it's available if telescope is not yet available.
   lvim.builtin.telescope = {
@@ -92,8 +90,8 @@ function M.find_lunarvim_files(opts)
     layout_strategy = "bottom_pane",
     prompt_prefix = ">> ",
     prompt_title = "~ LunarVim files ~",
-    cwd = utils.join_paths(get_runtime_dir(), "lvim"),
-    find_command = { "git", "ls-files" },
+    cwd = get_runtime_dir(),
+    search_dirs = { get_runtime_dir() .. "/lvim", lvim.lsp.templates_dir },
   }
   opts = vim.tbl_deep_extend("force", theme_opts, opts)
   require("telescope.builtin").find_files(opts)
@@ -107,7 +105,8 @@ function M.grep_lunarvim_files(opts)
     layout_strategy = "bottom_pane",
     prompt_prefix = ">> ",
     prompt_title = "~ search LunarVim ~",
-    cwd = utils.join_paths(get_runtime_dir(), "lvim"),
+    cwd = get_runtime_dir(),
+    search_dirs = { get_runtime_dir() .. "/lvim", lvim.lsp.templates_dir },
   }
   opts = vim.tbl_deep_extend("force", theme_opts, opts)
   require("telescope.builtin").live_grep(opts)

+ 3 - 3
lua/core/terminal.lua → lua/lvim/core/terminal.lua

@@ -1,5 +1,5 @@
 local M = {}
-local Log = require "core.log"
+local Log = require "lvim.core.log"
 
 M.config = function()
   lvim.builtin["terminal"] = {
@@ -48,7 +48,7 @@ end
 M.setup = function()
   local terminal = require "toggleterm"
   for _, exec in pairs(lvim.builtin.terminal.execs) do
-    require("core.terminal").add_exec(exec[1], exec[2], exec[3])
+    require("lvim.core.terminal").add_exec(exec[1], exec[2], exec[3])
   end
   terminal.setup(lvim.builtin.terminal)
 
@@ -61,7 +61,7 @@ M.add_exec = function(exec, keymap, name)
   vim.api.nvim_set_keymap(
     "n",
     "<leader>" .. keymap,
-    "<cmd>lua require('core.terminal')._exec_toggle('" .. exec .. "')<CR>",
+    "<cmd>lua require('lvim.core.terminal')._exec_toggle('" .. exec .. "')<CR>",
     { noremap = true, silent = true }
   )
   lvim.builtin.which_key.mappings[keymap] = name

+ 1 - 1
lua/core/treesitter.lua → lua/lvim/core/treesitter.lua

@@ -1,5 +1,5 @@
 local M = {}
-local Log = require "core.log"
+local Log = require "lvim.core.log"
 
 M.config = function()
   lvim.builtin.treesitter = {

+ 18 - 15
lua/core/which-key.lua → lua/lvim/core/which-key.lua

@@ -98,7 +98,7 @@ M.config = function()
         name = "Packer",
         c = { "<cmd>PackerCompile<cr>", "Compile" },
         i = { "<cmd>PackerInstall<cr>", "Install" },
-        r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload" },
+        r = { "<cmd>lua require('lvim.utils').reload_lv_config()<cr>", "Reload" },
         s = { "<cmd>PackerSync<cr>", "Sync" },
         S = { "<cmd>PackerStatus<cr>", "Status" },
         u = { "<cmd>PackerUpdate<cr>", "Update" },
@@ -162,9 +162,9 @@ M.config = function()
         l = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" },
         p = {
           name = "Peek",
-          d = { "<cmd>lua require('lsp.peek').Peek('definition')<cr>", "Definition" },
-          t = { "<cmd>lua require('lsp.peek').Peek('typeDefinition')<cr>", "Type Definition" },
-          i = { "<cmd>lua require('lsp.peek').Peek('implementation')<cr>", "Implementation" },
+          d = { "<cmd>lua require('lvim.lsp.peek').Peek('definition')<cr>", "Definition" },
+          t = { "<cmd>lua require('lvim.lsp.peek').Peek('typeDefinition')<cr>", "Type Definition" },
+          i = { "<cmd>lua require('lvim.lsp.peek').Peek('implementation')<cr>", "Implementation" },
         },
         q = { "<cmd>lua vim.lsp.diagnostic.set_loclist()<cr>", "Quickfix" },
         r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
@@ -181,43 +181,46 @@ M.config = function()
           "Edit config.lua",
         },
         f = {
-          "<cmd>lua require('core.telescope').find_lunarvim_files()<cr>",
+          "<cmd>lua require('lvim.core.telescope').find_lunarvim_files()<cr>",
           "Find LunarVim files",
         },
         g = {
-          "<cmd>lua require('core.telescope').grep_lunarvim_files()<cr>",
+          "<cmd>lua require('lvim.core.telescope').grep_lunarvim_files()<cr>",
           "Grep LunarVim files",
         },
-        k = { "<cmd>lua require('keymappings').print()<cr>", "View LunarVim's default keymappings" },
+        k = { "<cmd>lua require('lvim.keymappings').print()<cr>", "View LunarVim's default keymappings" },
         i = {
-          "<cmd>lua require('core.info').toggle_popup(vim.bo.filetype)<cr>",
+          "<cmd>lua require('lvim.core.info').toggle_popup(vim.bo.filetype)<cr>",
           "Toggle LunarVim Info",
         },
         I = {
-          "<cmd>lua require('core.telescope').view_lunarvim_changelog()<cr>",
+          "<cmd>lua require('lvim.core.telescope').view_lunarvim_changelog()<cr>",
           "View LunarVim's changelog",
         },
         l = {
           name = "+logs",
           d = {
-            "<cmd>lua require('core.terminal').toggle_log_view(require('core.log').get_path())<cr>",
+            "<cmd>lua require('lvim.core.terminal').toggle_log_view(require('lvim.core.log').get_path())<cr>",
             "view default log",
           },
-          D = { "<cmd>lua vim.fn.execute('edit ' .. require('core.log').get_path())<cr>", "Open the default logfile" },
-          l = { "<cmd>lua require('core.terminal').toggle_log_view(vim.lsp.get_log_path())<cr>", "view lsp log" },
+          D = {
+            "<cmd>lua vim.fn.execute('edit ' .. require('lvim.core.log').get_path())<cr>",
+            "Open the default logfile",
+          },
+          l = { "<cmd>lua require('lvim.core.terminal').toggle_log_view(vim.lsp.get_log_path())<cr>", "view lsp log" },
           L = { "<cmd>lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())<cr>", "Open the LSP logfile" },
           n = {
-            "<cmd>lua require('core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))<cr>",
+            "<cmd>lua require('lvim.core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))<cr>",
             "view neovim log",
           },
           N = { "<cmd>edit $NVIM_LOG_FILE<cr>", "Open the Neovim logfile" },
           p = {
-            "<cmd>lua require('core.terminal').toggle_log_view('packer.nvim')<cr>",
+            "<cmd>lua require('lvim.core.terminal').toggle_log_view('packer.nvim')<cr>",
             "view packer log",
           },
           P = { "<cmd>exe 'edit '.stdpath('cache').'/packer.nvim.log'<cr>", "Open the Packer logfile" },
         },
-        r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload configurations" },
+        r = { "<cmd>lua require('lvim.utils').reload_lv_config()<cr>", "Reload configurations" },
         u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" },
       },
       s = {

+ 2 - 2
lua/impatient.lua → lua/lvim/impatient.lua

@@ -121,12 +121,12 @@ end
 function M.enable_profile()
   M.profile = {}
   M.print_profile = function()
-    M.profile["impatient"] = {
+    M.profile["lvim.impatient"] = {
       resolve = 0,
       load = impatient_dur,
       loader = "standard",
     }
-    require("impatient.profile").print_profile(M.profile)
+    require("lvim.impatient.profile").print_profile(M.profile)
   end
   vim.cmd [[command! LuaCacheProfile lua _G.__luacache.print_profile()]]
 end

+ 0 - 0
lua/impatient/profile.lua → lua/lvim/impatient/profile.lua


+ 0 - 0
lua/interface/popup.lua → lua/lvim/interface/popup.lua


+ 0 - 0
lua/interface/text.lua → lua/lvim/interface/text.lua


+ 1 - 1
lua/keymappings.lua → lua/lvim/keymappings.lua

@@ -1,5 +1,5 @@
 local M = {}
-local Log = require "core.log"
+local Log = require "lvim.core.log"
 
 local generic_opts_any = { noremap = true, silent = true }
 

+ 2 - 2
lua/lsp/config.lua → lua/lvim/lsp/config.lua

@@ -30,9 +30,9 @@ return {
       ["gr"] = { "<cmd>lua vim.lsp.buf.references()<CR>", "Goto references" },
       ["gI"] = { "<cmd>lua vim.lsp.buf.implementation()<CR>", "Goto Implementation" },
       ["gs"] = { "<cmd>lua vim.lsp.buf.signature_help()<CR>", "show signature help" },
-      ["gp"] = { "<cmd>lua require'lsp.peek'.Peek('definition')<CR>", "Peek definition" },
+      ["gp"] = { "<cmd>lua require'lvim.lsp.peek'.Peek('definition')<CR>", "Peek definition" },
       ["gl"] = {
-        "<cmd>lua require'lsp.handlers'.show_line_diagnostics()<CR>",
+        "<cmd>lua require'lvim.lsp.handlers'.show_line_diagnostics()<CR>",
         "Show line diagnostics",
       },
     },

+ 0 - 0
lua/lsp/handlers.lua → lua/lvim/lsp/handlers.lua


+ 6 - 6
lua/lsp/init.lua → lua/lvim/lsp/init.lua

@@ -1,6 +1,6 @@
 local M = {}
-local Log = require "core.log"
-local utils = require "utils"
+local Log = require "lvim.core.log"
+local utils = require "lvim.utils"
 
 local function lsp_highlight_document(client)
   if lvim.lsp.document_highlight == false then
@@ -149,17 +149,17 @@ function M.setup()
     vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name })
   end
 
-  require("lsp.handlers").setup()
+  require("lvim.lsp.handlers").setup()
 
   if not utils.is_directory(lvim.lsp.templates_dir) then
-    require("lsp.templates").generate_templates()
+    require("lvim.lsp.templates").generate_templates()
   end
 
   bootstrap_nlsp { config_home = utils.join_paths(get_config_dir(), "lsp-settings") }
 
-  require("lsp.null-ls").setup()
+  require("lvim.lsp.null-ls").setup()
 
-  require("utils").toggle_autoformat()
+  require("lvim.utils").toggle_autoformat()
 end
 
 return M

+ 6 - 6
lua/lsp/manager.lua → lua/lvim/lsp/manager.lua

@@ -1,7 +1,7 @@
 local M = {}
 
-local Log = require "core.log"
-local lsp_utils = require "lsp.utils"
+local Log = require "lvim.core.log"
+local lsp_utils = require "lvim.lsp.utils"
 
 function M.init_defaults(languages)
   for _, entry in ipairs(languages) do
@@ -30,12 +30,12 @@ end
 ---@return table
 local function resolve_config(name, user_config)
   local config = {
-    on_attach = require("lsp").common_on_attach,
-    on_init = require("lsp").common_on_init,
-    capabilities = require("lsp").common_capabilities(),
+    on_attach = require("lvim.lsp").common_on_attach,
+    on_init = require("lvim.lsp").common_on_init,
+    capabilities = require("lvim.lsp").common_capabilities(),
   }
 
-  local status_ok, custom_config = pcall(require, "lsp/providers/" .. name)
+  local status_ok, custom_config = pcall(require, "lvim.lsp/providers/" .. name)
   if status_ok then
     Log:debug("Using custom configuration for requested server: " .. name)
     config = vim.tbl_deep_extend("force", config, custom_config)

+ 3 - 3
lua/lsp/null-ls/formatters.lua → lua/lvim/lsp/null-ls/formatters.lua

@@ -1,8 +1,8 @@
 local M = {}
 
 local null_ls = require "null-ls"
-local services = require "lsp.null-ls.services"
-local Log = require "core.log"
+local services = require "lvim.lsp.null-ls.services"
+local Log = require "lvim.core.log"
 
 function M.list_supported_names(filetype)
   local null_ls_methods = require "null-ls.methods"
@@ -13,7 +13,7 @@ end
 
 function M.list_available(filetype)
   local formatters = {}
-  local tbl = require "utils.table"
+  local tbl = require "lvim.utils.table"
   for _, provider in pairs(null_ls.builtins.formatting) do
     if tbl.contains(provider.filetypes or {}, function(ft)
       return ft == "*" or ft == filetype

+ 3 - 3
lua/lsp/null-ls/init.lua → lua/lvim/lsp/null-ls/init.lua

@@ -1,8 +1,8 @@
 local M = {}
 
-local Log = require "core.log"
-local formatters = require "lsp.null-ls.formatters"
-local linters = require "lsp.null-ls.linters"
+local Log = require "lvim.core.log"
+local formatters = require "lvim.lsp.null-ls.formatters"
+local linters = require "lvim.lsp.null-ls.linters"
 
 function M:setup()
   local status_ok, null_ls = pcall(require, "null-ls")

+ 3 - 3
lua/lsp/null-ls/linters.lua → lua/lvim/lsp/null-ls/linters.lua

@@ -1,8 +1,8 @@
 local M = {}
 
 local null_ls = require "null-ls"
-local services = require "lsp.null-ls.services"
-local Log = require "core.log"
+local services = require "lvim.lsp.null-ls.services"
+local Log = require "lvim.core.log"
 
 function M.list_supported_names(filetype)
   local null_ls_methods = require "null-ls.methods"
@@ -13,7 +13,7 @@ end
 
 function M.list_available(filetype)
   local linters = {}
-  local tbl = require "utils.table"
+  local tbl = require "lvim.utils.table"
   for _, provider in pairs(null_ls.builtins.diagnostics) do
     if tbl.contains(provider.filetypes or {}, function(ft)
       return ft == "*" or ft == filetype

+ 1 - 1
lua/lsp/null-ls/services.lua → lua/lvim/lsp/null-ls/services.lua

@@ -2,7 +2,7 @@ local M = {}
 
 local function find_root_dir()
   local util = require "lspconfig/util"
-  local lsp_utils = require "lsp.utils"
+  local lsp_utils = require "lvim.lsp.utils"
 
   local ts_client = lsp_utils.is_client_active "typescript"
   if ts_client then

+ 1 - 1
lua/lsp/peek.lua → lua/lvim/lsp/peek.lua

@@ -130,7 +130,7 @@ function M.Peek(what)
       M.floating_buf,
       "n",
       "<CR>",
-      ":lua require('lsp.peek').open_file()<CR>",
+      ":lua require('lvim.lsp.peek').open_file()<CR>",
       { noremap = true, silent = true }
     )
   else

+ 0 - 0
lua/lsp/providers/jsonls.lua → lua/lvim/lsp/providers/jsonls.lua


+ 1 - 1
lua/lsp/providers/sumneko_lua.lua → lua/lvim/lsp/providers/sumneko_lua.lua

@@ -6,7 +6,7 @@ local opts = {
       },
       workspace = {
         library = {
-          [require("utils").join_paths(get_runtime_dir(), "lvim", "lua")] = true,
+          [require("lvim.utils").join_paths(get_runtime_dir(), "lvim", "lua")] = true,
           [vim.fn.expand "$VIMRUNTIME/lua"] = true,
           [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
         },

+ 1 - 1
lua/lsp/providers/vuels.lua → lua/lvim/lsp/providers/vuels.lua

@@ -1,7 +1,7 @@
 local opts = {
   setup = {
     root_dir = function(fname)
-      local util = require "lspconfig/util"
+      local util = require "lvim.lspconfig/util"
       return util.root_pattern "package.json"(fname) or util.root_pattern "vue.config.js"(fname) or vim.fn.getcwd()
     end,
     init_options = {

+ 0 - 0
lua/lsp/providers/yamlls.lua → lua/lvim/lsp/providers/yamlls.lua


+ 4 - 4
lua/lsp/templates.lua → lua/lvim/lsp/templates.lua

@@ -1,8 +1,8 @@
 local M = {}
 
-local Log = require "core.log"
-local utils = require "utils"
-local get_supported_filetypes = require("lsp.utils").get_supported_filetypes
+local Log = require "lvim.core.log"
+local utils = require "lvim.utils"
+local get_supported_filetypes = require("lvim.lsp.utils").get_supported_filetypes
 
 local ftplugin_dir = lvim.lsp.templates_dir
 
@@ -59,7 +59,7 @@ function M.generate_ftplugin(server_name, dir)
 
   for _, filetype in ipairs(filetypes) do
     local filename = join_paths(dir, filetype .. ".lua")
-    local setup_cmd = string.format([[require("lsp.manager").setup(%q)]], server_name)
+    local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name)
     -- print("using setup_cmd: " .. setup_cmd)
     -- overwrite the file completely
     utils.write_file(filename, setup_cmd .. "\n", "a")

+ 1 - 1
lua/lsp/utils.lua → lua/lvim/lsp/utils.lua

@@ -1,6 +1,6 @@
 local M = {}
 
-local tbl = require "utils.table"
+local tbl = require "lvim.utils.table"
 
 function M.is_client_active(name)
   local clients = vim.lsp.get_active_clients()

+ 0 - 0
lua/lualine/themes/onedarker.lua → lua/lvim/lualine/themes/onedarker.lua


+ 2 - 2
lua/plugin-loader.lua → lua/lvim/plugin-loader.lua

@@ -1,7 +1,7 @@
 local plugin_loader = {}
 
-local utils = require "utils"
-local Log = require "core.log"
+local utils = require "lvim.utils"
+local Log = require "lvim.core.log"
 -- we need to reuse this outside of init()
 local compile_path = get_config_dir() .. "/plugin/packer_compiled.lua"
 

+ 15 - 15
lua/plugins.lua → lua/lvim/plugins.lua

@@ -15,7 +15,7 @@ return {
   {
     "nvim-telescope/telescope.nvim",
     config = function()
-      require("core.telescope").setup()
+      require("lvim.core.telescope").setup()
     end,
     disable = not lvim.builtin.telescope.active,
   },
@@ -23,7 +23,7 @@ return {
   {
     "hrsh7th/nvim-cmp",
     config = function()
-      require("core.cmp").setup()
+      require("lvim.core.cmp").setup()
     end,
     requires = {
       "L3MON4D3/LuaSnip",
@@ -36,7 +36,7 @@ return {
     run = function()
       -- cmp's config requires cmp to be installed to run the first time
       if not lvim.builtin.cmp then
-        require("core.cmp").config()
+        require("lvim.core.cmp").config()
       end
     end,
   },
@@ -51,7 +51,7 @@ return {
     "windwp/nvim-autopairs",
     -- event = "InsertEnter",
     config = function()
-      require("core.autopairs").setup()
+      require("lvim.core.autopairs").setup()
     end,
     disable = not lvim.builtin.autopairs.active,
   },
@@ -62,7 +62,7 @@ return {
     branch = "0.5-compat",
     -- run = ":TSUpdate",
     config = function()
-      require("core.treesitter").setup()
+      require("lvim.core.treesitter").setup()
     end,
   },
 
@@ -73,7 +73,7 @@ return {
     -- cmd = "NvimTreeToggle",
     -- commit = "fd7f60e242205ea9efc9649101c81a07d5f458bb",
     config = function()
-      require("core.nvimtree").setup()
+      require("lvim.core.nvimtree").setup()
     end,
     disable = not lvim.builtin.nvimtree.active,
   },
@@ -82,7 +82,7 @@ return {
     "lewis6991/gitsigns.nvim",
 
     config = function()
-      require("core.gitsigns").setup()
+      require("lvim.core.gitsigns").setup()
     end,
     event = "BufRead",
     disable = not lvim.builtin.gitsigns.active,
@@ -92,7 +92,7 @@ return {
   {
     "folke/which-key.nvim",
     config = function()
-      require("core.which-key").setup()
+      require("lvim.core.which-key").setup()
     end,
     event = "BufWinEnter",
     disable = not lvim.builtin.which_key.active,
@@ -103,7 +103,7 @@ return {
     "terrortylor/nvim-comment",
     event = "BufRead",
     config = function()
-      require("core.comment").setup()
+      require("lvim.core.comment").setup()
     end,
     disable = not lvim.builtin.comment.active,
   },
@@ -112,7 +112,7 @@ return {
   {
     "ahmedkhalf/project.nvim",
     config = function()
-      require("core.project").setup()
+      require("lvim.core.project").setup()
     end,
     disable = not lvim.builtin.project.active,
   },
@@ -126,7 +126,7 @@ return {
     "shadmansaleh/lualine.nvim",
     -- "Lunarvim/lualine.nvim",
     config = function()
-      require("core.lualine").setup()
+      require("lvim.core.lualine").setup()
     end,
     disable = not lvim.builtin.lualine.active,
   },
@@ -134,7 +134,7 @@ return {
   {
     "romgrk/barbar.nvim",
     config = function()
-      require("core.bufferline").setup()
+      require("lvim.core.bufferline").setup()
     end,
     event = "BufWinEnter",
     disable = not lvim.builtin.bufferline.active,
@@ -145,7 +145,7 @@ return {
     "mfussenegger/nvim-dap",
     -- event = "BufWinEnter",
     config = function()
-      require("core.dap").setup()
+      require("lvim.core.dap").setup()
     end,
     disable = not lvim.builtin.dap.active,
   },
@@ -163,7 +163,7 @@ return {
     "ChristianChiarulli/dashboard-nvim",
     event = "BufWinEnter",
     config = function()
-      require("core.dashboard").setup()
+      require("lvim.core.dashboard").setup()
     end,
     disable = not lvim.builtin.dashboard.active,
   },
@@ -173,7 +173,7 @@ return {
     "akinsho/toggleterm.nvim",
     event = "BufWinEnter",
     config = function()
-      require("core.terminal").setup()
+      require("lvim.core.terminal").setup()
     end,
     disable = not lvim.builtin.terminal.active,
   },

+ 0 - 0
lua/utils/ft.lua → lua/lvim/utils/ft.lua


+ 7 - 5
lua/utils/hooks.lua → lua/lvim/utils/hooks.lua

@@ -1,24 +1,26 @@
 local M = {}
 
-local Log = require "core.log"
+local Log = require "lvim.core.log"
 local in_headless = #vim.api.nvim_list_uis() == 0
 
 function M.run_pre_update()
   Log:debug "Starting pre-update hook"
+  _G.__luacache.clear_cache()
 end
 
 ---Reset any startup cache files used by Packer and Impatient
+---It also forces regenerating any template ftplugin files
 ---Tip: Useful for clearing any outdated settings
 function M.reset_cache()
   _G.__luacache.clear_cache()
-  require("plugin-loader"):cache_reset()
+  require("lvim.plugin-loader"):cache_reset()
+  package.loaded["lvim.lsp.templates"] = nil
+  require("lvim.lsp.templates").generate_templates()
 end
 
 function M.run_post_update()
-  M.reset_cache()
   Log:debug "Starting post-update hook"
-  package.loaded["lsp.templates"] = nil
-  require("lsp.templates").generate_templates()
+  M.reset_cache()
 
   if not in_headless then
     vim.schedule(function()

+ 3 - 35
lua/utils/init.lua → lua/lvim/utils/init.lua

@@ -1,5 +1,5 @@
 local utils = {}
-local Log = require "core.log"
+local Log = require "lvim.core.log"
 local uv = vim.loop
 
 -- recursive Print (structure, limit, separator)
@@ -61,7 +61,7 @@ end
 -- autoformat
 function utils.toggle_autoformat()
   if lvim.format_on_save then
-    require("core.autocmds").define_augroups {
+    require("lvim.core.autocmds").define_augroups {
       autoformat = {
         {
           "BufWritePre",
@@ -83,26 +83,6 @@ function utils.toggle_autoformat()
   end
 end
 
-function utils.reload_lv_config()
-  require("core.lualine").config()
-
-  local config = require "config"
-  config:load()
-
-  require("keymappings").setup() -- this should be done before loading the plugins
-  vim.cmd("source " .. utils.join_paths(get_runtime_dir(), "lvim", "lua", "plugins.lua"))
-  local plugins = require "plugins"
-  utils.toggle_autoformat()
-  local plugin_loader = require "plugin-loader"
-  plugin_loader:cache_reset()
-  plugin_loader:load { plugins, lvim.plugins }
-  vim.cmd ":PackerInstall"
-  vim.cmd ":PackerCompile"
-  -- vim.cmd ":PackerClean"
-  require("lsp").setup()
-  Log:info "Reloaded configuration"
-end
-
 function utils.unrequire(m)
   package.loaded[m] = nil
   _G[m] = nil
@@ -147,18 +127,6 @@ function utils.is_directory(path)
   return stat and stat.type == "directory" or false
 end
 
-function utils.write_file(path, txt, flag)
-  uv.fs_open(path, flag, 438, function(open_err, fd)
-    assert(not open_err, open_err)
-    uv.fs_write(fd, txt, -1, function(write_err)
-      assert(not write_err, write_err)
-      uv.fs_close(fd, function(close_err)
-        assert(not close_err, close_err)
-      end)
-    end)
-  end)
-end
-
 utils.join_paths = _G.join_paths
 
 function utils.write_file(path, txt, flag)
@@ -215,7 +183,7 @@ function utils.file_contains(file, query)
 end
 
 function utils.log_contains(query)
-  local logfile = require("core.log"):get_path()
+  local logfile = require("lvim.core.log"):get_path()
   local stdout, ret, stderr = utils.search_file(logfile, query)
   if ret == 0 then
     return true

+ 0 - 0
lua/utils/table.lua → lua/lvim/utils/table.lua


+ 1 - 1
tests/bootstrap_spec.lua

@@ -8,7 +8,7 @@ a.describe("initial start", function()
 
   a.it("shoud be able to detect test environment", function()
     assert.truthy(os.getenv "LVIM_TEST_ENV")
-    assert.falsy(package.loaded["impatient"])
+    assert.falsy(package.loaded["lvim.impatient"])
   end)
 
   a.it("should not be reading default neovim directories in the home directoies", function()

+ 37 - 0
tests/config_loader_spec.lua

@@ -0,0 +1,37 @@
+local a = require "plenary.async_lib.tests"
+local config = require "lvim.config"
+
+a.describe("config-loader", function()
+  local user_config_path = config:get_user_config_path()
+
+  a.it("should be able to find user-config", function()
+    assert.equal(user_config_path, get_config_dir() .. "/config.lua")
+  end)
+
+  a.it("should be able to load user-config without errors", function()
+    config:load(user_config_path)
+    local errmsg = vim.fn.eval "v:errmsg"
+    local exception = vim.fn.eval "v:exception"
+    assert.equal("", errmsg) -- v:errmsg was not updated.
+    assert.equal("", exception)
+  end)
+
+  a.it("should be able to reload user-config without errors", function()
+    vim.opt.undodir = "/tmp"
+    assert.equal(vim.opt.undodir:get()[1], "/tmp")
+    config:reload()
+    assert.equal(vim.opt.undodir:get()[1], get_cache_dir() .. "/undo")
+  end)
+
+  a.it("should not get interrupted by errors in user-config", function()
+    vim.opt.undodir = "/tmp"
+    assert.equal(vim.opt.undodir:get()[1], "/tmp")
+    os.execute("echo bad_string_test >> " .. user_config_path)
+    local error_handler = function(msg)
+      return msg
+    end
+    local err = xpcall(config:reload(), error_handler)
+    assert.falsy(err)
+    assert.equal(vim.opt.undodir:get()[1], get_cache_dir() .. "/undo")
+  end)
+end)

+ 11 - 11
tests/lsp_spec.lua

@@ -1,9 +1,9 @@
 local a = require "plenary.async_lib.tests"
-local utils = require "utils"
+local utils = require "lvim.utils"
 lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "lvim", "tests", "artifacts")
 
 a.describe("lsp workflow", function()
-  local Log = require "core.log"
+  local Log = require "lvim.core.log"
   local logfile = Log:get_path()
 
   a.it("shoud be able to delete ftplugin templates", function()
@@ -17,7 +17,7 @@ a.describe("lsp workflow", function()
     if utils.is_directory(lvim.lsp.templates_dir) then
       assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
     end
-    require("lsp").setup()
+    require("lvim.lsp").setup()
 
     -- we need to delay this check until the generation is completed
     vim.schedule(function()
@@ -28,15 +28,15 @@ a.describe("lsp workflow", function()
   a.it("shoud not attempt to re-generate ftplugin templates", function()
     lvim.log.level = "debug"
 
-    local plugins = require "plugins"
-    require("plugin-loader"):load { plugins, lvim.plugins }
+    local plugins = require "lvim.plugins"
+    require("lvim.plugin-loader"):load { plugins, lvim.plugins }
 
     if utils.is_file(logfile) then
       assert.equal(vim.fn.delete(logfile), 0)
     end
 
     assert.True(utils.is_directory(lvim.lsp.templates_dir))
-    require("lsp").setup()
+    require("lvim.lsp").setup()
 
     -- we need to delay this check until the log gets populated
     vim.schedule(function()
@@ -49,7 +49,7 @@ a.describe("lsp workflow", function()
       name = "ocamlls",
       filetypes = { "ocaml", "reason" },
     }
-    local ocaml_fts = require("lsp.utils").get_supported_filetypes(ocaml.name)
+    local ocaml_fts = require("lvim.lsp.utils").get_supported_filetypes(ocaml.name)
     assert.True(vim.deep_equal(ocaml.filetypes, ocaml_fts))
 
     local tsserver = {
@@ -63,17 +63,17 @@ a.describe("lsp workflow", function()
         "typescript.tsx",
       },
     }
-    local tsserver_fts = require("lsp.utils").get_supported_filetypes(tsserver.name)
+    local tsserver_fts = require("lvim.lsp.utils").get_supported_filetypes(tsserver.name)
     assert.True(vim.deep_equal(tsserver.filetypes, tsserver_fts))
   end)
 
   a.it("shoud ignore all javascript servers except tsserver and tailwindcss when generating templates", function()
     local test_server = { name = "denols", filetypes = {} }
-    test_server.filetypes = require("lsp.utils").get_supported_filetypes(test_server.name)
+    test_server.filetypes = require("lvim.lsp.utils").get_supported_filetypes(test_server.name)
 
     assert.True(vim.tbl_contains(test_server.filetypes, "javascript"))
 
-    local is_ignored = require("lsp.templates").is_ignored(test_server.name)
+    local is_ignored = require("lvim.lsp.templates").is_ignored(test_server.name)
     assert.True(is_ignored)
 
     local ts_template = utils.join_paths(lvim.lsp.templates_dir, "typescript.lua")
@@ -84,7 +84,7 @@ a.describe("lsp workflow", function()
 
   a.it("shoud not include blacklisted servers in the generated templates", function()
     assert.True(utils.is_directory(lvim.lsp.templates_dir))
-    require("lsp").setup()
+    require("lvim.lsp").setup()
 
     local blacklisted = { "jedi_language_server", "pylsp", "sqlls", "sqls", "angularls", "ansiblels" }
 

+ 1 - 5
tests/minimal_init.lua

@@ -2,8 +2,4 @@ local path_sep = vim.loop.os_uname().version:match "Windows" and "\\" or "/"
 
 vim.opt.rtp:append(os.getenv "LUNARVIM_RUNTIME_DIR" .. path_sep .. "lvim")
 
-require("bootstrap"):init()
-
-local config = require "config"
--- config:init()
-config:load()
+require("lvim.bootstrap"):init()

+ 103 - 0
tests/minimal_rtp.lua

@@ -0,0 +1,103 @@
+vim.cmd [[set runtimepath=$VIMRUNTIME]]
+vim.cmd [[set packpath=/tmp/nvim/site]]
+
+local package_root = "/tmp/nvim/site/pack"
+local install_path = package_root .. "/packer/start/packer.nvim"
+
+local function load_plugins()
+  require("packer").startup {
+    {
+      "wbthomason/packer.nvim",
+      "neovim/nvim-lspconfig",
+      {
+        "aserowy/tmux.nvim",
+        config = function()
+          require("tmux").setup {
+            navigation = {
+              -- cycles to opposite pane while navigating into the border
+              cycle_navigation = true,
+
+              -- enables default keybindings (C-hjkl) for normal mode
+              enable_default_keybindings = true,
+
+              -- prevents unzoom tmux when navigating beyond vim border
+              persist_zoom = true,
+            },
+            resize = {
+              -- enables default keybindings (A-hjkl) for normal mode
+              enable_default_keybindings = true,
+            },
+          }
+        end,
+      },
+    },
+    config = {
+      package_root = package_root,
+      compile_path = install_path .. "/plugin/packer_compiled.lua",
+    },
+  }
+end
+
+_G.load_config = function()
+  vim.lsp.set_log_level "trace"
+  local nvim_lsp = require "lspconfig"
+  local on_attach = function(_, bufnr)
+    local function buf_set_keymap(...)
+      vim.api.nvim_buf_set_keymap(bufnr, ...)
+    end
+    local function buf_set_option(...)
+      vim.api.nvim_buf_set_option(bufnr, ...)
+    end
+
+    buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
+
+    -- Mappings.
+    local opts = { noremap = true, silent = true }
+    buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
+    buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
+    buf_set_keymap("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
+    buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
+    buf_set_keymap("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
+    buf_set_keymap("n", "<space>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
+    buf_set_keymap("n", "<space>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
+    buf_set_keymap("n", "<space>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
+    buf_set_keymap("n", "<space>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
+    buf_set_keymap("n", "<space>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
+    buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
+    buf_set_keymap("n", "<space>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
+    buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
+    buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
+    buf_set_keymap("n", "<space>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
+    buf_set_keymap("n", "<space>li", "<cmd>LspInfo<CR>", opts)
+  end
+
+  -- Add the server that troubles you here
+  local name = "sumneko_lua"
+  local sumneko_root_dir = vim.fn.stdpath "data" .. "/lsp_servers/sumneko_lua/extension/server"
+  local cmd = { sumneko_root_dir .. "/bin/Linux/lua-language-server", "-E", sumneko_root_dir .. "/main.lua" }
+  if not name then
+    print "You have not defined a server name, please edit minimal_init.lua"
+  end
+  if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
+    print [[You have not defined a server default cmd for a server
+      that requires it please edit minimal_init.lua]]
+  end
+
+  nvim_lsp[name].setup {
+    cmd = cmd,
+    on_attach = on_attach,
+  }
+
+  print [[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]]
+end
+
+if vim.fn.isdirectory(install_path) == 0 then
+  vim.fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path }
+  load_plugins()
+  require("packer").sync()
+  vim.cmd [[autocmd User PackerComplete ++once lua load_config()]]
+else
+  load_plugins()
+  require("packer").sync()
+  _G.load_config()
+end

+ 6 - 5
tests/plugins_load_spec.lua

@@ -1,9 +1,11 @@
 local a = require "plenary.async_lib.tests"
 
 a.describe("plugin-loader", function()
+  local plugins = require "lvim.plugins"
+  local loader = require "lvim.plugin-loader"
+
   a.it("should be able to load default packages without errors", function()
-    local plugins = require "plugins"
-    require("plugin-loader"):load { plugins, lvim.plugins }
+    loader:load { plugins, lvim.plugins }
 
     -- TODO: maybe there's a way to avoid hard-coding the names of the modules?
     local startup_plugins = {
@@ -16,10 +18,9 @@ a.describe("plugin-loader", function()
   end)
 
   a.it("should be able to load lsp packages without errors", function()
-    local plugins = require "plugins"
-    require("plugin-loader"):load { plugins, lvim.plugins }
+    loader:load { plugins, lvim.plugins }
 
-    require("lsp").setup()
+    require("lvim.lsp").setup()
 
     local lsp_packages = {
       "lspconfig",