commit 71861ceb50828174bb6e69b06e2db0025ab2381f
parent 8a9adc9cfc627f5dac5aaf725b44526bb055374c
Author: Tomas Nemec <owl@gtms.dev>
Date: Tue, 4 Jun 2024 13:37:10 +0200
update
Diffstat:
11 files changed, 127 insertions(+), 113 deletions(-)
diff --git a/after/plugin/cmp.lua b/after/plugin/cmp.lua
@@ -100,8 +100,8 @@ cmp.setup({
['<c-y>'] = cmp.mapping.confirm({ select = true }),
['<c-u>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<c-d>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
- ['<c-n>'] = cmp.mapping({ i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }) }),
- ['<c-p>'] = cmp.mapping({ i = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }) }),
+ ['<c-n>'] = cmp.mapping({ i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }) }),
+ ['<c-p>'] = cmp.mapping({ i = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }) }),
['<c-space>'] = cmp.mapping({ i = cmp.mapping.complete() }),
},
@@ -113,7 +113,7 @@ cmp.setup({
-- }, { { name = 'buffer' } }),
sources = cmp.config.sources({
- { name = 'snippets', max_item_count = 3 },
+ { name = 'snippets', max_item_count = 3 },
{
name = 'nvim_lsp',
-- entry_filter = function(entry, ctx)
@@ -203,9 +203,9 @@ cmp.setup.cmdline(':', {
},
sources = cmp.config.sources({ --
{ name = 'path' },
- }, { --
+ }, { --
{ name = 'cmdline' },
- }, { --
+ }, { --
{ name = 'cmdline_history' },
}),
})
diff --git a/after/plugin/format.lua b/after/plugin/format.lua
@@ -11,11 +11,29 @@ require 'conform'.setup {
bash = shfmt,
zsh = shfmt,
yaml = prettier,
+ json = prettier,
+ markdown = prettier,
html = prettier,
css = prettier,
graphql = prettier,
scss = prettier,
},
+ formatters = {
+ prettier = {
+ options = {
+ ft_parsers = {
+ css = "css",
+ scss = "scss",
+ less = "less",
+ html = "html",
+ json = "json",
+ yaml = "yaml",
+ markdown = "markdown",
+ graphql = "graphql",
+ }
+ }
+ }
+ },
}
vim.o.formatexpr = "v:lua.require'conform'.formatexpr({'lsp_fallback': 'always'})"
diff --git a/after/plugin/leap.lua b/after/plugin/leap.lua
@@ -2,65 +2,30 @@ if not pcall(require, 'leap') then
return
end
-local leap = require 'leap'
-leap.opts.highlight_unlabeled_phase_one_targets = true
-
-local ast_ns = require 'tms.p.leap'.ast_ns
-
-local function default_highlights()
- vim.api.nvim_set_hl_ns(0)
-end
-
-local function ast_highlights()
- vim.api.nvim_set_hl_ns(ast_ns)
+vim.keymap.set('n', 's', '<Plug>(leap)')
+vim.keymap.set('n', 'S', '<Plug>(leap-from-window)')
+vim.keymap.set({ 'x', 'o' }, 's', '<Plug>(leap)')
+
+if pcall(require, 'tms.p.leap.line') then
+ -- For maximum comfort, force linewise selection in the mappings:
+ vim.keymap.set('x', '|', function()
+ -- Only force V if not already in it (otherwise it would exit Visual mode).
+ if vim.fn.mode(1) ~= 'V' then vim.cmd('normal! V') end
+ require 'tms.p.leap.line'.leap_line_start()
+ end)
+ vim.keymap.set('o', '|', "V<cmd>lua require 'tms.p.leap.line'.leap_line_start()<cr>")
end
-default_highlights()
-leap.add_default_mappings()
-
if pcall(require, 'tms.p.leap.ast') then
- vim.keymap.set({ 'n', 'x', 'o' }, 'gp', function()
- require 'tms.p.leap.ast'.parent()
- end, { desc = 'Leap AST Parent' })
-
- local leap_ast_group = vim.api.nvim_create_augroup('leap-ast', {})
- vim.api.nvim_create_autocmd('User', {
- group = leap_ast_group,
- pattern = 'LeapEnter',
- callback = function()
- if require 'leap'.state.args.ast then
- ast_highlights()
- end
- end,
- desc = 'Default -> Ast highlights',
- })
- vim.api.nvim_create_autocmd('User', {
- group = leap_ast_group,
- pattern = 'LeapLeave',
- callback = function()
- if require('leap').state.args.ast then
- default_highlights()
- end
- end,
- desc = 'AST -> Default highlights',
- })
+ vim.keymap.set({ 'x', 'o' }, 'gp', function()
+ require 'tms.p.leap.ast'.leap_ts()
+ end, { desc = 'Leap AST' })
end
if pcall(require, 'telepath') then
- require 'telepath'.use_default_mappings()
+ require 'telepath'.use_default_mappings {}
end
--- if pcall(require, 'leap-spooky') then
--- require 'leap-spooky'.setup {
--- affixes = {
--- -- These will generate mappings for all native text objects, like:
--- -- (ir|ar|iR|aR|im|am|iM|aM){obj}.
--- -- Special line objects will also be added, by repeating the affixes.
--- -- E.g. `yrr<leap>` and `ymm<leap>` will yank a line in the current
--- -- window.
--- -- You can also use 'rest' & 'move' as mnemonics.
--- remote = { window = 'r', cross_window = 'R' },
--- -- magnetic = { window = 'm', cross_window = 'M' },
--- },
--- }
--- end
+if pcall(require, 'flit') then
+ require('flit').setup {}
+end
diff --git a/colors/tms.lua b/colors/tms.lua
@@ -282,7 +282,6 @@ vim.api.nvim_set_hl(0, 'javaOperator', { fg = gui0D, ctermfg = cterm0D })
-- vim: filetype=lua
-- end color
---
vim.api.nvim_set_hl(0, 'LineNr', { fg = gui03, bg = 'background' })
vim.api.nvim_set_hl(0, 'WinBar', { fg = gui03, bg = 'background' })
@@ -306,13 +305,6 @@ vim.api.nvim_set_hl(0, 'CmpItemKindMethod', { link = 'CmpItemKindFunction' })
vim.api.nvim_set_hl(0, 'CmpItemKindClass', { fg = gui0A })
vim.api.nvim_set_hl(0, 'CmpItemKindConstructor', { fg = gui0D })
--- leap
-vim.api.nvim_set_hl(0, 'LeapBackdrop', { link = 'Comment' })
-vim.api.nvim_set_hl(0, 'LeapMatch', { fg = '#00ff00' })
-vim.api.nvim_set_hl(0, 'LeapLabelPrimary', { fg = '#ffff00' })
-vim.api.nvim_set_hl(require('tms.p.leap').ast_ns, 'LeapLabelPrimary', { link = 'LeapMatch' })
-vim.api.nvim_set_hl(0, 'LeapLabelSecondary', { fg = '#ff0000' })
-
-- Diff highlighting
vim.api.nvim_set_hl(0, 'DiffAdd', { fg = gui0B, bg = gui00 })
vim.api.nvim_set_hl(0, 'DiffChange', { fg = gui03, bg = gui00 })
diff --git a/lua/plugins.lua b/lua/plugins.lua
@@ -9,6 +9,7 @@ return require('paq') {
'xxdavid/bez-diakritiky.vim',
'ggandor/leap.nvim',
'ggandor/leap-spooky.nvim',
+ 'ggandor/flit.nvim',
'rasulomaroff/telepath.nvim',
'tpope/vim-repeat',
'kylechui/nvim-surround',
diff --git a/lua/tms/lsp/dart.lua b/lua/tms/lsp/dart.lua
@@ -21,7 +21,7 @@ function M.start()
-- '--port=10000',
-- '--instrumentation-log-file=/tmp/dart-plugin-log',
},
- root_dir = vim.fs.find('pubspec.yaml', { upward = true, stop = vim.uv.os_homedir() })[1],
+ root_dir = vim.fs.dirname(vim.fs.find('pubspec.yaml', { upward = true, stop = vim.uv.os_homedir() })[1]),
capabilities = vim.tbl_deep_extend('force', require 'tms.lsp'.capabilities(), capabilities),
init_options = {
closingLabels = true,
@@ -64,7 +64,6 @@ function M.provided_references(opts)
opts.items = vim.tbl_filter(function(item)
return string.match(item.text, "Provider%(")
end, opts.items)
- vim.print(opts.items)
if #opts.items == 0 then
vim.notify('Not provided')
diff --git a/lua/tms/p/leap/ast.lua b/lua/tms/p/leap/ast.lua
@@ -1,16 +1,14 @@
local api = vim.api
--- Note: The functions used here will be upstreamed eventually.
-local ts_utils = require('nvim-treesitter.ts_utils')
-local M = {}
+local ts = vim.treesitter
-local get_nodes = function()
+local M = {}
+
+local function get_ts_nodes()
+ if not pcall(ts.get_parser) then return end
local wininfo = vim.fn.getwininfo(api.nvim_get_current_win())[1]
- -- Get current TS node.
- local cur_node = ts_utils.get_node_at_cursor(0)
- if not cur_node then
- return
- end
- -- Get parent nodes recursively.
+ -- Get current node, and then its parent nodes recursively.
+ local cur_node = ts.get_node()
+ if not cur_node then return end
local nodes = { cur_node }
local parent = cur_node:parent()
while parent do
@@ -19,42 +17,38 @@ local get_nodes = function()
end
-- Create Leap targets from TS nodes.
local targets = {}
+ local startline, startcol
for _, node in ipairs(nodes) do
- local startline, startcol, _, _ = node:range() -- (0,0)
+ startline, startcol, endline, endcol = node:range() -- (0,0)
+ local startpos = { startline + 1, startcol + 1 }
+ local endpos = { endline + 1, endcol + 1 }
+ -- Add both ends of the node.
if startline + 1 >= wininfo.topline then
- local target = { node = node, pos = { startline + 1, startcol + 1 } }
- table.insert(targets, target)
+ table.insert(targets, { pos = startpos, altpos = endpos })
+ end
+ if endline + 1 <= wininfo.botline then
+ table.insert(targets, { pos = endpos, altpos = startpos })
end
end
- if #targets >= 1 then
- return targets
- end
+ if #targets >= 1 then return targets end
end
-local select_range = function(target)
+local function select_node_range(target)
local mode = api.nvim_get_mode().mode
- if not mode:match('n?o') then
- -- Force going back to Normal (implies mode = v | V | ).
- vim.cmd.normal { mode, bang = true }
- end
- local vmode = 'charwise'
- if mode:match('V') then
- vmode = 'linewise'
- elseif mode:match('') then
- vmode = 'blockwise'
- end
- ts_utils.update_selection(0, target.node, vmode)
-end
-
-local jump = function(target)
- local startline, startcol, _, _ = target.node:range() -- (0,0)
- api.nvim_win_set_cursor(0, { startline + 1, startcol }) -- (1,0)
+ -- Force going back to Normal from Visual mode.
+ if not mode:match('no?') then vim.cmd('normal! ' .. mode) end
+ vim.fn.cursor(unpack(target.pos))
+ local v = mode:match('V') and 'V' or mode:match('�') and '�' or 'v'
+ vim.cmd('normal! ' .. v)
+ vim.fn.cursor(unpack(target.altpos))
end
-M.parent = function()
- local targets = get_nodes()
- local action = api.nvim_get_mode().mode == 'n' and jump or select_range
- require('leap').leap { ast = true, targets = targets, action = action, backward = true }
+function M.leap_ts()
+ require('leap').leap {
+ target_windows = { api.nvim_get_current_win() },
+ targets = get_ts_nodes,
+ action = select_node_range,
+ }
end
return M
diff --git a/lua/tms/p/leap/init.lua b/lua/tms/p/leap/init.lua
@@ -1,5 +0,0 @@
-local M = {}
-
-M.ast_ns = vim.api.nvim_create_namespace('user-leap-ast')
-
-return M
diff --git a/lua/tms/p/leap/line.lua b/lua/tms/p/leap/line.lua
@@ -0,0 +1,50 @@
+local M = {}
+
+local function get_line_starts(winid, skip_range)
+ local wininfo = vim.fn.getwininfo(winid)[1]
+ local cur_line = vim.fn.line('.')
+ -- Skip lines close to the cursor.
+ local skip_range = skip_range or 2
+
+ -- Get targets.
+ local targets = {}
+ local lnum = wininfo.topline
+ while lnum <= wininfo.botline do
+ local fold_end = vim.fn.foldclosedend(lnum)
+ -- Skip folded ranges.
+ if fold_end ~= -1 then
+ lnum = fold_end + 1
+ else
+ if (lnum < cur_line - skip_range) or (lnum > cur_line + skip_range) then
+ table.insert(targets, { pos = { lnum, 1 } })
+ end
+ lnum = lnum + 1
+ end
+ end
+
+ -- Sort them by vertical screen distance from cursor.
+ local cur_screen_row = vim.fn.screenpos(winid, cur_line, 1)['row']
+ local function screen_rows_from_cur(t)
+ local t_screen_row = vim.fn.screenpos(winid, t.pos[1], t.pos[2])['row']
+ return math.abs(cur_screen_row - t_screen_row)
+ end
+ table.sort(targets, function(t1, t2)
+ return screen_rows_from_cur(t1) < screen_rows_from_cur(t2)
+ end)
+
+ if #targets >= 1 then
+ return targets
+ end
+end
+
+-- You can pass an argument to specify a range to be skipped
+-- before/after the cursor (default is +/-2).
+function M.leap_line_start(skip_range)
+ local winid = vim.api.nvim_get_current_win()
+ require('leap').leap {
+ target_windows = { winid },
+ targets = get_line_starts(winid, skip_range),
+ }
+end
+
+return M
diff --git a/plugin/options.lua b/plugin/options.lua
@@ -1,6 +1,6 @@
vim.opt.exrc = true
vim.opt.clipboard = 'unnamedplus'
-vim.opt.completeopt = 'menu,menuone,noselect'
+vim.opt.completeopt = 'menu,menuone,noselect,noinsert'
-- vim.opt.equalalways = false -- exp
vim.opt.grepprg = 'rg --vimgrep --no-heading --smart-case --ignore-case'
vim.opt.grepformat = '%f:%l:%c:%m'
diff --git a/plugin/snippet.lua b/plugin/snippet.lua
@@ -10,7 +10,7 @@ vim.keymap.set({ 'i', 's' }, '<c-h>', function()
end
end, { desc = 'Snippet Jump Forward' })
-vim.keymap.set({ 'i', 's' }, '<c-e>', function()
+vim.keymap.set({ 'i', 's' }, '<c-x>', function()
if vim.snippet.active() then
vim.snippet.stop()
end