init.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. local utils = require "lvim.utils"
  2. local Log = require "lvim.core.log"
  3. local M = {}
  4. local user_config_dir = get_config_dir()
  5. local user_config_file = utils.join_paths(user_config_dir, "config.lua")
  6. ---Get the full path to the user configuration file
  7. ---@return string
  8. function M:get_user_config_path()
  9. return user_config_file
  10. end
  11. --- Initialize lvim default configuration
  12. -- Define lvim global variable
  13. function M:init()
  14. if vim.tbl_isempty(lvim or {}) then
  15. lvim = require "lvim.config.defaults"
  16. local home_dir = vim.loop.os_homedir()
  17. lvim.vsnip_dir = utils.join_paths(home_dir, ".config", "snippets")
  18. lvim.database = { save_location = utils.join_paths(home_dir, ".config", "lunarvim_db"), auto_execute = 1 }
  19. end
  20. local builtins = require "lvim.core.builtins"
  21. builtins.config { user_config_file = user_config_file }
  22. local settings = require "lvim.config.settings"
  23. settings.load_options()
  24. local lvim_lsp_config = require "lvim.lsp.config"
  25. lvim.lsp = vim.deepcopy(lvim_lsp_config)
  26. local supported_languages = {
  27. "asm",
  28. "bash",
  29. "beancount",
  30. "bibtex",
  31. "bicep",
  32. "c",
  33. "c_sharp",
  34. "clojure",
  35. "cmake",
  36. "comment",
  37. "commonlisp",
  38. "cpp",
  39. "crystal",
  40. "cs",
  41. "css",
  42. "cuda",
  43. "d",
  44. "dart",
  45. "dockerfile",
  46. "dot",
  47. "elixir",
  48. "elm",
  49. "emmet",
  50. "erlang",
  51. "fennel",
  52. "fish",
  53. "fortran",
  54. "gdscript",
  55. "glimmer",
  56. "go",
  57. "gomod",
  58. "graphql",
  59. "haskell",
  60. "hcl",
  61. "heex",
  62. "html",
  63. "java",
  64. "javascript",
  65. "javascriptreact",
  66. "jsdoc",
  67. "json",
  68. "json5",
  69. "jsonc",
  70. "julia",
  71. "kotlin",
  72. "latex",
  73. "ledger",
  74. "less",
  75. "lua",
  76. "markdown",
  77. "nginx",
  78. "nix",
  79. "ocaml",
  80. "ocaml_interface",
  81. "perl",
  82. "php",
  83. "pioasm",
  84. "ps1",
  85. "puppet",
  86. "python",
  87. "ql",
  88. "query",
  89. "r",
  90. "regex",
  91. "rst",
  92. "ruby",
  93. "rust",
  94. "scala",
  95. "scss",
  96. "sh",
  97. "solidity",
  98. "sparql",
  99. "sql",
  100. "supercollider",
  101. "surface",
  102. "svelte",
  103. "swift",
  104. "tailwindcss",
  105. "terraform",
  106. "tex",
  107. "tlaplus",
  108. "toml",
  109. "tsx",
  110. "turtle",
  111. "typescript",
  112. "typescriptreact",
  113. "verilog",
  114. "vim",
  115. "vue",
  116. "yaml",
  117. "yang",
  118. "zig",
  119. }
  120. require("lvim.lsp.manager").init_defaults(supported_languages)
  121. end
  122. local function deprecation_notice()
  123. local in_headless = #vim.api.nvim_list_uis() == 0
  124. if in_headless then
  125. return
  126. end
  127. for lang, entry in pairs(lvim.lang) do
  128. local deprecated_config = entry["lvim.lsp"] or {}
  129. if not vim.tbl_isempty(deprecated_config) then
  130. local msg = string.format(
  131. "Deprecation notice: [lvim.lang.%s.lsp] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
  132. lang
  133. )
  134. vim.schedule(function()
  135. vim.notify(msg, vim.log.levels.WARN)
  136. end)
  137. end
  138. end
  139. end
  140. --- Override the configuration with a user provided one
  141. -- @param config_path The path to the configuration overrides
  142. function M:load(config_path)
  143. config_path = config_path or self.get_user_config_path()
  144. local ok, err = pcall(dofile, config_path)
  145. if not ok then
  146. if utils.is_file(user_config_file) then
  147. Log:warn("Invalid configuration: " .. err)
  148. else
  149. Log:warn(string.format("Unable to find configuration file [%s]", config_path))
  150. end
  151. end
  152. deprecation_notice()
  153. local autocmds = require "lvim.core.autocmds"
  154. autocmds.define_augroups(lvim.autocommands)
  155. local settings = require "lvim.config.settings"
  156. settings.load_commands()
  157. end
  158. --- Override the configuration with a user provided one
  159. -- @param config_path The path to the configuration overrides
  160. function M:reload()
  161. local lvim_modules = {}
  162. for module, _ in pairs(package.loaded) do
  163. if module:match "lvim" then
  164. package.loaded.module = nil
  165. table.insert(lvim_modules, module)
  166. end
  167. end
  168. M:init()
  169. M:load()
  170. require("lvim.keymappings").setup() -- this should be done before loading the plugins
  171. local plugins = require "lvim.plugins"
  172. utils.toggle_autoformat()
  173. local plugin_loader = require "lvim.plugin-loader"
  174. plugin_loader:cache_reset()
  175. plugin_loader:load { plugins, lvim.plugins }
  176. vim.cmd ":PackerInstall"
  177. vim.cmd ":PackerCompile"
  178. -- vim.cmd ":PackerClean"
  179. require("lvim.lsp").setup()
  180. Log:info "Reloaded configuration"
  181. end
  182. return M