Shougo / neosnippet.vim

neo-snippet plugin
Other
1.12k stars 108 forks source link

Snippets and LanguageClient-neovim: no indent, undesired synchronized placeholder #475

Closed pappasam closed 4 years ago

pappasam commented 4 years ago

Thanks for this awesome plugin! These fixes may be out of scope because they're related to language-servers that focus more on vscode. That said, maybe you'll consider it in-scope, so I'll outline the problems in case it helps you and/or others who run into similar issues.

Problems

I've run into two issues using the latest version of this plugin with the latest version of LanguageClient-neovim.

  1. Snippets completed from a language server do not expand tabs
  2. The placeholders in vscode use the same symtax as neosnippet's synchronized placeholder ($1, not ${1}), which means snippet completion does not work as intended by the language-server.

Gif

COMPLETION

Value of v:completed_item

{'word': 'license:
        name: $1', 'menu': '[LC] ', 'user_data': '{"lspitem":{"label":"license","kind":10,"documentation":"","insertText":"license:\n\tname: $1","insertTextFormat":2,"textEdit":{"range":{"start":{"line
":10,"character":2},"end":{"line":10,"character":6}},"newText":"license:\n\tname: $1"}},"snippet":"license:\n\tname: $1"}', 'info': '', 'kind': 'Property', 'abbr': 'license'}

Environment

vimrc:

let g:neosnippet#enable_completed_snippet = 1
let g:neosnippet#enable_complete_done = 1
let g:LanguageClient_serverCommands = {
      \ 'yaml': ['yaml-language-server', '--stdio'],
      \ }
pappasam commented 4 years ago

A custom function I've written to work around the problem in this special case (disabling enablecompleted* neosnippet variables):

function! s:format_yaml_snippet()
  " Find and replace things with $0, $1, $2, etc
  s/$\([0-9]\+\)/<`\1`>/g
  " Expand custom yaml snippet
  execute 's/\%x00  /\r'
        \ . repeat(' ', indent('.'))
        \ . repeat(' ', &shiftwidth)
        \ . '/g'
endfunction
command! FormatYamlSnippet call s:format_yaml_snippet()
Shougo commented 4 years ago

Fixed.

pappasam commented 4 years ago

Unfortunately, while the latest fix gets us closer, it ignores the current level of indentation and does not convert the tab character to spaces when expandtab is set to 1. See below for a gif:

only-indent

Thanks for addressing this so quickly btw, your plugins are the best!

Shougo commented 4 years ago

Sorry. It is feature.

pappasam commented 4 years ago

Possibly, but the same thing now happens with my Python language snippets that come directly from the neosnippet-snippets plugin. I suspect this may be a bug, not a feature:

broken_python

Shougo commented 4 years ago

Please test the latest version of neosnippet.

pappasam commented 4 years ago

Python: now cares about current level of indentation, but has two levels of indentation:

double-indent-python

pappasam commented 4 years ago

Snippets coming from the language server for YAML are doing the correct thing now, for the most part. Two minor issues that I will document soon.

pappasam commented 4 years ago
  1. there's one extra space created for the first snippet location

yaml-extra-space

Shougo commented 4 years ago

there's one extra space created for the first snippet location

Please upload v:completed_item result.

pappasam commented 4 years ago
  1. Spuriously (not every time), the first "jump to next symbol" inserts the snippet again when using this key mapping: imap <C-b> <Plug>(neosnippet_expand_or_jump)

random-paste

pappasam commented 4 years ago

Python's v:completed_item: {'word': 'defd', 'menu': '[ns] def function(...): """..."""', 'user_data': '{"snippet_trigger": "defd", "snippet": "def ${1:#:n ame}(${2}):\n\t\t\"\"\"${3:#:function documentation}\"\"\"\n\t\t${0:pass}"}', 'info': '', 'kind': '', 'abbr': ''}

pappasam commented 4 years ago

Yaml's v:completed_item: {'word': 'info: title: $1 version: $2', 'menu': '[LC] ', 'user_data': '{"lspitem":{"label":"info","kind":10,"documentation":"","insertText":"info :\n\ttitle: $1\n\tversion: $2","insertTextFormat":2,"textEdit":{"range":{"start":{"line":2,"character":0},"end":{"line":2,"char acter":3}},"newText":"info:\n\ttitle: $1\n\tversion: $2"}},"snippet":"info:\n\ttitle: $1\n\tversion: $2"}', 'info': '', 'kind': 'Property', 'abbr': 'info'}

Shougo commented 4 years ago

Spuriously (not every time), the first "jump to next symbol" inserts the snippet again when using this key mapping: imap (neosnippet_expand_or_jump)

Because, LanguageClient-neovim's word is broken. Snippet item is inserted directly.

2nd problem is not bug of neosnippet.

Shougo commented 4 years ago

And sorry. I cannot test yaml-language-server. So I don't want to test your problem.

pappasam commented 4 years ago

No worries! The python snippet problem will probably affect way more people, so that’s the important one. I just listed the yaml issue for completeness.

On Sun, Oct 13, 2019 at 12:17 PM Shougo notifications@github.com wrote:

And sorry. I cannot test yaml-language-server. So I don't want to test your problem.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Shougo/neosnippet.vim/issues/475?email_source=notifications&email_token=AA4NDF7ZOBWBXVJCPGG2OITQONC2XA5CNFSM4I7RU4K2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCZV3Q#issuecomment-541432558, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4NDF3XQVRQKHT7GB6S6XDQONC2XANCNFSM4I7RU4KQ .

Shougo commented 4 years ago

https://github.com/Shougo/neosnippet.vim/issues/475#issuecomment-541431230

Fixed. Please test the latest version.

Shougo commented 4 years ago

I have tested and installed yaml-languege-server. But it does not work for me.

Oh, it is bad.

pappasam commented 4 years ago

Haha, yeah, the latest version is broken. 0.4.1 is the most recent working version. https://github.com/redhat-developer/yaml-language-server/issues/192

And I tested your fixes; they work!

Shougo commented 4 years ago

Oh...

pappasam commented 4 years ago

If you want 0.4.1 of yaml-language-server to work, you'll need to configure it according to these docs: https://github.com/autozimu/LanguageClient-neovim/wiki/yaml-language-server . It's buggy, but is the only option I could find for editing openapi specs.

pappasam commented 4 years ago

Thanks for all the help! I'm guessing that based on your fixes, neosnippet will better-support more vscode-like language-servers going forward, which will be a great user experience improvement for lsp-supported snippets in neovim.

Shougo commented 4 years ago

OK. I get it. yaml-language-server works.

Shougo commented 4 years ago

version snippet is generated, but info is not generated.

Shougo commented 4 years ago

why?? I am confusing by the behavior.

Shougo commented 4 years ago

I don't fix the non-reproducible problems. It is my policy.

Shougo commented 4 years ago

If you create the reproducible steps, I will test it later for yaml languege-server. If not, my work is done.

pappasam commented 4 years ago

I'll open a new issue if I figure out how to describe the yaml-language-server issue clearly. I think this current issue is definitely resolved, thanks again for your help!