commit 711ea8dd465d7e381c7d7d0ba4c34d45d27c455e
parent 247e622e4b1d23245becf876d6d259e46601a548
Author: Tomas Nemec <nemi@skaut.cz>
Date: Sat, 15 Oct 2022 06:25:21 +0200
update
Diffstat:
5 files changed, 108 insertions(+), 1 deletion(-)
diff --git a/after/plugin/comment.lua b/after/plugin/comment.lua
@@ -1,8 +1,12 @@
if not pcall(require, 'Comment') then
return
end
+local comment = require('Comment')
-require('Comment').setup({
+comment.setup({
ignore = '^$',
pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
})
+
+local ft = require('Comment.ft')
+ft.dart = { '//%s', '/*%s*/' }
diff --git a/after/plugin/typebreak.lua b/after/plugin/typebreak.lua
@@ -0,0 +1,3 @@
+if pcall(require, 'typebreak') then
+ vim.api.nvim_create_user_command('Typebreak', require('typebreak').start, {});
+end
diff --git a/ftplugin/json.lua b/ftplugin/json.lua
@@ -1,3 +1,11 @@
vim.cmd('match Comment +\\/\\/.\\+$+')
vim.keymap.set('n', 'gO', '<cmd>Json<cr>')
+
+if vim.fn.exists('+winbar') then
+ vim.opt_local.winbar = '%{luaeval(\'require\"tms.p.jsonpath\".get()\')}'
+end
+
+vim.keymap.set('n', 'y<c-p>', function()
+ vim.fn.setreg('+', require('tms.p.jsonpath').get())
+end, { buffer = true, desc = 'Yank Json Path' })
diff --git a/lua/plugins.lua b/lua/plugins.lua
@@ -61,6 +61,7 @@ return packer.startup({
-- how to vim
use 'ThePrimeagen/vim-be-good'
+ use { 'nagy135/typebreak.nvim' }
-- vcs
use { 'lewis6991/gitsigns.nvim', requires = { 'nvim-lua/plenary.nvim' } }
diff --git a/lua/tms/p/jsonpath.lua b/lua/tms/p/jsonpath.lua
@@ -0,0 +1,91 @@
+local M = {}
+
+local parsers = require('nvim-treesitter.parsers')
+local ts_utils = require('nvim-treesitter.ts_utils')
+
+local get_node_text = function(node)
+ return vim.treesitter.get_node_text(node, 0)
+end
+
+local get_string_content = function(node)
+ for _, child in ipairs(ts_utils.get_named_children(node)) do
+ if child:type() == 'string_content' then
+ return get_node_text(child)
+ end
+ end
+
+ return ''
+end
+
+local starts_with_number = function(str)
+ return str:match('^%d')
+end
+
+local contains_special_characters = function(str)
+ return str:match('[^a-zA-Z0-9_]')
+end
+
+M.get = function()
+ if not parsers.has_parser() then
+ return ''
+ end
+
+ local current_node = ts_utils.get_node_at_cursor()
+ if not current_node then
+ return ''
+ end
+
+ local accessors = {}
+ local node = current_node
+
+ while node do
+ local accessor = ''
+
+ if node:type() == 'pair' then
+ local key_node = unpack(node:field('key'))
+ local key = get_string_content(key_node)
+
+ if starts_with_number(key) or contains_special_characters(key) then
+ accessor = string.format('["%s"]', key)
+ else
+ accessor = string.format('%s', key)
+ end
+ end
+
+ if node:type() == 'array' then
+ accessor = '[]'
+
+ for i, child in ipairs(ts_utils.get_named_children(node)) do
+ if ts_utils.is_parent(child, current_node) then
+ accessor = string.format('[%d]', i - 1)
+ end
+ end
+ end
+
+ if accessor ~= '' then
+ table.insert(accessors, 1, accessor)
+ end
+
+ node = node:parent()
+ end
+
+ if #accessors == 0 then
+ return '.'
+ end
+
+ local path = ''
+
+ for i, accessor in ipairs(accessors) do
+ if i == 1 then
+ path = path .. '.' .. accessor
+ elseif vim.startswith(accessor, '[') then
+ path = path .. accessor
+ else
+ path = path .. '.' .. accessor
+ end
+ end
+
+ return path
+end
+
+return M