aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nvim/init.lua2
-rw-r--r--nvim/lua/plugins/lsp.lua37
-rw-r--r--nvim/lua/shared.lua40
3 files changed, 54 insertions, 25 deletions
diff --git a/nvim/init.lua b/nvim/init.lua
index dcbd2f8..d79e5e0 100644
--- a/nvim/init.lua
+++ b/nvim/init.lua
@@ -57,7 +57,7 @@ vim.opt.showtabline = 1
vim.opt.list = true
vim.opt.listchars = "tab:▸ ,trail:·,nbsp:·,extends:+,lead:·"
--- tab settings
+-- tab settings (space supremacy :) )
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua
index 69e6765..f71ebda 100644
--- a/nvim/lua/plugins/lsp.lua
+++ b/nvim/lua/plugins/lsp.lua
@@ -35,6 +35,7 @@ local lspconfig = {
{
'gd',
function()
+ -- TODO: add fallback to default gd + warning
vim.lsp.buf.definition()
end,
mode = 'n',
@@ -46,9 +47,27 @@ local lspconfig = {
function()
vim.lsp.buf.format()
end,
- mode = { 'n', 'v' },
- desc = "Format code"
+ mode = { 'n' },
+ desc = "Format entire buffer"
},
+ {
+ '<leader>f',
+ function()
+ local opts = {}
+ local clients = vim.lsp.get_clients({ bufnr = 0 })
+ for _, client in ipairs(clients) do
+ if client:supports_method("textDocument/rangesFormatting") then
+ local range = require("shared").get_visual_range({})
+ opts.range.start = range.start
+ opts.range["end"] = range.stop
+ break
+ end
+ end
+ vim.lsp.buf.format(opts)
+ end,
+ mode = { 'v' },
+ desc = "Format visual selection"
+ }
}
}
@@ -89,20 +108,6 @@ local mason_lspconfig = {
}
})
end,
- ["html"] = function()
- local capabilities = vim.lsp.protocol.make_client_capabilities()
- capabilities.textDocument.completion.completionItem.snippetSupport = true
- require('lspconfig').html.setup({
- capabilities = capabilities,
- })
- end,
- ["cssls"] = function()
- local capabilities = vim.lsp.protocol.make_client_capabilities()
- capabilities.textDocument.completion.completionItem.snippetSupport = true
- require('lspconfig').cssls.setup({
- capabilities = capabilities,
- })
- end,
["basedpyright"] = function()
require('lspconfig').basedpyright.setup({
settings = {
diff --git a/nvim/lua/shared.lua b/nvim/lua/shared.lua
index ae97cdd..2dc398e 100644
--- a/nvim/lua/shared.lua
+++ b/nvim/lua/shared.lua
@@ -5,18 +5,44 @@ function M.cmd_pcall(string)
local success, msg = pcall(function() vim.cmd(string) end)
if not success then
msg = string.match(tostring(msg), "E%d+.*")
- vim.api.nvim_err_writeln(msg)
+ vim.api.nvim_echo({ { msg } }, true, { err = true })
end
end
---- Get the lines of a visual selection
---- @return { lines : string[], range : { start : integer, stop : integer } }
-M.get_visual = function()
+--- Get the positions of the current visual selection using (1,0) indexing
+--- @param opts {reset_mark: boolean?, reselect_text: boolean?}
+--- @return { start: integer[], stop:integer[]}
+M.get_visual_range = function(opts)
+ local old_start = {}
+ local old_stop = {}
+ if opts.reset_mark then
+ old_start = vim.api.nvim_buf_get_mark(0, "<")
+ old_stop = vim.api.nvim_buf_get_mark(0, ">")
+ end
-- return to normal mode to correctly set '< and '> marks
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<ESC>", true, false, true), 'x', false)
+ local start_sel = vim.api.nvim_buf_get_mark(0, "<")
+ local stop_sel = vim.api.nvim_buf_get_mark(0, ">")
- local range = { start = vim.api.nvim_buf_get_mark(0, "<")[1], stop = vim.api.nvim_buf_get_mark(0, ">")[1] }
+ if opts.reselect_text then
+ vim.cmd("normal! gv")
+ end
+
+ if opts.reset_mark then
+ vim.api.nvim_buf_set_mark(0, "<", old_start[1], old_start[2], {})
+ vim.api.nvim_buf_set_mark(0, ">", old_stop[1], old_stop[2], {})
+ end
+ return {
+ start = start_sel,
+ stop = stop_sel,
+ }
+end
+
+--- Get the lines of a visual selection
+--- @return { lines : string[], range : { start : integer, stop : integer } }
+M.get_visual = function()
+ local range = M.get_visual_range({})
local lines = vim.api.nvim_buf_get_lines(0, range.start - 1, range.stop, false)
return { lines = lines, range = range }
@@ -39,9 +65,7 @@ end
-- Shift the visual selection by amount, clamping to buffer size
--- @param amount integer
function M.vert_shift_selection(amount)
- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<ESC>", true, false, true), 'x', false)
-
- local init = { start = vim.api.nvim_buf_get_mark(0, '<'), stop = vim.api.nvim_buf_get_mark(0, '>') }
+ local init = M.get_visual_range({})
local target = {
start = { init.start[1] + amount, init.start[2] },
stop = { init.stop[1] + amount, init.stop[2] }