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

Use sign_getplaced instead of :sign place when possible. #14

Open
aktau opened this issue Jun 10, 2019 · 3 comments
Open

Use sign_getplaced instead of :sign place when possible. #14

aktau opened this issue Jun 10, 2019 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@aktau
Copy link

aktau commented Jun 10, 2019

There's a new signs API (available in Vim 8.1.0772 and in Neovim), it doesn't need text parsing to get at the juicy bits, unlike :signs place list.

Of course, wholesale moving to this easier-to-use API does mean the plugin wouldn't be compatible with older versions o (Neo)Vim anymore. Another option is conditional usage, though that likely only has the disadvantage of quasi-duplicating code.

I'm unsure whether it has performance benefits.

Usage of it in vim-lsp:

$ rg 'sign_[a-z_]*\('
autoload/lsp/ui/vim/signs.vim
55:    call sign_define(a:sign_name, l:options)
78:    call sign_undefine('LspError')
79:    call sign_undefine('LspWarning')
80:    call sign_undefine('LspInformation')
81:    call sign_undefine('LspHint')
104:    let l:sign_group = s:get_sign_group(a:server_name)
105:    call sign_unplace(l:sign_group, { 'buffer': a:path })
108:function! s:get_sign_group(server_name) abort
115:    let l:sign_group = s:get_sign_group(a:server_name)
125:                let l:sign_id = sign_place(0, l:sign_group, l:sign_name, a:path, { 'lnum': l:line })
   vim
@ZeroKnight
Copy link
Owner

Wonderful, I was hoping they'd add to the signs API.

I would like to continue supporting versions without this new API, so I wonder what the best way would be to go about that. Using has v:version is what immediately comes to mind, but I wonder if there's a better way?

@ZeroKnight ZeroKnight added the enhancement New feature or request label Jun 12, 2019
@ZeroKnight ZeroKnight added this to the Version 0.7 milestone Jun 12, 2019
@aktau
Copy link
Author

aktau commented Jun 12, 2019

I think the best option is to check for the existence of this API:

if exists('*sign_define') ...

(See prabirshrestha/vim-lsp#322, which has a discussion on this topic.)

@aktau
Copy link
Author

aktau commented Jun 12, 2019

Thinking about this, I think it's best to emulate vim-lsp check before using the new API:

if exists('*sign_define') && (has('nvim') || has('patch-8.1.0772'))
   " Both group=* and the new API are available.
endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants