mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
parent
dad88aa92f
commit
1bdcd3386e
13 changed files with 0 additions and 0 deletions
83
.config/nvim/plugin/autopairs.lua
Normal file
83
.config/nvim/plugin/autopairs.lua
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
local Rule = require("nvim-autopairs.rule")
|
||||
local cond = require("nvim-autopairs.conds")
|
||||
local npairs = require("nvim-autopairs")
|
||||
local cmp = require("cmp")
|
||||
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
|
||||
|
||||
npairs.setup {
|
||||
disable_filetype = { "fennel", "clojure", "lisp", "racket", "scheme" },
|
||||
}
|
||||
|
||||
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|
||||
|
||||
for _, punct in pairs { ",", ";" } do
|
||||
npairs.add_rule(
|
||||
Rule("", punct)
|
||||
:with_move(function(opts) return opts.char == punct end)
|
||||
:with_pair(function() return false end)
|
||||
:with_del(function() return false end)
|
||||
:with_cr(function() return false end)
|
||||
:use_key(punct)
|
||||
)
|
||||
end
|
||||
|
||||
local function double_trouble(opts, pattern) return select(2, opts.line:gsub(pattern, "")) % 2 == 0 end
|
||||
npairs.add_rules {
|
||||
Rule("$", "$", "typst")
|
||||
:with_pair(function(opts) return double_trouble(opts, "%$") end)
|
||||
:with_del(function(opts) return double_trouble(opts, "%$") end)
|
||||
:with_move(cond.done()),
|
||||
|
||||
Rule("<", ">", { "html" })
|
||||
:with_pair(function(opts) return double_trouble(opts, "[<>]") end)
|
||||
:with_del(function(opts) return double_trouble(opts, "[<>]") end)
|
||||
:with_move(function(opts) return opts.char == ">" end),
|
||||
}
|
||||
|
||||
local function pair_with_insertion(a1, ins, a2, lang)
|
||||
npairs.add_rule(
|
||||
Rule(ins, ins, lang)
|
||||
:with_pair(function(opts) return a1 .. a2 == opts.line:sub(opts.col - #a1, opts.col + #a2 - 1) end)
|
||||
:with_move(cond.none())
|
||||
:with_cr(cond.none())
|
||||
:with_del(function(opts)
|
||||
local col = vim.api.nvim_win_get_cursor(0)[2]
|
||||
return a1 .. ins .. ins .. a2 == opts.line:sub(col - #a1 - #ins + 1, col + #ins + #a2) -- insert only works for #ins == 1 anyway
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
pair_with_insertion("(", "*", ")", { "ocaml", "why3", "skel", "isabelle" })
|
||||
pair_with_insertion("(*", " ", "*)", { "ocaml", "why3", "skel", "isabelle" })
|
||||
|
||||
pair_with_insertion("[", " ", "]", { "typst", "python", "haskell", "nix", "sh" })
|
||||
pair_with_insertion("{", " ", "}", nil)
|
||||
|
||||
npairs.add_rules {
|
||||
Rule("*", "*/", { "typst", "go", "rust", "scss" })
|
||||
:with_pair(function(opts) return "/" == opts.line:sub(opts.col - 1, opts.col) end)
|
||||
:with_del(cond.none()) -- this is only a partial rule, deletion doesn't make sense
|
||||
:with_move(cond.none()), -- allow java doc
|
||||
}
|
||||
pair_with_insertion("/*", " ", "*/", { "typst", "go", "java", "rust", "scss" })
|
||||
|
||||
pair_with_insertion("{", "#", "}", { "html", "htmldjango" })
|
||||
pair_with_insertion("{#", " ", "#}", { "html", "htmldjango" })
|
||||
pair_with_insertion("{#", "-", "#}", { "html", "htmldjango" })
|
||||
pair_with_insertion("{#-", " ", "-#}", { "html", "htmldjango" })
|
||||
|
||||
pair_with_insertion("{", "%", "}", { "html", "htmldjango" })
|
||||
pair_with_insertion("{%", " ", "%}", { "html", "htmldjango" })
|
||||
pair_with_insertion("{%", "-", "%}", { "html", "htmldjango" })
|
||||
pair_with_insertion("{%-", " ", "-%}", { "html", "htmldjango" })
|
||||
|
||||
pair_with_insertion("{{", " ", "}}", { "html", "htmldjango" })
|
||||
pair_with_insertion("{{", "-", "}}", { "html", "htmldjango" })
|
||||
pair_with_insertion("{{-", " ", "-}}", { "html", "htmldjango" })
|
||||
|
||||
pair_with_insertion("$", " ", "$", { "typst" })
|
||||
|
||||
pair_with_insertion("{", "-", "}", { "haskell" })
|
||||
pair_with_insertion("{-", " ", "-}", { "haskell" }) -- block comment
|
||||
pair_with_insertion("{-", "#", "-}", { "haskell" }) -- language flags
|
||||
pair_with_insertion("{-#", " ", "#-}", { "haskell" })
|
||||
208
.config/nvim/plugin/cmp.lua
Normal file
208
.config/nvim/plugin/cmp.lua
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
local cmp = require("cmp")
|
||||
local ls = require("luasnip")
|
||||
|
||||
local s = ls.snippet
|
||||
local sn = ls.snippet_node
|
||||
local t = ls.text_node
|
||||
local cr = function() return t { "", "" } end -- linebreak
|
||||
local i = ls.insert_node
|
||||
local f = ls.function_node
|
||||
local c = ls.choice_node
|
||||
local d = ls.dynamic_node
|
||||
local r = ls.restore_node
|
||||
local l = require("luasnip.extras").lambda
|
||||
local rep = require("luasnip.extras").rep
|
||||
local p = require("luasnip.extras").partial
|
||||
local m = require("luasnip.extras").match
|
||||
local n = require("luasnip.extras").nonempty
|
||||
local dl = require("luasnip.extras").dynamic_lambda
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
local types = require("luasnip.util.types")
|
||||
local conds = require("luasnip.extras.conditions")
|
||||
local conds_expand = require("luasnip.extras.conditions.expand")
|
||||
|
||||
local has_words_before = function()
|
||||
unpack = unpack or table.unpack
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
|
||||
-----------------
|
||||
-- Lazy loader --
|
||||
-----------------
|
||||
require("luasnip.loaders.from_vscode").lazy_load { paths = { "./snippets" } }
|
||||
|
||||
----------
|
||||
-- Init --
|
||||
----------
|
||||
ls.setup { update_events = { "TextChanged", "TextChangedI" } }
|
||||
|
||||
-----------
|
||||
-- Typst --
|
||||
-----------
|
||||
local function show_date_typst_entry() return os.date('"%Y-%m-%d %H:%M:%S"') end
|
||||
ls.add_snippets("typst", {
|
||||
s("entry", {
|
||||
t("#entry("),
|
||||
f(show_date_typst_entry),
|
||||
t { ")[", "" },
|
||||
t(" "),
|
||||
i(0),
|
||||
t { "", "]" },
|
||||
}),
|
||||
s("lang", {
|
||||
t('#set text(lang: "'),
|
||||
i(0),
|
||||
t('")'),
|
||||
cr(),
|
||||
}),
|
||||
})
|
||||
|
||||
local function get_cms()
|
||||
assert(vim.bo.commentstring ~= "", "comment string is not set")
|
||||
local left = vim.bo.commentstring:gsub("%s*%%s.*", "")
|
||||
local right = vim.bo.commentstring:gsub(".*%%s%s*", "")
|
||||
if right == "" then
|
||||
right = left
|
||||
end
|
||||
return { left = left, right = right }
|
||||
end
|
||||
local function horizon(args)
|
||||
local cms = get_cms()
|
||||
local chr = cms.left:sub(-1)
|
||||
local len = vim.fn.strdisplaywidth(args[1][1])
|
||||
|
||||
local acc = cms.left
|
||||
for _ = cms.left:len(), len + cms.right:len() + 1, 1 do
|
||||
acc = acc .. chr
|
||||
end
|
||||
acc = acc .. cms.right
|
||||
|
||||
return acc
|
||||
end
|
||||
local function left()
|
||||
local cms = get_cms()
|
||||
return cms.left .. " "
|
||||
end
|
||||
local function right()
|
||||
local cms = get_cms()
|
||||
return " " .. cms.right
|
||||
end
|
||||
|
||||
-- stylua: ignore start
|
||||
ls.add_snippets("all", {
|
||||
s("banner", {
|
||||
f(horizon, { 1 }), cr(),
|
||||
f(left), i(1), f(right), cr(),
|
||||
f(horizon, { 1 }),
|
||||
}),
|
||||
})
|
||||
-- stylua: ignore end
|
||||
|
||||
-------------
|
||||
-- Haskell --
|
||||
-------------
|
||||
local haskell_snippets = require("haskell-snippets").all
|
||||
ls.add_snippets("haskell", haskell_snippets, { key = "haskell" })
|
||||
|
||||
------------
|
||||
-- Golang --
|
||||
------------
|
||||
-- stylua: ignore start
|
||||
ls.add_snippets("go", {
|
||||
s("ie", {
|
||||
t("if err != nil {"), cr(),
|
||||
t("\t"), i(0), cr(),
|
||||
t("}"),
|
||||
}),
|
||||
})
|
||||
-- stylua: ignore end
|
||||
|
||||
---------------
|
||||
-- Setup CMP --
|
||||
---------------
|
||||
local of_filetype = function(fts)
|
||||
local ft = vim.bo.filetype
|
||||
for _, v in ipairs(fts) do
|
||||
if v == ft then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
cmp.setup {
|
||||
snippet = {
|
||||
expand = function(args) ls.lsp_expand(args.body) end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert {
|
||||
["<Tab>"] = cmp.mapping(function(fallback) -- Next or jump
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif ls.expand_or_locally_jumpable() then
|
||||
ls.expand_or_jump()
|
||||
elseif has_words_before() and (not of_filetype { "ledger" }) then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback) -- Previous
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif ls.jumpable(-1) then
|
||||
ls.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<A-Tab>"] = cmp.mapping(function(fallback) -- Force jump
|
||||
if ls.expand_or_locally_jumpable() then
|
||||
ls.expand_or_jump()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<CR>"] = cmp.mapping(function(fallback) -- Confirm
|
||||
if cmp.visible() then
|
||||
cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Insert,
|
||||
select = true,
|
||||
}()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<S-CR>"] = cmp.mapping(function(fallback) -- Confirm and replace
|
||||
if cmp.visible() then
|
||||
cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = true,
|
||||
}()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
},
|
||||
sources = {
|
||||
{ name = "luasnip" },
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "path" },
|
||||
{
|
||||
name = "buffer",
|
||||
keyword_length = 10,
|
||||
option = {
|
||||
enable_in_context = function() return of_filetype { "tex", "markdown", "typst" } end,
|
||||
},
|
||||
},
|
||||
{
|
||||
name = "spell",
|
||||
keyword_length = 10,
|
||||
option = {
|
||||
keep_all_entries = true,
|
||||
enable_in_context = function() return of_filetype { "tex", "markdown", "typst" } end,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
21
.config/nvim/plugin/colorizer.lua
Normal file
21
.config/nvim/plugin/colorizer.lua
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
local default = {
|
||||
RGB = true, -- #RGB hex codes
|
||||
RRGGBB = true, -- #RRGGBB hex codes
|
||||
names = false, -- "Name" codes like Blue or blue
|
||||
RRGGBBAA = false, -- #RRGGBBAA hex codes
|
||||
AARRGGBB = false, -- 0xAARRGGBB hex codes
|
||||
rgb_fn = false, -- CSS rgb() and rgba() functions
|
||||
hsl_fn = false, -- CSS hsl() and hsla() functions
|
||||
css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
|
||||
css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn
|
||||
|
||||
mode = "background",
|
||||
always_update = true,
|
||||
}
|
||||
|
||||
require("colorizer").setup {
|
||||
filetypes = {
|
||||
"*",
|
||||
},
|
||||
user_default_options = default,
|
||||
}
|
||||
38
.config/nvim/plugin/gitsigns.lua
Normal file
38
.config/nvim/plugin/gitsigns.lua
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
require("gitsigns").setup {
|
||||
on_attach = function(bufnr)
|
||||
local gs = package.loaded.gitsigns
|
||||
|
||||
local function map(mode, l, r, opts)
|
||||
opts = opts or {}
|
||||
opts.buffer = bufnr
|
||||
vim.keymap.set(mode, l, r, opts)
|
||||
end
|
||||
|
||||
-- Navigation
|
||||
map("n", "<leader>hj", gs.next_hunk)
|
||||
map("n", "<leader>hk", gs.prev_hunk)
|
||||
|
||||
-- Actions
|
||||
map("n", "<leader>hs", gs.stage_hunk)
|
||||
map("n", "<leader>hu", gs.undo_stage_hunk)
|
||||
map("n", "<leader>hr", gs.reset_hunk)
|
||||
|
||||
map("v", "<leader>hs", function() gs.stage_hunk { vim.fn.line("."), vim.fn.line("v") } end)
|
||||
map("v", "<leader>hr", function() gs.reset_hunk { vim.fn.line("."), vim.fn.line("v") } end)
|
||||
|
||||
map("n", "<leader>hS", gs.stage_buffer)
|
||||
map("n", "<leader>hR", gs.reset_buffer)
|
||||
|
||||
map("n", "<leader>hp", gs.preview_hunk)
|
||||
map("n", "<leader>hb", function() gs.blame_line { full = true } end)
|
||||
map("n", "<leader>tb", gs.toggle_current_line_blame)
|
||||
|
||||
map("n", "<leader>hd", gs.diffthis)
|
||||
map("n", "<leader>hD", function() gs.diffthis("~") end)
|
||||
|
||||
map("n", "<leader>pd", gs.toggle_deleted)
|
||||
|
||||
-- Text object
|
||||
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
|
||||
end,
|
||||
}
|
||||
20
.config/nvim/plugin/harpoon.lua
Normal file
20
.config/nvim/plugin/harpoon.lua
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
local harpoon = require("harpoon")
|
||||
local map = vim.keymap.set
|
||||
|
||||
harpoon:setup {
|
||||
settings = { save_on_toggle = true },
|
||||
}
|
||||
|
||||
-- add and view
|
||||
map({ "n", "i" }, "<A-c>", function() harpoon:list():add() end)
|
||||
map({ "n", "i" }, "<A-g>", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
|
||||
|
||||
-- switch it up!
|
||||
map({ "n", "i" }, "<A-h>", function() harpoon:list():select(1) end)
|
||||
map({ "n", "i" }, "<A-t>", function() harpoon:list():select(2) end)
|
||||
map({ "n", "i" }, "<A-n>", function() harpoon:list():select(3) end)
|
||||
map({ "n", "i" }, "<A-s>", function() harpoon:list():select(4) end)
|
||||
map({ "n", "i" }, "<A-m>", function() harpoon:list():select(5) end)
|
||||
map({ "n", "i" }, "<A-w>", function() harpoon:list():select(6) end)
|
||||
map({ "n", "i" }, "<A-v>", function() harpoon:list():select(7) end)
|
||||
map({ "n", "i" }, "<A-z>", function() harpoon:list():select(8) end)
|
||||
2
.config/nvim/plugin/leap.lua
Normal file
2
.config/nvim/plugin/leap.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
local leap = require("leap")
|
||||
leap.add_default_mappings()
|
||||
282
.config/nvim/plugin/lsp.lua
Normal file
282
.config/nvim/plugin/lsp.lua
Normal file
|
|
@ -0,0 +1,282 @@
|
|||
local map = vim.keymap.set
|
||||
local methods = vim.lsp.protocol.Methods
|
||||
|
||||
----------------------
|
||||
-- Language servers --
|
||||
----------------------
|
||||
-- NOTE: put settings into `settings`
|
||||
-- use another `on_attach` field if needed
|
||||
local servers = {
|
||||
clangd = {}, -- C/CPP
|
||||
cssls = {}, -- CSS
|
||||
html = {}, -- HTML
|
||||
jsonls = {}, -- JSON
|
||||
lemminx = {}, -- XML
|
||||
phpactor = {}, -- PHP
|
||||
pylsp = {}, -- Python
|
||||
pyright = {},
|
||||
taplo = {}, -- TOML
|
||||
texlab = {}, -- texlab
|
||||
ts_ls = {}, -- TypeScript
|
||||
vimls = {}, -- Vim Script
|
||||
ocamllsp = {}, -- OCaml
|
||||
gleam = {}, -- Gleam
|
||||
yamlls = {}, -- yaml
|
||||
gopls = {}, -- Golang
|
||||
elmls = {}, -- elm
|
||||
|
||||
-- -- fix this, it shows spamming message on top
|
||||
-- golangci_lint_ls = {},
|
||||
|
||||
fish_lsp = {},
|
||||
|
||||
bashls = { -- Bash
|
||||
on_attach = function(_, bufno)
|
||||
map("n", "<leader>f", function()
|
||||
local saved = vim.fn.winsaveview()
|
||||
vim.cmd([[silent exec "%!shfmt"]])
|
||||
vim.fn.winrestview(saved)
|
||||
end, { buffer = bufno })
|
||||
end,
|
||||
},
|
||||
|
||||
tinymist = {
|
||||
on_attach = function(_, bufno)
|
||||
map("n", "<leader>f", function()
|
||||
local saved = vim.fn.winsaveview()
|
||||
vim.cmd([[silent exec "%!typstyle -c 100"]])
|
||||
vim.fn.winrestview(saved)
|
||||
end, { buffer = bufno })
|
||||
end,
|
||||
},
|
||||
|
||||
lua_ls = { -- Lua
|
||||
on_attach = function(_, bufno)
|
||||
map("n", "<leader>f", function()
|
||||
local saved = vim.fn.winsaveview()
|
||||
vim.cmd([[silent exec "!stylua %"]])
|
||||
vim.fn.winrestview(saved)
|
||||
end, { buffer = bufno })
|
||||
end,
|
||||
settings = {
|
||||
Lua = {
|
||||
workspace = {
|
||||
checkThirdParty = "Disable",
|
||||
library = { vim.env.VIMRUNTIME },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
nil_ls = { -- Nix
|
||||
settings = { ["nil"] = { formatting = { command = { "alejandra" } } } },
|
||||
},
|
||||
}
|
||||
|
||||
-------------
|
||||
-- Helpers --
|
||||
-------------
|
||||
local on_attach = function(client, bufnr)
|
||||
vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc", { buf = bufnr })
|
||||
local telescope = require("telescope.builtin")
|
||||
|
||||
map("n", "K", vim.lsp.buf.hover, { buffer = bufnr })
|
||||
map("n", "<C-k>", vim.lsp.buf.signature_help, { buffer = bufnr })
|
||||
map("n", "gd", telescope.lsp_definitions, { buffer = bufnr })
|
||||
-- conflicts with tabs
|
||||
-- map("n", "gtd", vim.lsp.buf.type_definition, { buffer = bufnr })
|
||||
-- map("n", "gi", vim.lsp.buf.implementation, { buffer = bufnr })
|
||||
map("n", "gu", telescope.lsp_references, { buffer = bufnr })
|
||||
map("n", "<leader>ca", vim.lsp.buf.code_action, { buffer = bufnr })
|
||||
map("n", "<leader>cl", vim.lsp.codelens.run, { buffer = bufnr })
|
||||
map("n", "<leader>r", vim.lsp.buf.rename, { buffer = bufnr })
|
||||
map("n", "<leader>f", function() vim.lsp.buf.format { async = true } end, { buffer = bufnr })
|
||||
|
||||
local filetype = vim.api.nvim_get_option_value("filetype", { buf = bufnr })
|
||||
if
|
||||
client:supports_method(methods.textDocument_inlayHint)
|
||||
-- Never start cabal with inlay hint request
|
||||
-- Related: https://github.com/mrcjkb/haskell-tools.nvim/discussions/485
|
||||
and filetype ~= "cabal"
|
||||
then
|
||||
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
|
||||
end
|
||||
end
|
||||
|
||||
-- Helix style border
|
||||
local border = {
|
||||
{ " ", "FloatBorder" },
|
||||
{ " ", "FloatBorder" },
|
||||
{ " ", "FloatBorder" },
|
||||
{ " ", "FloatBorder" },
|
||||
{ " ", "FloatBorder" },
|
||||
{ " ", "FloatBorder" },
|
||||
{ " ", "FloatBorder" },
|
||||
{ " ", "FloatBorder" },
|
||||
}
|
||||
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
|
||||
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
|
||||
opts = opts or {}
|
||||
opts.border = border
|
||||
return orig_util_open_floating_preview(contents, syntax, opts, ...)
|
||||
end
|
||||
|
||||
-- Diagnostic display configuration
|
||||
vim.diagnostic.config { virtual_text = false, severity_sort = true }
|
||||
|
||||
-- Set log level
|
||||
vim.lsp.set_log_level("off")
|
||||
|
||||
-- Gutter symbols setup
|
||||
vim.fn.sign_define("DiagnosticSignError", { text = "E", texthl = "DiagnosticSignError", numhl = "DiagnosticSignError" })
|
||||
vim.fn.sign_define("DiagnosticSignWarn", { text = "W", texthl = "DiagnosticSignWarn", numhl = "DiagnosticSignWarn" })
|
||||
vim.fn.sign_define("DiagnosticSignHint", { text = "H", texthl = "DiagnosticSignHint", numhl = "DiagnosticSignHint" })
|
||||
vim.fn.sign_define("DiagnosticSignInfo", { text = "·", texthl = "DiagnosticSignInfo", numhl = "DiagnosticSignInfo" })
|
||||
|
||||
-- Capabilities
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
|
||||
|
||||
----------
|
||||
-- Init --
|
||||
----------
|
||||
require("fidget").setup()
|
||||
|
||||
for name, config in pairs(servers) do
|
||||
require("lspconfig")[name].setup {
|
||||
capabilities = capabilities,
|
||||
settings = config.settings,
|
||||
-- NOTE: https://github.com/neovim/neovim/issues/30675
|
||||
offset_encoding = config.offset_encoding or "utf-8",
|
||||
on_attach = function(client, bufno)
|
||||
on_attach(client, bufno);
|
||||
(config.on_attach or function(...) end)(client, bufno)
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
------------------------
|
||||
-- Standalone plugins --
|
||||
------------------------
|
||||
-- Java
|
||||
local config = {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
cmd = {
|
||||
-- https://github.com/NixOS/nixpkgs/issues/232822#issuecomment-1564243667
|
||||
-- `-data` argument is necessary
|
||||
"jdtls",
|
||||
"-data",
|
||||
vim.fn.expand("~/.cache/jdtls") .. vim.fn.expand("%:p:h"),
|
||||
},
|
||||
root_dir = vim.fs.dirname(vim.fs.find({ "gradlew", ".git", "mvnw" }, { upward = true })[1]),
|
||||
}
|
||||
local jdtls_group = vim.api.nvim_create_augroup("jdtls", { clear = true })
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "java" },
|
||||
callback = function() require("jdtls").start_or_attach(config) end,
|
||||
group = jdtls_group,
|
||||
})
|
||||
|
||||
-- Scala
|
||||
local metals = require("metals")
|
||||
local metals_config = metals.bare_config()
|
||||
metals_config.capabilities = capabilities
|
||||
metals_config.settings.useGlobalExecutable = true
|
||||
|
||||
require("dap").configurations.scala = {
|
||||
{
|
||||
type = "scala",
|
||||
request = "launch",
|
||||
name = "RunOrTest",
|
||||
metals = { runType = "runOrTestFile" },
|
||||
},
|
||||
{
|
||||
type = "scala",
|
||||
request = "launch",
|
||||
name = "Test Target",
|
||||
metals = { runType = "testTarget" },
|
||||
},
|
||||
}
|
||||
|
||||
metals_config.on_attach = function(client, bufnr)
|
||||
metals.setup_dap()
|
||||
|
||||
map("n", "<leader>ws", metals.hover_worksheet)
|
||||
|
||||
map("n", "<leader>dc", require("dap").continue)
|
||||
map("n", "<leader>dr", require("dap").repl.toggle)
|
||||
map("n", "<leader>dK", require("dap.ui.widgets").hover)
|
||||
map("n", "<leader>dt", require("dap").toggle_breakpoint)
|
||||
map("n", "<leader>dso", require("dap").step_over)
|
||||
map("n", "<leader>dsi", require("dap").step_into)
|
||||
map("n", "<leader>dl", require("dap").run_last)
|
||||
|
||||
on_attach(client, bufnr)
|
||||
end
|
||||
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "scala", "sbt" },
|
||||
callback = function() require("metals").initialize_or_attach(metals_config) end,
|
||||
group = nvim_metals_group,
|
||||
})
|
||||
|
||||
-- Haskell
|
||||
vim.g.haskell_tools = {
|
||||
tools = {
|
||||
log = { level = vim.log.levels.OFF },
|
||||
hover = {
|
||||
border = border,
|
||||
stylize_markdown = true,
|
||||
},
|
||||
},
|
||||
hls = {
|
||||
on_attach = function(client, bufnr)
|
||||
local ht = require("haskell-tools")
|
||||
local opts = { buffer = bufnr }
|
||||
|
||||
map("n", "<leader>hhe", ht.lsp.buf_eval_all, opts)
|
||||
map("n", "<leader>hhs", ht.hoogle.hoogle_signature, opts)
|
||||
map("n", "<leader>hhr", ht.repl.toggle, opts)
|
||||
|
||||
vim.opt_local.shiftwidth = 2
|
||||
on_attach(client, bufnr)
|
||||
end,
|
||||
default_settings = {
|
||||
haskell = {
|
||||
checkProject = false, -- PERF: don't check the entire project on initial load
|
||||
formattingProvider = "fourmolu",
|
||||
plugin = {
|
||||
rename = {
|
||||
config = {
|
||||
diff = true, -- (experimental) rename across modules
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
settings = function(project_root)
|
||||
local ht = require("haskell-tools")
|
||||
return ht.lsp.load_hls_settings(project_root, { settings_file_pattern = "hls.json" })
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
----------
|
||||
-- Rust --
|
||||
----------
|
||||
vim.g.rustaceanvim = {
|
||||
server = {
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
["rust-analyzer"] = { files = { excludeDirs = { ".direnv/" } } },
|
||||
},
|
||||
},
|
||||
tools = {
|
||||
hover = {
|
||||
border = border,
|
||||
stylize_markdown = true,
|
||||
},
|
||||
log = { level = vim.log.levels.OFF },
|
||||
},
|
||||
}
|
||||
6
.config/nvim/plugin/no-neck-pain.lua
Normal file
6
.config/nvim/plugin/no-neck-pain.lua
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
require("no-neck-pain").setup {
|
||||
width = 75,
|
||||
buffers = {
|
||||
right = { enabled = false },
|
||||
},
|
||||
}
|
||||
34
.config/nvim/plugin/oil.lua
Normal file
34
.config/nvim/plugin/oil.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
require("oil").setup {
|
||||
-- This bug would prevent downloading language files from working
|
||||
-- https://github.com/stevearc/oil.nvim/issues/483
|
||||
default_file_explorer = false,
|
||||
columns = {
|
||||
-- "icon",
|
||||
-- "permissions",
|
||||
-- "size",
|
||||
-- "mtime",
|
||||
},
|
||||
skip_confirm_for_simple_edits = true,
|
||||
prompt_save_on_select_new_entry = false,
|
||||
keymaps = {
|
||||
["g?"] = "actions.show_help",
|
||||
["<CR>"] = "actions.select",
|
||||
-- ["<C-v>"] = "actions.select_vsplit",
|
||||
["<C-x>"] = "actions.select_split",
|
||||
["<C-t>"] = "actions.select_tab",
|
||||
["<C-p>"] = "actions.preview",
|
||||
["<C-c>"] = "actions.close",
|
||||
["<C-l>"] = "actions.refresh",
|
||||
["-"] = "actions.parent",
|
||||
["_"] = "actions.open_cwd",
|
||||
["`"] = "actions.cd",
|
||||
["~"] = "actions.tcd",
|
||||
["gs"] = "actions.change_sort",
|
||||
["gx"] = "actions.open_external",
|
||||
["g."] = "actions.toggle_hidden",
|
||||
["g\\"] = "actions.toggle_trash",
|
||||
},
|
||||
view_options = {
|
||||
show_hidden = true,
|
||||
},
|
||||
}
|
||||
14
.config/nvim/plugin/reload.lua
Normal file
14
.config/nvim/plugin/reload.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-- helper to reload module
|
||||
|
||||
local usercmd = vim.api.nvim_create_user_command
|
||||
local remove = require("plenary.reload").reload_module
|
||||
|
||||
usercmd("Reload", function(opts)
|
||||
remove(opts.fargs[1])
|
||||
require(opts.fargs[1])
|
||||
end, { nargs = 1 })
|
||||
|
||||
usercmd("ReloadCurry", function(_)
|
||||
remove("curry")
|
||||
require("curry").setup()
|
||||
end, {})
|
||||
95
.config/nvim/plugin/telescope.lua
Normal file
95
.config/nvim/plugin/telescope.lua
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
local telescope = require("telescope")
|
||||
local actions = require("telescope.actions")
|
||||
local themes = require("telescope.themes")
|
||||
local config = require("telescope.config")
|
||||
local builtin = require("telescope.builtin")
|
||||
local state = require("telescope.state")
|
||||
|
||||
-- Clone the default Telescope configuration
|
||||
local vimgrep_arguments = { unpack(config.values.vimgrep_arguments) }
|
||||
|
||||
table.insert(vimgrep_arguments, "--hidden") -- search hidden
|
||||
table.insert(vimgrep_arguments, "--glob") -- ignore git
|
||||
table.insert(vimgrep_arguments, "!**/.git/*")
|
||||
|
||||
telescope.setup {
|
||||
-- Workaround
|
||||
-- https://github.com/nvim-telescope/telescope.nvim/issues/938#issuecomment-877539724
|
||||
defaults = themes.get_ivy {
|
||||
vimgrep_arguments = vimgrep_arguments,
|
||||
mappings = {
|
||||
n = {
|
||||
["<C-c>"] = actions.close,
|
||||
["r"] = actions.to_fuzzy_refine,
|
||||
["j"] = actions.move_selection_next,
|
||||
["k"] = actions.move_selection_previous,
|
||||
},
|
||||
i = {
|
||||
["<Up>"] = actions.cycle_history_prev,
|
||||
["<Down>"] = actions.cycle_history_next,
|
||||
},
|
||||
},
|
||||
layout_config = { height = 0.5 },
|
||||
borderchars = { "", "", "", "│", "", "", "", "" },
|
||||
},
|
||||
pickers = {
|
||||
find_files = {
|
||||
find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" },
|
||||
},
|
||||
current_buffer_fuzzy_find = {
|
||||
mappings = {
|
||||
n = {
|
||||
["n"] = actions.move_selection_next,
|
||||
["N"] = actions.move_selection_previous,
|
||||
},
|
||||
},
|
||||
},
|
||||
lsp_references = {
|
||||
layout_config = { height = 0.7 },
|
||||
initial_mode = "normal",
|
||||
},
|
||||
live_grep = {
|
||||
layout_config = { height = 0.7 },
|
||||
},
|
||||
buffers = {
|
||||
initial_mode = "normal",
|
||||
},
|
||||
resume = {
|
||||
initial_mode = "normal",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Enable telescope fzf native, if installed
|
||||
pcall(require("telescope").load_extension, "fzf")
|
||||
|
||||
local function find_undercursor_in_buffer()
|
||||
builtin["current_buffer_fuzzy_find"] {
|
||||
layout_config = { height = 0.8 }, -- Already have word, no need to think
|
||||
default_text = vim.fn.expand("<cword>"),
|
||||
initial_mode = "normal",
|
||||
}
|
||||
end
|
||||
local function grep_undercursor()
|
||||
builtin["live_grep"] {
|
||||
layout_config = { height = 0.8 }, -- Already have word, no need to think
|
||||
default_text = vim.fn.expand("<cword>"),
|
||||
initial_mode = "normal",
|
||||
}
|
||||
end
|
||||
|
||||
-- Better than builtin /
|
||||
vim.keymap.set("n", "/", builtin["current_buffer_fuzzy_find"])
|
||||
vim.keymap.set("n", "<leader>w", find_undercursor_in_buffer)
|
||||
vim.keymap.set("n", "<leader>W", grep_undercursor)
|
||||
|
||||
-- Use / as prefix to avoid collision in bindings
|
||||
vim.keymap.set("n", "<leader>/f", builtin["find_files"])
|
||||
vim.keymap.set("n", "<leader>/?", builtin["help_tags"])
|
||||
vim.keymap.set("n", "<leader>/g", builtin["live_grep"])
|
||||
vim.keymap.set("n", "<leader>/d", builtin["diagnostics"])
|
||||
vim.keymap.set("n", "<leader>/b", builtin["buffers"])
|
||||
vim.keymap.set("n", "<leader>/p", builtin["spell_suggest"])
|
||||
|
||||
-- for GHC
|
||||
-- grep -> refine for `.hs:` files
|
||||
17
.config/nvim/plugin/todo-comments.lua
Normal file
17
.config/nvim/plugin/todo-comments.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require("todo-comments").setup {
|
||||
keywords = {
|
||||
FIX = { icon = " ", color = "error", alt = { "FIXME", "BUG", "FIXIT", "ISSUE" } },
|
||||
TODO = { icon = " ", color = "info" },
|
||||
HACK = { icon = "!", color = "warning", alt = { "DEBUG" } },
|
||||
WARN = { icon = "!", color = "warning", alt = { "WARNING", "XXX" } },
|
||||
NOTE = { icon = "·", color = "hint", alt = { "INFO" } },
|
||||
TEST = { icon = "T", color = "test", alt = { "TESTING", "PASSED", "FAILED" } },
|
||||
UNIMPLEMENTED = { icon = "@", color = "hint" },
|
||||
-- Q = { icon = "?", color = "warning" },
|
||||
-- R = { icon = "=", color = "hint" },
|
||||
},
|
||||
colors = {
|
||||
info = { "#696c77" },
|
||||
hint = { "#696c77" },
|
||||
},
|
||||
}
|
||||
31
.config/nvim/plugin/treesitter.lua
Normal file
31
.config/nvim/plugin/treesitter.lua
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
require("nvim-treesitter.configs").setup {
|
||||
|
||||
ensure_installed = {
|
||||
-- funny language hehe
|
||||
"haskell",
|
||||
"rust",
|
||||
"nix",
|
||||
-- vim
|
||||
"lua",
|
||||
-- misc
|
||||
"html",
|
||||
"scss",
|
||||
"css",
|
||||
"json",
|
||||
},
|
||||
ignore_install = { "typst", "markdown" },
|
||||
sync_install = false,
|
||||
auto_install = true,
|
||||
highlight = { enable = true },
|
||||
|
||||
-- Disable for large files
|
||||
disable = function(lang, buf)
|
||||
local max_filesize = 100 * 1024 -- 100 KB
|
||||
local ok, stats = pcall(vim.uv.fs_stat, vim.api.nvim_buf_get_name(buf))
|
||||
if ok and stats and stats.size > max_filesize then
|
||||
return true
|
||||
end
|
||||
end,
|
||||
|
||||
indent = true,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue