Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mini.snippets and snippets presets #877

Merged
merged 12 commits into from
Jan 7, 2025

Conversation

abeldekat
Copy link
Contributor

@abeldekat abeldekat commented Jan 3, 2025

Resolves #741

Tested with the LazyVim PR mentioned below. Snippets appear and can be expanded.

Checklist

  • Expand and select
  • Implement resolve function
  • Correct caching

See also:

@Saghen
Copy link
Owner

Saghen commented Jan 3, 2025

TODO: Should the new source be added to configurations.md

I can handle the documentation when it's ready for review

@abeldekat
Copy link
Contributor Author

I can handle the documentation when it's ready for review

Great!

@abeldekat
Copy link
Contributor Author

abeldekat commented Jan 4, 2025

Ready for review.

I do hope I implemented caching correctly!

Given buf_id/ft combination, snippets don't change in a vim session.
In order to also reuse the generated documentation, I would like to change function resolve into:

function source:resolve(item, callback)
  local snip = item.data.snip

  ---@diagnostic disable-next-line: undefined-field
  local desc = snip.desc
  if desc and not item.documentation then
    item.documentation = {
      kind = 'markdown',
      value = table.concat(vim.lsp.util.convert_input_to_markdown_lines(desc), '\n'),
    }
  end

  ---@diagnostic disable-next-line: undefined-field
  local detail = snip.body
  if not item.detail then
    if type(detail) == 'table' then detail = table.concat(detail, '\n') end
    item.detail = detail
  end

  callback(item)
end

Question: Is the deepcopy to resolved_item on line 81 important? The suggested changes seem to be working fine.

@abeldekat abeldekat marked this pull request as ready for review January 4, 2025 09:28
lua/blink/cmp/sources/mini_snippets.lua Outdated Show resolved Hide resolved
lua/blink/cmp/sources/mini_snippets.lua Outdated Show resolved Hide resolved
@abeldekat
Copy link
Contributor Author

@Saghen

I also committed the source:resolve I suggested in this comment.
If you don't agree I will revert the change.

@Saghen
Copy link
Owner

Saghen commented Jan 7, 2025

@echasnovski For the active function, we use vim.snippet.active({ direction = -1 | 1 }). I wasn't able to find an equivalent in mini.snippets, although it's not a deal breaker if this is unsupported

@echasnovski
Copy link

@echasnovski For the active function, we use vim.snippet.active({ direction = -1 | 1 }). I wasn't able to find an equivalent in mini.snippets, although it's not a deal breaker if this is unsupported

That would be MiniSnippets.session.get() ~= nil, which checks if there is an active session. Checking for "active in particular direction" does not make much sense with default_insert() since it wraps around the edge when jumping through tabstops. So if snippet session is active it is active in any direction.

@Saghen
Copy link
Owner

Saghen commented Jan 7, 2025

Makes sense, thank you!

@abeldekat
Copy link
Contributor Author

I use it like this in Lazyvim PR

@Saghen Saghen force-pushed the add_mini_snippets branch from bf9c078 to 66d6e38 Compare January 7, 2025 21:55
@Saghen Saghen merged commit 201a9b0 into Saghen:main Jan 7, 2025
2 checks passed
@Saghen
Copy link
Owner

Saghen commented Jan 7, 2025

Brilliant work, thank you @abeldekat! And thank you for the reviews @echasnovski!

Saghen added a commit that referenced this pull request Jan 7, 2025
* feat: mini.snippets and snippets presets

* feat: mini.snippets and snippets presets: Remove a vim.notify...

* feat: mini.snippets and snippets presets: Review echasnovski. Enabled should use _G.MiniSnippets

* feat: mini.snippets and snippets presets: Implemented source:resolve

* feat: mini.snippets and snippets presets: Review echasnovski, changed caching

* feat: mini.snippets and snippets presets: Improve source:resolve

* feat: mini.snippets and snippets presets: Review echasnovski, snippets can be cleared

* feat: mini.snippets and snippets presets: Added class blink.cmp.MiniSnippetsSnippet and removed to vim.print

* feat: mini.snippets and snippets presets: Review echasnovski, add note about default context. Extra: add option use_items_cache

* feat: snippet presets

* feat: merge snippets to single source

* docs: add back note about wrapping `vim.snippet` calls

---------

Co-authored-by: abeldekat <[email protected]>
Co-authored-by: Liam Dyer <[email protected]>
@abeldekat
Copy link
Contributor Author

That's great! Thank you both!

@abeldekat abeldekat deleted the add_mini_snippets branch January 7, 2025 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mini.snippets and snippets presets
3 participants