init.lua 4.4 KB

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