diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2021-08-20 11:11:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-20 11:11:24 -0400 |
| commit | a97af306c4e9c9a6fa7c886c0ffe3079822c5203 (patch) | |
| tree | f5e2b50a767e93618d0d8fdddb8a964c90633c8a /scratch | |
| parent | d6d28dbe324de9826a579155076873888169ba0f (diff) | |
feat(performance): Major performance improvements using async v2 from @oberblastmeister (#987)
* start: Working w/ async jobs
* short circuit to using bad finder if you pass writer.
Diffstat (limited to 'scratch')
28 files changed, 0 insertions, 1485 deletions
diff --git a/scratch/better_defaults_init.vim b/scratch/better_defaults_init.vim deleted file mode 100644 index 0bf73e0..0000000 --- a/scratch/better_defaults_init.vim +++ /dev/null @@ -1,322 +0,0 @@ - -" default.vim - Better vim than the default -" Maintainer: Liu-Cheng Xu <https://github.com/liuchengxu> -" Version: 1.0 -" vim: et ts=2 sts=2 sw=2 - -scriptencoding utf-8 - -if &compatible || exists('g:loaded_vim_better_default') - finish -endif -let g:loaded_vim_better_default = 1 - -let s:save_cpo = &cpo -set cpo&vim - -" Neovim has set these as default -if !has('nvim') - - set nocompatible - - syntax on " Syntax highlighting - filetype plugin indent on " Automatically detect file types - set autoindent " Indent at the same level of the previous line - set autoread " Automatically read a file changed outside of vim - set backspace=indent,eol,start " Backspace for dummies - set complete-=i " Exclude files completion - set display=lastline " Show as much as possible of the last line - set encoding=utf-8 " Set default encoding - set history=10000 " Maximum history record - set hlsearch " Highlight search terms - set incsearch " Find as you type search - set laststatus=2 " Always show status line - set mouse=a " Automatically enable mouse usage - set smarttab " Smart tab - set ttyfast " Faster redrawing - set viminfo+=! " Viminfo include ! - set wildmenu " Show list instead of just completing - - set ttymouse=xterm2 - -endif - -set shortmess=atOI " No help Uganda information, and overwrite read messages to avoid PRESS ENTER prompts -set ignorecase " Case insensitive search -set smartcase " ... but case sensitive when uc present -set scrolljump=5 " Line to scroll when cursor leaves screen -set scrolloff=3 " Minumum lines to keep above and below cursor -set nowrap " Do not wrap long lines -set shiftwidth=4 " Use indents of 4 spaces -set tabstop=4 " An indentation every four columns -set softtabstop=4 " Let backspace delete indent -set splitright " Puts new vsplit windows to the right of the current -set splitbelow " Puts new split windows to the bottom of the current -set autowrite " Automatically write a file when leaving a modified buffer -set mousehide " Hide the mouse cursor while typing -set hidden " Allow buffer switching without saving -set t_Co=256 " Use 256 colors -set ruler " Show the ruler -set showcmd " Show partial commands in status line and Selected characters/lines in visual mode -set showmode " Show current mode in command-line -set showmatch " Show matching brackets/parentthesis -set matchtime=5 " Show matching time -set report=0 " Always report changed lines -set linespace=0 " No extra spaces between rows -set pumheight=20 " Avoid the pop up menu occupying the whole screen - -if !exists('g:vim_better_default_tabs_as_spaces') || g:vim_better_default_tabs_as_spaces - set expandtab " Tabs are spaces, not tabs -end - -" http://stackoverflow.com/questions/6427650/vim-in-tmux-background-color-changes-when-paging/15095377#15095377 -set t_ut= - -set winminheight=0 -set wildmode=list:longest,full - -set listchars=tab:→\ ,eol:↵,trail:·,extends:↷,precedes:↶ - -set whichwrap+=<,>,h,l " Allow backspace and cursor keys to cross line boundaries - -set termencoding=utf-8 -set fileencoding=utf-8 -set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 - -set wildignore+=*swp,*.class,*.pyc,*.png,*.jpg,*.gif,*.zip -set wildignore+=*/tmp/*,*.o,*.obj,*.so " Unix -set wildignore+=*\\tmp\\*,*.exe " Windows - -" Visual shifting (does not exit Visual mode) -vnoremap < <gv -vnoremap > >gv -" Treat long lines as break lines (useful when moving around in them) -nmap j gj -nmap k gk -vmap j gj -vmap k gk - -" :W sudo saves the file -" (useful for handling the permission-denied error) -command! W w !sudo tee % > /dev/null - -" Change cursor shape for iTerm2 on macOS { - " bar in Insert mode - " inside iTerm2 - if $TERM_PROGRAM =~# 'iTerm' - let &t_SI = "\<Esc>]50;CursorShape=1\x7" - let &t_SR = "\<Esc>]50;CursorShape=2\x7" - let &t_EI = "\<Esc>]50;CursorShape=0\x7" - endif - - " inside tmux - if exists('$TMUX') && $TERM != 'xterm-kitty' - let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\" - let &t_SR = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=2\x7\<Esc>\\" - let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\" - endif - - " inside neovim - if has('nvim') - let $NVIM_TUI_ENABLE_CURSOR_SHAPE=2 - endif -" } - -if get(g:, 'vim_better_default_minimum', 0) - finish -endif - -if get(g:, 'vim_better_default_backup_on', 0) - set backup -else - set nobackup - set noswapfile - set nowritebackup -endif - -if get(g:, 'vim_better_default_enable_folding', 1) - set foldenable - set foldmarker={,} - set foldlevel=0 - set foldmethod=marker - " set foldcolumn=3 - set foldlevelstart=99 -endif - -set background=dark " Assume dark background -set cursorline " Highlight current line -set fileformats=unix,dos,mac " Use Unix as the standard file type -set number " Line numbers on -set relativenumber " Relative numbers on -set fillchars=stl:\ ,stlnc:\ ,fold:\ ,vert:│ - -" Annoying temporary files -set directory=/tmp//,. -set backupdir=/tmp//,. -if v:version >= 703 - set undodir=/tmp//,. -endif - -highlight clear SignColumn " SignColumn should match background -" highlight clear LineNr " Current line number row will have same background color in relative mode - -if has('unnamedplus') - set clipboard=unnamedplus,unnamed -else - set clipboard+=unnamed -endif - -if get(g:, 'vim_better_default_persistent_undo', 0) - if has('persistent_undo') - set undofile " Persistent undo - set undolevels=1000 " Maximum number of changes that can be undone - set undoreload=10000 " Maximum number lines to save for undo on a buffer reload - endif -endif - -if has('gui_running') - set guioptions-=r " Hide the right scrollbar - set guioptions-=L " Hide the left scrollbar - set guioptions-=T - set guioptions-=e - set shortmess+=c - " No annoying sound on errors - set noerrorbells - set novisualbell - set visualbell t_vb= -endif - -" Key (re)Mappings { - - if get(g:, 'vim_better_default_key_mapping', 1) - - " Basic { - if get(g:, 'vim_better_default_basic_key_mapping', 1) - " Add <slient> for the rhs is Ex-cmd as some GUI app, e.g., gnvim, - " flashes when you use these mappings. - " Quit normal mode - nnoremap <silent> <Leader>q :q<CR> - nnoremap <silent> <Leader>Q :qa!<CR> - " Move half page faster - nnoremap <Leader>d <C-d> - nnoremap <Leader>u <C-u> - " Insert mode shortcut - inoremap <C-h> <BS> - inoremap <C-j> <Down> - inoremap <C-k> <Up> - inoremap <C-b> <Left> - inoremap <C-f> <Right> - " Bash like - inoremap <C-a> <Home> - inoremap <C-e> <End> - inoremap <C-d> <Delete> - " Command mode shortcut - cnoremap <C-h> <BS> - cnoremap <C-j> <Down> - cnoremap <C-k> <Up> - cnoremap <C-b> <Left> - cnoremap <C-f> <Right> - cnoremap <C-a> <Home> - cnoremap <C-e> <End> - cnoremap <C-d> <Delete> - " jj | escaping - inoremap jj <Esc> - cnoremap jj <C-c> - " Quit visual mode - vnoremap v <Esc> - " Move to the start of line - nnoremap H ^ - " Move to the end of line - nnoremap L $ - " Redo - nnoremap U <C-r> - " Quick command mode - nnoremap <CR> : - " In the quickfix window, <CR> is used to jump to the error under the - " cursor, so undefine the mapping there. - autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR> - " Yank to the end of line - nnoremap Y y$ - " Auto indent pasted text - " nnoremap p p=`]<C-o> - " Open shell in vim - if has('nvim') || has('terminal') - map <silent> <Leader>' :terminal<CR> - else - map <silent> <Leader>' :shell<CR> - endif - " Search result highlight countermand - nnoremap <silent> <Leader>sc :nohlsearch<CR> - " Toggle pastemode - nnoremap <silent> <Leader>tp :setlocal paste!<CR> - endif - " } - - " Buffer { - if get(g:, 'vim_better_default_buffer_key_mapping', 1) - nnoremap <silent> <Leader>bp :bprevious<CR> - nnoremap <silent> <Leader>bn :bnext<CR> - nnoremap <silent> <Leader>bf :bfirst<CR> - nnoremap <silent> <Leader>bl :blast<CR> - nnoremap <silent> <Leader>bd :bd<CR> - nnoremap <silent> <Leader>bk :bw<CR> - endif - " } - - " File { - if get(g:, 'vim_better_default_file_key_mapping', 1) - " File save - nnoremap <silent> <Leader>fs :update<CR> - endif - " } - - " Fold { - if get(g:, 'vim_better_default_fold_key_mapping', 1) - nnoremap <silent> <Leader>f0 :set foldlevel=0<CR> - nnoremap <silent> <Leader>f1 :set foldlevel=1<CR> - nnoremap <silent> <Leader>f2 :set foldlevel=2<CR> - nnoremap <silent> <Leader>f3 :set foldlevel=3<CR> - nnoremap <silent> <Leader>f4 :set foldlevel=4<CR> - nnoremap <silent> <Leader>f5 :set foldlevel=5<CR> - nnoremap <silent> <Leader>f6 :set foldlevel=6<CR> - nnoremap <silent> <Leader>f7 :set foldlevel=7<CR> - nnoremap <silent> <Leader>f8 :set foldlevel=8<CR> - nnoremap <silent> <Leader>f9 :set foldlevel=9<CR> - endif - " } - - " Window { - if get(g:, 'vim_better_default_window_key_mapping', 1) - nnoremap <Leader>ww <C-W>w - nnoremap <Leader>wr <C-W>r - nnoremap <Leader>wd <C-W>c - nnoremap <Leader>wq <C-W>q - nnoremap <Leader>wj <C-W>j - nnoremap <Leader>wk <C-W>k - nnoremap <Leader>wh <C-W>h - nnoremap <Leader>wl <C-W>l - if has('nvim') || has('terminal') - tnoremap <Leader>wj <C-W>j - tnoremap <Leader>wk <C-W>k - tnoremap <Leader>wh <C-W>h - tnoremap <Leader>wl <C-W>l - endif - nnoremap <Leader>wH <C-W>5< - nnoremap <Leader>wL <C-W>5> - nnoremap <Leader>wJ :resize +5<CR> - nnoremap <Leader>wK :resize -5<CR> - nnoremap <Leader>w= <C-W>= - nnoremap <Leader>ws <C-W>s - nnoremap <Leader>w- <C-W>s - nnoremap <Leader>wv <C-W>v - nnoremap <Leader>w\| <C-W>v - nnoremap <Leader>w2 <C-W>v - endif - " } - - endif - -" } - -let &cpo = s:save_cpo -unlet s:save_cpo diff --git a/scratch/bk_tree.lua b/scratch/bk_tree.lua deleted file mode 100644 index 3957224..0000000 --- a/scratch/bk_tree.lua +++ /dev/null @@ -1,270 +0,0 @@ - ---------------------------- --- bk-tree datastructure --- --- http://en.wikipedia.org/wiki/BK-tree --- @module bk-tree --- @author Robin Hübner --- robinhubner@gmail.com --- @release version 1.0.2 --- @license MIT - -local bk_tree = {} - - -local function lazy_copy(t1) - - local cp = {} - - for k, v in pairs(t1) do - cp[k] = v - end - - return cp - -end - -local function min(a, b, c) - - local min_val = a - - if b < min_val then min_val = b end - if c < min_val then min_val = c end - - return min_val - -end - ----------------------------------- ---- Levenshtein distance function. --- @tparam string s1 --- @tparam string s2 --- @treturn number the levenshtein distance --- @within Metrics -function bk_tree.levenshtein_dist(s1, s2) - - if s1 == s2 then return 0 end - if s1:len() == 0 then return s2:len() end - if s2:len() == 0 then return s1:len() end - if s1:len() < s2:len() then s1, s2 = s2, s1 end - - t = {} - for i=1, #s1+1 do - t[i] = {i-1} - end - - for i=1, #s2+1 do - t[1][i] = i-1 - end - - local cost - for i=2, #s1+1 do - - for j=2, #s2+1 do - cost = (s1:sub(i-1,i-1) == s2:sub(j-1,j-1) and 0) or 1 - t[i][j] = min( - t[i-1][j] + 1, - t[i][j-1] + 1, - t[i-1][j-1] + cost) - end - - end - - return t[#s1+1][#s2+1] - -end - -function bk_tree.hook(param) - - local name, callee = debug.getlocal(2, 1) - local f = debug.getinfo(2, "f").func - local p = debug.getinfo(3, "f").func - --[[ previous function in the callstack, if called from the same place, - don't add to the insert/remove counters. ]]-- - - if f == bk_tree.insert and p ~= bk_tree.insert then - callee.stats.nodes = callee.stats.nodes + 1 - elseif f == bk_tree.remove and p ~= bk_tree.remove then - callee.stats.nodes = callee.stats.nodes - 1 - elseif f == bk_tree.query and p == bk_tree.query then - callee.stats.queries = callee.stats.queries + 1 - end - -end - ---- Hooks debugging into tree execution. --- Keeps track of number of nodes created, queries made, --- note that this must be run directly after tree is created --- in order to get correct information. --- @within Debug ---- @usage --- local bktree = require "bk-tree" --- local tree = bktree:new("word") --- tree:debug() --- tree:insert("perceive") --- tree:insert("beautiful") --- tree:insert("definitely") --- local result = tree:query("definately", 3) --- tree:print_stats() --- --- -- output --- Nodes: 4 --- Queries: 3 --- Nodes Queried: 75% -function bk_tree:debug() - - local nc = 0 - if self.root then nc = 1 end - self.stats = { nodes = nc, queries = 0 } - debug.sethook(self.hook, "c") - -end - ---- Print execution stats. --- Prints nodes queried and total nodes, as well as a fraction of --- nodes visited to satisfy the query, resets the counter of nodes queried when called. --- @within Debug --- @see debug -function bk_tree:print_stats() - - print("\nNodes: " .. self.stats.nodes) - print("Queries: " .. self.stats.queries) - print("Nodes Queried: " .. self.stats.queries/self.stats.nodes*100 .. "%\n") - self.stats.queries = 0 - -end - ---- Fetch execution stats. --- Returns a copy of the execution stats that @{print_stats} would print, requires debug to have been enabled --- to not just return defaults. Useful if you want to profile things. --- @within Debug --- @return {key = value,...} -function bk_tree:get_stats() - - return lazy_copy(self.stats) - -end - ---------------------------- ---- Creates a new bk-tree. --- @constructor --- @string[opt] root_word the root of the new tree --- @tparam[opt=levenshtein_dist] function dist_func the distance function used --- @see levenshtein_dist --- @return the new bk-tree instance ---- @usage --- local bktree = require "bk-tree" --- local tree = bktree:new("word") -function bk_tree:new(root_word, dist_func) - - local n_obj = {} - if root_word then n_obj.root = { str = root_word, children = {} } end - n_obj.dist_func = dist_func or self.levenshtein_dist - - setmetatable(n_obj, self) - self.__index = self - - return n_obj - -end - --------------------------------- ---- Inserts word into the tree. --- @string word --- @treturn bool true if inserted, false if word already exists in tree ---- @usage --- local bktree = require "bk-tree" --- local tree = bktree:new("root") --- local success = tree:insert("other_word") -function bk_tree:insert(word, node) - - node = node or self.root - - if not node then - self.root = { str = word, children = {} } - return true - end - - local dist = self.dist_func(word, node.str) - if dist == 0 then return false end - - local some_node = node.children[dist] - - if not some_node then - node.children[dist] = { str = word, children = {} } - return true - end - - return self:insert(word, some_node) - -end - --------------------------------- ---- Query the tree for matches. --- @string word --- @tparam number n max edit distance to use when querying --- @treturn {{str=string,distance=number},....} table of tables with matching words, empty table if no matches ---- @usage --- local bktree = require "bk-tree" --- local tree = bktree:new("word") --- tree:insert("hello") --- tree:insert("goodbye") --- tree:insert("woop") --- local result = tree:query("woop", 1) -function bk_tree:query(word, n, node, matches) - - node = node or self.root - matches = matches or {} - - if not node then return matches end - - local dist = self.dist_func(word, node.str) - if dist <= n then matches[#matches+1] = {str = node.str, distance = dist} end - - for k, child in pairs(node.children) do - if child ~= nil then - if k >= dist-n and k <= dist+n then - self:query(word, n, child, matches) - end - end - end - - return matches - -end - ---------------------------------------------------------- ---- Queries the the tree for a match, sorts the results. --- Calls @{query} and returns the results sorted. --- @string word --- @tparam number n max edit distance to use when querying --- @treturn {{str=string,distance=number},....} table of tables with matching words sorted by distance, empty table if no matches ---- @usage --- local bktree = require "bk-tree" --- local tree = bktree:new("word") --- tree:insert("woop") --- tree:insert("worp") --- tree:insert("warp") --- local result = tree:query_sorted("woop", 3) -function bk_tree:query_sorted(word, n) - - local result = self:query(word, n) - - table.sort(result, function(a,b) return a.distance < b.distance end) - - return result - -end - - -local tree = bk_tree:new("word") -tree:insert("hello") -tree:insert("welp") -tree:insert("function") -tree:insert("this long line what") -tree:insert("what this long line what") -print(vim.inspect(tree)) -print(vim.inspect(tree:query_sorted("what", 3))) - - -return bk_tree diff --git a/scratch/buffer_highlights.lua b/scratch/buffer_highlights.lua deleted file mode 100644 index ee9edae..0000000 --- a/scratch/buffer_highlights.lua +++ /dev/null @@ -1,24 +0,0 @@ -local a = vim.api - -local ns = a.nvim_create_namespace("treesitter/highlighter") -print(ns) -local bufnr = 0 - --- P(a.nvim_buf_get_extmarks(bufnr, ns, 0, -1, { details = true })) - -local parser = vim.treesitter.get_parser(bufnr, "lua") -local query = vim.treesitter.get_query("lua", "highlights") -P(query) - -local root = parser:parse()[1]:root() -print("root", root) - -local highlighter = vim.treesitter.highlighter.new(parser) -local highlighter_query = highlighter:get_query("lua") - -for id, node, metadata in query:iter_captures(root, bufnr, 0, -1) do - local row1, col1, row2, col2 = node:range() - print(highlighter_query.hl_cache[id]) - -- print(id, node, metadata, vim.treesitter.get_node_text(node, bufnr)) - -- print(">>>>", row1, col1, row2, col2) -end diff --git a/scratch/clason_finders.lua b/scratch/clason_finders.lua deleted file mode 100644 index f6d730b..0000000 --- a/scratch/clason_finders.lua +++ /dev/null @@ -1,140 +0,0 @@ -vim.cmd [[packadd! plenary.nvim]] -vim.cmd [[packadd! telescope.nvim]] - -local finders = require "telescope.finders" -local previewers = require "telescope.previewers" -local pickers = require "telescope.pickers" -local sorters = require "telescope.sorters" -local utils = require "telescope.utils" - -local rgargs = { "--color=never", "--no-heading", "--with-filename", "--line-number", "--column", "--smart-case" } --- grep typed string in current directory (live, not fuzzy!) -finders.rg_live = function(opts) - local live_grepper = finders.new { - fn_command = function(_, prompt) - if not prompt or prompt == "" then - return nil - end - - return { - command = "rg", - args = vim.tbl_flatten { rgargs, prompt }, - } - end, - } - - pickers.new(opts, { - prompt = "Live Grep", - finder = live_grepper, - previewer = previewers.vimgrep, - }):find() -end - --- fuzzy grep string in current directory (slow!) -finders.rg = function(opts) - opts = opts or {} - - local search = opts.search or "" - - pickers.new(opts, { - prompt = "Find Word", - finder = finders.new_oneshot_job(vim.tbl_flatten { "rg", rgargs, search }), - previewer = previewers.vimgrep, - sorter = sorters.get_norcalli_sorter(), - }):find() -end - --- fuzzy find files in current directory (may be slow in root dir) -finders.fd = function(opts) - pickers.new(opts, { - prompt = "Find Files", - finder = finders.new_oneshot_job { "fd" }, - previewer = previewers.bat, - sorter = sorters.get_fuzzy_file(), - }):find() -end - --- fuzzy find in references to symbol under cursor -finders.lsp_references = function(opts) - local params = vim.lsp.util.make_position_params() - params.context = { includeDeclaration = false } - - local results_lsp, err = vim.lsp.buf_request_sync(0, "textDocument/references", params) - if err then - vim.api.nvim_err_writeln("Error when finding references: " .. err) - return - end - local locations = {} - for _, server_results in pairs(results_lsp) do - vim.list_extend(locations, vim.lsp.util.locations_to_items(server_results.result) or {}) - end - - local results = utils.quickfix_items_to_entries(locations) - - if vim.tbl_isempty(results) then - return - end - - pickers.new(opts, { - prompt = "LSP References", - finder = finders.new_table(results), - previewer = previewers.qflist, - sorter = sorters.get_norcalli_sorter(), - }):find() -end - --- fuzzy find in document symbols -finders.lsp_document_symbols = function(opts) - local params = vim.lsp.util.make_position_params() - local results_lsp, err = vim.lsp.buf_request_sync(0, "textDocument/documentSymbol", params) - if err then - vim.api.nvim_err_writeln("Error when finding document symbols: " .. err) - return - end - local locations = {} - for _, server_results in pairs(results_lsp) do - vim.list_extend(locations, vim.lsp.util.symbols_to_items(server_results.result, 0) or {}) - end - - local results = utils.quickfix_items_to_entries(locations) - - if vim.tbl_isempty(results) then - return - end - - pickers.new(opts, { - prompt = "LSP Document Symbols", - finder = finders.new_table(results), - previewer = previewers.qflist, - sorter = sorters.get_norcalli_sorter(), - }):find() -end - --- fuzzy find in all workspace symbols (may need longer timeout!) -finders.lsp_workspace_symbols = function(opts) - local params = { query = "" } - local results_lsp, err = vim.lsp.buf_request_sync(0, "workspace/symbol", params, 1000) - if err then - vim.api.nvim_err_writeln("Error when finding symbols: " .. err) - return - end - local locations = {} - for _, server_results in pairs(results_lsp) do - vim.list_extend(locations, vim.lsp.util.symbols_to_items(server_results.result, 0) or {}) - end - - local results = utils.quickfix_items_to_entries(locations) - - if vim.tbl_isempty(results) then - return - end - - pickers.new(opts, { - prompt = "LSP Workspace Symbols", - finder = finders.new_table(results), - previewer = previewers.qflist, - sorter = sorters.get_norcalli_sorter(), - }):find() -end - -return finders diff --git a/scratch/completion_init.vim b/scratch/completion_init.vim deleted file mode 100644 index 9c51428..0000000 --- a/scratch/completion_init.vim +++ /dev/null @@ -1,13 +0,0 @@ - -set rtp+=. -set rtp+=../plenary.nvim/ - -source plugin/telescope.vim - -inoremap <tab> <c-n> - -let case = 1 - -if case == 1 - set completeopt=menu -endif diff --git a/scratch/diag_test.lua b/scratch/diag_test.lua deleted file mode 100644 index 589b6c2..0000000 --- a/scratch/diag_test.lua +++ /dev/null @@ -1,10 +0,0 @@ -local y = function() end - -local x = function() - asdf - print(y) -end - -x() - -y() diff --git a/scratch/digia_init.vim b/scratch/digia_init.vim deleted file mode 100644 index a619fef..0000000 --- a/scratch/digia_init.vim +++ /dev/null @@ -1,15 +0,0 @@ -set rtp+=. -set rtp+=../plenary.nvim/ - - -set statusline="" -set statusline+=%<%f:%l:%v " filename:col:line/total lines -set statusline+=\ " -set statusline+=%h%m%r " help/modified/readonly -set statusline+=\ " -set statusline+=[%{&ft}] " filetype -set statusline+=%= " alignment group -set statusline+=\ " - -" nnoremap <silent> <c-p> :lua require('telescope.builtin').git_files()<CR> -nnoremap <silent> <c-p> :lua require("telescope.builtin").find_files{ find_command = { "rg", "--smart-case", "--files", "--hidden", "--follow", "-g", "!.git/*" } }<CR> diff --git a/scratch/example.lua b/scratch/example.lua deleted file mode 100644 index 19952dc..0000000 --- a/scratch/example.lua +++ /dev/null @@ -1,68 +0,0 @@ - -local finder = Finder:new { - 'rg %s -l', - pipeable = true, - ... -} - -local filter = Filter:new { - "fzf --filter '%s'" -} - -local lua_filter = Filter:new { - function(input, line) - if string.match(line, input) then - return true - end - - return false - end -} - - -local picker_read = Picker:new { - filter = filter, - - previewer = function(window, buffer, line) - local file = io.open(line, "r") - - local filename = vim.split(line, ':')[1] - if vim.fn.bufexists(filename) then - vim.api.nvim_win_set_buf(window, vim.fn.bufnr(filename)) - return - end - - local lines = {} - for _ = 1, 100 do - table.insert(lines, file:read("l")) - - -- TODO: Check if we're out of lines - end - - -- optionally set the filetype or whatever... - vim.api.nvim_buf_set_lines(buffer, 0, -1, false, lines) - end, - - mappings = { - ["<CR>"] = function(line) - vim.cmd(string.format('e ', vim.split(line, ':'))) - end, - }, -} - -local picker = Picker:new { - filter = filter, - - -- idk - previewer = function(window, line) - vim.api.nvim_win_set_current_window(window) - - -- if is_file_loaded(line) then - -- lien_number = vim.api.nvim_... - - vim.fn.termopen(string.format( - 'bat --color=always --style=grid %s', - vim.split(line, ':')[1] - )) - end -} diff --git a/scratch/fast_split.lua b/scratch/fast_split.lua deleted file mode 100644 index 0c5ea88..0000000 --- a/scratch/fast_split.lua +++ /dev/null @@ -1,28 +0,0 @@ -local test_line = "/home/tj/hello/world.lua" - -local function fast_split(line, split) - -- local split_line = vim.split(line, split) - local areas = {} - - local processed = 1 - local line_length = #line + 1 - - local part, start - repeat - start = string.find(line, split, processed, true) or line_length - part = string.sub(line, processed, start - 1) - - if start - processed > 0 then - table.insert(areas, { - word = part, - offset = processed - }) - end - - processed = start + 1 - until start == line_length - - return areas -end - -print(vim.inspect(fast_split(test_line, '/'))) diff --git a/scratch/file_finder.lua b/scratch/file_finder.lua deleted file mode 100644 index bf3c411..0000000 --- a/scratch/file_finder.lua +++ /dev/null @@ -1,80 +0,0 @@ -local telescope = require('telescope') - --- Goals: --- 1. You pick a directory --- 2. We `git ls-files` in that directory ONCE and ONLY ONCE to get the results. --- 3. You can fuzzy find those results w/ fzf --- 4. Select one and go to file. - - ---[[ -ls_files_job.start() -fzf_job.stdin = ls_files_job.stdout - - self.stdin = vim.loop.new_pipe(false) - -> self.stdin = finder.stdout - - - -- Finder: - intermediary_pipe = self.stdout - - -- repeat send this pipe when we want to get new filtering - self.stdin = intermediary_pipe - - - -- Filter + Sort - ok, we could do scoring + cutoff and have that always be the case. - - OR - - filter takes a function, signature (prompt: str, line: str): number - - => echo $line | fzf --filter "prompt" - return stdout != "" - - => lua_fuzzy_finder(prompt, line) return true if good enough - - TODO: Rename everything to be more clear like the name below. - IFilterSorterAbstractFactoryGeneratorv1ProtoBeta - ---]] - - -local file_finder = telescope.finders.new { - static = true, - - -- self, prompt - fn_command = function() - return 'git ls-files' - end, -} - -local file_sorter = telescope.sorters.get_ngram_sorter() - --- local string_distance = require('telescope.algos.string_distance') --- new { --- scoring_function = function(self, prompt, line) --- if prompt == '' then return 0 end --- if not line then return -1 end - --- return tonumber(vim.fn.systemlist(string.format( --- "echo '%s' | ~/tmp/fuzzy_test/target/debug/fuzzy_test '%s'", --- line, --- prompt --- ))[1]) --- end --- } - - -local file_previewer = telescope.previewers.vim_buffer_or_bat - -local file_picker = telescope.pickers.new { - previewer = file_previewer -} - -file_picker:find { - prompt = 'Find File', - finder = file_finder, - sorter = file_sorter, -} - diff --git a/scratch/fuzzy_tester.lua b/scratch/fuzzy_tester.lua deleted file mode 100644 index 0971381..0000000 --- a/scratch/fuzzy_tester.lua +++ /dev/null @@ -1,8 +0,0 @@ - -line = "hello" -prompt = "h" -print(vim.inspect(vim.fn.systemlist(string.format( - "echo '%s' | ~/tmp/fuzzy_test/target/debug/fuzzy_test '%s'", - line, - prompt -)))) diff --git a/scratch/how_long_does_time_take.lua b/scratch/how_long_does_time_take.lua deleted file mode 100644 index a77e47b..0000000 --- a/scratch/how_long_does_time_take.lua +++ /dev/null @@ -1,8 +0,0 @@ -local start = vim.loop.hrtime() - -local counts = 1e6 -for _ = 1, counts do - local _ = vim.loop.hrtime() -end - -print(counts, ":", (vim.loop.hrtime() - start) / 1e9) diff --git a/scratch/ivy.lua b/scratch/ivy.lua deleted file mode 100644 index 65d9049..0000000 --- a/scratch/ivy.lua +++ /dev/null @@ -1,31 +0,0 @@ - -RELOAD('telescope') -require('telescope.builtin').find_files(require('telescope.themes').get_ivy { previewer = false }) - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/scratch/new_index.lua b/scratch/new_index.lua deleted file mode 100644 index 3aa6a91..0000000 --- a/scratch/new_index.lua +++ /dev/null @@ -1,9 +0,0 @@ - -local t = setmetatable({}, { - __newindex = function(t, k, v) - print(t, k, v) - end -}) - --- table.insert(t, "hello") -t[1] = "hello" diff --git a/scratch/ngrams.lua b/scratch/ngrams.lua deleted file mode 100644 index 8b763a8..0000000 --- a/scratch/ngrams.lua +++ /dev/null @@ -1,87 +0,0 @@ - -local function ngrams(counts, doc) - local DEPTH = 5 - local docLen = #doc - local min, concat = math.min, table.concat - for i = 1, docLen - 1 do - for j = i, min(i + DEPTH - 1, docLen) do - if not doc[j] then break end - local k = concat(doc, " ", i, j) - counts[k] = (counts[k] or 0) + 1 - end - end -end - - -local bz = io.popen('bzcat /home/tj/Downloads/pages.xml.bz2') -local title, content = "", "" -local inText = false - -local numDocs = 0 -local globalCounts = {} - -local function set(t) - local s = {} - for _, v in pairs(t) do s[v] = true end - return s -end - -local bad = set({ - 'after', 'also', 'article', 'date', 'defaultsort', 'external', 'first', 'from', - 'have', 'html', 'http', 'image', 'infobox', 'links', 'name', 'other', 'preserve', - 'references', 'reflist', 'space', 'that', 'this', 'title', 'which', 'with', - 'quot', 'ref', 'name', 'http', 'amp', 'ndash', 'www', 'cite', 'nbsp', - 'style', 'text', 'align', 'center', 'background' - }) - -local function isnumber(w) - s, e = w:find("[0-9]+") - return s -end - -for line in bz:lines() do - local _, _, mTitle = line:find("<title>(.*)</title>") - local _, _, bText = line:find("<text[^>]*>([^<]*)") - local eText, _ = line:find("</text>") - - if mTitle then - title = mTitle - elseif bText then - content = bText - inText = true - elseif inText then - content = content .. line - end - - if eText then - words = {} - for v in content:gmatch("%w+") do - v = v:lower() - if #v >= 3 and #v < 12 and not bad[v] and not isnumber(v) then - table.insert(words, v) - else - table.insert(words, nil) - end - end - - ngrams(globalCounts, words) - inText = false - - numDocs = numDocs + 1 - if numDocs % 10 == 0 then - io.write(string.format("Working... %d documents processed.\r", numDocs)) - io.flush() - end - - if numDocs == 500 then - local f = io.open('/tmp/freqs.lua.txt', 'w') - for k, v in pairs(globalCounts) do - f:write(k, '\t', v, '\n') - end - f:close() - - globalCounts = {} - os.exit(0) - end - end -end diff --git a/scratch/nvim_ffi.lua b/scratch/nvim_ffi.lua deleted file mode 100644 index 6fc01c1..0000000 --- a/scratch/nvim_ffi.lua +++ /dev/null @@ -1,15 +0,0 @@ -local ffi = require("ffi") --- ffi.load("/home/tj/build/neovim/build/include/eval/funcs.h.generated.h") - -ffi.cdef [[ - typedef unsigned char char_u; - char_u *shorten_dir(char_u *str); -]] - -local text = "scratch/file.lua" -local c_str = ffi.new("char[?]", #text) -ffi.copy(c_str, text) - -print(vim.inspect(ffi.string(ffi.C.shorten_dir(c_str)))) - - diff --git a/scratch/picker_locations.lua b/scratch/picker_locations.lua deleted file mode 100644 index 251b617..0000000 --- a/scratch/picker_locations.lua +++ /dev/null @@ -1,7 +0,0 @@ --- Hot reload stuff -package.loaded['telescope'] = nil -package.loaded['telescope.init'] = nil -package.loaded['telescope.picker'] = nil -package.loaded['telescope.finder'] = nil - - diff --git a/scratch/prime_prompt_cache.lua b/scratch/prime_prompt_cache.lua deleted file mode 100644 index 20fb67a..0000000 --- a/scratch/prime_prompt_cache.lua +++ /dev/null @@ -1,138 +0,0 @@ -local log = require('telescope.log') - -local PromptCache = {} - -function getFirstByteDiffIdx(a, b) - local idx = 1 - local max_idx = #a - while a:byte(idx) == b:byte(idx) and idx <= max_idx do - idx = idx + 1 - end - - return idx -end - -function PromptCache:new(opts) - self.__index = self - local obj = setmetatable({ - current_line = nil, - cached_results = {}, - cache_round = 0 - }, self) - - return obj -end - -function PromptCache:set_cache(prompt, item_to_cache) - self.results = item_to_cache - self:_complete(prompt) -end - -function PromptCache:_complete(prompt) - if #prompt == 0 then - self:_reset() - return - end - - local cached_lines = self.results - - local idx = 1 - if self.current_line ~= nil then - idx = getFirstByteDiffIdx(self.current_line, prompt) - end - - -- ABC - -- ABDC - -- IDX = 3 - -- cr = 3 - -- diff = 1 - local diff = #self.cached_results - (idx - 1) - while diff > 0 do - table.remove(self.cached_results) - diff = diff - 1 - end - - -- ABC - -- ADBC - -- diff = 2 - for i = idx, #prompt do - if #self.cached_results < (#prompt - 1) then - local last_cache = self:get_last_cache() - table.insert(self.cached_results, last_cache) - else - table.insert(self.cached_results, cached_lines) - end - end - - self.current_line = prompt -end - -function PromptCache:start_round(cache_round) - self.cache_round = cache_round - log.trace("start_round (had this", self.results and #self.results or nil, "for past results)", self.cache_round) - self.results = {} -end - -function PromptCache:add_to_round(cache_round, line, score) - if cache_round < self.cache_round or score == -1 then - return - end - - table.insert(self.results, line) -end - -function PromptCache:get_last_cache() - local last_cache = nil - - for idx = 1, #self.cached_results do - local cache = self.cached_results[idx] - if cache then - last_cache = cache - end - end - - return last_cache -end - -function PromptCache:complete_round(cache_round, prompt) - if cache_round ~= self.cache_round then - return - end - - self:_complete(prompt) -end - -function PromptCache:get_cache(prompt) - if self.current_line == nil or #prompt == 0 then - return nil - end - - local idx = getFirstByteDiffIdx(self.current_line, prompt) - - if idx == 1 then - self:_reset() - return nil - end - - -- if we are off, then we simply need to prune the cache or let complete do - -- that - local results = nil - repeat - results = self.cached_results[idx - 1] - idx = idx - 1 - until idx <= 1 or results - -return results -end - -function PromptCache:_reset() - self.current_line = nil - self.cached_results = {} -end - - -return { - PromptCache = PromptCache -} - - diff --git a/scratch/rg_lua_jobstart.lua b/scratch/rg_lua_jobstart.lua deleted file mode 100644 index 4b551d4..0000000 --- a/scratch/rg_lua_jobstart.lua +++ /dev/null @@ -1,21 +0,0 @@ - -local function get_rg_results(bufnr, search_string) - local start_time = vim.fn.reltime() - - vim.fn.jobstart(string.format('rg %s', search_string), { - cwd = '/home/tj/build/neovim', - - on_stdout = function(job_id, data, event) - vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, data) - end, - - on_exit = function() - print("Finished in: ", vim.fn.reltimestr(vim.fn.reltime(start_time))) - end, - - stdout_buffer = true, - }) -end - -local bufnr = 14 -get_rg_results(bufnr, 'vim.api') diff --git a/scratch/rocker_example.lua b/scratch/rocker_example.lua deleted file mode 100644 index 0e73114..0000000 --- a/scratch/rocker_example.lua +++ /dev/null @@ -1,24 +0,0 @@ - - -builtin.git_files = function(opts) - opts = opts or {} - - opts.show_preview = get_default(opts.show_preview, true) - - opts.finder = opts.finder or finders.new { - static = true, - - fn_command = function() - return { - command = 'git', - args = {'ls-files'} - } - end, - } - - opts.prompt = opts.prompt or 'Simple File' - opts.previewer = opts.previewer or previewers.cat - opts.sorter = opts.sorter or sorters.get_norcalli_sorter() - - pickers.new(opts):find() -end diff --git a/scratch/short_buf.lua b/scratch/short_buf.lua deleted file mode 100644 index 387b2b5..0000000 --- a/scratch/short_buf.lua +++ /dev/null @@ -1,4 +0,0 @@ -local x = {} -print(x); print("wow"); - -local function other() end diff --git a/scratch/simple_rg.lua b/scratch/simple_rg.lua deleted file mode 100644 index 8bd2586..0000000 --- a/scratch/simple_rg.lua +++ /dev/null @@ -1,23 +0,0 @@ -local telescope = require('telescope') - --- Uhh, finder should probably just GET the results --- and then update some table. --- When updating the table, we should call filter on those items --- and then only display ones that pass the filter -local rg_finder = telescope.finders.new { - fn_command = function(_, prompt) - return string.format('rg --vimgrep %s', prompt) - end, - - responsive = false -} - -local p = telescope.pickers.new { - previewer = telescope.previewers.vim_buffer -} -p:find { - prompt = 'grep', - finder = rg_finder -} - - diff --git a/scratch/simplest_test.lua b/scratch/simplest_test.lua deleted file mode 100644 index c653632..0000000 --- a/scratch/simplest_test.lua +++ /dev/null @@ -1,30 +0,0 @@ -require('plenary.reload').reload_module('telescope') - -local telescope = require('telescope') - --- What is a finder? --- Finders return a list of stuff that you want to fuzzy look through. --- Finders can be static or not. --- Static finders just return a list that never changes --- Otherwise they return a new list on each input, you should handle them async. -local file_finder = telescope.finders.new { - static = true, - - fn_command = function() return 'git ls-files' end, -} - -local file_previewer = telescope.previewers.vim_buffer_or_bat - -local file_picker = telescope.pickers.new { - previewer = file_previewer -} - --- local file_sorter = telescope.sorters.get_ngram_sorter() --- local file_sorter = require('telescope.sorters').get_levenshtein_sorter() -local file_sorter = require('telescope.sorters').get_norcalli_sorter() - -file_picker:find { - prompt = 'Simple File', - finder = file_finder, - sorter = file_sorter, -} diff --git a/scratch/string_distance_stuff.lua b/scratch/string_distance_stuff.lua deleted file mode 100644 index 283f00f..0000000 --- a/scratch/string_distance_stuff.lua +++ /dev/null @@ -1,7 +0,0 @@ - -local string_distance = require('telescope.algos.string_distance') - -print(string_distance("hello", "help")) -print(string_distance("hello", "hello")) -print(string_distance("hello", "asdf")) - diff --git a/scratch/temp_goals.txt b/scratch/temp_goals.txt deleted file mode 100644 index 6827cad..0000000 --- a/scratch/temp_goals.txt +++ /dev/null @@ -1,17 +0,0 @@ - -Goal: Implement scrolling - -So we want to start keeping track of more/all of the results - -We still want them sorted, so when you scroll past, - you still get the stuff you'd expect. - - -Notes: - -Probably want some X / Y count - - - -Options - diff --git a/scratch/test_fuzzy_file.lua b/scratch/test_fuzzy_file.lua deleted file mode 100644 index 85d083a..0000000 --- a/scratch/test_fuzzy_file.lua +++ /dev/null @@ -1,20 +0,0 @@ -RELOAD('telescope') - -local sorter = require('telescope.sorters').get_fuzzy_file() - --- Test for tail. -assert(sorter:score("aaa", "aaa/bbb") > sorter:score("aaa", "bbb/aaa")) -assert( - sorter:score("path", "/path/to/directory/file.txt") - > sorter:score("path", "/file/to/directory/path.txt") -) - --- Matches well for UpperCase (basically just bonus points for having uppercase letters) -assert(sorter:score("AAA", "/blah/this/aaa/that") > sorter:score("AAA", "/blah/this/AAA/that")) - --- TODO: Determine our strategy for these --- TODO: Make it so that capital letters count extra for being after a path sep. --- assert(sorter:score("ftp", "/folder/to/python") > sorter:score("FTP", "/folder/to/python")) - --- TODO: Make it so that --- assert(sorter:score("build", "/home/tj/build/neovim") > sorter:score("htbn", "/home/tj/build/neovim")) diff --git a/scratch/threaded_lua.lua b/scratch/threaded_lua.lua deleted file mode 100644 index 68eddb0..0000000 --- a/scratch/threaded_lua.lua +++ /dev/null @@ -1,15 +0,0 @@ -local uv = require('luv') - --- print(vim.inspect(uv)) - - -local my_table = {} -local my_value = 1 - -local table_adder = uv.new_thread(function(tbl) - table.insert(tbl, "HELLO") -end, my_table) - -uv.thread_join(table_adder) --- print(vim.inspect(MY_TABLE)) - diff --git a/scratch/ts_example.lua b/scratch/ts_example.lua deleted file mode 100644 index 5d6469c..0000000 --- a/scratch/ts_example.lua +++ /dev/null @@ -1,51 +0,0 @@ -local uv = vim.loop - -local has_ts, _ = pcall(require, 'nvim-treesitter') -if not has_ts then - error("ASKDLFJAKLSJFLASKDFJ") -end - -local ts_highlight = require('nvim-treesitter.highlight') -local ts_parsers = require('nvim-treesitter.parsers') - -local function readFile(path, callback) - uv.fs_open(path, "r", 438, function(err, fd) - assert(not err, err) - uv.fs_fstat(fd, function(err, stat) - assert(not err, err) - uv.fs_read(fd, stat.size, 0, function(err, data) - assert(not err, err) - uv.fs_close(fd, function(err) - assert(not err, err) - return callback(data) - end) - end) - end) - end) -end - -local determine_filetype = function(filepath) - -- Obviously TODO - return "lua" -end - -local filepath = "lua/telescope/init.lua" - -local load_ts_buffer = function(bufnr, filepath) - local filetype = determine_filetype(filepath) - if not ts_parsers.has_parser(filetype) then - error("TODO CONNI") - end - - readFile(filepath, vim.schedule_wrap(function(data) - if not vim.api.nvim_buf_is_valid(bufnr) then - return - end - - -- pcall(ts_highlight.detach, bufnr) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, vim.split(data, "\n")) - ts_highlight.attach(bufnr, filetype) - end)) -end - -load_ts_buffer(3, filepath) |
