nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

feat: Refactor compare.scopes

Open pynappo opened this issue 1 year ago • 0 comments

On nvim-treesitter main, some of the methods used in cmp's compare.scopes now error instead of returning an empty table when no tree-sitter parser exists (specifically, locals.get_*). This implements a basic fix.

~~Leaving it as a draft because:~~

  • Not sure on the best way to track whether a buffer has tree-sitter parsing.
    • Maybe track the buffers in compare.scopes instead of vim.b?
    • Would it be better to not track buffers and just pcall the affected locals.get_* methods?
  • Not sure about modifying autocmd helpers to include the lua callback table.

Edit: This PR has also turned into an overhaul of compare.scopes:

  • Improves performance a bit by only looping over definitions once per update()
  • Clears previous results on each update, leading to more expected sorting (previously, nothing ever got removed or modified once it was put into the scopes_map).

edit2: I can also revert the renaming of the variables if you'd like, I just did it out of my preference when I was changing the function around

pynappo avatar Aug 02 '24 10:08 pynappo