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

WIP: Provide folding support #614

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ augroup omnisharp_commands
autocmd FileType cs nmap <silent> <buffer> <Leader>osd <Plug>(omnisharp_documentation)
autocmd FileType cs nmap <silent> <buffer> <Leader>osfs <Plug>(omnisharp_find_symbol)
autocmd FileType cs nmap <silent> <buffer> <Leader>osfx <Plug>(omnisharp_fix_usings)
autocmd FileType cs nmap <silent> <buffer> <Leader>osfo <Plug>(omnisharp_fold)
autocmd FileType cs nmap <silent> <buffer> <C-\> <Plug>(omnisharp_signature_help)
autocmd FileType cs imap <silent> <buffer> <C-\> <Plug>(omnisharp_signature_help)

Expand Down
4 changes: 2 additions & 2 deletions autoload/OmniSharp/actions/codestructure.vim
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let s:save_cpo = &cpoptions
set cpoptions&vim

function! OmniSharp#actions#codestructure#Get(bufnr, Callback) abort
function! OmniSharp#actions#codestructure#Get(bufnr, sendbuffer, Callback) abort
let opts = {
\ 'ResponseHandler': function('s:CodeStructureRH', [a:bufnr, a:Callback]),
\ 'BufNum': a:bufnr,
\ 'SendBuffer': 0
\ 'SendBuffer': a:sendbuffer
\}
call OmniSharp#stdio#Request('/v2/codestructure', opts)
endfunction
Expand Down
6 changes: 3 additions & 3 deletions autoload/OmniSharp/actions/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ endfunction

function! s:StdioGetCompletions(partial, Callback) abort
let wantDocPopup = OmniSharp#popup#Enabled()
\ && g:omnicomplete_fetch_full_documentation
\ && g:OmniSharp_complete_documentation
\ && &completeopt =~# 'popup'
let wantDoc = wantDocPopup ? 'false'
\ : g:omnicomplete_fetch_full_documentation ? 'true' : 'false'
\ : g:OmniSharp_complete_documentation ? 'true' : 'false'
let wantSnippet = g:OmniSharp_want_snippet ? 'true' : 'false'
let parameters = {
\ 'WordToComplete': a:partial,
Expand Down Expand Up @@ -109,7 +109,7 @@ function! s:StdioGetCompletionsRH(Callback, wantDocPopup, response) abort
\}
if a:wantDocPopup
let completion.info = cmp.MethodHeader . "\n ..."
elseif g:omnicomplete_fetch_full_documentation
elseif g:OmniSharp_complete_documentation
let completion.info = ' '
if has_key(cmp, 'Description') && cmp.Description != v:null
let completion.info = cmp.Description
Expand Down
51 changes: 51 additions & 0 deletions autoload/OmniSharp/actions/fold.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
let s:save_cpo = &cpoptions
set cpoptions&vim

function! OmniSharp#actions#fold#Create() abort
if !g:OmniSharp_server_stdio
echomsg 'This functionality is only available with the stdio server'
return
endif
call OmniSharp#actions#codestructure#Get(bufnr('%'), 1,
\ function('s:CreateFolds'))
endfunction

function! s:CreateFolds(bufnr, codeElements) abort
if a:bufnr != bufnr('%') | return | endif
let ranges = reverse(s:FindBlocks(a:codeElements))
if len(ranges) == 0
return
endif
setlocal foldmethod=manual
normal! zE
for range in ranges
execute printf('%d,%dfold', range[0], range[1])
endfor
" All folds are currently closed - reset to current foldlevel
let &l:foldlevel = &foldlevel
endfunction

function! s:FindBlocks(codeElements) abort
if type(a:codeElements) != type([]) | return [] | endif
let ranges = []
for element in a:codeElements
if len(g:OmniSharp_fold_kinds) == 0 ||
\ index(g:OmniSharp_fold_kinds, get(element, 'Kind', '')) >= 0
if has_key(element, 'Ranges') && has_key(element.Ranges, 'full')
let full = element.Ranges.full
let start = get(get(full, 'Start', {}), 'Line', 0)
let end = get(get(full, 'End', {}), 'Line', 0)
if end - start >= &foldminlines
call add(ranges, [start, end])
endif
endif
endif
call extend(ranges, s:FindBlocks(get(element, 'Children', [])))
endfor
return ranges
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo

" vim:et:sw=2:sts=2
4 changes: 2 additions & 2 deletions autoload/OmniSharp/actions/test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function! OmniSharp#actions#test#Run(...) abort
return
endif
let s:runningTest = 1
call OmniSharp#actions#codestructure#Get(bufnr,
call OmniSharp#actions#codestructure#Get(bufnr, 0,
\ function('s:RunTest', [function('s:CBRunTest')]))
endfunction

Expand Down Expand Up @@ -176,7 +176,7 @@ endfunction

function! s:FindTestsInFiles(Callback, buffers, ...) abort
call OmniSharp#util#AwaitParallel(
\ map(copy(a:buffers), {i,b -> function('OmniSharp#actions#codestructure#Get', [b])}),
\ map(copy(a:buffers), {i,b -> function('OmniSharp#actions#codestructure#Get', [b, 0])}),
\ function('s:RunTestsInFiles', [a:Callback]))
endfunction

Expand Down
2 changes: 1 addition & 1 deletion autoload/OmniSharp/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function! OmniSharp#util#CheckCapabilities() abort

if !s:capable
" Clear BufEnter and InsertLeave autocmds
silent! autocmd! OmniSharp_HighlightTypes
silent! autocmd! OmniSharp_Highlighting
" Clear plugin integration autocmds
silent! autocmd! OmniSharp_Integrations
endif
Expand Down
36 changes: 31 additions & 5 deletions doc/omnisharp-vim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,24 @@ Use this option to enable syntastic integration >
-------------------------------------------------------------------------------
3.7 MISCELLANEOUS *omnisharp-miscellaneous-options*

*g:OmniSharp_fold_kinds*
The "kinds" of elements to fold with |:OmniSharpFold|. Possible values are:

// types
class, delegate, enum, interface, struct

// members
constant, constructor, destructor, enumMember, event, field, indexer,
method, operator, property

// other
namespace, unknown

An empty list means that _all_ kinds should be folded, when they span a range
greater than 'foldminlines'.
Default: [] >
let g:OmniSharp_fold_kinds = ['method', 'constructor', 'destructor']
<
*g:OmniSharp_lookup_metadata*
When using `OmniSharpGotoDefinition` and `OmniSharpPreviewDefinition`,
fall back to looking up metadata for compiled types.
Expand Down Expand Up @@ -381,12 +399,13 @@ Window. Type lookups will display in the status line if this is `0`.
Default: 0 >
let g:OmniSharp_typeLookupInPreview = 0
<
*g:omnicomplete_fetch_full_documentation*
*g:OmniSharp_complete_documentation*
Use this option to specify whether OmniSharp will fetch full documentation on
completion suggestions. By default, only type/method signatures are fetched for
performance reasons. Full documentation can still be fetched when needed using
the |:OmniSharpDocumentation| command. Default: 1 >
let g:omnicomplete_fetch_full_documentation = 1
completion suggestions. When set to 0, only type/method signatures are fetched -
full documentation can still be fetched when needed using the
|:OmniSharpDocumentation| command.
Default: 1 >
let g:OmniSharp_complete_documentation = 1
<
===============================================================================
4. COMMANDS *omnisharp-commands*
Expand Down Expand Up @@ -446,6 +465,13 @@ convenient user re-mapping. These can be used like so: >
:OmniSharpFixUsings
Removes unused using directives

*:OmniSharpFold*
*<Plug>(omnisharp_fold)*
:OmniSharpFold
Create folds around code structure elements such as methods and classes.
Folds are only created for elements spanning over 'foldminlines' lines.
The kinds of elements to fold can be configured with |g:OmniSharp_fold_kinds|

*:OmniSharpTypeLookup*
*<Plug>(omnisharp_type_lookup)*
:OmniSharpTypeLookup
Expand Down
3 changes: 3 additions & 0 deletions ftplugin/cs/OmniSharp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ command! -buffer -bar -nargs=? OmniSharpFindSymbol call OmniSharp#actions#symbol
command! -buffer -bar -nargs=? OmniSharpFindType call OmniSharp#actions#symbols#Find(<q-args>, 'Type')
command! -buffer -bar OmniSharpFindUsages call OmniSharp#actions#usages#Find()
command! -buffer -bar OmniSharpFixUsings call OmniSharp#actions#usings#Fix()
command! -buffer -bar OmniSharpFold call OmniSharp#actions#fold#Create()
command! -buffer -bar OmniSharpGetCodeActions call OmniSharp#actions#codeactions#Get('normal')
command! -buffer -bar OmniSharpGlobalCodeCheck call OmniSharp#actions#diagnostics#CheckGlobal()
command! -buffer -bar OmniSharpGotoDefinition call OmniSharp#actions#definition#Find()
Expand All @@ -59,6 +60,7 @@ nnoremap <buffer> <Plug>(omnisharp_find_symbol) :OmniSharpFindSymbol<CR>
nnoremap <buffer> <Plug>(omnisharp_find_type) :OmniSharpFindType<CR>
nnoremap <buffer> <Plug>(omnisharp_find_usages) :OmniSharpFindUsages<CR>
nnoremap <buffer> <Plug>(omnisharp_fix_usings) :OmniSharpFixUsings<CR>
nnoremap <buffer> <Plug>(omnisharp_fold) :OmniSharpFold<CR>
nnoremap <buffer> <Plug>(omnisharp_code_actions) :OmniSharpGetCodeActions<CR>
xnoremap <buffer> <Plug>(omnisharp_code_actions) :call OmniSharp#actions#codeactions#Get('visual')<CR>
nnoremap <buffer> <Plug>(omnisharp_code_action_repeat) :OmniSharpRepeatCodeAction<CR>
Expand Down Expand Up @@ -105,6 +107,7 @@ let b:undo_ftplugin .= '
\| delcommand OmniSharpFindType
\| delcommand OmniSharpFindUsages
\| delcommand OmniSharpFixUsings
\| delcommand OmniSharpFold
\| delcommand OmniSharpGetCodeActions
\| delcommand OmniSharpGlobalCodeCheck
\| delcommand OmniSharpGotoDefinition
Expand Down
46 changes: 15 additions & 31 deletions plugin/OmniSharp.vim
Original file line number Diff line number Diff line change
@@ -1,45 +1,29 @@
if exists('g:OmniSharp_loaded') | finish | endif
let g:OmniSharp_loaded = 1

let g:OmniSharp_lookup_metadata = get(g:, 'OmniSharp_lookup_metadata', 1)

" Default to `1`, except in cygwin defaults to `0`
let g:OmniSharp_server_stdio = get(g:, 'OmniSharp_server_stdio', !has('win32unix'))
let g:OmniSharp_server_stdio = get(g:, 'OmniSharp_server_stdio', !has('win32unix')) " Default to 1, except in cygwin

" Server selection/initialization variables
let g:OmniSharp_autoselect_existing_sln = get(g:, 'OmniSharp_autoselect_existing_sln', 0)
let g:OmniSharp_prefer_global_sln = get(g:, 'OmniSharp_prefer_global_sln', 0)
let g:OmniSharp_server_display_loading = get(g:, 'OmniSharp_server_display_loading', 1)
let g:OmniSharp_server_loading_timeout = get(g:, 'OmniSharp_server_loading_timeout', 180)

" Use mono to start the roslyn server on *nix
let g:OmniSharp_server_use_mono = get(g:, 'OmniSharp_server_use_mono', 0)

let g:OmniSharp_open_quickfix = get(g:, 'OmniSharp_open_quickfix', 1)

let g:OmniSharp_timeout = get(g:, 'OmniSharp_timeout', 1)

" Default to `0`, except in cygwin
let g:OmniSharp_translate_cygwin_wsl = get(g:, 'OmniSharp_translate_cygwin_wsl', has('win32unix'))

let g:OmniSharp_typeLookupInPreview = get(g:, 'OmniSharp_typeLookupInPreview', 0)

let g:OmniSharp_sln_list_index = get(g:, 'OmniSharp_sln_list_index', -1)

let g:OmniSharp_autoselect_existing_sln = get(g:, 'OmniSharp_autoselect_existing_sln', 0)
let g:OmniSharp_prefer_global_sln = get(g:, 'OmniSharp_prefer_global_sln', 0)
let g:OmniSharp_start_server = get(g:, 'OmniSharp_start_server', 1)
let g:OmniSharp_start_without_solution = get(g:, 'OmniSharp_start_without_solution', 1)

" Automatically start server
let g:OmniSharp_start_server = get(g:, 'OmniSharp_start_server', get(g:, 'Omnisharp_start_server', 1))

let defaultlevel = g:OmniSharp_server_stdio ? 'info' : 'warning'
let g:OmniSharp_loglevel = get(g:, 'OmniSharp_loglevel', defaultlevel)

let g:OmniSharp_complete_documentation = get(g:, 'OmniSharp_complete_documentation', get(g:, 'omnicomplete_fetch_full_documentation', 1))
let g:OmniSharp_fold_kinds = get(g:, 'OmniSharp_fold_kinds', [])
let g:OmniSharp_loglevel = get(g:, 'OmniSharp_loglevel', g:OmniSharp_server_stdio ? 'info' : 'warning')
let g:OmniSharp_lookup_metadata = get(g:, 'OmniSharp_lookup_metadata', 1)
let g:OmniSharp_open_quickfix = get(g:, 'OmniSharp_open_quickfix', 1)
let g:OmniSharp_runtests_parallel = get(g:, 'OmniSharp_runtests_parallel', 1)
let g:OmniSharp_runtests_echo_output = get(g:, 'OmniSharp_runtests_echo_output', 1)

" Set to 1 when ultisnips is installed
let g:OmniSharp_want_snippet = get(g:, 'OmniSharp_want_snippet', 0)

let g:omnicomplete_fetch_full_documentation = get(g:, 'omnicomplete_fetch_full_documentation', 1)
let g:OmniSharp_timeout = get(g:, 'OmniSharp_timeout', 1)
let g:OmniSharp_translate_cygwin_wsl = get(g:, 'OmniSharp_translate_cygwin_wsl', has('win32unix')) " Default to 0, except in cygwin
let g:OmniSharp_typeLookupInPreview = get(g:, 'OmniSharp_typeLookupInPreview', 0)
let g:OmniSharp_want_snippet = get(g:, 'OmniSharp_want_snippet', 0) " Set to 1 when ultisnips is installed

command! -bar -nargs=? OmniSharpInstall call OmniSharp#Install(<f-args>)
command! -bar -nargs=? OmniSharpOpenLog call OmniSharp#log#Open(<q-args>)
Expand All @@ -49,7 +33,7 @@ command! -bar -bang OmniSharpStatus call OmniSharp#Status(<bang>0)
" Preserve backwards compatibility with older version g:OmniSharp_highlight_types
let g:OmniSharp_highlighting = get(g:, 'OmniSharp_highlighting', get(g:, 'OmniSharp_highlight_types', 2))
if g:OmniSharp_highlighting
augroup OmniSharp_HighlightTypes
augroup OmniSharp_Highlighting
autocmd!
autocmd BufEnter *.cs,*.csx
\ if !pumvisible() && OmniSharp#util#CheckCapabilities() |
Expand Down
2 changes: 1 addition & 1 deletion python/omnisharp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def getCompletions(partialWord):
parameters['WordToComplete'] = partialWord

parameters['WantDocumentationForEveryCompletionResult'] = \
bool(int(vim.eval('g:omnicomplete_fetch_full_documentation')))
bool(int(vim.eval('g:OmniSharp_complete_documentation')))

want_snippet = \
bool(int(vim.eval('g:OmniSharp_want_snippet')))
Expand Down