clean up: formatted kickstart plugins

This commit is contained in:
Baipyrus 2024-01-10 14:59:59 +01:00
parent 7a8ca584c8
commit 4c01ef51f0
2 changed files with 107 additions and 142 deletions

View File

@ -1,74 +1,60 @@
-- autoformat.lua -- Uses installed LSP servers to automatically format code on save.
--
-- Use your language server to automatically format your code on save.
-- Adds additional commands as well to manage the behavior
return { return {
'neovim/nvim-lspconfig', 'neovim/nvim-lspconfig',
config = function() config = function()
-- Switch for controlling whether you want autoformatting. -- Switch for controlling whether you want autoformatting.
-- Use :KickstartFormatToggle to toggle autoformatting on or off local format_is_enabled = true
local format_is_enabled = true vim.api.nvim_create_user_command('KickstartFormatToggle', function()
vim.api.nvim_create_user_command('KickstartFormatToggle', function() format_is_enabled = not format_is_enabled
format_is_enabled = not format_is_enabled print('Setting autoformatting to: ' .. tostring(format_is_enabled))
print('Setting autoformatting to: ' .. tostring(format_is_enabled)) end, {})
end, {})
-- Create an augroup that is used for managing our formatting autocmds. -- Create an augroup that is used for managing our formatting autocmds.
-- We need one augroup per client to make sure that multiple clients local _augroups = {}
-- can attach to the same buffer without interfering with each other. local get_augroup = function(client)
local _augroups = {} if not _augroups[client.id] then
local get_augroup = function(client) local group_name = 'kickstart-lsp-format-' .. client.name
if not _augroups[client.id] then local id = vim.api.nvim_create_augroup(group_name, { clear = true })
local group_name = 'kickstart-lsp-format-' .. client.name _augroups[client.id] = id
local id = vim.api.nvim_create_augroup(group_name, { clear = true }) end
_augroups[client.id] = id
end
return _augroups[client.id] return _augroups[client.id]
end end
-- Whenever an LSP attaches to a buffer, we will run this function. -- Whenever an LSP attaches to a buffer, we will run this function.
-- vim.api.nvim_create_autocmd('LspAttach', {
-- See `:help LspAttach` for more information about this autocmd event. group = vim.api.nvim_create_augroup('kickstart-lsp-attach-format', { clear = true }),
vim.api.nvim_create_autocmd('LspAttach', { -- This is where we attach the autoformatting for reasonable clients
group = vim.api.nvim_create_augroup('kickstart-lsp-attach-format', { clear = true }), callback = function(args)
-- This is where we attach the autoformatting for reasonable clients local client_id = args.data.client_id
callback = function(args) local client = vim.lsp.get_client_by_id(client_id)
local client_id = args.data.client_id local bufnr = args.buf
local client = vim.lsp.get_client_by_id(client_id)
local bufnr = args.buf
-- Only attach to clients that support document formatting -- Only attach to clients that support document formatting
if not client.server_capabilities.documentFormattingProvider then if not client.server_capabilities.documentFormattingProvider then
return return
end end
-- Tsserver usually works poorly. Sorry you work with bad languages -- Create an autocmd that will run *before* we save the buffer.
-- You can remove this line if you know what you're doing :) -- Runhe formatting command for the LSP that has just attached.
if client.name == 'tsserver' then vim.api.nvim_create_autocmd('BufWritePre', {
return group = get_augroup(client),
end buffer = bufnr,
callback = function()
if not format_is_enabled then
return
end
-- Create an autocmd that will run *before* we save the buffer. vim.lsp.buf.format {
-- Run the formatting command for the LSP that has just attached. async = false,
vim.api.nvim_create_autocmd('BufWritePre', { filter = function(c)
group = get_augroup(client), return c.id == client.id
buffer = bufnr, end,
callback = function() }
if not format_is_enabled then end,
return })
end end,
})
vim.lsp.buf.format { end,
async = false,
filter = function(c)
return c.id == client.id
end,
}
end,
})
end,
})
end,
} }

View File

@ -1,87 +1,66 @@
-- debug.lua
--
-- Shows how to use the DAP plugin to debug your code.
--
-- Primarily focused on configuring the debugger for Go, but can
-- be extended to other languages as well. That's why it's called
-- kickstart.nvim and not kitchen-sink.nvim ;)
return { return {
-- NOTE: Yes, you can install new plugins here! 'mfussenegger/nvim-dap',
'mfussenegger/nvim-dap', dependencies = {
-- NOTE: And you can specify dependencies as well -- Creates a beautiful debugger UI
dependencies = { 'rcarriga/nvim-dap-ui',
-- Creates a beautiful debugger UI
'rcarriga/nvim-dap-ui',
-- Installs the debug adapters for you -- Installs the debug adapters for you
'williamboman/mason.nvim', 'williamboman/mason.nvim',
'jay-babu/mason-nvim-dap.nvim', 'jay-babu/mason-nvim-dap.nvim',
-- Add your own debuggers here -- Debugger dependencies
'leoluz/nvim-dap-go', 'leoluz/nvim-dap-go',
}, },
config = function() config = function()
local dap = require 'dap' local dap = require 'dap'
local dapui = require 'dapui' local dapui = require 'dapui'
require('mason-nvim-dap').setup { require('mason-nvim-dap').setup {
-- Makes a best effort to setup the various debuggers with automatic_setup = true,
-- reasonable debug configurations handlers = {},
automatic_setup = true, -- Installed language debuggers
ensure_installed = {
'delve',
},
}
-- You can provide additional configuration to the handlers, -- Basic debugging keymaps, feel free to change to your liking!
-- see mason-nvim-dap README for more information vim.keymap.set('n', '<F5>', dap.continue, { desc = 'Debug: Start/Continue' })
handlers = {}, vim.keymap.set('n', '<F1>', dap.step_into, { desc = 'Debug: Step Into' })
vim.keymap.set('n', '<F2>', dap.step_over, { desc = 'Debug: Step Over' })
vim.keymap.set('n', '<F3>', dap.step_out, { desc = 'Debug: Step Out' })
vim.keymap.set('n', '<leader>b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' })
vim.keymap.set('n', '<leader>B', function()
dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ')
end, { desc = 'Debug: Set Breakpoint' })
-- You'll need to check that you have the required things installed -- Dap UI setup
-- online, please don't ask me how to install them :) dapui.setup {
ensure_installed = { -- Set icons to characters that are more likely to work in every terminal.
-- Update this to ensure that you have the debuggers for the langs you want icons = { expanded = '', collapsed = '', current_frame = '*' },
'delve', controls = {
}, icons = {
} pause = '',
play = '',
step_into = '',
step_over = '',
step_out = '',
step_back = 'b',
run_last = '▶▶',
terminate = '',
disconnect = '',
},
},
}
-- Basic debugging keymaps, feel free to change to your liking! -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
vim.keymap.set('n', '<F5>', dap.continue, { desc = 'Debug: Start/Continue' }) vim.keymap.set('n', '<F7>', dapui.toggle, { desc = 'Debug: See last session result.' })
vim.keymap.set('n', '<F1>', dap.step_into, { desc = 'Debug: Step Into' })
vim.keymap.set('n', '<F2>', dap.step_over, { desc = 'Debug: Step Over' })
vim.keymap.set('n', '<F3>', dap.step_out, { desc = 'Debug: Step Out' })
vim.keymap.set('n', '<leader>b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' })
vim.keymap.set('n', '<leader>B', function()
dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ')
end, { desc = 'Debug: Set Breakpoint' })
-- Dap UI setup dap.listeners.after.event_initialized['dapui_config'] = dapui.open
-- For more information, see |:help nvim-dap-ui| dap.listeners.before.event_terminated['dapui_config'] = dapui.close
dapui.setup { dap.listeners.before.event_exited['dapui_config'] = dapui.close
-- Set icons to characters that are more likely to work in every terminal.
-- Feel free to remove or use ones that you like more! :)
-- Don't feel like these are good choices.
icons = { expanded = '', collapsed = '', current_frame = '*' },
controls = {
icons = {
pause = '',
play = '',
step_into = '',
step_over = '',
step_out = '',
step_back = 'b',
run_last = '▶▶',
terminate = '',
disconnect = '',
},
},
}
-- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. -- Install golang specific config
vim.keymap.set('n', '<F7>', dapui.toggle, { desc = 'Debug: See last session result.' }) require('dap-go').setup()
end,
dap.listeners.after.event_initialized['dapui_config'] = dapui.open
dap.listeners.before.event_terminated['dapui_config'] = dapui.close
dap.listeners.before.event_exited['dapui_config'] = dapui.close
-- Install golang specific config
require('dap-go').setup()
end,
} }