diff --git a/bash/default.nix b/bash/default.nix index 4d985de..de170fe 100644 --- a/bash/default.nix +++ b/bash/default.nix @@ -6,6 +6,7 @@ shellAliases = { grep = "grep --color"; ssh = "TERM=xterm-256color ssh"; + flush_dns = "sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder"; }; profileExtra = '' SHELL="$BASH" diff --git a/nvim/config/lua/lsp-config.lua b/nvim/config/lua/lsp-config.lua index ce6d931..04d79f1 100644 --- a/nvim/config/lua/lsp-config.lua +++ b/nvim/config/lua/lsp-config.lua @@ -12,7 +12,9 @@ local on_attach = function(client, bufnr) vim.api.nvim_create_autocmd("BufWritePre", { group = augroup, buffer = bufnr, - callback = function() vim.lsp.buf.format({async = false}) end + callback = function() + vim.lsp.buf.format({async = false, timeout_ms = 2000}) + end }) end @@ -24,8 +26,9 @@ local on_attach = function(client, bufnr) vim.keymap.set('n', 'ln', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', 'lr', vim.lsp.buf.references, bufopts) vim.keymap.set('n', 'lt', vim.lsp.buf.type_definition, bufopts) - vim.keymap.set('n', 'lf', - function() vim.lsp.buf.format {async = true} end, bufopts) + vim.keymap.set('n', 'lf', function() + vim.lsp.buf.format {async = true, timeout_ms = 2000} + end, bufopts) end local on_attach_no_formatting = function(client, bufnr) @@ -138,49 +141,33 @@ nvim_lsp.golangci_lint_ls.setup { ------------------------------------------------------ local null_ls = require("null-ls") -local function has_file_in_parents(current_dir, file_pattern) - -- Check if directory has file pattern - local function has_file(dir) - local handle = vim.loop.fs_scandir(dir) - if handle then - while true do - local name, type = vim.loop.fs_scandir_next(handle) - if not name then break end - if type == "file" and name:match(file_pattern) then - return true - end - end - end - return false - end +local eslintFiles = { + '.eslintrc', '.eslintrc.js', '.eslintrc.cjs', '.eslintrc.yaml', + '.eslintrc.yml', '.eslintrc.json', 'eslint.config.js', 'eslint.config.mjs', + 'eslint.config.cjs', 'eslint.config.ts', 'eslint.config.mts', + 'eslint.config.cts' +} - -- Continously walk upwards - while true do - if has_file(current_dir) then return true end - local parent_dir = vim.fn.fnamemodify(current_dir, ":h") - if parent_dir == current_dir then break end - current_dir = parent_dir - end +has_eslint_in_parents = function(fname) + root_file = nvim_lsp.util.insert_package_json(eslintFiles, 'eslintConfig', + fname) + return nvim_lsp.util.root_pattern(unpack(root_file))(fname) - -- No match found - return false -end - -null_ls.setup({ +end, null_ls.setup({ sources = { -- Prettier Formatting null_ls.builtins.formatting.prettier.with({ condition = function(utils) - return not has_file_in_parents(vim.fn.getcwd(), "^%.eslintrc%.") + return not has_eslint_in_parents(vim.fn.getcwd()) end }), -- ESLint Diagnostics & Formatting null_ls.builtins.diagnostics.eslint_d.with({ condition = function(utils) - return has_file_in_parents(vim.fn.getcwd(), "^%.eslintrc%.") + return has_eslint_in_parents(vim.fn.getcwd()) end }), null_ls.builtins.formatting.eslint_d.with({ condition = function(utils) - return has_file_in_parents(vim.fn.getcwd(), "^%.eslintrc%.") + return has_eslint_in_parents(vim.fn.getcwd()) end }), null_ls.builtins.formatting.djlint.with({filetypes = {"template"}}), null_ls.builtins.completion.spell, @@ -196,7 +183,7 @@ null_ls.setup({ group = augroup, buffer = bufnr, callback = function() - vim.lsp.buf.format({async = false}) + vim.lsp.buf.format({async = false, timeout_ms = 2000}) end }) end