diff --git a/lua/configs/conform.lua b/lua/configs/conform.lua index 35ba6cf..046975d 100644 --- a/lua/configs/conform.lua +++ b/lua/configs/conform.lua @@ -1,15 +1,64 @@ -local options = { - formatters_by_ft = { - lua = { "stylua" }, - -- css = { "prettier" }, - -- html = { "prettier" }, - }, +----------------------------------------------------------- +-- Conform.nvim Formatter Configuration +----------------------------------------------------------- - -- format_on_save = { - -- -- These options will be passed to conform.format() - -- timeout_ms = 500, - -- lsp_fallback = true, - -- }, +local options = { + -- Disable LSP formatting fallback + lsp_fallback = false, + + ----------------------------------------------------------- + -- Formatter Assignments by File Type + ----------------------------------------------------------- + formatters_by_ft = { + -- Lua + lua = { "stylua" }, + + -- Web Development + javascript = { "prettierd", "prettier", stop_after_first = true }, + typescript = { "prettierd", "prettier", stop_after_first = true }, + typescriptreact = { "prettierd", "prettier", stop_after_first = true }, + astro = { "prettierd", "prettier", stop_after_first = true }, + svelte = { "prettierd", "prettier", stop_after_first = true }, + html = { "prettierd", "prettier", stop_after_first = true }, + css = { "prettierd", "prettier", stop_after_first = true }, + json = { "prettierd" }, + yml = { "prettierd", "prettier", stop_after_first = true }, + toml = { "prettierd", "prettier", stop_after_first = true }, + + -- Systems Programming + rust = { "rustfmt" }, + c = { "clangformat" }, + cpp = { "clangformat" }, + + -- Shell and Configuration + sh = { "shfmt" }, + nix = { "nixpkgsfmt" }, + }, + + ----------------------------------------------------------- + -- Custom Formatter Configurations + ----------------------------------------------------------- + formatters = { + -- Nix formatter configuration + nixpkgsfmt = { + command = "nixpkgs-fmt", + args = {}, + }, + + -- C/C++ formatter configuration + clangformat = { + inherit = false, + command = "clang-format", + }, + }, + + ----------------------------------------------------------- + -- Format on Save Settings + ----------------------------------------------------------- + format_on_save = { + timeout_ms = 2500, -- Maximum time to wait for formatting + lsp_fallback = false, -- Don't fallback to LSP formatting + }, } -return options +return options \ No newline at end of file diff --git a/lua/configs/lspconfig.lua b/lua/configs/lspconfig.lua index 478df01..e165728 100644 --- a/lua/configs/lspconfig.lua +++ b/lua/configs/lspconfig.lua @@ -1,24 +1,101 @@ --- load defaults i.e lua_lsp +----------------------------------------------------------- +-- LSP Configuration +----------------------------------------------------------- + +-- Load NvChad LSP defaults require("nvchad.configs.lspconfig").defaults() -local lspconfig = require "lspconfig" +local lspconfig = require("lspconfig") +local nvlsp = require("nvchad.configs.lspconfig") --- EXAMPLE -local servers = { "html", "cssls" } -local nvlsp = require "nvchad.configs.lspconfig" +----------------------------------------------------------- +-- Language Server Configurations +----------------------------------------------------------- --- lsps with default config -for _, lsp in ipairs(servers) do - lspconfig[lsp].setup { - on_attach = nvlsp.on_attach, - on_init = nvlsp.on_init, - capabilities = nvlsp.capabilities, - } -end +local servers = { + ----------------------------------------------------------- + -- Web Development + ----------------------------------------------------------- + -- HTML & CSS + emmet_language_server = {}, + html = {}, + cssls = {}, + + -- JavaScript & Frameworks + svelte = {}, + astro = {}, + + -- Tailwind CSS + tailwindcss = { + settings = { + tailwindCSS = { + experimental = { + classRegex = { + { "cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]" }, + { "cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)" }, + { "cn\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)" }, + }, + }, + }, + }, + }, + + -- JSON & Linting + jsonls = {}, + eslint = {}, --- configuring single server, example: typescript --- lspconfig.ts_ls.setup { --- on_attach = nvlsp.on_attach, --- on_init = nvlsp.on_init, --- capabilities = nvlsp.capabilities, --- } + ----------------------------------------------------------- + -- DevOps & Infrastructure + ----------------------------------------------------------- + -- Docker + docker_compose_language_service = {}, + dockerls = {}, + + -- Server Configuration + nginx_language_server = {}, + + ----------------------------------------------------------- + -- Systems Programming + ----------------------------------------------------------- + -- Rust + rust_analyzer = {}, + + -- C/C++ + clangd = {}, + + -- Go + gopls = {}, + + ----------------------------------------------------------- + -- Scripting & Configuration + ----------------------------------------------------------- + -- Lua + lua_ls = {}, + + -- Nix + nixd = {}, + + -- C# (currently disabled) + -- csharp_ls = {}, + + ----------------------------------------------------------- + -- Database & Backend + ----------------------------------------------------------- + -- SQL + sqls = {}, + + -- PHP + phpactor = {}, +} + +----------------------------------------------------------- +-- Apply Server Configurations +----------------------------------------------------------- + +-- Iterate through servers and apply common configuration +for name, opts in pairs(servers) do + opts.on_init = nvlsp.on_init + opts.on_attach = nvlsp.on_attach + opts.capabilities = nvlsp.capabilities + lspconfig[name].setup(opts) +end \ No newline at end of file diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 71e5ada..f4425b2 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -1,16 +1,9 @@ return { - { - "stevearc/conform.nvim", - -- event = 'BufWritePre', -- uncomment for format on save - opts = require "configs.conform", - }, - { "charludo/projectmgr.nvim", lazy = false, -- Required for proper functionality }, - -- These are some examples, uncomment them if you want to see them work! { "neovim/nvim-lspconfig", config = function() @@ -19,33 +12,9 @@ return { }, { - "neovim/nvim-lspconfig", - dependencies = { - -- Installer for language servers - "williamboman/mason.nvim", - "williamboman/mason-lspconfig.nvim", - }, - config = function() - require("mason").setup() - require("mason-lspconfig").setup({ - ensure_installed = { - "lua_ls", -- Lua - "gopls", -- Go - "tsserver", -- JavaScript/TypeScript - }, - }) - - local lspconfig = require("lspconfig") - - -- Lua Language Server - lspconfig.lua_ls.setup {} - - -- Go Language Server - lspconfig.gopls.setup {} - - -- JavaScript/TypeScript Language Server - lspconfig.tsserver.setup {} - end, + "stevearc/conform.nvim", + event = "BufWritePre", + opts = require "configs.conform", }, -- Supermaven