init.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. -- Fallback config.lua to lv-config.lua
  7. if not utils.is_file(user_config_file) then
  8. local lv_config = utils.join_paths(user_config_dir, "lv-config.lua")
  9. Log:warn(string.format("[%s] not found, falling back to [%s]", user_config_file, lv_config))
  10. user_config_file = lv_config
  11. end
  12. function M:get_user_config_path()
  13. return user_config_file
  14. end
  15. --- Initialize lvim default configuration
  16. -- Define lvim global variable
  17. function M:init()
  18. if vim.tbl_isempty(lvim or {}) then
  19. lvim = require "lvim.config.defaults"
  20. local home_dir = vim.loop.os_homedir()
  21. lvim.vsnip_dir = utils.join_paths(home_dir, ".config", "snippets")
  22. lvim.database = { save_location = utils.join_paths(home_dir, ".config", "lunarvim_db"), auto_execute = 1 }
  23. end
  24. local builtins = require "lvim.core.builtins"
  25. builtins.config { user_config_file = user_config_file }
  26. local settings = require "lvim.config.settings"
  27. settings.load_options()
  28. local lvim_lsp_config = require "lvim.lsp.config"
  29. lvim.lsp = vim.deepcopy(lvim_lsp_config)
  30. local supported_languages = {
  31. "asm",
  32. "bash",
  33. "beancount",
  34. "bibtex",
  35. "bicep",
  36. "c",
  37. "c_sharp",
  38. "clojure",
  39. "cmake",
  40. "comment",
  41. "commonlisp",
  42. "cpp",
  43. "crystal",
  44. "cs",
  45. "css",
  46. "cuda",
  47. "d",
  48. "dart",
  49. "dockerfile",
  50. "dot",
  51. "elixir",
  52. "elm",
  53. "emmet",
  54. "erlang",
  55. "fennel",
  56. "fish",
  57. "fortran",
  58. "gdscript",
  59. "glimmer",
  60. "go",
  61. "gomod",
  62. "graphql",
  63. "haskell",
  64. "hcl",
  65. "heex",
  66. "html",
  67. "java",
  68. "javascript",
  69. "javascriptreact",
  70. "jsdoc",
  71. "json",
  72. "json5",
  73. "jsonc",
  74. "julia",
  75. "kotlin",
  76. "latex",
  77. "ledger",
  78. "less",
  79. "lua",
  80. "markdown",
  81. "nginx",
  82. "nix",
  83. "ocaml",
  84. "ocaml_interface",
  85. "perl",
  86. "php",
  87. "pioasm",
  88. "ps1",
  89. "puppet",
  90. "python",
  91. "ql",
  92. "query",
  93. "r",
  94. "regex",
  95. "rst",
  96. "ruby",
  97. "rust",
  98. "scala",
  99. "scss",
  100. "sh",
  101. "solidity",
  102. "sparql",
  103. "sql",
  104. "supercollider",
  105. "surface",
  106. "svelte",
  107. "swift",
  108. "tailwindcss",
  109. "terraform",
  110. "tex",
  111. "tlaplus",
  112. "toml",
  113. "tsx",
  114. "turtle",
  115. "typescript",
  116. "typescriptreact",
  117. "verilog",
  118. "vim",
  119. "vue",
  120. "yaml",
  121. "yang",
  122. "zig",
  123. }
  124. require("lvim.lsp.manager").init_defaults(supported_languages)
  125. end
  126. local function deprecation_notice()
  127. local in_headless = #vim.api.nvim_list_uis() == 0
  128. if in_headless then
  129. return
  130. end
  131. for lang, entry in pairs(lvim.lang) do
  132. local deprecated_config = entry["lvim.lsp"] or {}
  133. if not vim.tbl_isempty(deprecated_config) then
  134. local msg = string.format(
  135. "Deprecation notice: [lvim.lang.%s.lsp] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
  136. lang
  137. )
  138. vim.schedule(function()
  139. vim.notify(msg, vim.log.levels.WARN)
  140. end)
  141. end
  142. end
  143. end
  144. --- Override the configuration with a user provided one
  145. -- @param config_path The path to the configuration overrides
  146. function M:load(config_path)
  147. config_path = config_path or self.get_user_config_path()
  148. local ok, _ = pcall(dofile, config_path)
  149. if not ok then
  150. Log:warn("Invalid configuration: " .. config_path)
  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