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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] 馃 can we use VS Code user code-snippets? #705

Closed
2nthony opened this issue Dec 29, 2022 · 7 comments
Closed

[question] 馃 can we use VS Code user code-snippets? #705

2nthony opened this issue Dec 29, 2022 · 7 comments

Comments

@2nthony
Copy link

2nthony commented Dec 29, 2022

I created a bulk of code-snippets when I was using vscode, the path is: ~/Library/Application Support/Code/User/snippets/*.code-snippets

So, can I load these code-snippets via this plugin? I've read the doc, but I didn't see any guide for this(maybe I missed).

here is the vscode snippet template:

{
	// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
}
@2nthony 2nthony changed the title [question] 馃 can we use VS Code code-snippets? [question] 馃 can we use VS Code user code-snippets? Dec 29, 2022
@L3MON4D3
Copy link
Owner

Yeah, do you have the package.json accompanying them? Pass the path to the directory it's in to luasnip.loaders.from_vscode.load (see readme, or search for it in DOC.md), that should do it

@2nthony
Copy link
Author

2nthony commented Dec 30, 2022

OK, now works according to the doc.


It seems can not work like this:

~/.config/nvim/my-snippets/package.json
~/Library/Application Support/Code/User/snippets/dropcode.code-snippets
-- luasnip.lua
require("luasnip.loaders.from_vscode").lazy_load({
  paths = {
    "./my-snippets", 馃憟
  }
})
// my-snippets/package.json
{
  "name": "my-snippets",
  "contributes": {
    "snippets": [
      {
        "language": [
          "all"
        ],
        "path": "~/Library/Application Support/Code/User/snippets/dropcode.code-snippets" 馃憟
      }
    ]
  }
}

@2nthony 2nthony closed this as completed Dec 30, 2022
@hinell
Copy link

hinell commented Feb 6, 2023

@2nthony I've two questions:

  1. Are scope fields explicitly supported?
  2. Does the "package.json#language" field affects the scope field when snippets are loaded into luasnip engine?

Please, give answers in docs, thanks!

@2nthony
Copy link
Author

2nthony commented Feb 6, 2023

@hinell

  1. I didn't see it works.(if I do scope in javascript, it will still have the snippet in vue file)
  2. not sure

@leiserfg
Copy link
Contributor

leiserfg commented Feb 6, 2023

We don't support .code-snippets files as of now (mostly because I don't use vscode so I forgot (or didn't know about) them. But adding them should be quite easy, a PR will be appreciated 馃槂

@2nthony
Copy link
Author

2nthony commented Feb 6, 2023

Supported actually by adding ~/Library/Application Support/Code/User/snippets/package.json and do some figure.

@hinell
Copy link

hinell commented Feb 7, 2023

The problem is that I have snippets for various different, but similar languages: javascript,typescript,javascriptreact,typescriptreact in one place that I would like to import into luasnip.

@leiserfg If I have time on hands!

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

No branches or pull requests

4 participants