style(nvim): format lua
This commit is contained in:
parent
eb86f4860c
commit
3fd3d74ee5
|
@ -1,52 +1,61 @@
|
||||||
function _G.dump(...)
|
function _G.dump(...)
|
||||||
local objects = vim.tbl_map(vim.inspect, {...})
|
local objects = vim.tbl_map(vim.inspect, { ... })
|
||||||
print(unpack(objects))
|
print(unpack(objects))
|
||||||
return ...
|
return ...
|
||||||
end
|
end
|
||||||
|
|
||||||
function _G.insert_uuid()
|
function _G.insert_uuid()
|
||||||
local uuid = vim.fn.system("uuidprint")
|
local uuid = vim.fn.system("uuidprint")
|
||||||
local errcode = vim.v.shell_error
|
local errcode = vim.v.shell_error
|
||||||
if errcode ~= 0 then
|
if errcode ~= 0 then
|
||||||
vim.api.nvim_err_writeln("uuidprint returned error code: " .. errcode)
|
vim.api.nvim_err_writeln("uuidprint returned error code: " .. errcode)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.fn.setreg("u", uuid)
|
vim.fn.setreg("u", uuid)
|
||||||
vim.api.nvim_command([[normal! "up]])
|
vim.api.nvim_command([[normal! "up]])
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_set_keymap("n", "<leader>pu", [[:lua _G.insert_uuid()<cr>]], {noremap = true, silent = true})
|
vim.api.nvim_set_keymap("n", "<leader>pu", [[:lua _G.insert_uuid()<cr>]], { noremap = true, silent = true })
|
||||||
vim.api.nvim_set_keymap("i", "<c-d><c-u>", [[<esc>:lua _G.insert_uuid()<cr>a]], {noremap = true, silent = true})
|
vim.api.nvim_set_keymap("i", "<c-d><c-u>", [[<esc>:lua _G.insert_uuid()<cr>a]], { noremap = true, silent = true })
|
||||||
|
|
||||||
function _G.insert_jira_url()
|
function _G.insert_jira_url()
|
||||||
local url = vim.fn.system("jira")
|
local url = vim.fn.system("jira")
|
||||||
local errcode = vim.v.shell_error
|
local errcode = vim.v.shell_error
|
||||||
if errcode ~= 0 then
|
if errcode ~= 0 then
|
||||||
vim.api.nvim_err_writeln("jira returned error code: " .. errcode)
|
vim.api.nvim_err_writeln("jira returned error code: " .. errcode)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.fn.setreg("u", url)
|
vim.fn.setreg("u", url)
|
||||||
vim.api.nvim_command([[normal! "up]])
|
vim.api.nvim_command([[normal! "up]])
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_set_keymap("n", "<leader>pj", [[:lua _G.insert_jira_url()<cr>]], {noremap = true, silent = true})
|
vim.api.nvim_set_keymap("n", "<leader>pj", [[:lua _G.insert_jira_url()<cr>]], { noremap = true, silent = true })
|
||||||
vim.api.nvim_set_keymap("i", "<c-d><c-j>", [[<esc>:lua _G.insert_jira_url()<cr>a]], {noremap = true, silent = true})
|
vim.api.nvim_set_keymap("i", "<c-d><c-j>", [[<esc>:lua _G.insert_jira_url()<cr>a]], { noremap = true, silent = true })
|
||||||
|
|
||||||
function _G.insert_iso8601_timestamp()
|
function _G.insert_iso8601_timestamp()
|
||||||
local ts = vim.fn.system("echo -n $(date --iso-8601=seconds)")
|
local ts = vim.fn.system("echo -n $(date --iso-8601=seconds)")
|
||||||
|
|
||||||
local errcode = vim.v.shell_error
|
local errcode = vim.v.shell_error
|
||||||
if errcode ~= 0 then
|
if errcode ~= 0 then
|
||||||
vim.api.nvim_err_writeln("date returned error code: " .. errcode)
|
vim.api.nvim_err_writeln("date returned error code: " .. errcode)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.fn.setreg("u", ts)
|
vim.fn.setreg("u", ts)
|
||||||
vim.api.nvim_command([[normal! "up]])
|
vim.api.nvim_command([[normal! "up]])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_set_keymap(
|
||||||
vim.api.nvim_set_keymap("n", "<leader>pt", [[:lua _G.insert_iso8601_timestamp()<cr>]], {noremap = true, silent = true})
|
"n",
|
||||||
vim.api.nvim_set_keymap("i", "<c-d><c-t>", [[<esc>:lua _G.insert_iso8601_timestamp()<cr>a]], {noremap = true, silent = true})
|
"<leader>pt",
|
||||||
|
[[:lua _G.insert_iso8601_timestamp()<cr>]],
|
||||||
|
{ noremap = true, silent = true }
|
||||||
|
)
|
||||||
|
vim.api.nvim_set_keymap(
|
||||||
|
"i",
|
||||||
|
"<c-d><c-t>",
|
||||||
|
[[<esc>:lua _G.insert_iso8601_timestamp()<cr>a]],
|
||||||
|
{ noremap = true, silent = true }
|
||||||
|
)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
require('copilot').setup({
|
require("copilot").setup({
|
||||||
panel = {
|
panel = {
|
||||||
enabled = false,
|
enabled = false,
|
||||||
auto_refresh = true,
|
auto_refresh = true,
|
||||||
},
|
},
|
||||||
suggestion = {
|
suggestion = {
|
||||||
enabled = false,
|
enabled = false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end, 100)
|
end, 100)
|
||||||
|
|
|
@ -1,33 +1,36 @@
|
||||||
local prettier = function()
|
local prettier = function()
|
||||||
return {
|
return {
|
||||||
exe = Get_project_node_modules_path() .. "/.bin/prettier",
|
exe = Get_project_node_modules_path() .. "/.bin/prettier",
|
||||||
args = {"--stdin-filepath", vim.api.nvim_buf_get_name(0), '--single-quote'},
|
args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
|
||||||
stdin = true
|
stdin = true,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
require('formatter').setup({
|
require("formatter").setup({
|
||||||
log_level = vim.log.levels.INFO,
|
log_level = vim.log.levels.INFO,
|
||||||
filetype = {
|
filetype = {
|
||||||
javascript = { prettier },
|
javascript = { prettier },
|
||||||
typescript = { prettier },
|
typescript = { prettier },
|
||||||
typescriptreact = { prettier },
|
typescriptreact = { prettier },
|
||||||
|
|
||||||
-- https://github.com/JohnnyMorganz/StyLua
|
-- https://github.com/JohnnyMorganz/StyLua
|
||||||
-- cargo install stylua --features lua54
|
-- cargo install stylua --features lua54
|
||||||
lua = {
|
lua = {
|
||||||
require("formatter.filetypes.lua").stylua
|
require("formatter.filetypes.lua").stylua,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- TODO: use vim.api.nvim_create_augroup()
|
-- TODO: use vim.api.nvim_create_augroup()
|
||||||
vim.api.nvim_exec2([[
|
vim.api.nvim_exec2(
|
||||||
|
[[
|
||||||
augroup FormatAutogroup
|
augroup FormatAutogroup
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufWritePost *.js,*.ts,*.tsx,*.lua silent FormatWrite
|
autocmd BufWritePost *.js,*.ts,*.tsx,*.lua silent FormatWrite
|
||||||
augroup END
|
augroup END
|
||||||
]], { output = true })
|
]],
|
||||||
|
{ output = true }
|
||||||
|
)
|
||||||
|
|
||||||
local bufnr = vim.fn.bufnr("%")
|
local bufnr = vim.fn.bufnr("%")
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>F', '<Cmd>silent Format<CR>', { noremap=true, silent=true })
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>F", "<Cmd>silent Format<CR>", { noremap = true, silent = true })
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
-- Return the node_modules path for this project. If the project root contains a
|
-- Return the node_modules path for this project. If the project root contains a
|
||||||
-- frontend/ directory, assume node_modules lives there.
|
-- frontend/ directory, assume node_modules lives there.
|
||||||
function Get_project_node_modules_path()
|
function Get_project_node_modules_path()
|
||||||
local root_path = vim.fn.getcwd()
|
local root_path = vim.fn.getcwd()
|
||||||
local frontend_path = root_path .. "/frontend"
|
local frontend_path = root_path .. "/frontend"
|
||||||
local is_frontend = vim.fn.isdirectory(frontend_path) ~= 0
|
local is_frontend = vim.fn.isdirectory(frontend_path) ~= 0
|
||||||
local base_path = root_path
|
local base_path = root_path
|
||||||
if is_frontend then
|
if is_frontend then
|
||||||
base_path = frontend_path
|
base_path = frontend_path
|
||||||
end
|
end
|
||||||
return base_path .. "/node_modules"
|
return base_path .. "/node_modules"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,179 +1,179 @@
|
||||||
local nvim_lsp = require('lspconfig')
|
local nvim_lsp = require("lspconfig")
|
||||||
local on_attach = function(client, bufnr)
|
local on_attach = function(client, bufnr)
|
||||||
-- TODO: use vim.api.nvim_create_autocmd
|
-- TODO: use vim.api.nvim_create_autocmd
|
||||||
vim.api.nvim_exec2([[autocmd User LspDiagnosticsChanged call lightline#update()]], { output = false })
|
vim.api.nvim_exec2([[autocmd User LspDiagnosticsChanged call lightline#update()]], { output = false })
|
||||||
|
|
||||||
local opts = { noremap=true, silent=false }
|
local opts = { noremap = true, silent = false }
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<Cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<Cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>gD', '<Cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>gD", "<Cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>e', '<Cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>e", "<Cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>r', '<Cmd>lua vim.lsp.buf.references()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>r", "<Cmd>lua vim.lsp.buf.references()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>i', '<Cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>i", "<Cmd>lua vim.lsp.buf.implementation()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<Cmd>lua vim.lsp.buf.code_action()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ci', '<Cmd>lua vim.lsp.buf.incoming_calls()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ci", "<Cmd>lua vim.lsp.buf.incoming_calls()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>co', '<Cmd>lua vim.lsp.buf.outgoing_calls()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>co", "<Cmd>lua vim.lsp.buf.outgoing_calls()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']e', '<Cmd>lua vim.diagnostic.goto_next({severity="Error"})<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "]e", '<Cmd>lua vim.diagnostic.goto_next({severity="Error"})<CR>', opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[e', '<Cmd>lua vim.diagnostic.goto_prev({severity="Error"})<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "[e", '<Cmd>lua vim.diagnostic.goto_prev({severity="Error"})<CR>', opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', '<Cmd>lua vim.diagnostic.goto_next()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", "<Cmd>lua vim.diagnostic.goto_next()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', '<Cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", "<Cmd>lua vim.diagnostic.goto_prev()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'cd', '<Cmd>lua vim.diagnostic.hide(nil, 0)<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "cd", "<Cmd>lua vim.diagnostic.hide(nil, 0)<CR>", opts)
|
||||||
|
|
||||||
-- fzf triggers:
|
-- fzf triggers:
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>fr', '<Cmd>References<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fr", "<Cmd>References<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>fi', '<Cmd>Implementations<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fi", "<Cmd>Implementations<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>fs', '<Cmd>DocumentSymbols<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fs", "<Cmd>DocumentSymbols<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>fw', '<Cmd>WorkspaceSymbols<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fw", "<Cmd>WorkspaceSymbols<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>fc', '<Cmd>CodeActions<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fc", "<Cmd>CodeActions<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>fci', '<Cmd>IncomingCalls<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fci", "<Cmd>IncomingCalls<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>fco', '<Cmd>OutgoingCalls<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fco", "<Cmd>OutgoingCalls<CR>", opts)
|
||||||
|
|
||||||
require 'lsp_signature'.on_attach({
|
require("lsp_signature").on_attach({
|
||||||
hint_enable = false,
|
hint_enable = false,
|
||||||
})
|
})
|
||||||
|
|
||||||
require 'copilot_cmp'.setup();
|
require("copilot_cmp").setup()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Go
|
-- Go
|
||||||
|
|
||||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||||
capabilities.textDocument.completion.completionItem.resolveSupport = {
|
capabilities.textDocument.completion.completionItem.resolveSupport = {
|
||||||
properties = {
|
properties = {
|
||||||
'documentation',
|
"documentation",
|
||||||
'detail',
|
"detail",
|
||||||
'additionalTextEdits',
|
"additionalTextEdits",
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
nvim_lsp.gopls.setup{
|
nvim_lsp.gopls.setup({
|
||||||
settings = {
|
settings = {
|
||||||
gopls = {
|
gopls = {
|
||||||
staticcheck = true,
|
staticcheck = true,
|
||||||
-- Disalbing linksInHover may not be working as expected:
|
-- Disalbing linksInHover may not be working as expected:
|
||||||
linksInHover = false,
|
linksInHover = false,
|
||||||
usePlaceholders = true,
|
usePlaceholders = true,
|
||||||
analyses = {
|
analyses = {
|
||||||
unusedparams = true,
|
unusedparams = true,
|
||||||
shadow = true,
|
shadow = true,
|
||||||
unusedwrite = true,
|
unusedwrite = true,
|
||||||
unusedresult = true,
|
unusedresult = true,
|
||||||
nilness = true,
|
nilness = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
}
|
})
|
||||||
|
|
||||||
-- Rust
|
-- Rust
|
||||||
nvim_lsp.rust_analyzer.setup{
|
nvim_lsp.rust_analyzer.setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
settings = {
|
settings = {
|
||||||
["rust-analyzer"] = {
|
["rust-analyzer"] = {
|
||||||
imports = {
|
imports = {
|
||||||
granularity = {
|
granularity = {
|
||||||
group = "module",
|
group = "module",
|
||||||
},
|
},
|
||||||
prefix = "self",
|
prefix = "self",
|
||||||
},
|
},
|
||||||
cargo = {
|
cargo = {
|
||||||
buildScripts = {
|
buildScripts = {
|
||||||
enable = true,
|
enable = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
procMacro = {
|
procMacro = {
|
||||||
enable = false,
|
enable = false,
|
||||||
},
|
},
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
disabled = { "unresolved-proc-macro" },
|
disabled = { "unresolved-proc-macro" },
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
-- Ruby
|
-- Ruby
|
||||||
|
|
||||||
nvim_lsp.solargraph.setup{
|
nvim_lsp.solargraph.setup({
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
}
|
})
|
||||||
|
|
||||||
-- Typescript
|
-- Typescript
|
||||||
-- https://jose-elias-alvarez.medium.com/configuring-neovims-lsp-client-for-typescript-development-5789d58ea9c
|
-- https://jose-elias-alvarez.medium.com/configuring-neovims-lsp-client-for-typescript-development-5789d58ea9c
|
||||||
|
|
||||||
nvim_lsp.tsserver.setup{
|
nvim_lsp.tsserver.setup({
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
}
|
})
|
||||||
|
|
||||||
local filetypes = {
|
local filetypes = {
|
||||||
typescript = "eslint",
|
typescript = "eslint",
|
||||||
typescriptreact = "eslint",
|
typescriptreact = "eslint",
|
||||||
}
|
}
|
||||||
|
|
||||||
-- diagnosticls
|
-- diagnosticls
|
||||||
|
|
||||||
local linters = {
|
local linters = {
|
||||||
eslint = {
|
eslint = {
|
||||||
sourceName = "eslint",
|
sourceName = "eslint",
|
||||||
-- fallback to global eslint if the local is not found?
|
-- fallback to global eslint if the local is not found?
|
||||||
-- https://github.com/creativenull/diagnosticls-configs-nvim/blob/e7d6f7e99f6b416d2aeee89314bc46fc36df7b22/lua/diagnosticls-configs/fs.lua#L20
|
-- https://github.com/creativenull/diagnosticls-configs-nvim/blob/e7d6f7e99f6b416d2aeee89314bc46fc36df7b22/lua/diagnosticls-configs/fs.lua#L20
|
||||||
command = "./node_modules/.bin/eslint",
|
command = "./node_modules/.bin/eslint",
|
||||||
rootPatterns = {".eslintrc", ".eslintrc.js"},
|
rootPatterns = { ".eslintrc", ".eslintrc.js" },
|
||||||
debounce = 100,
|
debounce = 100,
|
||||||
args = {"--stdin", "--stdin-filename", "%filepath", "--format", "json"},
|
args = { "--stdin", "--stdin-filename", "%filepath", "--format", "json" },
|
||||||
parseJson = {
|
parseJson = {
|
||||||
errorsRoot = "[0].messages",
|
errorsRoot = "[0].messages",
|
||||||
line = "line",
|
line = "line",
|
||||||
column = "column",
|
column = "column",
|
||||||
endLine = "endLine",
|
endLine = "endLine",
|
||||||
endColumn = "endColumn",
|
endColumn = "endColumn",
|
||||||
message = "${message} [${ruleId}]",
|
message = "${message} [${ruleId}]",
|
||||||
security = "severity"
|
security = "severity",
|
||||||
},
|
},
|
||||||
securities = {[1] = "error", [2] = "warning"}
|
securities = { [1] = "error", [2] = "warning" },
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
nvim_lsp.diagnosticls.setup{
|
nvim_lsp.diagnosticls.setup({
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
filetypes = vim.tbl_keys(filetypes),
|
filetypes = vim.tbl_keys(filetypes),
|
||||||
init_options = {
|
init_options = {
|
||||||
linters = linters,
|
linters = linters,
|
||||||
filetypes = filetypes,
|
filetypes = filetypes,
|
||||||
}
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
-- Lua
|
-- Lua
|
||||||
|
|
||||||
local lua_ls_root_path = os.getenv("HOME").."/dev/lua-language-server"
|
local lua_ls_root_path = os.getenv("HOME") .. "/dev/lua-language-server"
|
||||||
local lua_ls_binary = lua_ls_root_path.."/bin/lua-language-server"
|
local lua_ls_binary = lua_ls_root_path .. "/bin/lua-language-server"
|
||||||
|
|
||||||
local runtime_path = vim.split(package.path, ';')
|
local runtime_path = vim.split(package.path, ";")
|
||||||
table.insert(runtime_path, "lua/?.lua")
|
table.insert(runtime_path, "lua/?.lua")
|
||||||
table.insert(runtime_path, "lua/?/init.lua")
|
table.insert(runtime_path, "lua/?/init.lua")
|
||||||
|
|
||||||
nvim_lsp.lua_ls.setup {
|
nvim_lsp.lua_ls.setup({
|
||||||
cmd = {lua_ls_binary, "-E", lua_ls_root_path .. "/main.lua"};
|
cmd = { lua_ls_binary, "-E", lua_ls_root_path .. "/main.lua" },
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
runtime = {
|
runtime = {
|
||||||
version = 'LuaJIT',
|
version = "LuaJIT",
|
||||||
path = runtime_path,
|
path = runtime_path,
|
||||||
},
|
},
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
globals = {'vim'},
|
globals = { "vim" },
|
||||||
},
|
},
|
||||||
workspace = {
|
workspace = {
|
||||||
library = vim.api.nvim_get_runtime_file("", true),
|
library = vim.api.nvim_get_runtime_file("", true),
|
||||||
},
|
},
|
||||||
telemetry = {
|
telemetry = {
|
||||||
enable = false,
|
enable = false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
}
|
})
|
||||||
|
|
|
@ -1,47 +1,48 @@
|
||||||
local cmp = require('cmp')
|
local cmp = require("cmp")
|
||||||
local cmp_buffer = require('cmp_buffer')
|
local cmp_buffer = require("cmp_buffer")
|
||||||
|
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
completion = {
|
completion = {
|
||||||
completeopt = 'menu,menuone,noinsert',
|
completeopt = "menu,menuone,noinsert",
|
||||||
},
|
},
|
||||||
snippet = {
|
snippet = {
|
||||||
expand = function(args)
|
expand = function(args)
|
||||||
vim.fn["vsnip#anonymous"](args.body)
|
vim.fn["vsnip#anonymous"](args.body)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
mapping = cmp.mapping.preset.insert({
|
mapping = cmp.mapping.preset.insert({
|
||||||
['<C-u>'] = cmp.mapping.scroll_docs(-4),
|
["<C-u>"] = cmp.mapping.scroll_docs(-4),
|
||||||
['<C-d>'] = cmp.mapping.scroll_docs(4),
|
["<C-d>"] = cmp.mapping.scroll_docs(4),
|
||||||
['<C-Space>'] = cmp.mapping.complete(),
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
['<C-e>'] = cmp.mapping.close(),
|
["<C-e>"] = cmp.mapping.close(),
|
||||||
['C-y'] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }),
|
["C-y"] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }),
|
||||||
['<CR>'] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }),
|
["<CR>"] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }),
|
||||||
}),
|
}),
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = 'copilot', keyword_length = 0 },
|
{ name = "copilot", keyword_length = 0 },
|
||||||
{ name = 'nvim_lsp', keyword_length = 3 },
|
{ name = "nvim_lsp", keyword_length = 3 },
|
||||||
{
|
{
|
||||||
name = 'buffer',
|
name = "buffer",
|
||||||
option = {
|
option = {
|
||||||
get_bufnrs = function()
|
get_bufnrs = function()
|
||||||
return vim.api.nvim_list_bufs()
|
return vim.api.nvim_list_bufs()
|
||||||
end
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ name = 'path' },
|
{ name = "path" },
|
||||||
{ name = 'calc' },
|
{ name = "calc" },
|
||||||
}),
|
}),
|
||||||
sorting = {
|
sorting = {
|
||||||
comparators = {
|
comparators = {
|
||||||
function(...) return cmp_buffer:compare_locality(...) end,
|
function(...)
|
||||||
}
|
return cmp_buffer:compare_locality(...)
|
||||||
},
|
end,
|
||||||
view = {
|
},
|
||||||
entries = 'native',
|
},
|
||||||
},
|
view = {
|
||||||
experimental = {
|
entries = "native",
|
||||||
ghost_text = true,
|
},
|
||||||
},
|
experimental = {
|
||||||
|
ghost_text = true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,104 +1,109 @@
|
||||||
_G._test_cmd_to_wins = {}
|
_G._test_cmd_to_wins = {}
|
||||||
|
|
||||||
_G._build_test_cmd = function()
|
_G._build_test_cmd = function()
|
||||||
local bufnr = vim.fn.bufnr("%")
|
local bufnr = vim.fn.bufnr("%")
|
||||||
local filetype = vim.fn.getbufvar(bufnr, "&filetype")
|
local filetype = vim.fn.getbufvar(bufnr, "&filetype")
|
||||||
if filetype == "" then
|
if filetype == "" then
|
||||||
vim.api.nvim_err_writeln("cannot build test command for filetype:" .. filetype)
|
vim.api.nvim_err_writeln("cannot build test command for filetype:" .. filetype)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local path = vim.fn.expand("%:p")
|
local path = vim.fn.expand("%:p")
|
||||||
|
|
||||||
-- TODO: allow line number to be passed
|
-- TODO: allow line number to be passed
|
||||||
-- TODO: check file exists before running command
|
-- TODO: check file exists before running command
|
||||||
if filetype == "ruby" then
|
if filetype == "ruby" then
|
||||||
if not path:find("_spec.rb") then
|
if not path:find("_spec.rb") then
|
||||||
path = path:gsub("/app/", "/spec/"):gsub([[.rb$]], "_spec.rb")
|
path = path:gsub("/app/", "/spec/"):gsub([[.rb$]], "_spec.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
return "bundle exec rspec --format=progress --no-profile " .. path
|
return "bundle exec rspec --format=progress --no-profile " .. path
|
||||||
elseif filetype == "go" then
|
elseif filetype == "go" then
|
||||||
return "go test -v " .. path:gsub("^(.*)/(.*go)$", "%1/...")
|
return "go test -v " .. path:gsub("^(.*)/(.*go)$", "%1/...")
|
||||||
else
|
else
|
||||||
vim.api.nvim_err_writeln("filetype not supported: " .. filetype)
|
vim.api.nvim_err_writeln("filetype not supported: " .. filetype)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.run_tests = function()
|
_G.run_tests = function()
|
||||||
local cmd = _G._build_test_cmd()
|
local cmd = _G._build_test_cmd()
|
||||||
if cmd == nil then
|
if cmd == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_command([[silent up]])
|
vim.api.nvim_command([[silent up]])
|
||||||
|
|
||||||
local winid = _G._test_cmd_to_wins[cmd]
|
local winid = _G._test_cmd_to_wins[cmd]
|
||||||
local current_winid = vim.fn.win_getid()
|
local current_winid = vim.fn.win_getid()
|
||||||
if winid == nil or not vim.api.nvim_win_is_valid(winid) or winid == current_winid or not vim.fn.win_gotoid(winid) == -1 then
|
if
|
||||||
vim.api.nvim_command([[10split]])
|
winid == nil
|
||||||
winid = vim.fn.win_getid()
|
or not vim.api.nvim_win_is_valid(winid)
|
||||||
_G._test_cmd_to_wins[cmd] = winid
|
or winid == current_winid
|
||||||
end
|
or not vim.fn.win_gotoid(winid) == -1
|
||||||
|
then
|
||||||
|
vim.api.nvim_command([[10split]])
|
||||||
|
winid = vim.fn.win_getid()
|
||||||
|
_G._test_cmd_to_wins[cmd] = winid
|
||||||
|
end
|
||||||
|
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
vim.api.nvim_buf_set_option(buf, "bufhidden", "delete")
|
vim.api.nvim_buf_set_option(buf, "bufhidden", "delete")
|
||||||
vim.api.nvim_win_set_buf(winid, buf)
|
vim.api.nvim_win_set_buf(winid, buf)
|
||||||
|
|
||||||
vim.fn.termopen(cmd)
|
vim.fn.termopen(cmd)
|
||||||
vim.api.nvim_command([[normal! G]])
|
vim.api.nvim_command([[normal! G]])
|
||||||
vim.api.nvim_command([[wincmd p]])
|
vim.api.nvim_command([[wincmd p]])
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.focus_tests = function()
|
_G.focus_tests = function()
|
||||||
local cmd = _G._build_test_cmd()
|
local cmd = _G._build_test_cmd()
|
||||||
if cmd == nil then
|
if cmd == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local winid = _G._test_cmd_to_wins[cmd]
|
local winid = _G._test_cmd_to_wins[cmd]
|
||||||
if winid == nil or not vim.api.nvim_win_is_valid(winid) then
|
if winid == nil or not vim.api.nvim_win_is_valid(winid) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.fn.win_gotoid(winid)
|
vim.fn.win_gotoid(winid)
|
||||||
vim.api.nvim_command([[wincmd =]])
|
vim.api.nvim_command([[wincmd =]])
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.close_tests = function()
|
_G.close_tests = function()
|
||||||
local current_winid = vim.api.nvim_get_current_win()
|
local current_winid = vim.api.nvim_get_current_win()
|
||||||
for _, winid in pairs(_G._test_cmd_to_wins) do
|
for _, winid in pairs(_G._test_cmd_to_wins) do
|
||||||
if current_winid == winid and vim.api.nvim_win_is_valid(winid) then
|
if current_winid == winid and vim.api.nvim_win_is_valid(winid) then
|
||||||
vim.api.nvim_win_close(winid, false)
|
vim.api.nvim_win_close(winid, false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local cmd = _G._build_test_cmd()
|
local cmd = _G._build_test_cmd()
|
||||||
if cmd == nil then
|
if cmd == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local winid = _G._test_cmd_to_wins[cmd]
|
local winid = _G._test_cmd_to_wins[cmd]
|
||||||
if winid == nil or not vim.api.nvim_win_is_valid(winid) then
|
if winid == nil or not vim.api.nvim_win_is_valid(winid) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_win_close(winid, false)
|
vim.api.nvim_win_close(winid, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.copy_test_cmd = function()
|
_G.copy_test_cmd = function()
|
||||||
local cmd = _G._build_test_cmd()
|
local cmd = _G._build_test_cmd()
|
||||||
if cmd == nil then
|
if cmd == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.fn.setreg("+", cmd)
|
vim.fn.setreg("+", cmd)
|
||||||
print("Copied: " .. cmd)
|
print("Copied: " .. cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_set_keymap("n", "<leader>cr", [[:lua _G.run_tests()<cr>]], {noremap = true, silent = true})
|
vim.api.nvim_set_keymap("n", "<leader>cr", [[:lua _G.run_tests()<cr>]], { noremap = true, silent = true })
|
||||||
vim.api.nvim_set_keymap("n", "<leader>cf", [[:lua _G.focus_tests()<cr>]], {noremap = true, silent = true})
|
vim.api.nvim_set_keymap("n", "<leader>cf", [[:lua _G.focus_tests()<cr>]], { noremap = true, silent = true })
|
||||||
vim.api.nvim_set_keymap("n", "<leader>cq", [[:lua _G.close_tests()<cr>]], {noremap = true, silent = true})
|
vim.api.nvim_set_keymap("n", "<leader>cq", [[:lua _G.close_tests()<cr>]], { noremap = true, silent = true })
|
||||||
vim.api.nvim_set_keymap("n", "<leader>cc", [[:lua _G.copy_test_cmd()<cr>]], {noremap = true, silent = true})
|
vim.api.nvim_set_keymap("n", "<leader>cc", [[:lua _G.copy_test_cmd()<cr>]], { noremap = true, silent = true })
|
||||||
|
|
|
@ -1,93 +1,93 @@
|
||||||
require 'nvim-treesitter.configs'.setup {
|
require("nvim-treesitter.configs").setup({
|
||||||
ensure_installed = "all",
|
ensure_installed = "all",
|
||||||
highlight = {
|
highlight = {
|
||||||
enable = true,
|
enable = true,
|
||||||
disable = {"vim", "swift"},
|
disable = { "vim", "swift" },
|
||||||
additional_vim_regex_highlighting = true,
|
additional_vim_regex_highlighting = true,
|
||||||
},
|
},
|
||||||
incremental_selection = {
|
incremental_selection = {
|
||||||
enable = true,
|
enable = true,
|
||||||
},
|
},
|
||||||
indent = {
|
indent = {
|
||||||
-- enabling breaks autoindent:
|
-- enabling breaks autoindent:
|
||||||
enable = false,
|
enable = false,
|
||||||
},
|
},
|
||||||
textobjects = {
|
textobjects = {
|
||||||
select = {
|
select = {
|
||||||
enable = true,
|
enable = true,
|
||||||
lookahead = true,
|
lookahead = true,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
["ak"] = "@keyed_element.outer",
|
["ak"] = "@keyed_element.outer",
|
||||||
["av"] = "@keyed_element.inner",
|
["av"] = "@keyed_element.inner",
|
||||||
["ia"] = "@parameter.inner",
|
["ia"] = "@parameter.inner",
|
||||||
["aa"] = "@parameter.outer",
|
["aa"] = "@parameter.outer",
|
||||||
["ac"] = "@comment.outer",
|
["ac"] = "@comment.outer",
|
||||||
["at"] = "@statement.outer",
|
["at"] = "@statement.outer",
|
||||||
["ar"] = "@return",
|
["ar"] = "@return",
|
||||||
["af"] = "@function.outer",
|
["af"] = "@function.outer",
|
||||||
["if"] = "@function.inner",
|
["if"] = "@function.inner",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
move = {
|
move = {
|
||||||
enable = true,
|
enable = true,
|
||||||
set_jumps = true,
|
set_jumps = true,
|
||||||
goto_next_start = {
|
goto_next_start = {
|
||||||
["]a"] = "@parameter.inner",
|
["]a"] = "@parameter.inner",
|
||||||
["]f"] = "@function.outer",
|
["]f"] = "@function.outer",
|
||||||
["]F"] = "@function.inner",
|
["]F"] = "@function.inner",
|
||||||
},
|
},
|
||||||
goto_previous_start = {
|
goto_previous_start = {
|
||||||
["[a"] = "@parameter.inner",
|
["[a"] = "@parameter.inner",
|
||||||
["[f"] = "@function.outer",
|
["[f"] = "@function.outer",
|
||||||
["[F"] = "@function.inner",
|
["[F"] = "@function.inner",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
lsp_interop = {
|
lsp_interop = {
|
||||||
enable = true,
|
enable = true,
|
||||||
peek_definition_code = {
|
peek_definition_code = {
|
||||||
["<leader>d"] = "@class.outer",
|
["<leader>d"] = "@class.outer",
|
||||||
-- ["<leader>d"] = "@function.outer",
|
-- ["<leader>d"] = "@function.outer",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
refactor = {
|
refactor = {
|
||||||
highlight_definitions = { enable = true },
|
highlight_definitions = { enable = true },
|
||||||
highlight_current_scope = { enable = false },
|
highlight_current_scope = { enable = false },
|
||||||
smart_rename = {
|
smart_rename = {
|
||||||
enable = true,
|
enable = true,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
smart_rename = "grr",
|
smart_rename = "grr",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
navigation = {
|
navigation = {
|
||||||
enable = true,
|
enable = true,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
-- goto_definition_lsp_fallback = "gd",
|
-- goto_definition_lsp_fallback = "gd",
|
||||||
goto_next_usage = "]r",
|
goto_next_usage = "]r",
|
||||||
goto_previous_usage = "[r",
|
goto_previous_usage = "[r",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
playground = {
|
playground = {
|
||||||
enable = true,
|
enable = true,
|
||||||
disable = {},
|
disable = {},
|
||||||
updatetime = 25,
|
updatetime = 25,
|
||||||
persist_queries = false,
|
persist_queries = false,
|
||||||
keybindings = {
|
keybindings = {
|
||||||
toggle_query_editor = 'o',
|
toggle_query_editor = "o",
|
||||||
toggle_hl_groups = 'i',
|
toggle_hl_groups = "i",
|
||||||
toggle_injected_languages = 't',
|
toggle_injected_languages = "t",
|
||||||
toggle_anonymous_nodes = 'a',
|
toggle_anonymous_nodes = "a",
|
||||||
toggle_language_display = 'I',
|
toggle_language_display = "I",
|
||||||
focus_language = 'f',
|
focus_language = "f",
|
||||||
unfocus_language = 'F',
|
unfocus_language = "F",
|
||||||
update = 'R',
|
update = "R",
|
||||||
goto_node = '<cr>',
|
goto_node = "<cr>",
|
||||||
show_help = '?',
|
show_help = "?",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
require'treesitter-context'.setup{
|
require("treesitter-context").setup({
|
||||||
enable = true,
|
enable = true,
|
||||||
}
|
})
|
||||||
|
|
Loading…
Reference in New Issue