From ead16ef1729f46ade2a7161778e23cf37d223edb Mon Sep 17 00:00:00 2001 From: Zacharias-Brohn Date: Wed, 10 Dec 2025 18:42:52 +0100 Subject: [PATCH] neoformat --- .prettierrc | 14 +++++ .stylua.toml | 6 +- init.lua | 47 +++++++-------- lua/autocmd.lua | 20 +++--- lua/config/lspconfig.lua | 124 +++++++++++++++++++++----------------- lua/config/null-ls.lua | 32 ++++++++++ lua/config/prettier.lua | 19 ++++++ lua/plugins/init.lua | 91 ++++++++++++++++------------ lua/plugins/neoformat.vim | 14 +++++ 9 files changed, 236 insertions(+), 131 deletions(-) create mode 100644 .prettierrc create mode 100644 lua/config/null-ls.lua create mode 100644 lua/config/prettier.lua create mode 100644 lua/plugins/neoformat.vim diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..3e0813d --- /dev/null +++ b/.prettierrc @@ -0,0 +1,14 @@ +{ + "trailingComma": "es5", + "tabWidth": 4, + "semi": false, + "singleQuote": true, + "overrides": [ + { + "files": ".prettierrc", + "options": { + "parser": "json" + } + } + ] +} diff --git a/.stylua.toml b/.stylua.toml index ecb6dca..91aa655 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -1,6 +1,6 @@ -column_width = 120 +column_width = 80 line_endings = "Unix" -indent_type = "Spaces" -indent_width = 2 +indent_type = "Tabs" +indent_width = 4 quote_style = "AutoPreferDouble" call_parentheses = "None" diff --git a/init.lua b/init.lua index 91d0e76..6578a64 100644 --- a/init.lua +++ b/init.lua @@ -1,44 +1,41 @@ if vim.env.PROF then - local snacks = vim.fn.stdpath("data") .. "/lazy/snacks.nvim" + local snacks = vim.fn.stdpath "data" .. "/lazy/snacks.nvim" - vim.opt.rtp:append( snacks ) - require("snacks.profiler").startup({ + vim.opt.rtp:append(snacks) + require("snacks.profiler").startup { startup = { event = "UIEnter", }, - }) + } end -vim.g.base46_cache = vim.fn.stdpath("data") .. "/base46_cache/" - -local home = os.getenv("HOME") +local home = os.getenv "HOME" package.path = package.path - .. ";" .. home .. "/.luarocks/share/lua/5.4/?.lua" - .. ";" .. home .. "/.luarocks/share/lua/5.4/?/init.lua" + .. ";" + .. home + .. "/.luarocks/share/lua/5.4/?.lua" + .. ";" + .. home + .. "/.luarocks/share/lua/5.4/?/init.lua" -package.cpath = package.cpath - .. ";" .. home .. "/.luarocks/lib/lua/5.4/?.so" +package.cpath = package.cpath .. ";" .. home .. "/.luarocks/lib/lua/5.4/?.so" -vim.cmd('source ' .. vim.fn.stdpath("config") .. "/cursor.vim") -require("config.lazy") -require("options") -require("globals") -require("mappings") -require("autocmd") +vim.cmd("source " .. vim.fn.stdpath "config" .. "/cursor.vim") +require "config.lazy" +require "options" +require "globals" +require "mappings" +require "autocmd" require("minimodules").load_modules() -- require("coc-settings") if vim.g.neovide then - require("config.neovide") + require "config.neovide" end -vim.filetype.add({ +vim.filetype.add { pattern = { [".*/hypr/.*%.conf"] = "hyprlang", [".*/uwsm/env.*"] = "zsh", - } -}) - --- for _, v in ipairs( vim.fn.readdir( vim.g.base46_cache )) do --- dofile( vim.g.base46_cache .. v ) --- end + }, +} diff --git a/lua/autocmd.lua b/lua/autocmd.lua index 7167813..b0d4e41 100644 --- a/lua/autocmd.lua +++ b/lua/autocmd.lua @@ -2,26 +2,28 @@ local autocmd = vim.api.nvim_create_autocmd autocmd("LspAttach", { callback = function(args) - local client = vim.lsp.get_client_by_id( args.data.client_id ) + local client = vim.lsp.get_client_by_id(args.data.client_id) if client then vim.lsp.document_color.enable(false, args.buf, { "background" }) - -- require("workspace-diagnostics").populate_workspace_diagnostics(client, 0) end end, }) autocmd("VimLeave", { - command = "set guicursor=a:ver25-Cursor" + command = "set guicursor=a:ver25-Cursor", }) --- autocmd({ "CursorHold" }, { --- callback = function() --- vim.diagnostic.open_float(nil, { focus = false }) --- end --- }) +autocmd("BufWritePre", { + callback = function() + local ok = pcall(function() + vim.cmd "undojoin" + end) + vim.cmd "Neoformat" + end, +}) autocmd({ "InsertLeave" }, { callback = function() require("lint").try_lint() - end + end, }) diff --git a/lua/config/lspconfig.lua b/lua/config/lspconfig.lua index 10e94ab..bfba1d9 100644 --- a/lua/config/lspconfig.lua +++ b/lua/config/lspconfig.lua @@ -12,46 +12,15 @@ local function flatten_to_array(t) _flatten(t) return res end --- local cmp = require("cmp") --- local cmp_lsp = require("cmp_nvim_lsp") local capabilities = vim.tbl_deep_extend( "force", {}, vim.lsp.protocol.make_client_capabilities() - -- cmp_lsp.default_capabilities() ) -local cmp_kinds = { - Text = ' ', - Method = ' ', - Function = ' ', - Constructor = ' ', - Field = ' ', - Variable = ' ', - Class = ' ', - Interface = ' ', - Module = ' ', - Property = ' ', - Unit = ' ', - Value = ' ', - Enum = ' ', - Keyword = ' ', - Snippet = ' ', - Color = ' ', - File = ' ', - Reference = ' ', - Folder = ' ', - EnumMember = ' ', - Constant = ' ', - Struct = ' ', - Event = ' ', - Operator = ' ', - TypeParameter = ' ', -} - -require("fidget").setup({}) +require("fidget").setup {} require("mason").setup() -require("mason-lspconfig").setup({ +require("mason-lspconfig").setup { automatic_enable = true, ensure_installed = { "lua_ls", @@ -66,24 +35,28 @@ require("mason-lspconfig").setup({ end, ["tailwindcss"] = function() - local lspconfig = require("lspconfig") + local lspconfig = require "lspconfig" lspconfig.tailwindcss.setup { capabilities = capabilities, } end, ["css-lsp"] = function() - local lspconfig = require("lspconfig") + local lspconfig = require "lspconfig" lspconfig.cssls.setup { capabilities = capabilities, } end, zls = function() - local lspconfig = require("lspconfig") - lspconfig.zls.setup({ + local lspconfig = require "lspconfig" + lspconfig.zls.setup { capabilities = capabilities, - root_dir = lspconfig.util.root_pattern(".git", "build.zig", "zls.json"), + root_dir = lspconfig.util.root_pattern( + ".git", + "build.zig", + "zls.json" + ), settings = { zls = { enable_inlay_hints = true, @@ -91,27 +64,33 @@ require("mason-lspconfig").setup({ warn_style = true, }, }, - }) + } vim.g.zig_fmt_parse_errors = 0 vim.g.zig_fmt_autosave = 0 - end, ["lua_ls"] = function() - local lspconfig = require("lspconfig") + local lspconfig = require "lspconfig" lspconfig.lua_ls.setup { capabilities = capabilities, settings = { Lua = { runtime = { version = "Lua 5.1" }, diagnostics = { - globals = { "bit", "vim", "it", "describe", "before_each", "after_each" }, - } - } - } + globals = { + "bit", + "vim", + "it", + "describe", + "before_each", + "after_each", + }, + }, + }, + }, } end, - } -}) + }, +} -- cmp.setup { -- preselect = 'None', @@ -172,7 +151,7 @@ require("mason-lspconfig").setup({ -- }), -- } -vim.diagnostic.config({ +vim.diagnostic.config { -- update_in_insert = true, virtual_text = false, virtual_lines = false, @@ -186,20 +165,32 @@ vim.diagnostic.config({ header = "", prefix = "", }, -}) +} local lspconfig = vim.lsp.config lspconfig("texlab", { cmd = { "texlab" }, filetypes = { "tex", "bib", "plaintex" }, - root_markers = { ".git", ".latexmkrc", "latexmkrc", ".texlabroot", "texlabroot", "Tectonic.toml" }, + root_markers = { + ".git", + ".latexmkrc", + "latexmkrc", + ".texlabroot", + "texlabroot", + "Tectonic.toml", + }, settings = { texlab = { rootDirectory = nil, build = { executable = "latexmk", - args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", "%f" }, + args = { + "-pdf", + "-interaction=nonstopmode", + "-synctex=1", + "%f", + }, onSave = true, forwardSearchAfter = true, }, @@ -207,7 +198,8 @@ lspconfig("texlab", { executable = "zathura", args = { "--synctex-editor-command", - [[ nvim-texlabconfig -file '%%%{input}' -line %%%{line} -server ]] .. vim.v.servername, + [[ nvim-texlabconfig -file '%%%{input}' -line %%%{line} -server ]] + .. vim.v.servername, "--synctex-forward", "%l:1:%f", "%p", @@ -220,7 +212,7 @@ lspconfig("texlab", { diagnosticsDelay = 300, latexFormatter = "latexindent", latexindent = { - ['local'] = nil, + ["local"] = nil, modifyLineBreaks = false, }, bibtexFormatter = "texlab", @@ -233,6 +225,27 @@ lspconfig("qmlls", { cmd = { "qmlls6" }, }) +lspconfig("jsonls", { + settings = { + json = { + schemas = require("schemastore").json.schemas(), + validate = { enable = true }, + }, + }, +}) + +lspconfig("yamlls", { + settings = { + yaml = { + schemaStore = { + enable = false, + url = "", + }, + schemas = require("schemastore").yaml.schemas(), + }, + }, +}) + local lspenable = vim.lsp.enable local servers = { "html", @@ -251,7 +264,10 @@ local flat_servers = flatten_to_array(servers) for _, server in ipairs(flat_servers) do lspconfig(server, { on_attach = function(client, bufnr) - require("workspace-diagnostics").populate_workspace_diagnostics( client, bufnr ) + require("workspace-diagnostics").populate_workspace_diagnostics( + client, + bufnr + ) end, }) lspenable(server) diff --git a/lua/config/null-ls.lua b/lua/config/null-ls.lua new file mode 100644 index 0000000..3113689 --- /dev/null +++ b/lua/config/null-ls.lua @@ -0,0 +1,32 @@ +-- local null_ls = require("null-ls") +-- +-- local group = vim.api.nvim_create_augroup("lsp_format_on_save", { clear = false }) +-- local event = "BufWritePre" -- or "BufWritePost" +-- local async = event == "BufWritePost" +-- +-- null_ls.setup({ +-- on_attach = function(client, bufnr) +-- if client.supports_method("textDocument/formatting") then +-- vim.keymap.set("n", "f", function() +-- vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() }) +-- end, { buffer = bufnr, desc = "[lsp] format" }) +-- +-- -- format on save +-- vim.api.nvim_clear_autocmds({ buffer = bufnr, group = group }) +-- vim.api.nvim_create_autocmd(event, { +-- buffer = bufnr, +-- group = group, +-- callback = function() +-- vim.lsp.buf.format({ bufnr = bufnr, async = async }) +-- end, +-- desc = "[lsp] format on save", +-- }) +-- end +-- +-- if client.supports_method("textDocument/rangeFormatting") then +-- vim.keymap.set("x", "f", function() +-- vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() }) +-- end, { buffer = bufnr, desc = "[lsp] format" }) +-- end +-- end, +-- }) diff --git a/lua/config/prettier.lua b/lua/config/prettier.lua new file mode 100644 index 0000000..d96c585 --- /dev/null +++ b/lua/config/prettier.lua @@ -0,0 +1,19 @@ +local prettier = require("prettier") + +prettier.setup({ + bin = 'prettier', + filetypes = { + "css", + "graphql", + "html", + "javascript", + "javascriptreact", + "json", + "less", + "markdown", + "scss", + "typescript", + "typescriptreact", + "yaml", + }, +}) diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 1a27426..80c59e9 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -1,25 +1,25 @@ return { { - require("plugins.colorschemes") + require "plugins.colorschemes", }, { "nvim-mini/mini.nvim", version = false, modules = function() - require("config.mini-modules") + require "config.mini-modules" end, }, { "nvim-treesitter/nvim-treesitter", config = function() - require("config.treesitter") + require "config.treesitter" end, }, { "rmagatti/auto-session", config = function() - require("config.autosession") + require "config.autosession" end, }, { @@ -28,7 +28,7 @@ return { "nvim-lua/plenary.nvim", }, config = function() - require("config.telescope") + require "config.telescope" end, }, { @@ -44,26 +44,26 @@ return { "akinsho/bufferline.nvim", event = "VeryLazy", config = function() - require("config.barbar") + require "config.barbar" end, }, { "nvim-lualine/lualine.nvim", event = "VeryLazy", - config = function () - require("config.lualine") + config = function() + require "config.lualine" end, }, { "mawkler/modicator.nvim", config = function() - require("config.modicator") - end + require "config.modicator" + end, }, { "jiaoshijie/undotree", config = function() - require("config.undotree") + require "config.undotree" end, }, { @@ -74,7 +74,7 @@ return { "windwp/nvim-autopairs", event = "InsertEnter", config = function() - require("config.autopairs") + require "config.autopairs" end, }, { @@ -109,17 +109,17 @@ return { { "mfussenegger/nvim-dap", config = function() - require("config.dapconf") + require "config.dapconf" end, }, { - require("config.snacks") + require "config.snacks", }, { "folke/lazydev.nvim", ft = "lua", opts = function() - require("config.lazydev") + require "config.lazydev" end, }, { @@ -131,20 +131,21 @@ return { "L3MON4D3/LuaSnip", -- "saadparwaiz1/cmp_luasnip", "j-hui/fidget.nvim", + "b0o/schemastore.nvim", }, config = function() - require("config.lspconfig") + require "config.lspconfig" end, }, - -- { - -- "smolck/command-completion.nvim", - -- opts = { - -- border = nil, - -- highlight_selection = true, - -- use_matchfuzzy = true, - -- tab_completion = true, - -- }, - -- }, + { + "smolck/command-completion.nvim", + opts = { + border = nil, + highlight_selection = true, + use_matchfuzzy = true, + tab_completion = true, + }, + }, { "andweeb/presence.nvim", }, @@ -158,7 +159,7 @@ return { "nvim-lua/plenary.nvim", }, config = function() - require("config.harpoon") + require "config.harpoon" end, }, -- { @@ -180,7 +181,7 @@ return { { "f3fora/nvim-texlabconfig", config = function() - require("config.texlab") + require "config.texlab" end, build = "go build", }, @@ -199,7 +200,7 @@ return { { "ThePrimeagen/refactoring.nvim", config = function() - require("config.refactoring") + require "config.refactoring" end, }, { @@ -226,27 +227,27 @@ return { }, }, opts = { - picker_opts = require("telescope.themes").get_dropdown({ + picker_opts = require("telescope.themes").get_dropdown { enable_preview = true, - }), - } + }, + }, }, { "aznhe21/actions-preview.nvim", config = function() - require("config.actions-preview") + require "config.actions-preview" end, }, { "mfussenegger/nvim-lint", config = function() - require("config.lint") + require "config.lint" end, }, { "rachartier/tiny-inline-diagnostic.nvim", config = function() - require("config.TID") + require "config.TID" end, }, { @@ -256,27 +257,37 @@ return { "artemave/workspace-diagnostics.nvim", }, { - require("config.dev-tools") + require "config.dev-tools", }, { "Fildo7525/pretty_hover", event = "LspAttach", - opts = {} + opts = {}, }, { "knubie/vim-kitty-navigator", - build = "cp ./*.py ~/.config/kitty/" + build = "cp ./*.py ~/.config/kitty/", }, { - require("config.dropbar") + require "config.dropbar", }, { - require("config.blink") + require "config.blink", }, { "lewis6991/gitsigns.nvim", config = function() - require("config.gitsigns") + require "config.gitsigns" + end, + }, + { + "sbdchd/neoformat", + init = function() + vim.cmd( + "source " + .. vim.fn.stdpath "config" + .. "/lua/plugins/neoformat.vim" + ) end, }, } diff --git a/lua/plugins/neoformat.vim b/lua/plugins/neoformat.vim new file mode 100644 index 0000000..e75b126 --- /dev/null +++ b/lua/plugins/neoformat.vim @@ -0,0 +1,14 @@ +let g:neoformat_enabled_python = ['autopep8'] +let g:neoformat_enabled_javascript = ['prettier'] +let g:neoformat_enabled_html = ['prettier'] +let g:neoformat_enabled_css = ['prettier'] +let g:neoformat_enabled_json = ['prettier'] +let g:neoformat_enabled_yaml = ['prettier'] +let g:neoformat_enabled_lua = ['stylua'] +let g:neoformat_enabled_rust = ['rustfmt'] +let g:neoformat_enabled_cpp = ['uncrustify'] +let g:neoformat_enabled_markdown = ['prettier'] + +let g:neoformat_basic_format_align = 1 +let g:neoformat_basic_format_retab = 1 +let g:neoformat_basic_format_trim = 1