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

custom snippets does not trigger autoimports #356

Open
fabOnReact opened this issue Jul 31, 2024 · 1 comment
Open

custom snippets does not trigger autoimports #356

fabOnReact opened this issue Jul 31, 2024 · 1 comment

Comments

@fabOnReact
Copy link

fabOnReact commented Jul 31, 2024

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

Screen.Recording.2024-07-31.at.11.37.24.AM.mov

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
Screen.Recording.2024-07-31.at.11.39.11.AM.mov

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

@fabOnReact
Copy link
Author

There is another issue, but not with coc-snippets.

If the import already exist, auto-complete does not work.

for example, I already have import { useImperativeHandle } from 'react'.
The autocomplete for useImperativeHandle does not work, so in the end using custom snippets is better than the coc-tsserver auto-complete except if you need the auto-import functionality.

Screen.Recording.2024-07-31.at.12.19.52.PM.mov

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

1 participant