coc-snippets
coc-snippets copied to clipboard
custom snippets does not trigger autoimports
The coc-tsserver option typescript.suggest.paths does not work with snippets.
I created a snippet for useRef.
snippet user "useRef(defaultValue)" b
const ${1:ref} = useRef(${2:null})
endsnippet
When I use this snippet, instead of the autocomplete from coc-tsserver for useRef, the import statement is not added on top of the file.
import { useRef } from 'react'
a pop-up should appear in Neovim suggesting to import useRef from 'react'. This could be also fixed using a custom script to add imports on top + prettier to organize them. Ultisnips seems to not support adding import statements on top of the file.
https://github.com/SirVer/ultisnips/issues?q=is%3Aissue+import+statement+is%3Aclosed
The video below shows how useRef from coc-tsserver adds an import statement on top of the file
https://github.com/user-attachments/assets/5250140c-21d0-4370-b06e-950149c0862f
The video below shows how my custom snippet does not add the import statement.
snippet user "useRef(defaultValue)" b
const ${1:ref} = useRef(${2:null})
endsnippet
https://github.com/user-attachments/assets/3453c3cf-a735-41dc-bd80-a3c553af85c5
My solution is not using these snippets anymore, instead combining other snippets (in this case const does not need an import) with the coc-tsserver autocomplete. Thanks a lot