diff --git a/lua/doom/core/doom_global.lua b/lua/doom/core/doom_global.lua index b95647a4e..d4f518e62 100644 --- a/lua/doom/core/doom_global.lua +++ b/lua/doom/core/doom_global.lua @@ -192,14 +192,8 @@ doom = { -- Logging level -- Set Doom logging level - -- Available levels: - -- · trace - -- · debug - -- · info - -- · warn - -- · error - -- · fatal - -- @default = 'info' + -- @default = "info" + --- @type "trace"|"debug"|"info"|"warn"|"error"|"fatal" logging = "info", -- Default colorscheme diff --git a/lua/doom/core/functions.lua b/lua/doom/core/functions.lua index 408703746..d4b9e6535 100644 --- a/lua/doom/core/functions.lua +++ b/lua/doom/core/functions.lua @@ -178,9 +178,8 @@ end -- Set the indent and tab related numbers. -- Negative numbers mean tabstop -- Really though? Tabs? functions.set_indent = function() - local indent = tonumber( - vim.fn.input("Set indent (>0 uses spaces, <0 uses tabs, 0 uses vim defaults): ") - ) + local indent = + tonumber(vim.fn.input("Set indent (>0 uses spaces, <0 uses tabs, 0 uses vim defaults): ")) if not indent then indent = -8 end @@ -257,7 +256,7 @@ end functions.nuke = function(target) if target == nil or #target == 0 then vim.notify( - "Warning, this command deletes packer caches and causes a re-install of doom-nvim on next launch.\n\n :DoomNuke `plugins`|`cache`|`all`. \n\t `cache` - Clear packer_compiled.lua\n\t `plugins` - Clear all installed plugins\n\t `all` - Delete all of the above." + "Warning, this command deletes packer caches and causes a re-install of doom-nvim on next launch.\n\n :DoomNuke plugins|cache|mason|all. \n\t `cache` - Clear packer_compiled.lua\n\t `plugins` - Clear all installed plugins\n\t `mason` - Clear all Mason.nvim packages\n\t `all` - Delete all of the above." ) return end @@ -276,6 +275,13 @@ functions.nuke = function(target) fs.rm_dir(plugin_dir) log.info("DoomNuke: Deleting packer plugins. Doom-nvim will re-install on next launch.") end + + if target == "all" or target == "mason" then + local util = require("packer.util") + local mason_dir = util.join_paths(vim.fn.stdpath("data"), "mason") + fs.rm_dir(mason_dir) + log.info("DoomNuke: Deleting mason packages") + end end return functions diff --git a/lua/doom/modules/core/doom/init.lua b/lua/doom/modules/core/doom/init.lua index 43cb10ff1..100f0981d 100644 --- a/lua/doom/modules/core/doom/init.lua +++ b/lua/doom/modules/core/doom/init.lua @@ -1,5 +1,3 @@ -local system = require("doom.core.system") - local required = {} required.settings = { @@ -154,6 +152,11 @@ required.binds = function() ("e %s"):format(require("doom.core.modules").source), name = "Edit modules", }, + { + "d", + require('doom.core.functions').open_docs, + name = "Open documentation", + }, { "l", "DoomReload", name = "Reload config" }, { "r", "DoomRollback", name = "Rollback" }, { "R", "DoomReport", name = "Report issue" }, diff --git a/lua/doom/modules/features/auto_install/init.lua b/lua/doom/modules/features/auto_install/init.lua index de7082dcb..a4dbb5e34 100644 --- a/lua/doom/modules/features/auto_install/init.lua +++ b/lua/doom/modules/features/auto_install/init.lua @@ -1,45 +1,21 @@ +--- Auto installer module +--- Most logic for this module is inside of `lua/doom/modules/langs/utils` local auto_install = {} -auto_install.settings = { - lsp_dir = nil, -- Change to a custom path such as `vim.fn.stdpath("data") .. "/lsp-install"` - dap_dir = nil, -- Change to a custom path such as `vim.fn.stdpath("data") .. "/dap-install"` -} - -local is_module_enabled = require("doom.utils").is_module_enabled - auto_install.packages = { - ["DAPInstall.nvim"] = { - "Pocco81/DAPInstall.nvim", - commit = "24923c3819a450a772bb8f675926d530e829665f", - -- after = "nvim-dap", - cmd = { - "DIInstall", - "DIList", - "DIUninstall", - }, - disabled = not is_module_enabled("features", "dap"), - module = "dap-install", - disable = true, + ["mason.nvim"] = { + "williamboman/mason.nvim", + commit = "75860d253f9e66d08c9289dc43fae790882eb136", }, - ["nvim-lsp-installer"] = { - "williamboman/nvim-lsp-installer", - commit = "23820a878a5c2415bfd3b971d1fe3c79e4dd6763", - -- disabled = not is_module_enabled("features", "lsp"), + ["mason-lspconfig"] = { + "williamboman/mason-lspconfig", + commit = "b70dedab5ceb5f3f84c6bc9ceea013292a14f8dc", }, } auto_install.configs = {} -auto_install.configs["nvim-lsp-installer"] = function() - local lsp_installer = require("nvim-lsp-installer") - lsp_installer.settings({ - install_root_dir = doom.features.auto_install.settings.lsp_dir, - }) -end -auto_install.configs["DAPInstall.nvim"] = function() - local dap_install = require("dap-install") - dap_install.setup({ - installation_path = doom.features.auto_install.settings.dap_dir, - }) +auto_install.configs["mason.nvim"] = function() + require("mason").setup() end return auto_install diff --git a/lua/doom/modules/features/dashboard/init.lua b/lua/doom/modules/features/dashboard/init.lua index c924982b9..49de2def2 100644 --- a/lua/doom/modules/features/dashboard/init.lua +++ b/lua/doom/modules/features/dashboard/init.lua @@ -89,7 +89,7 @@ dashboard.configs["dashboard-nvim"] = function() doom.features.dashboard.settings.entries.a = { icon = " ", desc = "Load Last Session ", - shortcut = "SPC s r", + shortcut = "SPC q r", action = "lua require('persistence').load({ last = true })", } end diff --git a/lua/doom/modules/features/statusline/init.lua b/lua/doom/modules/features/statusline/init.lua index 64668816a..88d28e09a 100644 --- a/lua/doom/modules/features/statusline/init.lua +++ b/lua/doom/modules/features/statusline/init.lua @@ -54,6 +54,23 @@ local statusline = {} statusline.settings = {} +statusline.state = {} +statusline.state.installing_mason_packages = {} +--- Pushes a mason package to be shown in the statusline +---@param name string Name of the package +statusline.state.start_mason_package = function(name) + statusline.state.finish_mason_package(name) + table.insert(statusline.state.installing_mason_packages, name) +end +--- Removes a mason package from being shown in the statusline +---@param name string Name of the package +statusline.state.finish_mason_package = function(name) + local packages = statusline.state.installing_mason_packages + statusline.state.installing_mason_packages = vim.tbl_filter(function(val) + return val ~= name + end, packages) +end + statusline._safe_get_highlight = function(...) for _, hlname in ipairs({ ... }) do if vim.fn.hlexists(hlname) == 1 then @@ -142,7 +159,7 @@ end statusline.packages = { ["heirline.nvim"] = { "rebelot/heirline.nvim", - commit = "9af77c2531a8e10abebf45817e675ecd1966db02", + commit = "19cab76f52710ec67bd8829cbc96d0c322963090", }, } @@ -325,23 +342,47 @@ statusline.configs["heirline.nvim"] = function() unpack(FileFlags) -- A small optimisation, since their parent does nothing ) - local LSPActive = { - condition = conditions.lsp_attached, + -- Mason LSP indicator, shows when a package is being installed + -- Integrates with the use_mason_package utility function in langs/utils.lua + local MasonStatusElement = { + condition = function() + return #doom.features.statusline.state.installing_mason_packages > 0 + end, + provider = function() + local installing_mason_packages = doom.features.statusline.state.installing_mason_packages + return ( + ("Installing %s... "):format(table.concat(installing_mason_packages, ", ")) + ) + end, + on_click = { + callback = function() + vim.cmd("Mason") + end, + name = "mason", + }, + hl = { fg = colors.special }, + } - -- You can keep it simple, - -- provider = " [LSP]", + local FileTypeElement = { + provider = function() + return string.format(" %s ", vim.bo.filetype) + end, + hl = { fg = colors.dim }, + } - -- Or complicate things a bit and get the servers names + local LSPElement = { + condition = conditions.lsp_attached, provider = function() local servers = vim.lsp.buf_get_clients(0) - if #servers == 0 then - return string.format(" %s ", vim.bo.filetype) - elseif #servers == 1 then - return " LSP " - else - return (" LSP(%s) "):format(#servers) - end + return (" %s "):format(#servers) end, + + on_click = { + callback = function() + vim.cmd("LspInfo") + end, + name = "lspconfig", + }, hl = { fg = colors.dim }, } @@ -426,7 +467,9 @@ statusline.configs["heirline.nvim"] = function() { FileBlock }, { FileEncoding }, { provider = " %= " }, - { LSPActive }, + { MasonStatusElement }, + { FileTypeElement }, + { LSPElement }, { GitBlock }, { Ruler }, { Notch }, diff --git a/lua/doom/modules/langs/bash/init.lua b/lua/doom/modules/langs/bash/init.lua index ec8ba9db2..963d0525f 100644 --- a/lua/doom/modules/langs/bash/init.lua +++ b/lua/doom/modules/langs/bash/init.lua @@ -1,32 +1,96 @@ local bash = {} bash.settings = { + --- disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "bash", + + --- disables default lsp config + --- @type boolean + disable_lsp = false, + --- name of the language server + --- @type string language_server_name = "bashls", + + --- disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "shfmt", + --- string to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.shfmt", + --- function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "shellcheck", + --- string to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.shellcheck", + --- function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, + + --- disables null-ls diagnostic sources + --- @type boolean + disable_code_actions = false, + --- mason.nvim package to auto install the code_actions provider from + --- @type string + code_actions_package = "shellcheck", + --- string to access the null_ls diagnositcs provider + --- @type string + code_actions_provider = "builtins.code_actions.shellcheck", + --- function to configure null-ls code_actions + --- @type function|nil + code_actions_config = nil, } +local langs_utils = require("doom.modules.langs.utils") bash.autocmds = { { - "BufWinEnter", - "*.sh", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.bash.settings.language_server_name) - - vim.defer_fn(function() - require("nvim-treesitter.install").ensure_installed("bash") - end, 0) - - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.shfmt, - null_ls.builtins.code_actions.shellcheck, - null_ls.builtins.diagnostics.shellcheck, - }) + "FileType", + "bash,sh", + langs_utils.wrap_language_setup("bash", function() + if not bash.settings.disable_lsp then + langs_utils.use_lsp_mason(bash.settings.language_server_name) + end + + if not bash.settings.disable_treesitter then + langs_utils.use_tree_sitter(bash.settings.treesitter_grammars) + end + + if not bash.settings.disable_formatting then + langs_utils.use_null_ls( + bash.settings.formatting_package, + bash.settings.formatting_provider, + bash.settings.formatting_config + ) + end + if not bash.settings.disable_diagnostics then + langs_utils.use_null_ls( + bash.settings.diagnostics_package, + bash.settings.diagnostics_provider, + bash.settings.diagnostics_config + ) + end + if not bash.settings.disable_code_actions then + langs_utils.use_null_ls( + bash.settings.code_actions_package, + bash.settings.code_actions_provider, + bash.settings.code_actions_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/c_sharp/init.lua b/lua/doom/modules/langs/c_sharp/init.lua index 33e192e4a..4262b93b8 100644 --- a/lua/doom/modules/langs/c_sharp/init.lua +++ b/lua/doom/modules/langs/c_sharp/init.lua @@ -1,28 +1,68 @@ local c_sharp = {} c_sharp.settings = { + --- disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "c_sharp", + + --- disables default lsp config + --- @type boolean + disable_lsp = false, + --- name of the language server + --- @type string language_server_name = "omnisharp", + + --- disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "csharpier", + --- string to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.csharpier", + --- function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, } +local langs_utils = require("doom.modules.langs.utils") c_sharp.autocmds = { { - "BufWinEnter", - "*.cs", - function() - local langs_utils = require("doom.modules.langs.utils") - local lsp_util = require("lspconfig.util") - langs_utils.use_lsp(doom.langs.c_sharp.settings.language_server_name, { - config = { - root_dir = function(fname) - return lsp_util.root_pattern("*.sln")(fname) - or lsp_util.root_pattern("*.csproj")(fname) - or lsp_util.root_pattern("ProjectSettings")(fname) -- Add support for unity projects - end, - }, - }) - - require("nvim-treesitter.install").ensure_installed("c_sharp") - end, + "FileType", + "cs,vb", + langs_utils.wrap_language_setup("c_sharp", function() + vim.cmd("packadd nvim-lspconfig") + + if not c_sharp.settings.disable_lsp then + local lsp_util = require("lspconfig.util") + langs_utils.use_lsp_mason(c_sharp.settings.language_server_name, { + config = { + cmd = { c_sharp.settings.language_server_name }, + root_dir = function(fname) + return lsp_util.root_pattern("*.sln")(fname) + or lsp_util.root_pattern("*.csproj")(fname) + or lsp_util.root_pattern("ProjectSettings")(fname) -- Add support for unity projects + end, + }, + }) + end + + if not c_sharp.settings.disable_treesitter then + langs_utils.use_tree_sitter(c_sharp.settings.treesitter_grammars) + end + + if not c_sharp.settings.disable_formatting then + langs_utils.use_null_ls( + c_sharp.settings.formatting_package, + c_sharp.settings.formatting_provider, + c_sharp.settings.formatting_config + ) + end + end), once = true, }, } diff --git a/lua/doom/modules/langs/cc/init.lua b/lua/doom/modules/langs/cc/init.lua index 6b4170abc..3a02340b1 100644 --- a/lua/doom/modules/langs/cc/init.lua +++ b/lua/doom/modules/langs/cc/init.lua @@ -1,30 +1,84 @@ local utils = require("doom.utils") + local cc = {} cc.settings = { + --- disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- treesitter grammars to install + --- @type string|string[] + treesitter_grammars = { "c", "cpp" }, + + --- disables default lsp config + --- @type boolean + disable_lsp = false, + --- name of the language server + --- @type string language_server_name = utils.get_sysname() == "Darwin" and "clangd" or "ccls", + + --- disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + ---Mason.nvim package to auto install the formatter from. + --- @type string + formatting_package = "clang-format", + --- string to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.clang_format", + --- function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "cpplint", + --- string to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.cpplint", + --- function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, } +local langs_utils = require("doom.modules.langs.utils") cc.autocmds = { { - "BufWinEnter", - "*.cpp,*.cc,*.cxx,*.c,*.hpp,*.hh,*.hxx,*.h", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.cc.settings.language_server_name) - - require("nvim-treesitter.install").ensure_installed("cpp", "c") + "FileType", + "cpp,c", + langs_utils.wrap_language_setup("cc", function() + if not cc.settings.disable_lsp then + langs_utils.use_lsp_mason(cc.settings.language_server_name, { + config = { + capabilities = { + offsetEncoding = { "utf-16" }, + } + } + }) + end - -- Setup null-ls - if doom.modules.linter then - local null_ls = require("null-ls") + if not cc.settings.disable_treesitter then + langs_utils.use_tree_sitter(cc.settings.treesitter_grammars) + end - langs_utils.use_null_ls_source({ - null_ls.builtins.diagnostics.cppcheck, - null_ls.builtins.formatting.clang_format, - }) + if not cc.settings.disable_formatting then + langs_utils.use_null_ls( + cc.settings.formatting_package, + cc.settings.formatting_provider, + cc.settings.formatting_config + ) + end + if not cc.settings.disable_diagnostics then + langs_utils.use_null_ls( + cc.settings.diagnostics_package, + cc.settings.diagnostics_provider, + cc.settings.diagnostics_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/config/init.lua b/lua/doom/modules/langs/config/init.lua index d5f97ab8f..7f6ad9627 100644 --- a/lua/doom/modules/langs/config/init.lua +++ b/lua/doom/modules/langs/config/init.lua @@ -1,68 +1,8 @@ -local config = {} - --- TODO: Investigate broken yaml/toml language servers - -config.settings = { - json_schemas = { - ".eslintrc", - "package.json", - "prettierrc.json", - "tsconfig.json", - }, - json_language_server_name = "jsonls", - -- toml_language_server_name = 'taplo', -- Currently broken - -- yaml_language_server_name = 'yamlls', -- Currently broken -} - -config.packages = { - ["SchemaStore.nvim"] = { - "b0o/SchemaStore.nvim", - commit = "23bf2d69967491b1dc43f37c809f2711cc879fd2", - ft = { "json", "yaml", "toml" }, - }, -} -config.configs = {} -config.configs["SchemaStore.nvim"] = function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.config.settings.json_language_server_name, { - config = { - settings = { - json = { - schemas = require("schemastore").json.schemas({ - select = doom.langs.config.settings.json_schemas, - }), - }, - }, - }, - }) -end - -config.autocmds = { - { - "BufWinEnter", - "*.json,*.yaml,*.toml", - function() - local langs_utils = require("doom.modules.langs.utils") - -- langs_utils.use_lsp(doom.langs.config.settings.toml_language_server_name) - -- langs_utils.use_lsp(doom.langs.config.settings.yaml_language_server_name) +local log = require('doom.utils.logging') - vim.defer_fn(function() - require("nvim-treesitter.install").ensure_installed("json5", "yaml", "toml") - end, 0) - - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - -- null_ls.builtins.formatting.taplo, - -- null_ls.builtins.diagnostics.yamllint, - null_ls.builtins.diagnostics.jsonlint, - }) - end - end, - once = true, - }, -} +log.warn("The `config` language module is deprecated, please use `json`, `yaml` or `toml`.") +-- TODO: Delete this file in 1-2 months (written: 25/09/22) +local config = {} return config + diff --git a/lua/doom/modules/langs/css/init.lua b/lua/doom/modules/langs/css/init.lua index f2329cd64..5a1b702f1 100644 --- a/lua/doom/modules/langs/css/init.lua +++ b/lua/doom/modules/langs/css/init.lua @@ -1,31 +1,77 @@ local css = {} css.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "css", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string language_server_name = "cssls", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "stylelint-lsp", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.stylelint", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "stylelint-lsp", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.stylelint", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, + } +local langs_utils = require("doom.modules.langs.utils") css.autocmds = { { "FileType", "css,scss,vue,svelte,html", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.css.settings.language_server_name) - - vim.defer_fn(function() - require("nvim-treesitter.install").ensure_installed("css") - end, 0) - - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - null_ls.builtins.diagnostics.stylelint, - null_ls.builtins.formatting.stylelint, - }) + langs_utils.wrap_language_setup("css", function() + if not css.settings.disable_lsp then + langs_utils.use_lsp_mason(css.settings.language_server_name) + end + + if not css.settings.disable_treesitter then + langs_utils.use_tree_sitter(css.settings.treesitter_grammars) + end + + if not css.settings.disable_formatting then + langs_utils.use_null_ls( + css.settings.formatting_package, + css.settings.formatting_provider, + css.settings.formatting_config + ) + end + if not css.settings.disable_diagnostics then + langs_utils.use_null_ls( + css.settings.diagnostics_package, + css.settings.diagnostics_provider, + css.settings.diagnostics_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/dockerfile/init.lua b/lua/doom/modules/langs/dockerfile/init.lua index 622fd4f61..e0b6b08aa 100644 --- a/lua/doom/modules/langs/dockerfile/init.lua +++ b/lua/doom/modules/langs/dockerfile/init.lua @@ -1,36 +1,56 @@ local dockerfile = {} dockerfile.settings = { - --- Enable/Disable linting via hadolint + --- Disables auto installing the treesitter --- @type boolean - disable_linter = true, - --- Language server name + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "dockerfile", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server --- @type string language_server_name = "dockerls", + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "hadolint", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.hadolint", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, } +local langs_utils = require("doom.modules.langs.utils") dockerfile.autocmds = { { "FileType", "dockerfile", - function() - local settings = doom.langs.dockerfile.settings - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(settings.language_server_name) - - vim.defer_fn(function() - require("nvim-treesitter.install").ensure_installed("dockerfile") - end, 0) + langs_utils.wrap_language_setup("dockerfile", function() + if not dockerfile.settings.disable_lsp then + langs_utils.use_lsp_mason(dockerfile.settings.language_server_name) + end - -- Setup null-ls - if doom.features.linter and not settings.disable_linter then - local null_ls = require("null-ls") + if not dockerfile.settings.disable_treesitter then + langs_utils.use_tree_sitter(dockerfile.settings.treesitter_grammars) + end - langs_utils.use_null_ls_source({ - null_ls.builtins.diagnostics.hadolint, - }) + if not dockerfile.settings.disable_diagnostics then + langs_utils.use_null_ls( + dockerfile.settings.diagnostics_package, + dockerfile.settings.diagnostics_provider, + dockerfile.settings.diagnostics_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/fish/init.lua b/lua/doom/modules/langs/fish/init.lua index a7c597957..29037b5ea 100644 --- a/lua/doom/modules/langs/fish/init.lua +++ b/lua/doom/modules/langs/fish/init.lua @@ -1,23 +1,72 @@ local fish = {} -fish.settings = {} +fish.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "fish", + + -- --- Disables default LSP config + -- --- @type boolean + -- disable_lsp = false, + -- --- Name of the language server + -- --- @type string + -- language_server_name = "tsserver", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- WARN: No package yet. Mason.nvim package to auto install the formatter from + --- @type nil + formatting_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.fish_indent", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type nil + diagnostics_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.fish", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, +} + +local langs_utils = require("doom.modules.langs.utils") fish.autocmds = { { - "BufWinEnter", - "*.fish", - function() - require("nvim-treesitter.install").ensure_installed("fish") + "FileType", + "fish", + langs_utils.wrap_language_setup("fish", function() + if not fish.settings.disable_treesitter then + langs_utils.use_tree_sitter(fish.settings.treesitter_grammars) + end - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.fish_indent, - null_ls.builtins.diagnostics.fish, - }) + if not fish.settings.disable_formatting then + langs_utils.use_null_ls( + fish.settings.formatting_package, + fish.settings.formatting_provider, + fish.settings.formatting_config + ) + end + if not fish.settings.disable_diagnostics then + langs_utils.use_null_ls( + fish.settings.diagnostics_package, + fish.settings.diagnostics_provider, + fish.settings.diagnostics_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/gdscript/init.lua b/lua/doom/modules/langs/gdscript/init.lua index 2f4310be9..703e73db3 100644 --- a/lua/doom/modules/langs/gdscript/init.lua +++ b/lua/doom/modules/langs/gdscript/init.lua @@ -1,35 +1,84 @@ local gdscript = {} gdscript.settings = { - language_server_name = "gdscript", + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = { "gdscript", "godot_resource" }, + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "tsserver", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- WARN: No package yet. Mason.nvim package to auto install the formatter from + --- @type nil + formatting_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.gdformat", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- WARN: No package yet. Mason.nvim package to auto install the diagnostics provider from + --- @type nil + diagnostics_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.gdlint", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, } +local langs_utils = require("doom.modules.langs.utils") gdscript.autocmds = { { "BufWinEnter", "*.gd", - function() - print("gdscript") - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.modules.langs.gdscript.settings.language_server_name, { - no_installer = true, - config = { - flags = { - debounce_text_changes = 150, + langs_utils.wrap_language_setup("gdscript", function() + + if not gdscript.settings.disable_lsp then + langs_utils.use_lsp_mason(gdscript.settings.language_server_name, { + no_installer = true, + config = { + flags = { + debounce_text_changes = 150, + }, }, - }, - }) - if doom.features.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.gdformat, - null_ls.builtins.diagnostics.gdlint, }) end - require("nvim-treesitter.install").ensure_installed("gdscript", "godot_resource") - end, + if not gdscript.settings.disable_treesitter then + langs_utils.use_tree_sitter(gdscript.settings.treesitter_grammars) + end + + if not gdscript.settings.disable_formatting then + langs_utils.use_null_ls( + gdscript.settings.formatting_package, + gdscript.settings.formatting_provider, + gdscript.settings.formatting_config + ) + end + if not gdscript.settings.disable_diagnostics then + langs_utils.use_null_ls( + gdscript.settings.diagnostics_package, + gdscript.settings.diagnostics_provider, + gdscript.settings.diagnostics_config + ) + end + end), once = true, }, } diff --git a/lua/doom/modules/langs/glsl/init.lua b/lua/doom/modules/langs/glsl/init.lua index f2e227db8..8830007fc 100644 --- a/lua/doom/modules/langs/glsl/init.lua +++ b/lua/doom/modules/langs/glsl/init.lua @@ -1,36 +1,71 @@ local glsl = {} -glsl.settings = {} +glsl.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "glsl", + -- --- Disables default LSP config + -- --- @type boolean + -- disable_lsp = false, + -- --- Name of the language server + -- --- @type string + -- language_server_name = "tsserver", + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- WARN: No package. Mason.nvim package to auto install the diagnostics provider from + --- @type nil + diagnostics_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.glslc", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = function(glslc) + glslc.with({ + extra_args = { "--target-env=opengl" }, -- use opengl instead of vulkan1.0 + }) + end, +} + +local langs_utils = require("doom.modules.langs.utils") glsl.autocmds = { { "FileType", "glsl", - function() - pcall(function() - local langs_utils = require("doom.modules.langs.utils") - - require("nvim-treesitter.install").ensure_installed("glsl") - - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.shfmt, - }) - end - end) - end, + langs_utils.wrap_language_setup("glsl", function() + + -- if not glsl.settings.disable_lsp then + -- langs_utils.use_lsp_mason(glsl.settings.language_server_name) + -- end + + if not glsl.settings.disable_treesitter then + langs_utils.use_tree_sitter(glsl.settings.treesitter_grammars) + end + + if not glsl.settings.disable_diagnostics then + langs_utils.use_null_ls( + glsl.settings.diagnostics_package, + glsl.settings.diagnostics_provider, + glsl.settings.diagnostics_config + ) + end + end), once = true, }, + -- TODO: Refactor to use filetype.lua or filetype.vim { "BufWinEnter", - "*.glsl,*.vs,*.fs,*.frag,*.vert", - function() - vim.bo.filetype = "glsl" - end, - }, + "*.glsl,*.frag,*.vert,*.fs,*.vs", + function () + vim.bo.filetype = 'glsl' + end + } } return glsl diff --git a/lua/doom/modules/langs/go/init.lua b/lua/doom/modules/langs/go/init.lua index c5edfe647..20d1fccf2 100644 --- a/lua/doom/modules/langs/go/init.lua +++ b/lua/doom/modules/langs/go/init.lua @@ -1,28 +1,77 @@ local go = {} go.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "go", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string language_server_name = "gopls", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "gofumpt", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.gofumpt", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "golangci-lint", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.golangci_lint", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, } +local langs_utils = require("doom.modules.langs.utils") go.autocmds = { { "BufWinEnter", "*.go", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.go.settings.language_server_name) + langs_utils.wrap_language_setup("go", function() - require("nvim-treesitter.install").ensure_installed("go") + if not go.settings.disable_lsp then + langs_utils.use_lsp_mason(go.settings.language_server_name) + end - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") + if not go.settings.disable_treesitter then + langs_utils.use_tree_sitter(go.settings.treesitter_grammars) + end - langs_utils.use_null_ls_source({ - null_ls.builtins.diagnostics.golangci_lint, - }) + if not go.settings.disable_formatting then + langs_utils.use_null_ls( + go.settings.formatting_package, + go.settings.formatting_provider, + go.settings.formatting_config + ) + end + if not go.settings.disable_diagnostics then + langs_utils.use_null_ls( + go.settings.diagnostics_package, + go.settings.diagnostics_provider, + go.settings.diagnostics_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/haskell/init.lua b/lua/doom/modules/langs/haskell/init.lua index 1baff2429..6191b396a 100644 --- a/lua/doom/modules/langs/haskell/init.lua +++ b/lua/doom/modules/langs/haskell/init.lua @@ -1,35 +1,64 @@ local haskell = {} haskell.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "haskell", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string language_server_name = "hls", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- WARN: No package. Mason.nvim package to auto install the formatter from + --- @type nil + formatting_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.fourmolu", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, } +local langs_utils = require("doom.modules.langs.utils") haskell.autocmds = { { - "BufWinEnter", - "*.hs", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.haskell.settings.language_server_name) - - local parser_config = require("nvim-treesitter.parsers").get_parser_configs() - parser_config.haskell = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-haskell", - files = { "src/parser.c", "src/scanner.c" }, - }, - } - require("nvim-treesitter.install").ensure_installed("haskell") + "FileType", + "haskell", + langs_utils.wrap_language_setup("haskell", function() + if not haskell.settings.disable_lsp then + print("starting lsp") + langs_utils.use_lsp_mason(haskell.settings.language_server_name) + end - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") + if not haskell.settings.disable_treesitter then + local parser_config = require("nvim-treesitter.parsers").get_parser_configs() + parser_config.haskell = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-haskell", + files = { "src/parser.c", "src/scanner.c" }, + }, + } + langs_utils.use_tree_sitter(haskell.settings.treesitter_grammars) + end - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.fouremolu, - }) + if not haskell.settings.disable_formatting then + langs_utils.use_null_ls( + haskell.settings.diagnostics_package, + haskell.settings.formatting_provider, + haskell.settings.formatting_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/html/init.lua b/lua/doom/modules/langs/html/init.lua index 51ff64d84..db19c8b0f 100644 --- a/lua/doom/modules/langs/html/init.lua +++ b/lua/doom/modules/langs/html/init.lua @@ -1,30 +1,58 @@ -local utils = require("doom.utils") - local html = {} -html.settings = {} +html.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = {"html", "javascript", "css"}, + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "html", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "rome", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.rome", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = function(rome) + rome.with({ + filetypes = { "html" } + }) + end, +} +local langs_utils = require("doom.modules.langs.utils") html.autocmds = { { "BufWinEnter", "*.html", - utils.make_run_once_function(function() - print("html") - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp("html") - - vim.defer_fn(function() - local ts_install = require("nvim-treesitter.install") - ts_install.ensure_installed("html", "javascript", "css") - end, 0) + langs_utils.wrap_language_setup("html", function() + if not html.settings.disable_lsp then + langs_utils.use_lsp_mason(html.settings.language_server_name) + end - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") + if not html.settings.disable_treesitter then + langs_utils.use_tree_sitter(html.settings.treesitter_grammars) + end - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.tidy, - }) + if not html.settings.disable_formatting then + langs_utils.use_null_ls( + html.settings.diagnostics_package, + html.settings.formatting_provider, + html.settings.formatting_config + ) end end), once = true, diff --git a/lua/doom/modules/langs/java/init.lua b/lua/doom/modules/langs/java/init.lua index 1018514da..466ef1962 100644 --- a/lua/doom/modules/langs/java/init.lua +++ b/lua/doom/modules/langs/java/init.lua @@ -1,28 +1,57 @@ local java = {} java.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "java", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string language_server_name = "jdtls", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- WARN: No package. Mason.nvim package to auto install the formatter from + --- @type nil + formatting_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.google_java_format", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, } +local langs_utils = require("doom.modules.langs.utils") java.autocmds = { { "BufWinEnter", "*.java", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.java.settings.language_server_name) + langs_utils.wrap_language_setup("java", function() - require("nvim-treesitter.install").ensure_installed("java") + if not java.settings.disable_lsp then + langs_utils.use_lsp_mason(java.settings.language_server_name) + end - -- Setup null-ls - if doom.modules.linter then - local null_ls = require("null-ls") + if not java.settings.disable_treesitter then + langs_utils.use_tree_sitter(java.settings.treesitter_grammars) + end - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.google_java_format, - }) + if not java.settings.disable_formatting then + langs_utils.use_null_ls( + java.settings.diagnostics_package, + java.settings.formatting_provider, + java.settings.formatting_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/json/init.lua b/lua/doom/modules/langs/json/init.lua new file mode 100644 index 000000000..a18259d79 --- /dev/null +++ b/lua/doom/modules/langs/json/init.lua @@ -0,0 +1,75 @@ +local json = {} + +json.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "json", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "jsonls", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "fixjson", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.fixjson", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, +} + +json.packages = { + ["SchemaStore.nvim"] = { + "b0o/SchemaStore.nvim", + commit = "f55842dc797faad8cf7b0d9ce75c59da654aa018", + ft = "json", + }, +} + +local langs_utils = require("doom.modules.langs.utils") +json.autocmds = { + { + "FileType", + "json", + langs_utils.wrap_language_setup("json", function() + vim.cmd("packadd SchemaStore.nvim") + if not json.settings.disable_lsp then + langs_utils.use_lsp_mason(json.settings.language_server_name, { + config = { + settings = { + json = { + schemas = require("schemastore").json.schemas(), + }, + }, + }, + }) + end + + if not json.settings.disable_treesitter then + langs_utils.use_tree_sitter(json.settings.treesitter_grammars) + end + + if not json.settings.disable_formatting then + langs_utils.use_null_ls( + json.settings.diagnostics_package, + json.settings.formatting_provider, + json.settings.formatting_config + ) + end + end), + once = true, + }, +} + +return json diff --git a/lua/doom/modules/langs/kotlin/init.lua b/lua/doom/modules/langs/kotlin/init.lua index c9fb8080c..4f1dd9b06 100644 --- a/lua/doom/modules/langs/kotlin/init.lua +++ b/lua/doom/modules/langs/kotlin/init.lua @@ -1,27 +1,76 @@ local kotlin = {} kotlin.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "kotlin", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string language_server_name = "kotlin_language_server", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "ktlint", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.ktlint", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "ktlint", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.ktlint", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, } +local langs_utils = require("doom.modules.langs.utils") kotlin.autocmds = { { - "BufWinEnter", - "*.kt,*.kts", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.kotlin.settings.language_server_name) - - require("nvim-treesitter.install").ensure_installed("kotlin") - -- Setup null-ls - if doom.modules.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.ktlint, - }) + "FileType", + "kotlin", + langs_utils.wrap_language_setup("kotlin", function() + if not kotlin.settings.disable_lsp then + langs_utils.use_lsp_mason(kotlin.settings.language_server_name) + end + + if not kotlin.settings.disable_treesitter then + langs_utils.use_tree_sitter(kotlin.settings.treesitter_grammars) + end + + if not kotlin.settings.disable_formatting then + langs_utils.use_null_ls( + kotlin.settings.formatting_package, + kotlin.settings.formatting_provider, + kotlin.settings.formatting_config + ) + end + if not kotlin.settings.disable_diagnostics then + langs_utils.use_null_ls( + kotlin.settings.diagnostics_package, + kotlin.settings.diagnostics_provider, + kotlin.settings.diagnostics_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/lua/init.lua b/lua/doom/modules/langs/lua/init.lua index 03b3a140e..70ddee59b 100644 --- a/lua/doom/modules/langs/lua/init.lua +++ b/lua/doom/modules/langs/lua/init.lua @@ -1,29 +1,73 @@ local lua = {} lua.settings = { - formatter = { - enabled = true, - }, - settings = { - Lua = { - runtime = { - version = "LuaJIT", - }, - diagnostics = { - globals = { "vim", "doom" }, - }, - workspace = { - library = vim.api.nvim_get_runtime_file("", true), - maxPreload = 1000, - preloadFileSize = 150, - checkThirdParty = false, - }, - telemetry = { - enable = false, + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "lua", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "sumneko_lua", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "stylua", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.stylua", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "luacheck", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.luacheck", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, + + --- Options passed to language server + lsp_config = { + formatter = { + enabled = true, + }, + settings = { + Lua = { + runtime = { + version = "LuaJIT", + }, + diagnostics = { + globals = { "vim", "doom" }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + maxPreload = 1000, + preloadFileSize = 150, + checkThirdParty = false, + }, + telemetry = { + enable = false, + }, }, }, }, - dev = { + --- Config for the lua-dev plugin + lua_dev = { library = { vimruntime = true, types = true, @@ -40,20 +84,19 @@ lua.packages = { }, } +local langs_utils = require("doom.modules.langs.utils") lua.autocmds = { { "BufWinEnter", "*.lua", - function() - local langs_utils = require("doom.modules.langs.utils") - + langs_utils.wrap_language_setup("lua", function() local runtime_path = vim.split(package.path, ";") table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?/init.lua") local config = vim.tbl_deep_extend( "force", - doom.langs.lua.settings, + doom.langs.lua.settings.lsp_config, require("lua-dev").setup(doom.langs.lua.settings.dev), { settings = { @@ -66,24 +109,31 @@ lua.autocmds = { } ) - langs_utils.use_lsp("sumneko_lua", { - config = config, - }) - - vim.defer_fn(function() - require("nvim-treesitter.install").ensure_installed("lua") - end, 0) + if not lua.settings.disable_lsp then + langs_utils.use_lsp_mason(lua.settings.language_server_name, { + config = config, + }) + end - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") + if not lua.settings.disable_treesitter then + langs_utils.use_tree_sitter(lua.settings.treesitter_grammars) + end - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.stylua, - null_ls.builtins.diagnostics.luacheck, - }) + if not lua.settings.disable_formatting then + langs_utils.use_null_ls( + lua.settings.formatting_package, + lua.settings.formatting_provider, + lua.settings.formatting_config + ) + end + if not lua.settings.disable_diagnostics then + langs_utils.use_null_ls( + lua.settings.diagnostics_package, + lua.settings.diagnostics_provider, + lua.settings.diagnostics_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/markdown/init.lua b/lua/doom/modules/langs/markdown/init.lua index caf89aae3..6a199c4db 100644 --- a/lua/doom/modules/langs/markdown/init.lua +++ b/lua/doom/modules/langs/markdown/init.lua @@ -1,32 +1,56 @@ local markdown = {} -markdown.settings = {} +markdown.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "markdown", + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "remark_ls", + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "markdownlint", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.markdownlint", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, +} + +local langs_utils = require("doom.modules.langs.utils") markdown.autocmds = { { - "BufWinEnter", - "*.md", - function() - -- local langs_utils = require("doom.modules.langs.utils") - - -- Disabled due to unreliability (only works in projects with `remark` - -- npm package installed). - -- langs_utils.use_lsp("remark_ls") + "FileType", + "markdown", + langs_utils.wrap_language_setup("markdown", function() + if not markdown.settings.disable_lsp then + langs_utils.use_lsp_mason(markdown.settings.language_server_name) + end - vim.defer_fn(function() - require("nvim-treesitter.install").ensure_installed("markdown") - end, 0) + if not markdown.settings.disable_treesitter then + langs_utils.use_tree_sitter(markdown.settings.treesitter_grammars) + end - -- Setup null-ls - -- Disabled due to lsp being disabled. null-ls gets triggered by lspconfig - -- if doom.modules.linter then - -- local null_ls = require("null-ls") - -- - -- langs_utils.use_null_ls_source({ - -- null_ls.builtins.diagnostics.markdownlint, - -- }) - -- end - end, + if not markdown.settings.disable_diagnostics then + langs_utils.use_null_ls( + markdown.settings.diagnostics_package, + markdown.settings.diagnostics_provider, + markdown.settings.diagnostics_config + ) + end + end), once = true, }, } diff --git a/lua/doom/modules/langs/nix/init.lua b/lua/doom/modules/langs/nix/init.lua index c7fa0ac53..48bc4a160 100644 --- a/lua/doom/modules/langs/nix/init.lua +++ b/lua/doom/modules/langs/nix/init.lua @@ -11,17 +11,17 @@ nix.settings = { }, } +local langs_utils = require("doom.modules.langs.utils") nix.autocmds = { { "BufWinEnter", "*.nix", - function() + langs_utils.wrap_language_setup("nix", function() local utils = require("doom.utils") - local langs_utils = require("doom.modules.langs.utils") require("nvim-treesitter.install").ensure_installed("nix") - langs_utils.use_lsp("rnix-lsp") + langs_utils.use_lsp_mason("rnix") -- Setup null-ls if utils.is_module_enabled("features", "linter") then @@ -47,7 +47,7 @@ nix.autocmds = { langs_utils.use_null_ls_source(null_ls_source) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/ocaml/init.lua b/lua/doom/modules/langs/ocaml/init.lua index bcbc8370b..bf47e8131 100644 --- a/lua/doom/modules/langs/ocaml/init.lua +++ b/lua/doom/modules/langs/ocaml/init.lua @@ -1,24 +1,35 @@ local ocaml = {} ocaml.settings = { + --- disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- treesitter grammars to install + --- @type string|string[] + treesitter_grammars = {"ocaml", "ocaml_interface", "ocamllex"}, + + --- disables default lsp config + --- @type boolean + disable_lsp = false, + --- name of the language server + --- @type string language_server_name = "ocamllsp", } +local langs_utils = require("doom.modules.langs.utils") ocaml.autocmds = { { - "Filetype", - "ocaml,ocaml_interface,ocamllex", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.ocaml.settings.language_server_name) + "FileType", + "ocaml", + langs_utils.wrap_language_setup("ocaml", function() + if not ocaml.settings.disable_lsp then + langs_utils.use_lsp_mason(ocaml.settings.language_server_name) + end - vim.schedule(function() - require("nvim-treesitter.install").ensure_installed("ocaml", "ocaml_interface") - if vim.fn.executable("tree-sitter-cli") == 1 then - require("nvim-treesitter.install").ensure_installed("ocamllex") - end - end) - end, + if not ocaml.settings.disable_treesitter then + langs_utils.use_tree_sitter(ocaml.settings.treesitter_grammars) + end + end), once = true, }, } diff --git a/lua/doom/modules/langs/php/init.lua b/lua/doom/modules/langs/php/init.lua index 549d43dc5..73970c10d 100644 --- a/lua/doom/modules/langs/php/init.lua +++ b/lua/doom/modules/langs/php/init.lua @@ -1,29 +1,83 @@ local php = {} php.settings = { + --- disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "php", + + --- disables default lsp config + --- @type boolean + disable_lsp = false, + --- name of the language server + --- @type string language_server_name = "intelephense", + + --- disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "php-cs-fixer", + --- string to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.phpcsfixer", + --- function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "phpstan", + --- string to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.phpstan", + --- function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, } +local langs_utils = require("doom.modules.langs.utils") php.autocmds = { { - "BufWinEnter", - "*.php,*.phtml", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.php.settings.language_server_name) - - require("nvim-treesitter.install").ensure_installed("php") - - -- Setup null-ls - if doom.modules.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.phpcsfixer, - null_ls.builtins.diagnostics.phpstan, - }) + "FileType", + "php,phtml", + langs_utils.wrap_language_setup("php", function() + if not php.settings.disable_lsp then + langs_utils.use_lsp_mason(php.settings.language_server_name) + end + + if not php.settings.disable_treesitter then + langs_utils.use_tree_sitter(php.settings.treesitter_grammars) + end + + if not php.settings.disable_formatting then + langs_utils.use_null_ls( + php.settings.formatting_package, + php.settings.formatting_provider, + php.settings.formatting_config + ) + end + if not php.settings.disable_diagnostics then + langs_utils.use_null_ls( + php.settings.diagnostics_package, + php.settings.diagnostics_provider, + php.settings.diagnostics_config + ) + end + if not php.settings.disable_code_actions then + langs_utils.use_null_ls( + php.settings.code_actions_package, + php.settings.code_actions_provider, + php.settings.code_actions_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/python/init.lua b/lua/doom/modules/langs/python/init.lua index 2a8937ee0..ae2c5aaac 100644 --- a/lua/doom/modules/langs/python/init.lua +++ b/lua/doom/modules/langs/python/init.lua @@ -1,29 +1,76 @@ local python = {} python.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "python", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string language_server_name = "pyright", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "black", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.black", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "mypy", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.mypy", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, } +local langs_utils = require("doom.modules.langs.utils") python.autocmds = { { - "BufWinEnter", - "*.py", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.python.settings.language_server_name) - - require("nvim-treesitter.install").ensure_installed("python") - - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.black, - null_ls.builtins.diagnostics.mypy, - }) + "FileType", + "python", + langs_utils.wrap_language_setup("python", function() + if not python.settings.disable_lsp then + langs_utils.use_lsp_mason(python.settings.language_server_name) + end + + if not python.settings.disable_treesitter then + langs_utils.use_tree_sitter(python.settings.treesitter_grammars) + end + + if not python.settings.disable_formatting then + langs_utils.use_null_ls( + python.settings.formatting_package, + python.settings.formatting_provider, + python.settings.formatting_config + ) + end + if not python.settings.disable_diagnostics then + langs_utils.use_null_ls( + python.settings.diagnostics_package, + python.settings.diagnostics_provider, + python.settings.diagnostics_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/ruby/init.lua b/lua/doom/modules/langs/ruby/init.lua index 9bb751a61..07eb2bc9f 100644 --- a/lua/doom/modules/langs/ruby/init.lua +++ b/lua/doom/modules/langs/ruby/init.lua @@ -1,28 +1,56 @@ local ruby = {} ruby.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "ruby", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string language_server_name = "solargraph", + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "rubocop", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.rubocop", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, } +local langs_utils = require("doom.modules.langs.utils") ruby.autocmds = { { - "BufWinEnter", - "*.rb", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.ruby.settings.language_server_name) - - require("nvim-treesitter.install").ensure_installed("ruby") + "FileType", + "ruby", + langs_utils.wrap_language_setup("ruby", function() + if not ruby.settings.disable_lsp then + langs_utils.use_lsp_mason(ruby.settings.language_server_name) + end - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") + if not ruby.settings.disable_treesitter then + langs_utils.use_tree_sitter(ruby.settings.treesitter_grammars) + end - langs_utils.use_null_ls_source({ - null_ls.builtins.diagnostics.rubocop, - }) + if not ruby.settings.disable_diagnostics then + langs_utils.use_null_ls( + ruby.settings.diagnostics_package, + ruby.settings.diagnostics_provider, + ruby.settings.diagnostics_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/rust/init.lua b/lua/doom/modules/langs/rust/init.lua index 42dab8fae..54fbf6753 100644 --- a/lua/doom/modules/langs/rust/init.lua +++ b/lua/doom/modules/langs/rust/init.lua @@ -1,26 +1,56 @@ local rust = {} -rust.settings = {} +rust.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "rust", + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "rust_analyzer", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- WARN: No package yet. Mason.nvim package to auto install the formatter from + --- @type nil + formatting_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.rustfmt", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, +} + +local langs_utils = require("doom.modules.langs.utils") rust.autocmds = { { - "BufWinEnter", - "*.rs", - function() - local langs_utils = require("doom.modules.langs.utils") - - langs_utils.use_lsp("rust_analyzer") + "FileType", + "rust", + langs_utils.wrap_language_setup("rust", function() + if not rust.settings.disable_lsp then + langs_utils.use_lsp_mason(rust.settings.language_server_name) + end - require("nvim-treesitter.install").ensure_installed("rust") + if not rust.settings.disable_treesitter then + langs_utils.use_tree_sitter(rust.settings.treesitter_grammars) + end - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.rustfmt, - }) + if not rust.settings.disable_formatting then + langs_utils.use_null_ls( + rust.settings.formatting_package, + rust.settings.formatting_provider, + rust.settings.formatting_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/svelte/init.lua b/lua/doom/modules/langs/svelte/init.lua index 07c723d76..c592f2721 100644 --- a/lua/doom/modules/langs/svelte/init.lua +++ b/lua/doom/modules/langs/svelte/init.lua @@ -1,32 +1,96 @@ local svelte = {} svelte.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "svelte", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string language_server_name = "svelte", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "eslint_d", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.eslint_d", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "eslint_d", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.eslint_d", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_code_actions = false, + --- Mason.nvim package to auto install the code_actions provider from + --- @type string + code_actions_package = "eslint_d", + --- String to access the null_ls diagnositcs provider + --- @type string + code_actions_provider = "builtins.code_actions.eslint_d", + --- Function to configure null-ls code_actions + --- @type function|nil + code_actions_config = nil, } +local langs_utils = require("doom.modules.langs.utils") svelte.autocmds = { { - "BufWinEnter", - "*.svelte", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.svelte.settings.language_server_name) - - vim.defer_fn(function() - require("nvim-treesitter.install").ensure_installed("svelte") - end, 0) - - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.eslint_d, - null_ls.builtins.code_actions.eslint_d, - null_ls.builtins.diagnostics.eslint_d, - }) + "FileType", + "svelte", + langs_utils.wrap_language_setup("svelte", function() + if not svelte.settings.disable_lsp then + langs_utils.use_lsp_mason(svelte.settings.language_server_name) + end + + if not svelte.settings.disable_treesitter then + langs_utils.use_tree_sitter(svelte.settings.treesitter_grammars) + end + + if not svelte.settings.disable_formatting then + langs_utils.use_null_ls( + svelte.settings.diagnostics_package, + svelte.settings.formatting_provider, + svelte.settings.formatting_config + ) + end + if not svelte.settings.disable_diagnostics then + langs_utils.use_null_ls( + svelte.settings.diagnostics_package, + svelte.settings.diagnostics_provider, + svelte.settings.diagnostics_config + ) + end + if not svelte.settings.disable_code_actions then + langs_utils.use_null_ls( + svelte.settings.code_actions_package, + svelte.settings.code_actions_provider, + svelte.settings.code_actions_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/tailwindcss/init.lua b/lua/doom/modules/langs/tailwindcss/init.lua index 1f1c49d3a..fd4de6d69 100644 --- a/lua/doom/modules/langs/tailwindcss/init.lua +++ b/lua/doom/modules/langs/tailwindcss/init.lua @@ -1,29 +1,54 @@ -local utils = require("doom.utils") - local tailwindcss = {} -tailwindcss.settings = {} +tailwindcss.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = { "css", "html", "vue" }, + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "tailwindcss", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- WARN: No package yet. Mason.nvim package to auto install the formatter from + --- @type nil + formatting_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.rustywind", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, +} +local langs_utils = require("doom.modules.langs.utils") tailwindcss.autocmds = { { - "BufWinEnter", - "*.css,*.scss,*.vue,*.html,*.svelte,*.jsx,*.tsx", - utils.make_run_once_function(function() - local langs_utils = require("doom.modules.langs.utils") - - langs_utils.use_lsp("tailwindcss") - - vim.defer_fn(function() - require("nvim-treesitter.install").ensure_installed("css") - end, 0) + "FileType", + "javascript,typescript,javascriptreact,typescriptreact,css,html,vue,svelte", + langs_utils.wrap_language_setup("tailwindcss", function() + if not tailwindcss.settings.disable_lsp then + langs_utils.use_lsp_mason(tailwindcss.settings.language_server_name) + end - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") + if not tailwindcss.settings.disable_treesitter then + langs_utils.use_tree_sitter(tailwindcss.settings.treesitter_grammars) + end - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.rustywind, - }) + if not tailwindcss.settings.disable_formatting and tailwindcss.settings.formatting_package then + langs_utils.use_null_ls( + tailwindcss.settings.formatting_package, + tailwindcss.settings.formatting_provider, + tailwindcss.settings.formatting_config + ) end end), once = true, diff --git a/lua/doom/modules/langs/terraform/init.lua b/lua/doom/modules/langs/terraform/init.lua index 18411bad8..bcdd81c83 100644 --- a/lua/doom/modules/langs/terraform/init.lua +++ b/lua/doom/modules/langs/terraform/init.lua @@ -1,28 +1,56 @@ local terraform = {} terraform.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "hcl", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string language_server_name = "terraformls", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type nil + formatting_package = nil, + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.terraform_fmt", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, } +local langs_utils = require("doom.modules.langs.utils") terraform.autocmds = { { "BufWinEnter", "*.hcl,*.tf,*.tfvars,*.nomad", - function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp(doom.langs.terraform.settings.language_server_name) + langs_utils.wrap_language_setup("terraform", function() + if not terraform.settings.disable_lsp then + langs_utils.use_lsp_mason(terraform.settings.language_server_name) + end + + if not terraform.settings.disable_treesitter then + langs_utils.use_tree_sitter(terraform.treesitter_grammars) + end - local ts_install = require("nvim-treesitter.install") - ts_install.ensure_installed("hcl") - -- - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.terraform_fmt, - }) + if not terraform.settings.disable_formatting then + langs_utils.use_null_ls( + terraform.settings.diagnostics_package, + terraform.settings.formatting_provider, + terraform.settings.formatting_config + ) end - end, + end), once = true, }, } diff --git a/lua/doom/modules/langs/toml/init.lua b/lua/doom/modules/langs/toml/init.lua new file mode 100644 index 000000000..b537fcdc5 --- /dev/null +++ b/lua/doom/modules/langs/toml/init.lua @@ -0,0 +1,58 @@ +local typescript = {} + +typescript.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "toml", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "taplo", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "taplo", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.taplo", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, +} + +local langs_utils = require("doom.modules.langs.utils") +typescript.autocmds = { + { + "FileType", + "toml", + langs_utils.wrap_language_setup("toml", function() + if not typescript.settings.disable_lsp then + langs_utils.use_lsp_mason(typescript.settings.language_server_name) + end + + if not typescript.settings.disable_treesitter then + langs_utils.use_tree_sitter(typescript.settings.treesitter_grammars) + end + + if not typescript.settings.disable_formatting then + langs_utils.use_null_ls( + typescript.settings.formatting_package, + typescript.settings.formatting_provider, + typescript.settings.formatting_config + ) + end + end), + once = true, + }, +} + +return typescript diff --git a/lua/doom/modules/langs/typescript/init.lua b/lua/doom/modules/langs/typescript/init.lua index bcf8abf17..61b4c966c 100644 --- a/lua/doom/modules/langs/typescript/init.lua +++ b/lua/doom/modules/langs/typescript/init.lua @@ -1,31 +1,94 @@ -local utils = require("doom.utils") - local typescript = {} -typescript.settings = {} +typescript.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "typescript", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "tsserver", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "eslint_d", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.eslint_d", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "eslint_d", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.eslint_d", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_code_actions = false, + --- Mason.nvim package to auto install the code_actions provider from + --- @type string + code_actions_package = "eslint_d", + --- String to access the null_ls diagnositcs provider + --- @type string + code_actions_provider = "builtins.code_actions.eslint_d", + --- Function to configure null-ls code_actions + --- @type function|nil + code_actions_config = nil, +} +local langs_utils = require("doom.modules.langs.utils") typescript.autocmds = { { "BufWinEnter", - "*.js,*.jsx,*.ts,*.tsx", - utils.make_run_once_function(function() - local langs_utils = require("doom.modules.langs.utils") - langs_utils.use_lsp("tsserver") - - vim.defer_fn(function() - local ts_install = require("nvim-treesitter.install") - ts_install.ensure_installed("typescript", "javascript", "tsx") - end, 0) - - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") - - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.eslint_d, - null_ls.builtins.code_actions.eslint_d, - null_ls.builtins.diagnostics.eslint_d, - }) + "*.js,*.mjs,*.jsx,*.ts,*tsx", + langs_utils.wrap_language_setup("typescript/javascript", function() + if not typescript.settings.disable_lsp then + langs_utils.use_lsp_mason(typescript.settings.language_server_name) + end + + if not typescript.settings.disable_treesitter then + langs_utils.use_tree_sitter(typescript.settings.treesitter_grammars) + end + + if not typescript.settings.disable_formatting then + langs_utils.use_null_ls( + typescript.settings.formatting_package, + typescript.settings.formatting_provider, + typescript.settings.formatting_config + ) + end + if not typescript.settings.disable_diagnostics then + langs_utils.use_null_ls( + typescript.settings.diagnostics_package, + typescript.settings.diagnostics_provider, + typescript.settings.diagnostics_config + ) + end + if not typescript.settings.disable_code_actions then + langs_utils.use_null_ls( + typescript.settings.code_actions_package, + typescript.settings.code_actions_provider, + typescript.settings.code_actions_config + ) end end), once = true, diff --git a/lua/doom/modules/langs/utils.lua b/lua/doom/modules/langs/utils.lua index 3dc698fa1..c5bbe8430 100644 --- a/lua/doom/modules/langs/utils.lua +++ b/lua/doom/modules/langs/utils.lua @@ -4,6 +4,7 @@ local module = {} --- Stores the unique null_ls sources local registered_sources = {} + --- Registers a null_ls source only if it's unique -- @tparam source module.use_null_ls_source = function(sources) @@ -29,7 +30,138 @@ module.use_null_ls_source = function(sources) end end -module.use_lsp = function(lsp_name, options) +--- +---@param package_name string|nil Name of Mason.nvim package to install +---@param null_ls_path string Path of null-ls source i.e. `builtins.formatting.shfmt` +---@param configure_function function|nil optional configure function +---@language lua +--- ```lua +--- -- No mason.nvim package +--- langs_utils.use_null_ls(nil, "builtins.formatting.terrafmt") +--- -- Minimal +--- langs_utils.use_null_ls("stylua", "builtins.formatting.stylua") +--- -- Configure null_ls source +--- langs_utils.use_null_ls("shfmt", "builtins.formatting.shfmt", function(shfmt) +--- return shfmt.with({ +--- extra_args = { "-i", "2", "-ci" }, +--- }) +--- end) +--- ``` +module.use_null_ls = function(package_name, null_ls_path, configure_function) + if doom.features.linter then + -- Check if null-ls is loaded and load it if not. + local ok = pcall(require, "null-ls") + if not ok then + vim.cmd("packadd null-ls.nvim") + end + + local start_null_ls = function() + local null_ls = require("null-ls") + local path = vim.split(null_ls_path, "%.", nil) + if #path ~= 3 then + log.error(("Error setting up null-ls provider `%s`.\n\n null_ls_path should have 3 segments i.e. `builtins.formatting.stylua"):format(null_ls_path)) + end + local provider = null_ls[path[1]][path[2]][path[3]] + + if configure_function then + provider = configure_function(provider) + end + + module.use_null_ls_source({ provider }) + end + + -- If auto_install module is enabled, try to install package before starting + if doom.features.auto_install and package_name ~= nil then + module.use_mason_package(package_name, start_null_ls) + else + vim.defer_fn(function() + start_null_ls() + end, 1) + end + end +end + +--- Default error handler for use_mason_package utility function +---@param package_name string Name of the package that's being installed +---@param err_message string Reason for erroring out of installing mason package +local default_error_handler = function(package_name, err_message) + error(("Error installing mason package `%s`. Reason: %s "):format(package_name, err_message)) +end + +--- Installs a mason package and provides an on-ready handler +---@param package_name string|nil Name of mason.nvim package to install +---@param success_handler function +---@param error_handler function|nil +module.use_mason_package = function(package_name, success_handler, error_handler) + local mason = require("mason-registry") + local on_err = error_handler or default_error_handler + if package_name == nil then + on_err("nil", "No package_name provided.") + return + end + local ok, err = xpcall(function() + local package = mason.get_package(package_name) + if not package:is_installed() then + -- If statusline enabled, push the package to the statusline state + -- So we can provide feedback to user + local statusline = doom.features.statusline + if statusline then + statusline.state.start_mason_package(package_name) + end + + package:install() + package:on("install:success", function(handle) + -- Remove package from statusline state to hide it + if statusline then + statusline.state.finish_mason_package(package_name) + end + vim.schedule(function() + success_handler(handle) + end) + end) + package:on("install:failed", function(pkg) + -- Remove package from statusline state to hide it + if statusline then + statusline.state.finish_mason_package(package_name) + end + local err = "Mason.nvim failed safely. You might be missing the dependencies to install this package." + if (pkg and pkg.stdio and pkg.stdio.buffers and pkg.stdio.buffers.stderr) then + err = err .. "\n \n" + for _, line in ipairs(pkg.stdio.buffers.stderr) do + err = err .. line + end + end + + vim.schedule(function() + on_err(package_name, err) + end) + end) + else + success_handler(package, package.get_handle(package)) + end + end, debug.traceback) + if not ok then + on_err(package_name, "There was an unknown error when trying to install. \n\n" .. err) + end +end + +--- Installs treesitter grammars +---@param grammars string|string[] +--- +---@example +--- ```lua +--- langs_utils.use_tree_sitter("javascript") +--- langs_utils.use_tree_sitter({"c", "cpp"}) +--- ```` +module.use_tree_sitter = function(grammars) + if type(grammars) == "table" then + require("nvim-treesitter.install").ensure_installed(unpack(grammars)) + else + require("nvim-treesitter.install").ensure_installed(grammars) + end +end + +module.use_lsp_mason = function(lsp_name, options) local utils = require("doom.utils") if not utils.is_module_enabled("features", "lsp") then return @@ -64,44 +196,49 @@ module.use_lsp = function(lsp_name, options) } -- Start server and bind to buffers - local start_lsp = function(server) + local start_lsp = function() local final_config = vim.tbl_deep_extend("keep", opts.config or {}, capabilities_config) - if server and not is_custom_config then -- If using lsp-installer - server:setup(final_config) - else - lsp[config_name].setup(final_config) - local lsp_config_server = lsp[config_name] - if lsp_config_server.manager then - local buffer_handler = lsp_config_server.filetypes - and lsp_config_server.manager.try_add_wrapper - or lsp_config_server.manager.try_add - for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do - buffer_handler(bufnr) - end + lsp[config_name].setup(final_config) + local lsp_config_server = lsp[config_name] + if lsp_config_server.manager then + local buffer_handler = lsp_config_server.filetypes + and lsp_config_server.manager.try_add_wrapper + or lsp_config_server.manager.try_add + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do + buffer_handler(bufnr) end end end -- Auto install if possible if utils.is_module_enabled("features", "auto_install") and not opts.no_installer then - local lsp_installer = require("nvim-lsp-installer.servers") - local server_available, server = lsp_installer.get_server(lsp_name) - if server_available then - if not server:is_installed() then - vim.defer_fn(function() - server:install() - end, 50) - end - - server:on_ready(function() - start_lsp(server) - end) - end + local lspconfig_to_package = require("mason-lspconfig.mappings.server").lspconfig_to_package + module.use_mason_package(lspconfig_to_package[lsp_name], start_lsp) else start_lsp() end end +-- module.use_dap = function(config_name, settings) +-- local utils = require("doom.utils") +-- if utils.is_module_enabled("features", "dap") then +-- vim.defer_fn(function() +-- local dap = require("dap") +-- dap.configurations.python = { +-- { +-- type = "python", +-- request = "launch", +-- name = "Launch file", +-- program = "${file}", +-- pythonPath = function() +-- return "/usr/bin/python" +-- end, +-- }, +-- } +-- end) +-- end +-- end + --- Helper to attach illuminate on LSP module.illuminate_attach = function(client) require("illuminate").on_attach(client) @@ -145,4 +282,18 @@ module.get_capabilities = function() return capabilities end +--- Helper to wrap language setup functions with error handling + avoid raceconditions +---@param module_name string Name of module for error logging +---@param setup_fn function Function that sets up this language +---@return function Wrapped setup function +module.wrap_language_setup = function(module_name, setup_fn) + local setup_language = function() + local ok, error = xpcall(setup_fn, debug.traceback) + if not ok then + log.error(("Error setting up language `%s`. \n%s"):format(module_name, error)) + end + end + return setup_language +end + return module diff --git a/lua/doom/modules/langs/vue/init.lua b/lua/doom/modules/langs/vue/init.lua index d3fb3369f..e91dff6bb 100644 --- a/lua/doom/modules/langs/vue/init.lua +++ b/lua/doom/modules/langs/vue/init.lua @@ -1,6 +1,67 @@ local vue = {} vue.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = { + "vue", + "css", + "scss", + "html", + "scss", + "javascript", + "typescript", + }, + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "tsserver", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "eslint_d", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.eslint_d", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "eslint_d", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.eslint_d", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_code_actions = false, + --- Mason.nvim package to auto install the code_actions provider from + --- @type string + code_actions_package = "eslint_d", + --- String to access the null_ls diagnositcs provider + --- @type string + code_actions_provider = "builtins.code_actions.eslint_d", + --- Function to configure null-ls code_actions + --- @type function|nil + code_actions_config = nil, + -- Volar API lspconfig options volar_api = { default_config = { @@ -34,7 +95,7 @@ vue.settings = { default_config = { filetypes = { "vue" }, -- If you want to use Volar's Take Over Mode (if you know, you know): - --filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' }, + --filetypes = { 'vue', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' }, init_options = { languageFeatures = { documentHighlight = true, @@ -52,7 +113,7 @@ vue.settings = { default_config = { filetypes = { "vue" }, -- If you want to use Volar's Take Over Mode (if you know, you know), intentionally no 'json': - --filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, + --filetypes = { 'vue', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, init_options = { documentFeatures = { selectionRange = true, @@ -70,109 +131,115 @@ vue.settings = { }, } -vue.configs = {} - +local langs_utils = require("doom.modules.langs.utils") vue.autocmds = { { - "BufWinEnter", - "*.vue", - function() - local lspconfig_util = require("lspconfig/util") - local langs_utils = require("doom.modules.langs.utils") - - local function get_typescript_server_path(root_dir) - -- Alternative location if installed as root: - -- local global_ts = '/usr/local/lib/node_modules/typescript/lib/tsserverlibrary.js' - local found_ts = "" - local function check_dir(path) - found_ts = lspconfig_util.path.join( - path, - "node_modules", - "typescript", - "lib", - "tsserverlibrary.js" - ) - if lspconfig_util.path.exists(found_ts) then - return path + "FileType", + "vue", + langs_utils.wrap_language_setup("vue", function() + if not vue.settings.disable_lsp then + local lspconfig_util = require("lspconfig/util") + langs_utils.use_lsp_mason(vue.settings.language_server_name) + + local function get_typescript_server_path(root_dir) + -- Alternative location if installed as root: + -- local global_ts = '/usr/local/lib/node_modules/typescript/lib/tsserverlibrary.js' + local found_ts = "" + local function check_dir(path) + found_ts = lspconfig_util.path.join( + path, + "node_modules", + "typescript", + "lib", + "tsserverlibrary.js" + ) + if lspconfig_util.path.exists(found_ts) then + return path + end end + + if lspconfig_util.search_ancestors(root_dir, check_dir) then + return found_ts + end + return "" end - if lspconfig_util.search_ancestors(root_dir, check_dir) then - return found_ts - end - return "" - end - -- volar needs works with typescript server, needs to get the typescript server from the project's node_modules - local function on_new_config(new_config, new_root_dir) - if - new_config.init_options - and new_config.init_options.typescript - and new_config.init_options.typescript.serverPath == "" - then - new_config.init_options.typescript.serverPath = get_typescript_server_path(new_root_dir) + + -- volar needs works with typescript server, needs to get the typescript server from the project's node_modules + local function on_new_config(new_config, new_root_dir) + if + new_config.init_options + and new_config.init_options.typescript + and new_config.init_options.typescript.serverPath == "" + then + new_config.init_options.typescript.serverPath = get_typescript_server_path(new_root_dir) + end end - end - local volar_root_dir = lspconfig_util.root_pattern("package.json") - - -- Contains base configuration necessary for volar to start - local base_config = { - default_config = { - cmd = { "vue-language-server", "--stdio" }, - -- cmd = volar.document_config.default_config.cmd, - root_dir = volar_root_dir, - on_new_config = on_new_config, - init_options = { - typescript = { - serverPath = "", + + local volar_root_dir = lspconfig_util.root_pattern("package.json") + + -- Contains base configuration necessary for volar to start + local base_config = { + default_config = { + cmd = { "vue-language-server", "--stdio" }, + -- cmd = volar.document_config.default_config.cmd, + root_dir = volar_root_dir, + on_new_config = on_new_config, + init_options = { + typescript = { + serverPath = "", + }, }, }, - }, - } - - local volar_api_config = - vim.tbl_deep_extend("force", {}, doom.langs.vue.settings.volar_api, base_config) - langs_utils.use_lsp("volar", { - name = "volar_api", - config = volar_api_config, - }) - - local volar_doc_config = - vim.tbl_deep_extend("force", {}, doom.langs.vue.settings.volar_doc, base_config) - langs_utils.use_lsp("volar", { - name = "volar_doc", - config = volar_doc_config, - }) - - local volar_html_config = - vim.tbl_deep_extend("force", {}, doom.langs.vue.settings.volar_html, base_config) - langs_utils.use_lsp("volar", { - name = "volar_html", - config = volar_html_config, - }) - - vim.defer_fn(function() - local ts_install = require("nvim-treesitter.install") - ts_install.ensure_installed( - "vue", - "css", - "scss", - "html", - "scss", - "javascript", - "typescript" - ) - end, 0) + } - -- Setup null-ls - if doom.features.linter then - local null_ls = require("null-ls") + local volar_api_config = + vim.tbl_deep_extend("force", {}, doom.langs.vue.settings.volar_api, base_config) + langs_utils.use_lsp("volar", { + name = "volar_api", + config = volar_api_config, + }) + + local volar_doc_config = + vim.tbl_deep_extend("force", {}, doom.langs.vue.settings.volar_doc, base_config) + langs_utils.use_lsp("volar", { + name = "volar_doc", + config = volar_doc_config, + }) - langs_utils.use_null_ls_source({ - null_ls.builtins.formatting.eslint_d, - null_ls.builtins.code_actions.eslint_d, - null_ls.builtins.diagnostics.eslint_d, + local volar_html_config = + vim.tbl_deep_extend("force", {}, doom.langs.vue.settings.volar_html, base_config) + langs_utils.use_lsp("volar", { + name = "volar_html", + config = volar_html_config, }) end - end, + + if not vue.settings.disable_treesitter then + langs_utils.use_tree_sitter(vue.settings.treesitter_grammars) + end + + if not vue.settings.disable_formatting then + langs_utils.use_null_ls( + vue.settings.formatting_package, + vue.settings.formatting_provider, + vue.settings.formatting_config + ) + end + if not vue.settings.disable_diagnostics then + langs_utils.use_null_ls( + vue.settings.diagnostics_package, + vue.settings.diagnostics_provider, + vue.settings.diagnostics_config + ) + end + if not vue.settings.disable_code_actions then + langs_utils.use_null_ls( + vue.settings.code_actions_package, + vue.settings.code_actions_provider, + vue.settings.code_actions_config + ) + end + end), once = true, }, } diff --git a/lua/doom/modules/langs/yaml/init.lua b/lua/doom/modules/langs/yaml/init.lua new file mode 100644 index 000000000..a1e135b36 --- /dev/null +++ b/lua/doom/modules/langs/yaml/init.lua @@ -0,0 +1,78 @@ +local yaml = {} + +yaml.settings = { + --- Disables auto installing the treesitter + --- @type boolean + disable_treesitter = false, + --- Treesitter grammars to install + --- @type string|string[] + treesitter_grammars = "yaml", + + --- Disables default LSP config + --- @type boolean + disable_lsp = false, + --- Name of the language server + --- @type string + language_server_name = "tsserver", + + --- Disables null-ls formatting sources + --- @type boolean + disable_formatting = false, + --- Mason.nvim package to auto install the formatter from + --- @type string + formatting_package = "yamlfmt", + --- String to access the null_ls diagnositcs provider + --- @type string + formatting_provider = "builtins.formatting.yamlfmt", + --- Function to configure null-ls formatter + --- @type function|nil + formatting_config = nil, + + --- Disables null-ls diagnostic sources + --- @type boolean + disable_diagnostics = false, + --- Mason.nvim package to auto install the diagnostics provider from + --- @type string + diagnostics_package = "yamllint", + --- String to access the null_ls diagnositcs provider + --- @type string + diagnostics_provider = "builtins.diagnostics.yamllint", + --- Function to configure null-ls diagnostics + --- @type function|nil + diagnostics_config = nil, +} + +local langs_utils = require("doom.modules.langs.utils") +yaml.autocmds = { + { + "FileType", + "yaml", + langs_utils.wrap_language_setup("yaml", function() + if not yaml.settings.disable_lsp then + langs_utils.use_lsp_mason(yaml.settings.language_server_name) + end + + if not yaml.settings.disable_treesitter then + langs_utils.use_tree_sitter(yaml.settings.treesitter_grammars) + end + + if not yaml.settings.disable_formatting then + langs_utils.use_null_ls( + yaml.settings.formatting_package, + yaml.settings.formatting_provider, + yaml.settings.formatting_config + ) + end + if not yaml.settings.disable_diagnostics then + langs_utils.use_null_ls( + yaml.settings.diagnostics_package, + yaml.settings.diagnostics_provider, + yaml.settings.diagnostics_config + ) + end + end), + once = true, + }, +} + +return yaml diff --git a/lua/doom/utils/logging.lua b/lua/doom/utils/logging.lua index d7ef21bda..80717ef2e 100644 --- a/lua/doom/utils/logging.lua +++ b/lua/doom/utils/logging.lua @@ -73,18 +73,8 @@ log.new = function(config, standalone) local console_string = string.format("[%-6s%s] %s: %s", nameupper, os.date("%H:%M:%S"), console_lineinfo, msg) - if config.highlights and level_config.hl then - vim.cmd(string.format("echohl %s", level_config.hl)) - end - - local split_console = vim.split(console_string, "\n") - for _, v in ipairs(split_console) do - vim.cmd(string.format([[echom "[%s] %s"]], config.plugin, vim.fn.escape(v, '"'))) - end - - if config.highlights and level_config.hl then - vim.cmd("echohl NONE") - end + local message = {("[%s] %s"):format(config.plugin, console_string), level_config.hl} + vim.api.nvim_echo({ message }, true, {}) end) local log_at_level = function(level, level_config, message_maker, ...) diff --git a/modules.lua b/modules.lua index 2b7fb673f..e124db9a7 100644 --- a/modules.lua +++ b/modules.lua @@ -64,6 +64,7 @@ return { -- "gdscript", -- "gdscript", -- "php", + -- "ruby", -- Web -- "javascript", @@ -71,18 +72,22 @@ return { -- "css", -- "vue", -- "tailwindcss", + -- "svelte", -- Compiled -- "rust", -- "cc", -- "ocaml", + -- "haskell", -- JIT -- "c_sharp", -- "kotlin", -- "java", - -- "config", -- JSON, YAML, TOML + -- "json", + -- "yaml", + -- "toml", -- "markdown", -- "terraform", -- Terraform / hcl files support -- "dockerfile", diff --git a/tools/install.sh b/tools/install.sh index aaf25de43..fad6e624f 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -95,6 +95,44 @@ function check_dependency_group () { echo " " } +function check_doom_installed() { + doom_backed_up=0 + + if [ -d "${DOOM_CONFIG_DIR}/lua/doom" ]; then + echo "${YELLOW}Warning:$NC Doom nvim is already installed on your system." + echo " " + echo "Do you want to continue installing doom-nvim? (y/n)" + echo "Note: the old config will be backed up to ${XDG_CONFIG_HOME}/doom-nvim-old" + echo "" + read -p "" -n 1 -r + echo " " # (optional) move to a new line + if [[ $REPLY =~ ^[Yy]$ ]]; then + doom_backed_up=1 + # If doom-nvim-old directory doesn't exist, move 'nvim/' to 'doom-nvim-old/' + if [ ! -d "${XDG_CONFIG_HOME}/doom-nvim-old" ]; then + mv "${XDG_CONFIG_HOME}/nvim" "${XDG_CONFIG_HOME}/doom-nvim-old" + echo "Moved old config from \`${XDG_CONFIG_HOME}/nvim\` to \`${XDG_CONFIG_HOME}/doom-nvim-old\`" + else + # If it already exists try placing it in 'doom-nvim-old-1/' then 'doom-nvim-old-2' (up until 10) + local i=1 + local has_found_directory=0 + while [[ $has_found_directory -eq 0 && $i -lt 10 ]]; do + i=$((i+1)) + if [ ! -d "${XDG_CONFIG_HOME}/doom-nvim-old-${i}" ]; then + has_found_directory=1 + fi + done + + if [[ $has_found_directory -eq 1 ]]; then + mv "${XDG_CONFIG_HOME}/nvim" "${XDG_CONFIG_HOME}/doom-nvim-old-${i}" + echo "Moved old config from \`${XDG_CONFIG_HOME}/nvim\` to \`${XDG_CONFIG_HOME}/doom-nvim-old-${i}\`" + fi + fi + fi + fi + echo " " +} + function backup_existing_config() { if [ -d "$DOOM_CONFIG_DIR" ]; then echo "${YELLOW}Warning:$NC There is already a config at $DOOM_CONFIG_DIR." @@ -115,7 +153,9 @@ function backup_existing_config() { local has_found_directory=0 while [[ $has_found_directory -eq 0 && $i -lt 10 ]]; do i=$((i+1)) - has_found_directory=$([ -d "${XDG_CONFIG_HOME}/nvim-old-${i}" ]) + if [ ! -d "${XDG_CONFIG_HOME}/nvim-old-${i}" ]; then + has_found_directory=1 + fi done if [[ $has_found_directory -eq 1 ]]; then @@ -151,7 +191,6 @@ function install_doom_nvim() { echo "${GREEN}Installed doom-nvim!" echo "${YELLOW}Warn: Could not checkout latest tag due to uncommitted changes. \`:DoomUpdate\` command may not work." fi - } function main() { @@ -160,7 +199,12 @@ function main() { check_dependency_group "system" "Install missing dependencies using your operating system's package manager (brew/pacman/apt-get/dnf/...)." "${system_dependencies[@]}" check_dependency_group "npm" "Install missing dependencies using npm/yarn/pnpm." "${npm_dependencies[@]}" - backup_existing_config + check_doom_installed + + if [ $doom_backed_up -eq 0 ]; then + backup_existing_config + fi + install_doom_nvim echo "Run \`nvim\` in your terminal to start doom-nvim."