corvofeng/Vsnips

How to use UltiSnips?

Closed this issue · 17 comments

I'm trying to follow the instructions posted here: https://github.com/corvofeng/Vsnips#how-to-use-vsnips but I'm not able to make it work.

This is what I have put in my settings.json:

    "Vsnips.SnipsDir": [
        "~/.config/nvim/my_snippets",
        "~/.config/nvim/plugged/vim-snippets/UltiSnips",
    ],
    "Vsnips.VarFiles": [
        "~/.config/nvim/init.vim"
    ]

Directory ~/.config/nvim/my_snippets contains three files: nim.snippets python.snippets racket.snippets, but none of them is picked up.
Directory ~/.config/nvim/plugged/vim-snippets/UltiSnips contains lots of snippet files available at https://github.com/honza/vim-snippets/tree/master/UltiSnips

Can you tell me what I'm doing wrong and how can I make those snippets work with your plugin?

  1. Firstly, please check if default snippet works, like this:
    image

VSnips carry some default snippets from https://github.com/honza/vim-snippets/tree/master/UltiSnips

image

  1. Maybe you can use full path, like /home/corvo but not ~
{
    "Vsnips.VarFiles": [
        "/home/corvo/.vimrc",
        "/home/corvo/.vim/common.vim",
    ],
    "Vsnips.SnipsDir": [
        "/home/corvo/.vim/UltiSnips"
    ]
}
  1. If vsnips still can't display any snippets, please add
    "Vsnips.LogLevel": "ERROR",

Firstly, please check if default snippet works, like this:

Yes, they work, I tried it with Python file.

Maybe you can use full path, like /home/corvo but not ~

Originally I had it like this, but it didn't help.

If vsnips still can't display any snippets, please add

Added that. Where can I see those errors, so I can show it to you?

const UserLocalDir =
  process.env.APPDATA ||
  (process.platform === "darwin"
    ? process.env.HOME + "/Library/Preferences"
    : process.env.HOME + "/.local/share");

You can check logs:

Windows: 'C:\Users\xxxx\AppData\Roaming'
Linux: '/home/corvo/.local/share'
Mac: HOME + /Library/Preferences

You could send the file to me.

You could send the file to me.

It is an empty file. And I tried to do "show available snippets" in both Python file (where the default ones are shown) and in Racket file (where it should pick up my custom snippets file).

EDIT: After restarting VSCode, this file now contains one line:

2021-10-22 19:15:17: [E] Can"t parse the var file:  ~/.config/nvim/init.vim

This line is produced at VSCode startup, not when I try to use your plugin.
Commenting out Vsnips.VarFiles doesn't throw the error at startup, but it doesn't change the fact that custom snippets are not picked up.

"Can't parse" means that var file doesn't fit the extension.

Please paste the init.vim and racket.vsnippets.

I'd like to test and check for your problem.

init.vim, UltiSnips-related stuff is on line 397

racket.snippets

  1. When I use racket.snippets.

It does work, you need to add

image

Make sure that vscode detects the right languageId.

image

And add the config:

{
    "Vsnips.SnipsDir": [
        "/home/corvo/.vim/UltiSnips"
    ],
}
# dir structure
/home/corvo/.vim/UltiSnips
├── all.snippets
├── racket.snippets
└── vimwiki.snippets

image

image

I found that init.vim has some statements like this:


let g:fzf_colors =
\ { 'fg':      ['fg', 'Normal'],
  \ 'bg':      ['bg', 'Normal'],
  \ 'hl':      ['fg', 'Comment'],
  \ 'fg+':     ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
  \ 'bg+':     ['bg', 'CursorLine', 'CursorColumn'],
  \ 'hl+':     ['fg', 'Statement'],
  \ 'info':    ['fg', 'Type'],
  \ 'border':  ['fg', 'Ignore'],
  \ 'prompt':  ['fg', 'Character'],
  \ 'pointer': ['fg', 'Exception'],
  \ 'marker':  ['fg', 'Keyword'],
  \ 'spinner': ['fg', 'Label'],
  \ 'header':  ['fg', 'Comment'] }

Currently, vsnips can't parse it, I'll fix it, but in my opinion, it doesn't affect the show available snippets.

You can change init.vim to this:

let g:fzf_colors = {
\  'fg':      ['fg', 'Normal'],
....
}

I use 'Magic Racket' extension, and Racket is recognized in bottom-right corner of VSCode.

But it is not limited just to Racket files and Racket snippets. Here is my nim.snippets, which is not picked up for Nim files.

Also, in ~/.config/nvim/my_snippets I have python.snippets with this content:

extends python

snippet ifnn "if not None"
if ${1} is not None:
	${0:${VISUAL}}
endsnippet

and ifnn is also not picked up for Pyhton files.

  1. when I use python.snippets, it works.

Maybe you should edit snippets

image

and check whether there is a python.snippets with a ifnn in it.

image

If there is, then
image

  1. I have tested the nim.snippetes, currently vsnips identify it as an objc file, I'll fix it: 4294240.

image

Lately, I'll make publishing for new version vsnips.

Now, you could make update.

image

image

  1. If you still can't see any self-defined snippets, please use debug and send that logs to me.
    "Vsnips.LogLevel": "DEBUG",

I've changed log level and suddenly Python and Nim snippets started working!? I think it is a strange coincidence, but it worked.

Racket is still not working.
I tried disabling Magic Racket and using the Racket extension you mentioned earlier, and it seemed like that did the trick, but upon restarting VSCode, it was back to no snippets at all. So I had it working just for one time, and all other times is no snippets at all for .rkt files.

This seems to be the relevant part of the log: link

2021-10-23 11:47:23: [W] The /home/miran/code/AdventOfCode/2018/racket/day10.rkt.git didn't get the proper lauguageId, VSnips will try to find it.

I see the log, I'll add the rkt as racket's postfix. I also test the Magic Racket, It looks working fine

539863b

Please update to 0.5.6.

Please update to 0.5.6.

It works!!!

Thank you for the quick solution!

I've changed log level and suddenly Python and Nim snippets started working!? I think it is a strange coincidence, but it worked.

It is not a coincidence! I had the same problem but with a Latex File.
I have Latex Workshop installed (Maybe related to this issue).
Vsnips couldn't determine the filetype even tho VSCode clearly does.
image image

This Problem resolved after adding the line "Vsnips.LogLevel": "DEBUG", to the settings.json and all the snippets work fine now.

@Ynfiniti How can I reproduce your problem? Have you tried to use show available snippets?

image

How can I reproduce your problem? Have you tried to use show available snippets?

Yes I did try show available snippetsand it does not work (doesn't give any results).
On the other hand, edit snippets does show that all the snippets are loaded and correct.
Just after adding the line "Vsnips.LogLevel": "DEBUG", VSnips was able to detect the latex filetype at all.
Without it, the plugin always showed the message: End add language all on the bottom of VSCode, for every .tex file.
image

Don't know if it helps in any way, but these are my current settings
image

I found an error in the console. There is a temporary solution: Change filetype to TeX.

2022-10-24 20:33:54: [I] Get latex available snippet

/home/xxxx/.vscode-server/bin/d045a5eda657f4d7b676dedbfa7aab8207f8a075/out/vs/workbench/api/node/extensionHostProcess.js:94
rejected promise not handled within 1 second: The latex does't add yet

image