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

Adding Snippets #51

Closed
mikeTWC1984 opened this issue Jul 15, 2019 · 15 comments · Fixed by #55
Closed

Adding Snippets #51

mikeTWC1984 opened this issue Jul 15, 2019 · 15 comments · Fixed by #55
Labels
enhancement New feature or request

Comments

@mikeTWC1984
Copy link
Contributor

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).

@TylerLeonhardt
Copy link
Collaborator

TylerLeonhardt commented Jul 16, 2019

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?

@mikeTWC1984
Copy link
Contributor Author

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?

@mikeTWC1984
Copy link
Contributor Author

mikeTWC1984 commented Jul 17, 2019

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.

@TylerLeonhardt
Copy link
Collaborator

Hmm interesting. @yatli have you gotten snippets working in your other coc extensions?

@yatli
Copy link
Member

yatli commented Jul 17, 2019

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:

  1. Add the snippets folder in the "files" section.
  2. In the "contributes" section, list the snippet files, and associate them with language id "ps1"

I have no experience with the actual process though 😅

@yatli
Copy link
Member

yatli commented Jul 17, 2019

with language id "ps1"

maybe that's the thing, vscode extension uses "powershell"

@corbob
Copy link
Member

corbob commented Jul 17, 2019

@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.

@mikeTWC1984
Copy link
Contributor Author

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.

@corbob
Copy link
Member

corbob commented Jul 18, 2019

🤔 I can't seem to get it to work either.

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 😂

@corbob
Copy link
Member

corbob commented Jul 18, 2019

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 😂 and apparently you also need to install 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)

@TylerLeonhardt
Copy link
Collaborator

Nice. Seems pretty straightforward then. @corbob do you want to send the PR?

@corbob
Copy link
Member

corbob commented Jul 18, 2019

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.

@mikeTWC1984
Copy link
Contributor Author

@corbob Good news. Go ahead and throw your PR ( I don't have much to submit on my end :) )

@corbob
Copy link
Member

corbob commented Jul 18, 2019

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...

@TylerLeonhardt
Copy link
Collaborator

That seems pretty straightforward considering it's just json 👍

@corbob corbob mentioned this issue Jul 18, 2019
@TylerLeonhardt TylerLeonhardt added the enhancement New feature or request label Jul 26, 2019
@yatli yatli closed this as completed in #55 Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants