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

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

Closed
pappasam opened this issue Oct 10, 2019 · 28 comments

Comments

@pappasam
Copy link

pappasam commented Oct 10, 2019

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
Copy link
Author

A custom function I've written to work around the problem in this special case (disabling enable_completed_* 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 Shougo closed this as completed in 75106c0 Oct 13, 2019
@Shougo
Copy link
Owner

Shougo commented Oct 13, 2019

Fixed.

@pappasam
Copy link
Author

pappasam commented Oct 13, 2019

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
Copy link
Owner

Shougo commented Oct 13, 2019

Sorry. It is feature.

@pappasam
Copy link
Author

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
Copy link
Owner

Shougo commented Oct 13, 2019

Please test the latest version of neosnippet.

@pappasam
Copy link
Author

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

double-indent-python

@pappasam
Copy link
Author

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
Copy link
Author

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

yaml-extra-space

@Shougo
Copy link
Owner

Shougo commented Oct 13, 2019

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

Please upload v:completed_item result.

@pappasam
Copy link
Author

pappasam commented Oct 13, 2019

  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
Copy link
Author

pappasam commented Oct 13, 2019

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
Copy link
Author

pappasam commented Oct 13, 2019

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
Copy link
Owner

Shougo commented Oct 13, 2019

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
Copy link
Owner

Shougo commented Oct 13, 2019

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

@pappasam
Copy link
Author

pappasam commented Oct 13, 2019 via email

@Shougo
Copy link
Owner

Shougo commented Oct 13, 2019

#475 (comment)

Fixed. Please test the latest version.

@Shougo
Copy link
Owner

Shougo commented Oct 13, 2019

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

Oh, it is bad.

@pappasam
Copy link
Author

Haha, yeah, the latest version is broken. 0.4.1 is the most recent working version. redhat-developer/yaml-language-server#192

And I tested your fixes; they work!

@Shougo
Copy link
Owner

Shougo commented Oct 13, 2019

Oh...

@pappasam
Copy link
Author

pappasam commented Oct 13, 2019

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
Copy link
Author

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
Copy link
Owner

Shougo commented Oct 13, 2019

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

@Shougo
Copy link
Owner

Shougo commented Oct 13, 2019

version snippet is generated, but info is not generated.

@Shougo
Copy link
Owner

Shougo commented Oct 13, 2019

why?? I am confusing by the behavior.

@Shougo
Copy link
Owner

Shougo commented Oct 13, 2019

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

@Shougo
Copy link
Owner

Shougo commented Oct 13, 2019

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

@pappasam
Copy link
Author

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!

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

2 participants