-
Notifications
You must be signed in to change notification settings - Fork 167
Code Actions Available flag
To display a flag in the signs column when there are code actions available at the current cursor position, the OmniSharp#CountCodeActions
function can be used:
set updatetime=500
sign define OmniSharpCodeActions text=💡
augroup OSCountCodeActions
autocmd!
autocmd FileType cs set signcolumn=yes
autocmd CursorHold *.cs call OSCountCodeActions()
augroup END
function! OSCountCodeActions() abort
if OmniSharp#CountCodeActions({-> execute('sign unplace 99')})
let l = getpos('.')[1]
let f = expand('%:p')
execute ':sign place 99 line='.l.' name=OmniSharpCodeActions file='.f
endif
endfunction
This code includes an autocmd to call user function OSCountCodeActions
on CursorHold - so whenever the cursor is still for 'updatetime'
milliseconds (the vim default is 4000 or 4 seconds, so this has been set to 500 here). The function calls OmniSharp#CountCodeActions
and passes a callback function to clear the sign, which OmniSharp will call when the current code actions are no longer valid (i.e. whenever the cursor moves or leaves the buffer).
If there are any code actions, then the lightbulb glyph is displayed in the signs column.
Note that OmniSharp#CountCodeActions
is performed synchronously, which means this will result in a lag while the code actions are being fetched.