From 99b50d56dd1031621e256dbcda09c0836910dbf5 Mon Sep 17 00:00:00 2001 From: joshashtondev Date: Fri, 6 Nov 2026 18:57:22 -0700 Subject: [PATCH] =?UTF-8?q?nixos:=20gen=20131=20@=20lilac=20=E2=80=94=2020?= =?UTF-8?q?26-11-06=2018:57=2026.05.20261105.c56a87d=20(Yarara)=20-----?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- home/programs/nvim.nix | 137 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 2 deletions(-) diff --git a/home/programs/nvim.nix b/home/programs/nvim.nix index d1cdc3b..d6c45ad 100644 --- a/home/programs/nvim.nix +++ b/home/programs/nvim.nix @@ -151,7 +151,10 @@ in -- started per buffer. Indent is deliberately left alone so treesitter -- doesn't fight the Eclipse-matching tab settings below. vim.api.nvim_create_autocmd("FileType", { - pattern = { "java", "xml", "nix", "lua", "rs", "go", "gomod" }, + pattern = { + "java", "xml", "nix", "lua", "rs", "go", "gomod", + "php", "sql", "html", "css", "scss", "javascript", + }, callback = function(args) pcall(vim.treesitter.start, args.buf) end, @@ -179,6 +182,17 @@ in end, }) + -- PHP indentation must match PSR-12 (php-cs-fixer): 4 spaces. + vim.api.nvim_create_autocmd("FileType", { + pattern = "php", + callback = function() + vim.bo.expandtab = true + vim.bo.tabstop = 4 + vim.bo.shiftwidth = 4 + vim.bo.softtabstop = 4 + end, + }) + local cmp = require("cmp") local luasnip = require("luasnip") cmp.setup({ @@ -305,6 +319,123 @@ in end, }) + -- PHP / SQL / HTML / CSS / JS: same approach as Go above. Every server + -- and tool is resolved from PATH, so the project's flake devShell / + -- direnv provides them (launch Neovim from inside that environment). + local function web_attach(_, bufnr) + local map = function(k, f) vim.keymap.set("n", k, f, { buffer = bufnr, silent = true }) end + map("gd", vim.lsp.buf.definition) + map("gr", vim.lsp.buf.references) + map("K", vim.lsp.buf.hover) + map("rn", vim.lsp.buf.rename) + map("ca", vim.lsp.buf.code_action) + -- conform runs php-cs-fixer / prettierd / sqlfluff, falling back to the LSP. + map("f", function() + require("conform").format({ async = true, lsp_format = "fallback" }) + end) + end + + vim.lsp.config("phpactor", { + cmd = { "phpactor", "language-server" }, + filetypes = { "php" }, + root_markers = { "composer.json", ".phpactor.json", ".phpactor.yml", ".git" }, + capabilities = capabilities, + on_attach = web_attach, + }) + + -- sqls only gives real results once a connection is defined in its + -- config.yml (the root marker below); without one it attaches but is quiet. + vim.lsp.config("sqls", { + cmd = { "sqls" }, + filetypes = { "sql", "mysql" }, + root_markers = { "config.yml", ".git" }, + capabilities = capabilities, + on_attach = web_attach, + }) + + vim.lsp.config("html", { + cmd = { "vscode-html-language-server", "--stdio" }, + filetypes = { "html", "templ" }, + root_markers = { "package.json", ".git" }, + capabilities = capabilities, + init_options = { + provideFormatter = true, + embeddedLanguages = { css = true, javascript = true }, + configurationSection = { "html", "css", "javascript" }, + }, + on_attach = web_attach, + }) + + vim.lsp.config("cssls", { + cmd = { "vscode-css-language-server", "--stdio" }, + filetypes = { "css", "scss", "less" }, + root_markers = { "package.json", ".git" }, + capabilities = capabilities, + init_options = { provideFormatter = true }, + settings = { + css = { validate = true }, + scss = { validate = true }, + less = { validate = true }, + }, + on_attach = web_attach, + }) + + vim.lsp.config("ts_ls", { + cmd = { "typescript-language-server", "--stdio" }, + filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact" }, + root_markers = { "tsconfig.json", "jsconfig.json", "package.json", ".git" }, + capabilities = capabilities, + init_options = { hostInfo = "neovim" }, + on_attach = web_attach, + }) + + vim.lsp.config("emmet_ls", { + cmd = { "emmet-ls", "--stdio" }, + filetypes = { "html", "css", "scss", "less", "javascriptreact", "typescriptreact", "php" }, + root_markers = { ".git" }, + capabilities = capabilities, + }) + + vim.lsp.enable({ "phpactor", "sqls", "html", "cssls", "ts_ls", "emmet_ls" }) + + -- Linters (diagnostics): run on open and save. phpstan can be slow on + -- big projects, so it is deliberately not run on every keystroke. + -- sqlfluff needs a dialect, set it in a project .sqlfluff file. + local lint = require("lint") + lint.linters_by_ft = { + php = { "phpstan", "phpcs" }, + sql = { "sqlfluff" }, + css = { "stylelint" }, + scss = { "stylelint" }, + less = { "stylelint" }, + javascript = { "eslint_d" }, + javascriptreact = { "eslint_d" }, + typescript = { "eslint_d" }, + typescriptreact = { "eslint_d" }, + } + vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost" }, { + callback = function() + lint.try_lint() + end, + }) + + -- Formatters (f via web_attach). + require("conform").setup({ + formatters_by_ft = { + php = { "php_cs_fixer" }, + sql = { "sqlfluff" }, + html = { "prettierd" }, + css = { "prettierd" }, + scss = { "prettierd" }, + less = { "prettierd" }, + javascript = { "prettierd" }, + javascriptreact = { "prettierd" }, + typescript = { "prettierd" }, + typescriptreact = { "prettierd" }, + json = { "prettierd" }, + }, + }) + local bundles = vim.fn.glob( "${javaDebug}/share/vscode/extensions/vscjava.vscode-java-debug/server/com.microsoft.java.debug.plugin-*.jar", true, true) @@ -459,7 +590,9 @@ in { plugin = luasnip; } { plugin = cmp_luasnip; } { plugin = rustaceanvim; } - { plugin = (nvim-treesitter.withPlugins (p: [ p.java p.xml p.nix p.lua p.rust p.go p.gomod ])); } + { plugin = nvim-lint; } + { plugin = conform-nvim; } + { plugin = (nvim-treesitter.withPlugins (p: [ p.java p.xml p.nix p.lua p.rust p.go p.gomod p.php p.sql p.html p.css p.javascript ])); } { plugin = vim-obsession; } ];