Adding Snippets
mikeTWC1984 opened this issue ยท comments
Another useful feature to have. I personally like ISE way (ctr + j), but VSCode is good too (just typing snippet name and it appears on the autocomplete list).
coc.nvim already supports this: https://github.com/neoclide/coc.nvim/wiki/Using-snippets
Snippet completion items from coc extensions that contribute VSCode snippets.
So all we need to do is copy over the snippet file from vscode-powershell and then add these lines into our package.json!
@mikeTWC1984 looks like itโs just a bunch of json
changes, any interest in contributing?
Sure, will do. Is everything can be ported from vscode to vim that easy? ) I think the last thing left is ISE color theme (just for fun), can it be ported from VSCode too?
Can't figure out which package.json file to put that snippet config? I tried ~/.config/coc/extensions/node_modules/coc-powershell/package.json, has no any effect (using nvim). I created snippets folder in the same directory and put PowerShell.json file in there. I tried to install their sample js snippets with CocInstall and it seemed to work.
Hmm interesting. @yatli have you gotten snippets working in your other coc extensions?
I haven't played with snippets yet, but according to the doc, it supports quite a few snippet formats.
@mikeTWC1984 you'll need to edit package.json:
- Add the snippets folder in the "files" section.
- In the "contributes" section, list the snippet files, and associate them with language id "ps1"
I have no experience with the actual process though
with language id "ps1"
maybe that's the thing, vscode extension uses "powershell"
@mikeTWC1984 I'm currently working on a CONTRIBUTING.md document in PR #48. Perhaps take a look and let me know if you need assistance.
Basically what I do is checkout the repo to a directory, then tell vim to load the plugin from there.
I played a bit more and still wasn't able to modify coc-powershell's package.json to load snippets, however after replacing snippet file (to PowerShell.json) and language to ps1 in the sample snippet repo I was able to see ps snippets in autocomplete. So at least we can solve that by creating separate repo.
I added snippets to the contributes. And copied PowerShell.json to the coc-powershell directory:
"contributes": {
"snippets": [
{
"language": "ps1",
"path": "PowerShell.json"
}
],
"languages": [
then I made sure it was loading my config by revving the version to 0.0.38. And either I don't know how to trigger the snippets, or they're not actually loading. I'm going to go and read the docs and report back
OK, after reading the docs, there are two things I was missing... I forgot to read my contributing file to know that I needed to run build.ps1
coc-snippets
. After doing the build.ps1
I got PSIC and intellisense. Then after installing coc-snippets, I got snippets. To complete, you select it and then hit Ctrl+y (there's a snippet in the docs to update your vimrc to allow enter to expand the snippet)
Nice. Seems pretty straightforward then. @corbob do you want to send the PR?
I was going to let @mikeTWC1984 put it together (my testing was done within a differently tracked directory).
I'll throw a PR together tonight if mikeTWC1984 hasn't.
@corbob Good news. Go ahead and throw your PR ( I don't have much to submit on my end :) )
One thing to be aware of for snippets is to move between inputs: To navigate forward/backward of a snippet placeholder, use and . Vim global variable g:coc_snippet_next and g:coc_snippet_prev can be used to change the key-mapping.
Seeing that we can do that, I wonder if we should integrate something in the build script to pull the snippets out of the vscode-powershell repository... that way we're not duplicating work of including snippets...
That seems pretty straightforward considering it's just json