Formatting
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
-- Set <space> as the leader key
|
-- Set <space> as the leader key
|
||||||
-- See `:help mapleader`
|
-- See `:help mapleader`
|
||||||
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
|
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
|
||||||
|
vim.lsp.log.set_level 'debug'
|
||||||
vim.g.mapleader = ','
|
vim.g.mapleader = ','
|
||||||
vim.g.maplocalleader = ','
|
vim.g.maplocalleader = ','
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,13 @@ vim.api.nvim_create_autocmd({ 'User' }, {
|
|||||||
-- end,
|
-- end,
|
||||||
-- })
|
-- })
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
|
||||||
|
pattern = { '*.lua' },
|
||||||
|
callback = function(args)
|
||||||
|
require('helpers').format_buffer('stylua', args.buf)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
local modes_group = vim.api.nvim_create_augroup('modes', { clear = true })
|
local modes_group = vim.api.nvim_create_augroup('modes', { clear = true })
|
||||||
vim.api.nvim_create_autocmd('FocusLost', {
|
vim.api.nvim_create_autocmd('FocusLost', {
|
||||||
group = modes_group,
|
group = modes_group,
|
||||||
@@ -211,3 +218,4 @@ vim.api.nvim_create_autocmd('VimLeavePre', {
|
|||||||
})
|
})
|
||||||
|
|
||||||
require('helpers').edit_cf('a', '/lua/autocmd.lua')
|
require('helpers').edit_cf('a', '/lua/autocmd.lua')
|
||||||
|
|
||||||
|
|||||||
@@ -104,5 +104,54 @@ helpers.open_file_modal = function(path, title)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_formatter_bin(formatter)
|
||||||
|
return vim.fn.stdpath 'data' .. '/mason/bin/' .. formatter
|
||||||
|
end
|
||||||
|
|
||||||
|
local formatter_args = {
|
||||||
|
pint = function(file)
|
||||||
|
return {
|
||||||
|
get_formatter_bin 'pint',
|
||||||
|
'--stdin-filename',
|
||||||
|
file,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
eslint_d = function(file)
|
||||||
|
return {
|
||||||
|
get_formatter_bin 'eslint_d',
|
||||||
|
'--stdin',
|
||||||
|
'--stdin-filename',
|
||||||
|
file,
|
||||||
|
'--fix-to-stdout',
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
stylua = function(file)
|
||||||
|
return {
|
||||||
|
get_formatter_bin 'stylua',
|
||||||
|
'--stdin-filepath',
|
||||||
|
file,
|
||||||
|
'-',
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
helpers.format_buffer = function(formatter, buf, cwd)
|
||||||
|
local file = vim.api.nvim_buf_get_name(buf)
|
||||||
|
local input = table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), '\n')
|
||||||
|
local result = vim.system(formatter_args[formatter](file), {
|
||||||
|
text = true,
|
||||||
|
stdin = input,
|
||||||
|
cwd = cwd,
|
||||||
|
}):wait()
|
||||||
|
|
||||||
|
if result.code ~= 0 then
|
||||||
|
vim.notify(result.stderr, vim.log.levels.ERROR)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, vim.split(result.stdout, '\n', { plain = true }))
|
||||||
|
end
|
||||||
|
|
||||||
return helpers
|
return helpers
|
||||||
-- nnoremap <Leader>ev :tabedit $MYVIMRC<CR>
|
-- nnoremap <Leader>ev :tabedit $MYVIMRC<CR>
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -257,7 +257,14 @@ vim.keymap.set('n', '<Leader>sGS', '<CMD>Telescope git_stash<CR>', { desc = 'Sea
|
|||||||
vim.keymap.set('n', '<Leader>]', '<CMD>cnext<CR>', { desc = 'Next item in quickfix list' })
|
vim.keymap.set('n', '<Leader>]', '<CMD>cnext<CR>', { desc = 'Next item in quickfix list' })
|
||||||
vim.keymap.set('n', '<Leader>[', '<CMD>cprevious<CR>', { desc = 'Previous item in quickfix list' })
|
vim.keymap.set('n', '<Leader>[', '<CMD>cprevious<CR>', { desc = 'Previous item in quickfix list' })
|
||||||
vim.keymap.set('n', 'gd', '<CMD>Telescope lsp_definitions<CR>', { desc = 'Go to definition' })
|
vim.keymap.set('n', 'gd', '<CMD>Telescope lsp_definitions<CR>', { desc = 'Go to definition' })
|
||||||
vim.keymap.set('n', '<Leader>r', '<CMD>e!<CR>', { desc = 'Reload buffer' })
|
vim.keymap.set('n', '<Leader>r', function()
|
||||||
|
for _, c in ipairs(vim.lsp.get_clients { bufnr = 0 }) do
|
||||||
|
if c.name == 'phpantom_lsp' then
|
||||||
|
c:stop(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.cmd 'edit'
|
||||||
|
end, { desc = 'Reload buffer' })
|
||||||
|
|
||||||
local function open_test()
|
local function open_test()
|
||||||
require('neotest').summary.open()
|
require('neotest').summary.open()
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
return { -- Autoformat
|
|
||||||
'stevearc/conform.nvim',
|
|
||||||
event = { 'BufWritePre' },
|
|
||||||
cmd = { 'ConformInfo' },
|
|
||||||
keys = {
|
|
||||||
{
|
|
||||||
'<leader>f',
|
|
||||||
function()
|
|
||||||
require('conform').format { async = true, lsp_format = 'fallback' }
|
|
||||||
end,
|
|
||||||
mode = '',
|
|
||||||
desc = '[F]ormat buffer',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
config = function()
|
|
||||||
require('conform').setup({
|
|
||||||
notify_on_error = false,
|
|
||||||
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, vue = true, js = true }
|
|
||||||
if disable_filetypes[vim.bo[bufnr].filetype] then
|
|
||||||
return nil
|
|
||||||
else
|
|
||||||
return {
|
|
||||||
timeout_ms = 500,
|
|
||||||
lsp_format = 'fallback',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
formatters_by_ft = {
|
|
||||||
lua = { 'stylua' },
|
|
||||||
php = { 'pint' },
|
|
||||||
blade = { 'blade-formatter' },
|
|
||||||
-- Conform can also run multiple formatters sequentially
|
|
||||||
-- python = { "isort", "black" },
|
|
||||||
--
|
|
||||||
-- You can use 'stop_after_first' to run the first available formatter from the list
|
|
||||||
-- javascript = { "prettierd", "prettier", stop_after_first = true },
|
|
||||||
},
|
|
||||||
log_level = vim.log.levels.DEBUG
|
|
||||||
})
|
|
||||||
end
|
|
||||||
}
|
|
||||||
@@ -207,6 +207,8 @@ return {
|
|||||||
vim.list_extend(ensure_installed, {
|
vim.list_extend(ensure_installed, {
|
||||||
'stylua', -- Used to format Lua code
|
'stylua', -- Used to format Lua code
|
||||||
'blade-formatter',
|
'blade-formatter',
|
||||||
|
'eslint_d',
|
||||||
|
'pint',
|
||||||
})
|
})
|
||||||
|
|
||||||
-- LSP servers and clients are able to communicate to each other what features they support.
|
-- LSP servers and clients are able to communicate to each other what features they support.
|
||||||
|
|||||||
+46
-19
@@ -226,6 +226,34 @@ local PROJECTS = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
|
||||||
|
pattern = { '*.php' },
|
||||||
|
callback = function(args)
|
||||||
|
local cwd = vim.fn.getcwd()
|
||||||
|
if vim.fn.expand('%:p'):match(dir .. '/server/') then
|
||||||
|
cwd = dir .. '/server/'
|
||||||
|
end
|
||||||
|
local file = vim.api.nvim_buf_get_name(args.buf)
|
||||||
|
local input = table.concat(vim.api.nvim_buf_get_lines(args.buf, 0, -1, false), '\n')
|
||||||
|
local result = vim.system({
|
||||||
|
vim.fn.stdpath 'data' .. '/mason/bin/pint',
|
||||||
|
'--stdin-filename',
|
||||||
|
file,
|
||||||
|
}, {
|
||||||
|
text = true,
|
||||||
|
stdin = input,
|
||||||
|
cwd = dir .. '/server/',
|
||||||
|
}):wait()
|
||||||
|
|
||||||
|
if result.code ~= 0 then
|
||||||
|
vim.notify(result.stderr, vim.log.levels.ERROR)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_lines(args.buf, 0, -1, false, vim.split(result.stdout, '\n', { plain = true }))
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
create_bookmark('E', dir .. '/client/src/types/api/endpointMap.d.ts')
|
create_bookmark('E', dir .. '/client/src/types/api/endpointMap.d.ts')
|
||||||
create_bookmark('q', dir .. '/client/quasar.config.ts')
|
create_bookmark('q', dir .. '/client/quasar.config.ts')
|
||||||
create_bookmark('db', dir .. '/client/src/boot')
|
create_bookmark('db', dir .. '/client/src/boot')
|
||||||
@@ -251,28 +279,26 @@ local PROJECTS = {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
|
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
|
||||||
pattern = { '.graphql' },
|
pattern = { '*.js', '*.ts', '*.vue' },
|
||||||
callback = function()
|
callback = function(args)
|
||||||
vim.fn.jobstart('vendor/bin/sail artisan lighthouse:clear-cache', { stdout_buffered = true })
|
vim.env.ESLINT_D_PPID = vim.fn.getpid()
|
||||||
|
local cwd = vim.fn.getcwd()
|
||||||
|
if vim.fn.expand('%:p'):match(dir .. '/frontend2/') then
|
||||||
|
cwd = dir .. '/frontend2/'
|
||||||
|
end
|
||||||
|
require('helpers').format_buffer('eslint_d', args.buf, cwd)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end,
|
|
||||||
['server'] = function(dir)
|
|
||||||
map('<leader>pl', ':cexpr system("vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") <CR>', { desc = 'Run lint' })
|
|
||||||
map('<leader>pd', function()
|
|
||||||
helpers.open_term { cmd = 'lazysql pgsql://homestead:password@localhost:5432/homestead' }
|
|
||||||
end, { desc = 'Open database manager' })
|
|
||||||
laravel_keymaps()
|
|
||||||
laravel_makes()
|
|
||||||
map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c')
|
|
||||||
map('<Leader>pm', ':vendor/bin/sail composer migrate<CR>')
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
|
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
|
||||||
pattern = { '*.php', '.env', '.graphql' },
|
pattern = { '*.php' },
|
||||||
callback = function()
|
callback = function(args)
|
||||||
vim.fn.jobstart('vendor/bin/sail artisan octane:reload', { stdout_buffered = true })
|
local cwd = vim.fn.getcwd()
|
||||||
vim.fn.jobstart('vendor/bin/sail artisan horizon:terminate', { stdout_buffered = true })
|
if vim.fn.expand('%:p'):match(dir .. '/server/') then
|
||||||
|
cwd = dir .. '/server/'
|
||||||
|
end
|
||||||
|
require('helpers').format_buffer('pint', args.buf, cwd)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -334,3 +360,4 @@ end, {})
|
|||||||
|
|
||||||
-- Keep your helper line
|
-- Keep your helper line
|
||||||
require('helpers').edit_cf('w', '/lua/projects.lua')
|
require('helpers').edit_cf('w', '/lua/projects.lua')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user