aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/home/.config/nvim/lua/cfg
diff options
context:
space:
mode:
authorLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2024-05-20 17:08:02 +0100
committerLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2024-05-20 17:08:02 +0100
commit079c385b9bd40a73ebafae6d847f62c2bed5126c (patch)
tree95d5e270ac7dab639fe7bca9b7a02041bfadfa47 /home/.config/nvim/lua/cfg
parent1d6fe632512eca513dab6a8868298df638e50e5e (diff)
downloaddotfiles-079c385b9bd40a73ebafae6d847f62c2bed5126c.tar.gz
dotfiles-079c385b9bd40a73ebafae6d847f62c2bed5126c.tar.bz2
dotfiles-079c385b9bd40a73ebafae6d847f62c2bed5126c.zip
[nvim] Rewrite config motivated by nvim 0.10
Diffstat (limited to 'home/.config/nvim/lua/cfg')
-rw-r--r--home/.config/nvim/lua/cfg/lsp.lua107
-rw-r--r--home/.config/nvim/lua/cfg/options.lua16
-rw-r--r--home/.config/nvim/lua/cfg/utils.lua21
3 files changed, 60 insertions, 84 deletions
diff --git a/home/.config/nvim/lua/cfg/lsp.lua b/home/.config/nvim/lua/cfg/lsp.lua
index 5767ff6..894b578 100644
--- a/home/.config/nvim/lua/cfg/lsp.lua
+++ b/home/.config/nvim/lua/cfg/lsp.lua
@@ -1,64 +1,53 @@
-return {
- on_attach_wrapper = function(client, bufnr, opts)
- local map = require("mapper")
- local autocmd = vim.api.nvim_create_autocmd
+local M = {}
+local map = require("mapper")
+local lspconfig = require("lspconfig")
- opts = vim.tbl_extend("force", { auto_format = false }, opts or {})
+function M.on_attach_wrapper(client, bufnr, opts)
+ local autocmd = vim.api.nvim_create_autocmd
- if client.supports_method("textDocument/codeLens") then
- require("virtualtypes").on_attach(client, bufnr)
- autocmd(
- { "CursorHold", "CursorHoldI", "InsertLeave" },
- { buffer = bufnr, callback = vim.lsp.codelens.refresh }
- )
- map.n("gl", vim.lsp.codelens.run, { buffer = bufnr })
- end
-
- if client.supports_method("textDocument/definition") then
- map.n("<c-]>", vim.lsp.buf.definition, { buffer = bufnr })
- end
- if client.supports_method("textDocument/declaration") then
- map.n("gD", vim.lsp.buf.declaration, { buffer = bufnr })
- end
- if client.supports_method("textDocument/signatureHelp") then
- require("lsp_signature").on_attach(client, bufnr)
- map.n("gs", vim.lsp.buf.signature_help, { buffer = bufnr })
- end
- if client.supports_method("textDocument/rename") then
- map.n("gR", vim.lsp.buf.rename, { buffer = bufnr })
- end
- if client.supports_method("textDocument/codeAction") then
- map.n("ga", vim.lsp.buf.code_action, { buffer = bufnr })
- map.v("ga", vim.lsp.buf.code_action, { buffer = bufnr })
- end
-
- local buf_async_format = function()
- vim.lsp.buf.format(
- { bufnr = bufnr, async = true, id = client.id })
- end
- local buf_sync_format = function()
- vim.lsp.buf.format(
- { bufnr = bufnr, async = false, id = client.id })
- end
- local buf_async_format_hunks = function()
- require("cfg.utils").format_hunks(
- { bufnr = bufnr, async = true, id = client.id })
- end
+ if client.supports_method("textDocument/codeLens") then
+ autocmd(
+ { "CursorHold", "CursorHoldI", "InsertLeave" },
+ { buffer = bufnr, callback = vim.lsp.codelens.refresh }
+ )
+ map.n("gl", vim.lsp.codelens.run, { buffer = bufnr })
+ end
- if client.supports_method("textDocument/formatting") then
- map.n("<leader>f", buf_async_format, { buffer = bufnr })
- if opts.auto_format then
- autocmd(
- "BufWritePre",
- { buffer = bufnr, callback = buf_sync_format }
- )
- end
- end
- if client.supports_method("textDocument/rangeFormatting") then
- map.v("<leader>f", buf_async_format, { buffer = bufnr })
- map.n("<leader>hf", buf_async_format_hunks, { buffer = bufnr })
- end
+ map.n("<c-]>", vim.lsp.buf.definition, { buffer = bufnr })
+ map.n("gD", vim.lsp.buf.declaration, { buffer = bufnr })
+ map.n("gR", vim.lsp.buf.rename, { buffer = bufnr })
+ map.n("ga", vim.lsp.buf.code_action, { buffer = bufnr })
+ map.v("ga", vim.lsp.buf.code_action, { buffer = bufnr })
+end
- require("lsp-inlayhints").on_attach(client, bufnr, false)
+function M.switch_source_header_splitcmd(bufnr, splitcmd)
+ bufnr = lspconfig.util.validate_bufnr(bufnr)
+ local clangd_client = lspconfig.util.get_active_client_by_name(
+ bufnr,
+ "clangd"
+ )
+ local params = { uri = vim.uri_from_bufnr(bufnr) }
+ if clangd_client then
+ clangd_client.request(
+ "textDocument/switchSourceHeader",
+ params,
+ function(err, result)
+ if err then
+ error(tostring(err))
+ end
+ if not result then
+ print("Corresponding file cannot be determined")
+ return
+ end
+ vim.api.nvim_command(splitcmd .. " " .. vim.uri_to_fname(result))
+ end,
+ bufnr
+ )
+ else
+ print(
+ "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer"
+ )
end
-}
+end
+
+return M
diff --git a/home/.config/nvim/lua/cfg/options.lua b/home/.config/nvim/lua/cfg/options.lua
index cce808a..ee957a2 100644
--- a/home/.config/nvim/lua/cfg/options.lua
+++ b/home/.config/nvim/lua/cfg/options.lua
@@ -2,16 +2,11 @@ local opt = vim.opt
opt.undofile = true
opt.swapfile = false
-vim.opt.shadafile = "NONE"
-vim.g.ts_highlight_lua = true
-vim.g.ts_highlight_c = true
-vim.g.ts_highlight_vim = true
+opt.shadafile = "NONE"
-opt.showmode = true
opt.number = true
opt.cursorline = true
opt.signcolumn = "auto:2"
-opt.showtabline = 2
opt.showmatch = true
opt.expandtab = true
@@ -20,8 +15,6 @@ opt.shiftwidth = 0
opt.softtabstop = -1
opt.tabstop = 4
-opt.foldenable = false
-
opt.splitbelow = true
opt.splitright = true
@@ -32,7 +25,6 @@ opt.colorcolumn = "+1"
opt.formatoptions:remove("t")
opt.cmdheight = 2
-opt.updatetime = 300
opt.shortmess:append({ a = true })
@@ -106,7 +98,6 @@ opt.foldmethod = "expr"
opt.foldexpr = "nvim_treesitter#foldexpr()"
opt.foldenable = false
-opt.laststatus = 2
vim.g.mapleader = " "
vim.g.maplocalleader = ","
@@ -114,8 +105,5 @@ vim.diagnostic.config({
virtual_text = {
source = "if_many",
severity = vim.diagnostic.severity.ERROR,
- },
- signs = true,
- underline = true,
- update_in_insert = false,
+ }
})
diff --git a/home/.config/nvim/lua/cfg/utils.lua b/home/.config/nvim/lua/cfg/utils.lua
index abda35d..7cd172a 100644
--- a/home/.config/nvim/lua/cfg/utils.lua
+++ b/home/.config/nvim/lua/cfg/utils.lua
@@ -1,22 +1,21 @@
local M = {}
local gitsigns = require("gitsigns")
+local conform = require("conform")
function M.format_hunks(options)
- local hunks = require("gitsigns").get_hunks()
+ local hunks = gitsigns.get_hunks()
if not hunks or vim.tbl_isempty(hunks) then
return
end
for _, hunk in ipairs(hunks) do
- local added = hunk.added
- if added then
- local start_line = added.start
- local count = added.count
- if start_line and count and start_line > 0 and count > 0 then
- local end_line = start_line + added.count - 1
- local range = { start = { start_line, 0 }, ["end"] = { end_line, 0 } }
- options = vim.tbl_extend("force", { range = range }, options or {})
- vim.lsp.buf.format(options)
- end
+ if hunk and hunk.added then
+ local start = hunk.added.start
+ local last = start + hunk.added.count
+ -- nvim_buf_get_lines uses zero-based indexing -> subtract from last
+ local last_hunk_line = vim.api.nvim_buf_get_lines(0, last - 2, last - 1, true)[1]
+ local range = { start = { start, 0 }, ["end"] = { last - 1, last_hunk_line:len() } }
+ options = vim.tbl_extend("force", { range = range, lsp_fallback = true, quiet = true }, options or {})
+ conform.format(options)
end
end
end