neoclide / coc-snippets

Snippets solution for coc.nvim
970 stars 41 forks source link

Issue with identifying '#' and regular expression trigger words #330

Closed kevin61416 closed 1 year ago

kevin61416 commented 1 year ago

Issue 1: Identifying '#' in snippets

In the c.snippets file, I noticed that triggers starting with # are not being recognized correctly in C files. For example, #ifndef, #if in c.snippets both not works.

Additionally, the #v snippet in my sh.snippets file is also not being recognized. However, the only exception is the Shebang #!, which is identified correctly.

Figure 1 - #if only has LSP sources:

截圖 2023-05-28 01 53 31

Figure 2 - Other trigger words work fine:

截圖 2023-05-28 01 50 27

Issue 2: Ineffective regular expression trigger words

Trigger words defined with regular expressions are not working as expected too. For instance, in the sh.snippets file of UltiSnips, the trigger word /wh(ile)?/ is recognized when I type 'wh', but 'while' does not trigger the snippet. Similarly, the trigger word /case|sw(itch)?/ is identified correctly with 'case' but not with 'sw' or 'switch'.

Figure 3 - wh works well:

截圖 2023-05-28 01 39 24

Figure 4 - while not works:

截圖 2023-05-28 01 40 14

Environment:

I would greatly appreciate any guidance or solutions you can provide to resolve these issues. Please let me know if you need any further information.

Thank you!

kevin61416 commented 1 year ago

@chemzqm Still not works 🥲

For example, s#! works, but #! not

截圖 2023-09-07 21 23 21 截圖 2023-09-07 21 25 42
chemzqm commented 1 year ago

You need to include ! to configuration "snippets.triggerCharacters" for this case

kevin61416 commented 1 year ago

I don't know whether the recent version update caused most of the UltiSnips to become ineffective and unable to load. The output of CocCommand snippets.editSnippets:

截圖 2023-09-07 22 11 08
chemzqm commented 1 year ago

I don't know whether the recent version update caused most of the UltiSnips to become ineffective and unable to load. The output of CocCommand snippets.editSnippets

Fixed on latest 3.1.8 version.

kevin61416 commented 1 year ago

You need to include ! to configuration "snippets.triggerCharacters" for this case

Still does not work, also some snippets use regular expressions not work either, for example:

snippet /wh(ile)?/ "while ... (done)" rb
while ${2:[[ ${1:condition} ]]}; do
    ${0:${VISUAL}}
done
endsnippet

snippet /ift(est)?/ "if ... then (if)" rb
if ${2:[ ${1:condition} ]}; then
    ${0:${VISUAL}}
fi
endsnippet
chemzqm commented 1 year ago

Snippet with regex trigger are not included in completeion menu.

kevin61416 commented 1 year ago

Note: python regex in snippet are converted to javascript regex, however, some regex patterns can't be supported by javascript, including (?x) (?s) \Z (?(id/name)yes-pattern|no-pattern).

Thank you for the explanation! However, I believe this is a straightforward and simple regex that's compatible with both POSIX and JS. Could you consider adding support for this kind of simple regex? I think it would be very helpful!

chemzqm commented 1 year ago

@chemzqm Still not works 🥲

For example, s#! works, but #! not

There's bug

chemzqm commented 1 year ago

Fixed

kevin61416 commented 1 year ago

Still not works 🥲, my coc-settings.json:


{
    "snippets.triggerCharacters": ["!"]
}
chemzqm commented 1 year ago

Still not works 🥲, my coc-settings.json:

{
    "snippets.triggerCharacters": ["!"]
}

Should work when you type !

kevin61416 commented 1 year ago

I've tried it, but it didn't work.

截圖 2023-09-22 00 00 58

Snippets that start with English letters are all working properly.

截圖 2023-09-22 00 00 48

versions

vim version: VIM - Vi IMproved 9.0 9001850 node version: v18.17.0 coc.nvim version: 0.0.82-2a73b9dc 2023-09-21 23:24:13 +0800 coc.nvim directory: /Users/kevin/Workspace/dotfiles/.vim/plugged/coc.nvim term: iTerm.app platform: darwin