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

Load workspace setting snippets from .vscode dir #850

Closed
changangus opened this issue Mar 29, 2023 · 7 comments
Closed

Load workspace setting snippets from .vscode dir #850

changangus opened this issue Mar 29, 2023 · 7 comments

Comments

@changangus
Copy link

Hi,

First off thanks for the awesome project, it's much appreciated! I was wondering if there's a way to load snippets from a VScode workspace directory. Here's a screenshot of where the snippets are located:

Screenshot 2023-03-29 at 3 36 45 PM

I saw that it's possible to add a path to custom snippets from my lua config, but I was hoping to not have to manage workspace specific snippets in there.

@leiserfg
Copy link
Contributor

We are having a "discussion" about it right now, check here and (as ex-vscode user) help us to define what you need there.

@changangus
Copy link
Author

Hey @leiserfg, the need for me is to somehow load project specific .code-snippets files automatically. That way I can work across different repos without having to add all of those project specific snippets to my lua config. Let me know if there's anything else I can clear up, I did take a quick look at the comments in that PR and I think this comment makes sense to me as a solution that would be able to accommodate my use case. Thanks again for all of y'alls hard work!

@hinell
Copy link

hinell commented Mar 30, 2023

As a workaround you can pass absolute path to the .code-snippets to the package.json (which is specified by the require("LuaSnip").load() function. But be aware that LuaSnip may support a different mechanism to load these snippets in the future.

@evesdropper
Copy link
Contributor

Adding on to this but not from a vscode perspective, is it possible to have something which loads a relative path (e.g. a .luasnippets directory for specific projects)?

@L3MON4D3
Copy link
Owner

Oh, that's possible already, call

require("luasnip.loaders.from_lua").load({paths = {vim.fn.getcwd() .. "/.luasnippets/"}})

(getcwd because . is interpreted as relative to config-directory)

@L3MON4D3
Copy link
Owner

@changangus you can follow #894, it'll implement/enable this :)
Could you share a few of those .code-snippet-files you have? Just to make sure I'm not misunderstanding anything about the format

@L3MON4D3 L3MON4D3 linked a pull request May 25, 2023 that will close this issue
@L3MON4D3
Copy link
Owner

L3MON4D3 commented Dec 2, 2023

This has worked for some time now, since #1033 we can also detect .code-snippets-files created while the session is running.
require("luasnip.loaders.from_vscode").load_standalone({path = vim.fn.getcwd() .. "/.vscode/snippets.code-snippets", lazy = true})
(but you'll have to always use the same name for the file, is that a big limitation?)

@L3MON4D3 L3MON4D3 closed this as completed Dec 2, 2023
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 a pull request may close this issue.

5 participants