From b25c9186b9cd7766c50962d7e024bca951a0fd5a Mon Sep 17 00:00:00 2001 From: Taken Date: Sat, 7 Sep 2024 00:19:24 +0200 Subject: [PATCH] Updated config Added conform to replace null-ls --- lua/taken/core/remaps.lua | 6 ----- lua/taken/plugins/conform.lua | 38 ++++++++++++++++++++++++++++++ lua/taken/plugins/lsp/mason.lua | 18 +++++++++++--- lua/taken/plugins/lsp/null-ls.lua | 2 +- lua/taken/plugins/lsp/ts-tools.lua | 15 ------------ lua/taken/plugins/nvim-cmp.lua | 8 +++++++ 6 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 lua/taken/plugins/conform.lua diff --git a/lua/taken/core/remaps.lua b/lua/taken/core/remaps.lua index d56c5bc..8ae8355 100644 --- a/lua/taken/core/remaps.lua +++ b/lua/taken/core/remaps.lua @@ -18,12 +18,6 @@ local M = { ["0"] = { "0", desc = "Go to true line beggining" }, ["q"] = { ":noh", desc = "Clear highlights" }, -- buffer - ["bf"] = { - function() - vim.lsp.buf.format({ async = false }) - end, - desc = "Format buffer", - }, ["bs"] = { ":write ", desc = "Save buffer" }, [""] = { "cnextzz" }, [""] = { "cprevzz" }, diff --git a/lua/taken/plugins/conform.lua b/lua/taken/plugins/conform.lua new file mode 100644 index 0000000..df39f7a --- /dev/null +++ b/lua/taken/plugins/conform.lua @@ -0,0 +1,38 @@ +return { + "stevearc/conform.nvim", + event = { "BufReadPre", "BufNewFile" }, + config = function() + require("conform").setup({ + formatters_by_ft = { + lua = { "stylua" }, + javascript = { "dprint" }, + typescript = { "dprint" }, + json = { "dprint" }, + markdown = { "dprint" }, + }, + format_on_save = { + timeout_ms = 500, + lsp_format = "fallback", + }, + }) + + vim.api.nvim_create_user_command("Format", function(args) + local range = nil + if args.count ~= -1 then + local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1] + range = { + start = { args.line1, 0 }, + ["end"] = { args.line2, end_line:len() }, + } + end + require("conform").format({ async = true, lsp_format = "fallback", range = range }) + end, { range = true }) + + vim.api.nvim_set_keymap( + "n", + "bf", + "Format", + { noremap = true, silent = true, desc = "Format buffer" } + ) + end, +} diff --git a/lua/taken/plugins/lsp/mason.lua b/lua/taken/plugins/lsp/mason.lua index 1a8be25..fb06cf2 100644 --- a/lua/taken/plugins/lsp/mason.lua +++ b/lua/taken/plugins/lsp/mason.lua @@ -3,12 +3,14 @@ return { "williamboman/mason.nvim", dependencies = { "williamboman/mason-lspconfig.nvim", - "jayp0521/mason-null-ls.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", + -- "jayp0521/mason-null-ls.nvim", }, config = function() local mason = require("mason") local mason_lspconfig = require("mason-lspconfig") - local mason_null_ls = require("mason-null-ls") + local mason_tool_installer = require("mason-tool-installer") + -- local mason_null_ls = require("mason-null-ls") mason.setup({ ui = { @@ -36,12 +38,22 @@ return { automatic_installation = true, }) - mason_null_ls.setup({ + mason_tool_installer.setup({ ensure_installed = { "stylua", "prettier", + "dprint", }, automatic_installation = true, }) + + -- mason_null_ls.setup({ + -- ensure_installed = { + -- "stylua", + -- "prettier", + -- "dprint", + -- }, + -- automatic_installation = true, + -- }) end, } diff --git a/lua/taken/plugins/lsp/null-ls.lua b/lua/taken/plugins/lsp/null-ls.lua index 8dfd744..6de0f05 100644 --- a/lua/taken/plugins/lsp/null-ls.lua +++ b/lua/taken/plugins/lsp/null-ls.lua @@ -2,12 +2,12 @@ return { "nvimtools/none-ls.nvim", event = { "BufReadPre", "BufNewFile" }, + enabled = false, config = function() local null_ls = require("null-ls") local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) local formatting = null_ls.builtins.formatting - local diagnostics = null_ls.builtins.diagnostics local root_has_file = function(files) return function(utils) diff --git a/lua/taken/plugins/lsp/ts-tools.lua b/lua/taken/plugins/lsp/ts-tools.lua index df03190..a077b90 100644 --- a/lua/taken/plugins/lsp/ts-tools.lua +++ b/lua/taken/plugins/lsp/ts-tools.lua @@ -15,7 +15,6 @@ return { local on_attach = require("taken.utils.on_attach") local capabilities = cmp_nvim_lsp.default_capabilities() - local augroup = vim.api.nvim_create_augroup("Typescript_tools", {}) local cwd = vim.fn.getcwd() local tsserver_path = cwd .. "/node_modules/.bin/tsserver" @@ -26,7 +25,6 @@ return { else cmd = "typescript-language-server" end - local prettier_config = vim.fn.glob(cwd .. "/*prettierrc*", false, true) typescript_tools.setup({ capabilities = capabilities, @@ -35,19 +33,6 @@ return { if cmd == "typescript-language-server" then print("Using global tsserver") end - if prettier_config == "" then - print("Using prettier to format") - return - else - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - vim.lsp.buf.format({ async = false }) - end, - }) - end end, settings = { cmd = { cmd, "--stdio" }, diff --git a/lua/taken/plugins/nvim-cmp.lua b/lua/taken/plugins/nvim-cmp.lua index 3da7d72..e7447db 100644 --- a/lua/taken/plugins/nvim-cmp.lua +++ b/lua/taken/plugins/nvim-cmp.lua @@ -74,6 +74,14 @@ return { }, }) + cmp.setup({ + window = { + completion = { + scrollbar = false, + }, + }, + }) + vim.keymap.set({ "i", "s" }, "", function() luasnip.jump(1) end, { silent = true })