From 14edeb2713cb3c392d0b3febee7cab352ebd00c2 Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Wed, 5 Feb 2025 16:00:57 +0100 Subject: [PATCH] Add autocommand to run just on :make when justfile is present and add ccls --- lua/commands.lua | 15 ++++++++++++++- lua/plugins/lsp.lua | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lua/commands.lua b/lua/commands.lua index 5ee0ada..c809dc4 100644 --- a/lua/commands.lua +++ b/lua/commands.lua @@ -9,7 +9,7 @@ vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] vim.cmd 'command W :execute \':silent w !sudo tee % > /dev/null\' | :edit!' -- Array of file names indicating root directory. Modify to your liking. -local root_names = { '.git', 'Makefile' } +local root_names = { '.git', 'Makefile', 'justfile' } -- Cache to use for speed up (at cost of possibly outdated results) local root_cache = {} @@ -35,3 +35,16 @@ end local root_augroup = vim.api.nvim_create_augroup('MyAutoRoot', {}) vim.api.nvim_create_autocmd('BufEnter', { group = root_augroup, callback = set_root }) + +local function set_makeprg() + local cwd = vim.fn.getcwd() + + if vim.fn.filereadable(cwd .. '/justfile') == 1 then + vim.o.makeprg = 'just' + elseif vim.fn.filereadable(cwd .. '/Makefile') == 1 then + vim.o.makeprg = 'make' + end +end + +local makeprg_augroup = vim.api.nvim_create_augroup('MyMakeprg', {}) +vim.api.nvim_create_autocmd('BufEnter', { pattern = '*', group = makeprg_augroup, callback = set_makeprg, }) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index b0b19dd..0c2ee62 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -50,6 +50,10 @@ return { { 'williamboman/mason-lspconfig.nvim', config = true + --config = function() + -- ensure_installed = { "lua_ls", "ts_ls", "gopls", "rust_analyzer", "bashls", "sqlls", "html", "cssls", + -- "tailwindcss", "phpactor", "julials", "glsl_analyzer", "wgsl_analyzer", "emmet_language_server", "zls" } + --end }, { 'neovim/nvim-lspconfig', @@ -152,6 +156,10 @@ return { variables = {}, }, }) + lspconfig.ccls.setup { + capabilities = capabilities, + on_attach = lsp_attach, + } end }, {