refactor: unify syntax langs
This commit is contained in:
parent
bcbd5c9faa
commit
77d4250057
@ -2,6 +2,7 @@
|
|||||||
"conform.nvim": { "branch": "master", "commit": "235dd79731c1dc51ec04abb4045cbc54727a172a" },
|
"conform.nvim": { "branch": "master", "commit": "235dd79731c1dc51ec04abb4045cbc54727a172a" },
|
||||||
"invero.nvim": { "branch": "main", "commit": "6acdefa2f2fdf544b53b5786e748be0ae8e9fd23" },
|
"invero.nvim": { "branch": "main", "commit": "6acdefa2f2fdf544b53b5786e748be0ae8e9fd23" },
|
||||||
"lazy.nvim": { "branch": "main", "commit": "1ea3c4085785f460fb0e46d2fe1ee895f5f9e7c1" },
|
"lazy.nvim": { "branch": "main", "commit": "1ea3c4085785f460fb0e46d2fe1ee895f5f9e7c1" },
|
||||||
|
"mason-lspconfig.nvim": { "branch": "main", "commit": "2304ff65ecc8cb2afc2484de3e2ed9a407edf0b9" },
|
||||||
"mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" },
|
"mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" },
|
||||||
"nvim-autopairs": { "branch": "master", "commit": "7a2c97cccd60abc559344042fefb1d5a85b3e33b" },
|
"nvim-autopairs": { "branch": "master", "commit": "7a2c97cccd60abc559344042fefb1d5a85b3e33b" },
|
||||||
"nvim-lint": { "branch": "master", "commit": "9da1fb942dd0668d5182f9c8dee801b9c190e2bb" },
|
"nvim-lint": { "branch": "master", "commit": "9da1fb942dd0668d5182f9c8dee801b9c190e2bb" },
|
||||||
|
|||||||
@ -50,9 +50,9 @@ end
|
|||||||
map('n', ']b', cmd('bnext'))
|
map('n', ']b', cmd('bnext'))
|
||||||
map('n', '[b', cmd('bprevious'))
|
map('n', '[b', cmd('bprevious'))
|
||||||
map('n', '<leader>bl', cmd('ls'))
|
map('n', '<leader>bl', cmd('ls'))
|
||||||
map('n', '<leader>bb', '<C-^>') -- toggle between buffers
|
map('n', '<leader>bd', cmd(':bp | bd #'))
|
||||||
map('n', '<leader>bd', cmd('bdelete'))
|
|
||||||
map('n', '<leader>bo', cmd('%bd|e#')) -- close all except current
|
map('n', '<leader>bo', cmd('%bd|e#')) -- close all except current
|
||||||
|
map('n', '<leader>bb', '<C-^>') -- toggle between buffers
|
||||||
|
|
||||||
-- Terminal
|
-- Terminal
|
||||||
map('n', '<leader>xx', cmd('TermDefault'))
|
map('n', '<leader>xx', cmd('TermDefault'))
|
||||||
|
|||||||
@ -87,3 +87,25 @@ vim.opt.timeout = true
|
|||||||
vim.opt.ttimeout = true
|
vim.opt.ttimeout = true
|
||||||
vim.opt.timeoutlen = 500
|
vim.opt.timeoutlen = 500
|
||||||
vim.opt.ttimeoutlen = 10
|
vim.opt.ttimeoutlen = 10
|
||||||
|
|
||||||
|
vim.keymap.set('n', '<leader>d', vim.diagnostic.open_float, { noremap = true, silent = true })
|
||||||
|
vim.diagnostic.config({
|
||||||
|
update_in_insert = false,
|
||||||
|
virtual_text = {
|
||||||
|
prefix = '', -- remove annoying ▎ etc
|
||||||
|
format = function(diagnostic)
|
||||||
|
if diagnostic.source then
|
||||||
|
return string.format('[%s] %s', diagnostic.source, diagnostic.message)
|
||||||
|
end
|
||||||
|
return diagnostic.message
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
float = {
|
||||||
|
border = 'rounded',
|
||||||
|
source = true, -- show source in floating window too
|
||||||
|
},
|
||||||
|
severity_sort = true,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.opt.foldmethod = 'expr'
|
||||||
|
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'
|
||||||
|
|||||||
@ -1,31 +1,87 @@
|
|||||||
vim.keymap.set('n', '<leader>d', vim.diagnostic.open_float, { noremap = true, silent = true })
|
-- <treesitter> or { <treesitter>, <lsp>, <linter>, <formatter>, filetype=<ft> }
|
||||||
|
-- filetype defaults to <treesitter>. If different, specify it.
|
||||||
|
-- any positional argument can be skipped with nil
|
||||||
|
local languages = {
|
||||||
|
-- Docs / Config
|
||||||
|
'vim',
|
||||||
|
'vimdoc',
|
||||||
|
'markdown',
|
||||||
|
'markdown_inline',
|
||||||
|
'yaml',
|
||||||
|
'toml',
|
||||||
|
|
||||||
vim.diagnostic.config({
|
-- Data
|
||||||
update_in_insert = false,
|
'gitcommit',
|
||||||
virtual_text = {
|
'gitignore',
|
||||||
prefix = '', -- remove annoying ▎ etc
|
'dockerfile',
|
||||||
format = function(diagnostic)
|
'diff',
|
||||||
if diagnostic.source then
|
{ 'json', 'jsonls', nil, 'prettier' },
|
||||||
return string.format('[%s] %s', diagnostic.source, diagnostic.message)
|
{ 'jsonc', 'jsonls', nil, 'prettier' },
|
||||||
end
|
|
||||||
return diagnostic.message
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
float = {
|
|
||||||
border = 'rounded',
|
|
||||||
source = true, -- show source in floating window too
|
|
||||||
},
|
|
||||||
severity_sort = true,
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.lsp.enable({ 'lua_ls' })
|
-- Shell / Scripting
|
||||||
vim.lsp.enable({ 'json_ls' })
|
{ 'bash', 'bashls', 'shellcheck', 'shfmt' },
|
||||||
|
{ 'lua', 'luals', 'luacheck', 'stylua' },
|
||||||
|
{ 'sql', 'sqlls', nil, 'sqlfluff' },
|
||||||
|
|
||||||
|
-- Programming
|
||||||
|
{ 'c', 'clangd', nil, 'clang-format' },
|
||||||
|
{ 'cpp', 'clangd', nil, 'clang-format' },
|
||||||
|
{ 'go', 'gopls', 'golangci-lint', 'gofmt' },
|
||||||
|
{ 'rust', 'rust_analyzer', 'clippy', 'rustfmt' },
|
||||||
|
{ 'python', 'pyright', 'ruff', 'black' },
|
||||||
|
|
||||||
|
-- Web stack
|
||||||
|
{ 'html', 'html', nil, 'prettier' },
|
||||||
|
{ 'css', 'cssls', 'stylelint', 'prettier' },
|
||||||
|
{ 'javascript', 'tsls', 'eslint', 'prettier' },
|
||||||
|
{ 'typescript', 'tsls', 'eslint', 'prettier' },
|
||||||
|
{ nil, 'tsls', 'eslint', 'prettier', filetype = 'javascriptreact' },
|
||||||
|
{ 'tsx', 'tsls', 'eslint', 'prettier', filetype = 'typescriptreact' },
|
||||||
|
}
|
||||||
|
|
||||||
|
local function normalize(lang)
|
||||||
|
if type(lang) == 'string' then
|
||||||
|
lang = { lang }
|
||||||
|
end
|
||||||
|
local t = {
|
||||||
|
treesitter = lang[1],
|
||||||
|
lsp = lang[2],
|
||||||
|
linter = lang[3],
|
||||||
|
formatter = lang[4],
|
||||||
|
filetype = lang.filetype or lang[1],
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local normalized = vim.tbl_map(normalize, languages)
|
||||||
|
local general = {
|
||||||
|
ts_parsers = {},
|
||||||
|
lsps = {},
|
||||||
|
linters_by_ft = {},
|
||||||
|
formatters_by_ft = {},
|
||||||
|
}
|
||||||
|
for _, opts in ipairs(normalized) do
|
||||||
|
if opts.treesitter then
|
||||||
|
table.insert(general.ts_parsers, opts.treesitter)
|
||||||
|
end
|
||||||
|
|
||||||
|
if opts.lsp then
|
||||||
|
table.insert(general.lsps, opts.lsp)
|
||||||
|
end
|
||||||
|
|
||||||
|
if opts.linter then
|
||||||
|
general.linters_by_ft[opts.filetype] = { opts.linter }
|
||||||
|
end
|
||||||
|
|
||||||
|
if opts.formatter then
|
||||||
|
general.formatters_by_ft[opts.filetype] = { opts.formatter }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{ 'mason-org/mason.nvim', config = true },
|
|
||||||
{ 'windwp/nvim-ts-autotag', config = true },
|
{ 'windwp/nvim-ts-autotag', config = true },
|
||||||
{ 'windwp/nvim-autopairs', event = 'InsertEnter', config = true },
|
{ 'windwp/nvim-autopairs', event = 'InsertEnter', config = true },
|
||||||
|
{ 'mason-org/mason.nvim', config = true },
|
||||||
-- { 'saghen/blink.cmp', version = '1.*' },
|
-- { 'saghen/blink.cmp', version = '1.*' },
|
||||||
{
|
{
|
||||||
'nvim-treesitter/nvim-treesitter',
|
'nvim-treesitter/nvim-treesitter',
|
||||||
@ -35,48 +91,14 @@ return {
|
|||||||
highlight = { enable = true },
|
highlight = { enable = true },
|
||||||
incremental_selection = { enable = true },
|
incremental_selection = { enable = true },
|
||||||
textobjects = { enable = true },
|
textobjects = { enable = true },
|
||||||
ensure_installed = {
|
fold = { enable = true },
|
||||||
-- Documentation
|
ensure_installed = general.ts_parsers,
|
||||||
'vim',
|
|
||||||
'vimdoc',
|
|
||||||
'markdown',
|
|
||||||
'markdown_inline',
|
|
||||||
-- Data
|
|
||||||
'gitcommit',
|
|
||||||
'gitignore',
|
|
||||||
'dockerfile',
|
|
||||||
'diff',
|
|
||||||
'json',
|
|
||||||
'jsonc',
|
|
||||||
-- Scripting
|
|
||||||
'bash',
|
|
||||||
'lua',
|
|
||||||
'sql',
|
|
||||||
-- Programming
|
|
||||||
'c',
|
|
||||||
'cpp',
|
|
||||||
'go',
|
|
||||||
'rust',
|
|
||||||
'python',
|
|
||||||
-- Web
|
|
||||||
'html',
|
|
||||||
'css',
|
|
||||||
'javascript',
|
|
||||||
'typescript',
|
|
||||||
'tsx',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'mfussenegger/nvim-lint',
|
'mfussenegger/nvim-lint',
|
||||||
event = { 'BufReadPre', 'BufNewFile' },
|
event = { 'BufReadPre', 'BufNewFile' },
|
||||||
opts = {
|
opts = { linters_by_ft = general.linters_by_ft },
|
||||||
linters_by_ft = {
|
|
||||||
lua = { 'luacheck' },
|
|
||||||
python = { 'ruff' },
|
|
||||||
javascript = { 'eslint_d' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
local lint = require('lint')
|
local lint = require('lint')
|
||||||
lint.linters_by_ft = opts.linters_by_ft
|
lint.linters_by_ft = opts.linters_by_ft
|
||||||
@ -100,17 +122,7 @@ return {
|
|||||||
|
|
||||||
-- Formatters per filetype
|
-- Formatters per filetype
|
||||||
default_format_opts = { stop_after_first = true },
|
default_format_opts = { stop_after_first = true },
|
||||||
formatters_by_ft = {
|
formatters_by_ft = general.formatters_by_ft,
|
||||||
lua = { 'stylua' },
|
|
||||||
sh = { 'shfmt' },
|
|
||||||
swift = { 'swift_format' },
|
|
||||||
python = { 'isort', 'black' },
|
|
||||||
json = { 'jq' },
|
|
||||||
javascript = { 'prettierd', 'prettier' },
|
|
||||||
javascriptreact = { 'prettierd', 'prettier' },
|
|
||||||
typescript = { 'prettierd', 'prettier' },
|
|
||||||
typescriptreact = { 'prettierd', 'prettier' },
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user