From af21c78d942b3a57df07ff792c7cba43c545be3b Mon Sep 17 00:00:00 2001 From: Pgolik Date: Mon, 16 Dec 2024 07:44:33 +0100 Subject: [PATCH] Add files via upload --- init.lua | 47 ++++++++++++++++------------------ lua/custom/autocommands.lua | 10 ++++++++ lua/custom/keymap.lua | 3 +++ lua/kickstart/plugins/lint.lua | 2 +- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/init.lua b/init.lua index b26cdfb5..d8fa26dd 100644 --- a/init.lua +++ b/init.lua @@ -477,15 +477,6 @@ require('lazy').setup({ local servers = { clangd = {}, -- gopls = {}, - ruff = { - trace = 'messages', - on_attach = on_attach, - init_options = { - settings = { - logLevel = 'info', - }, - }, - }, -- rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- @@ -493,7 +484,7 @@ require('lazy').setup({ -- https://github.com/pmizio/typescript-tools.nvim -- -- But for many setups, the LSP (`tsserver`) will work just fine - tsserver = { + ts_ls = { init_options = { plugins = { { @@ -511,8 +502,15 @@ require('lazy').setup({ }, }, }, - -- - pylsp = {}, + pylsp = { + plugins = { + ruff = { + enabled = true, + formatEnabled = true, + }, + autopep8 = { enabled = false }, + }, + }, cmake = {}, lua_ls = { -- cmd = {...}, @@ -567,31 +565,29 @@ require('lazy').setup({ cmd = { 'ConformInfo' }, keys = { { - 'f', + 'ff', function() require('conform').format { async = true, lsp_format = 'fallback' } end, mode = '', - desc = '[F]ormat buffer', + desc = '[F]ormat [F]ile buffer', }, }, opts = { - notify_on_error = false, + notify_on_error = true, format_on_save = function(bufnr) -- Disable "format_on_save lsp_fallback" for languages that don't -- have a well standardized coding style. You can add additional -- languages here or re-enable it for the disabled ones. local disable_filetypes = { c = true, cpp = true, py = true, ts = true, vue = true } - local lsp_format_opt - if disable_filetypes[vim.bo[bufnr].filetype] then - lsp_format_opt = 'never' + if disable_filetypes[vim.bo[bufnr].filetype] or vim.g.disable_autoformat then + return else - lsp_format_opt = 'fallback' + return { + timeout_ms = 500, + lsp_format = 'fallback', + } end - return { - timeout_ms = 500, - lsp_format = lsp_format_opt, - } end, formatters_by_ft = { cmake = { 'cmakelang' }, @@ -599,7 +595,8 @@ require('lazy').setup({ json = { 'clang-format-15' }, lua = { 'stylua' }, -- Conform can also run multiple formatters sequentially - python = { 'ruff_format', 'ruff_fix' }, + python = { 'ruff_format', 'ruff_fix', 'ruff_organize_imports' }, + ['*'] = { 'codespell' }, -- -- You can use a sub-list to tell conform to run *until* a formatter -- is found. @@ -818,7 +815,7 @@ require('lazy').setup({ end, }, - -- The following comments only work if you have downloaded the kickstart repo, not just copy pasted the + -- The following comments only work if you have downloaded the kickstart repo, not just copy pasted thefals -- init.lua. If you want these files, they are in the repository, so you can just download them and -- place them in the correct locations. diff --git a/lua/custom/autocommands.lua b/lua/custom/autocommands.lua index 533cb3c2..55951d04 100644 --- a/lua/custom/autocommands.lua +++ b/lua/custom/autocommands.lua @@ -11,3 +11,13 @@ vim.api.nvim_create_autocmd('TextYankPost', { vim.highlight.on_yank() end, }) +vim.api.nvim_create_user_command('FormatDisable', function() + vim.g.disable_autoformat = true +end, { + desc = 'Disable autoformat-on-save', +}) +vim.api.nvim_create_user_command('FormatEnable', function() + vim.g.disable_autoformat = false +end, { + desc = 'Re-enable autoformat-on-save', +}) diff --git a/lua/custom/keymap.lua b/lua/custom/keymap.lua index 92720a4c..4096d7e1 100644 --- a/lua/custom/keymap.lua +++ b/lua/custom/keymap.lua @@ -12,6 +12,9 @@ vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagn vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) vim.keymap.set('n', 'z', require('telescope').extensions.zoxide.list, { desc = '[Z]oxide to different dir' }) vim.keymap.set('n', 'jl', require('telescope.builtin').jumplist, { desc = '[J]ump [L]ist' }) +vim.keymap.set('n', 'ft', function() + vim.g.disable_format = not vim.g.disable_autoformat +end, { desc = 'Auto[F]ormat [T]oggle ' }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which -- is not what someone will guess without a bit more experience. diff --git a/lua/kickstart/plugins/lint.lua b/lua/kickstart/plugins/lint.lua index 933ce9da..59db2c79 100644 --- a/lua/kickstart/plugins/lint.lua +++ b/lua/kickstart/plugins/lint.lua @@ -6,7 +6,7 @@ return { config = function() local lint = require 'lint' lint.linters_by_ft = { - python = { 'pylint' }, + python = { 'ruff' }, markdown = { 'markdownlint' }, } -- To allow other plugins to add linters to require('lint').linters_by_ft,