From 64964b22684ad344a006894d891e73984589a64b Mon Sep 17 00:00:00 2001 From: Chris Griffing Date: Sun, 28 Mar 2021 12:33:40 -0700 Subject: [PATCH] initial commit --- .gitignore | 2 + LICENSE | 7 +++ README.md | 75 +++++++++++++++++++++++ lua/nvim-biscuits/config.lua | 44 ++++++++++++++ lua/nvim-biscuits/init.lua | 115 +++++++++++++++++++++++++++++++++++ lua/nvim-biscuits/utils.lua | 46 ++++++++++++++ plugin/nvim-biscuits.vim | 6 ++ 7 files changed, 295 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 lua/nvim-biscuits/config.lua create mode 100644 lua/nvim-biscuits/init.lua create mode 100644 lua/nvim-biscuits/utils.lua create mode 100644 plugin/nvim-biscuits.vim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..faa1838 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2535d9d --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2021 Chris Griffing + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ef41c58 --- /dev/null +++ b/README.md @@ -0,0 +1,75 @@ +# nvim-biscuits + +Every dev needs something sweet sometimes. Code Biscuits are in-editor annotations usually at the end of a closing tag/bracket/parenthisis/etc. They help you get the context of the end of that AST node so you don't have to navigate to find it. + +## Installation + +In your nvim config, add the Plug dependencies: + +```lua +call plug#begin() +Plug 'nvim-lua/plenary.nvim' +Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} +Plug 'code-biscuits/nvim-biscuits' +call plug#end() +``` + +You will also need to configure which language parsers you want to have enabled for tree-sitter. "maintained" currently will install 40 languages. "all" will install even more. + +```lua +lua <= max_length then + text = string.sub(text, 1, max_length) + end + + text = text:gsub('"', '\\"') + + local prefix_string = config.get_language_config(final_config, lang, "prefix_string") + + text = prefix_string..text + + local nvim_clear_script = "nvim_buf_clear_namespace("..bufnr..", 0, "..end_line..", "..(end_line + 1)..")" + vim.api.nvim_eval(nvim_clear_script) + + local nvim_script = "nvim_buf_set_virtual_text("..bufnr..", 0, "..end_line..", [[\""..text.."\"]], [])" + vim.api.nvim_eval(nvim_script) + else + utils.console_log('empty') + end + + end + + nodes = children + children = {} + + if table.getn(nodes) == 0 then + has_nodes = false + end + end +end + +nvim_biscuits.setup = function (user_config) + final_config = utils.merge_tables(final_config, user_config) + + if user_config.default_config then + final_config = utils.merge_tables(final_config, user_config.default_config) + end + + utils.clear_log() +end + +nvim_biscuits.BufferAttach = function() + local bufnr = vim.fn.bufnr() + local lang = ts_parsers.get_buf_lang(bufnr) + decorateNodes(bufnr, lang) + + -- edit event + vim.api.nvim_buf_attach(bufnr, false, { + on_lines=function(lines_string, edited_bufnr) + decorateNodes(edited_bufnr, lang) + end + }) +end + +return nvim_biscuits diff --git a/lua/nvim-biscuits/utils.lua b/lua/nvim-biscuits/utils.lua new file mode 100644 index 0000000..6a97a65 --- /dev/null +++ b/lua/nvim-biscuits/utils.lua @@ -0,0 +1,46 @@ +local Path = require("plenary.path") + +local utils = {} + +local debug = false +local debug_path = '~/vim-biscuits.log' + + +utils.console_log = function (the_string) + if debug then + Path:new(debug_path):write(the_string..'\n', 'a') + end +end + +utils.merge_arrays = function(a, b) + local result = {unpack(a)} + table.move(b, 1, #b, #result + 1, result) + return result +end + +utils.merge_tables = function(t1, t2) + for k,v in pairs(t2) do + if type(v) == "table" then + if type(t1[k] or false) == "table" then + tableMerge(t1[k] or {}, t2[k] or {}) + else + t1[k] = v + end + else + t1[k] = v + end + end + return t1 +end + +utils.trim = function(s) + return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)' +end + +utils.clear_log = function () + if debug == true then + Path:new(debug_path):write('', 'w') + end +end + +return utils diff --git a/plugin/nvim-biscuits.vim b/plugin/nvim-biscuits.vim new file mode 100644 index 0000000..f7826c2 --- /dev/null +++ b/plugin/nvim-biscuits.vim @@ -0,0 +1,6 @@ +:lua require('nvim-biscuits') + +augroup NVIM_BISCUITS + autocmd! + autocmd BufEnter * :lua require('nvim-biscuits').BufferAttach() +augroup END