From c9e2adbbc8fd7a5398c8c66d21f0e02dc7b60203 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Mon, 8 Nov 2021 23:13:05 +0100 Subject: Add new lunarvin updates --- .config/nvim/lua/config/defaults.lua | 24 +-- .config/nvim/lua/config/init.lua | 212 +++++++++++------------- .config/nvim/lua/config/settings.lua | 1 + .config/nvim/lua/config/supported_languages.lua | 94 +++++++++++ 4 files changed, 199 insertions(+), 132 deletions(-) create mode 100644 .config/nvim/lua/config/supported_languages.lua (limited to '.config/nvim/lua/config') diff --git a/.config/nvim/lua/config/defaults.lua b/.config/nvim/lua/config/defaults.lua index bb2bcc6..a4b1140 100644 --- a/.config/nvim/lua/config/defaults.lua +++ b/.config/nvim/lua/config/defaults.lua @@ -1,21 +1,19 @@ -local home_dir = vim.loop.os_homedir() -local utils = require "utils" - -options = { +return { leader = "space", colorscheme = "dark", 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", "nvim_db"), - auto_execute = 1, - }, keys = {}, builtin = {}, + plugins = { + -- use config.lua for this not put here + }, + + autocommands = {}, + lang = {}, log = { ---@usage can be { "trace", "debug", "info", "warn", "error", "fatal" }, level = "warn", @@ -30,11 +28,7 @@ options = { float_opts = {}, }, }, + -- currently disabled due to instabilities + override_notify = false, }, - plugins = { - -- use config.lua for this not put here - }, - - autocommands = {}, - lang = {}, } diff --git a/.config/nvim/lua/config/init.lua b/.config/nvim/lua/config/init.lua index f4179ee..f40e30e 100644 --- a/.config/nvim/lua/config/init.lua +++ b/.config/nvim/lua/config/init.lua @@ -1,148 +1,126 @@ -local M = {} +local utils = require "utils" +local Log = require "core.log" ---- Initialize nvim default configuration --- Define nvim global variable -function M:init(opts) - opts = opts or {} - self.path = opts.path - local utils = require "utils" +local M = {} +local user_config_dir = get_config_dir() +local user_config_file = utils.join_paths(user_config_dir, "config.lua") - require "config.defaults" +local function apply_defaults(configs, defaults) + configs = configs or {} + return vim.tbl_deep_extend("keep", configs, defaults) +end - -- Fallback config.lua to config.lua - if not utils.is_file(self.path) then - local config = self.path:gsub("config.lua$", "config.lua") - print(self.path, "not found, falling back to", config) +---Get the full path to the user configuration file +---@return string +function M:get_user_config_path() + return user_config_file +end - self.path = config +--- Initialize nvim default configuration +-- Define options global variable +function M:init() + if vim.tbl_isempty(nvim or {}) then + options = require "config.defaults" + local home_dir = vim.loop.os_homedir() + options.vsnip_dir = utils.join_paths(home_dir, ".config", "snippets") + options.database = { + save_location = utils.join_paths(home_dir, ".config", "lunarvim_db"), + auto_execute = 1, + } end local builtins = require "core.builtins" - builtins.config(self) + builtins.config { user_config_file = user_config_file } local settings = require "config.settings" settings.load_options() + local default_keymaps = require("keymappings").get_defaults() + options.keys = apply_defaults(options.keys, default_keymaps) + + local autocmds = require "core.autocmds" + options.autocommands = apply_defaults(options.autocommands, autocmds.load_augroups()) + local lsp_config = require "lsp.config" - options.lsp = vim.deepcopy(lsp_config) - - local supported_languages = { - "asm", - "bash", - "beancount", - "bibtex", - "bicep", - "c", - "c_sharp", - "clojure", - "cmake", - "comment", - "commonlisp", - "cpp", - "crystal", - "cs", - "css", - "cuda", - "d", - "dart", - "dockerfile", - "dot", - "elixir", - "elm", - "emmet", - "erlang", - "fennel", - "fish", - "fortran", - "gdscript", - "glimmer", - "go", - "gomod", - "graphql", - "haskell", - "hcl", - "heex", - "html", - "java", - "javascript", - "javascriptreact", - "jsdoc", - "json", - "json5", - "jsonc", - "julia", - "kotlin", - "latex", - "ledger", - "less", - "lua", - "markdown", - "nginx", - "nix", - "ocaml", - "ocaml_interface", - "perl", - "php", - "pioasm", - "ps1", - "puppet", - "python", - "ql", - "query", - "r", - "regex", - "rst", - "ruby", - "rust", - "scala", - "scss", - "sh", - "solidity", - "sparql", - "sql", - "supercollider", - "surface", - "svelte", - "swift", - "tailwindcss", - "terraform", - "tex", - "tlaplus", - "toml", - "tsx", - "turtle", - "typescript", - "typescriptreact", - "verilog", - "vim", - "vue", - "yaml", - "yang", - "zig", - } + options.lsp = apply_defaults(options.lsp, vim.deepcopy(lsp_config)) + local supported_languages = require "config.supported_languages" require("lsp.manager").init_defaults(supported_languages) end +local function handle_deprecated_settings() + local function deprecation_notice(setting) + local in_headless = #vim.api.nvim_list_uis() == 0 + if in_headless then + return + end + + local msg = string.format( + "Deprecation notice: [%s] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes", + setting + ) + vim.schedule(function() + Log:warn(msg) + end) + end + + for lang, entry in pairs(options.lang) do + local deprecated_config = entry.formatters or entry.linters or {} + if not vim.tbl_isempty(deprecated_config) then + deprecation_notice(string.format("lang.%s", lang)) + end + end +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, err = pcall(dofile, config_path) if not ok then - print("Invalid configuration", config_path) - print(err) - return + if utils.is_file(user_config_file) then + Log:warn("Invalid configuration: " .. err) + else + Log:warn(string.format("Unable to find configuration file [%s]", config_path)) + end end - self.path = config_path + handle_deprecated_settings() autocmds.define_augroups(options.autocommands) + vim.g.mapleader = (options.leader == "space" and " ") or options.leader + require("keymappings").load(options.keys) + local settings = require "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 core_modules = {} + for module, _ in pairs(package.loaded) do + if module:match "core" then + package.loaded[module] = nil + table.insert(core_modules, module) + end + end + + M:init() + M:load() + + local plugins = require "plugins" + utils.toggle_autoformat() + local plugin_loader = require "plugin-loader" + plugin_loader.cache_clear() + plugin_loader.load { plugins, options.plugins } + vim.cmd ":PackerInstall" + vim.cmd ":PackerCompile" + -- vim.cmd ":PackerClean" + require("lsp").setup() + Log:info "Reloaded configuration" +end + return M diff --git a/.config/nvim/lua/config/settings.lua b/.config/nvim/lua/config/settings.lua index 09f4a8b..4b5c340 100644 --- a/.config/nvim/lua/config/settings.lua +++ b/.config/nvim/lua/config/settings.lua @@ -70,6 +70,7 @@ M.load_commands = function() 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 "au ColorScheme * hi EndOfBuffer ctermbg=none guibg=none" cmd "let &fcs='eob: '" end end diff --git a/.config/nvim/lua/config/supported_languages.lua b/.config/nvim/lua/config/supported_languages.lua new file mode 100644 index 0000000..db28df1 --- /dev/null +++ b/.config/nvim/lua/config/supported_languages.lua @@ -0,0 +1,94 @@ +return { + "asm", + "bash", + "beancount", + "bibtex", + "bicep", + "c", + "c_sharp", + "clojure", + "cmake", + "comment", + "commonlisp", + "cpp", + "crystal", + "cs", + "css", + "cuda", + "d", + "dart", + "dockerfile", + "dot", + "elixir", + "elm", + "emmet", + "erlang", + "fennel", + "fish", + "fortran", + "gdscript", + "glimmer", + "go", + "gomod", + "graphql", + "haskell", + "hcl", + "heex", + "html", + "java", + "javascript", + "javascriptreact", + "jsdoc", + "json", + "json5", + "jsonc", + "julia", + "kotlin", + "latex", + "ledger", + "less", + "lua", + "markdown", + "nginx", + "nix", + "ocaml", + "ocaml_interface", + "perl", + "php", + "pioasm", + "ps1", + "puppet", + "python", + "ql", + "query", + "r", + "regex", + "rst", + "ruby", + "rust", + "scala", + "scss", + "sh", + "solidity", + "sparql", + "sql", + "supercollider", + "surface", + "svelte", + "swift", + "tailwindcss", + "terraform", + "tex", + "tlaplus", + "toml", + "tsx", + "turtle", + "typescript", + "typescriptreact", + "verilog", + "vim", + "vue", + "yaml", + "yang", + "zig", +} -- cgit v1.2.3-70-g09d2