diff --git a/README.md b/README.md index 69147b293..a647ebd8b 100644 --- a/README.md +++ b/README.md @@ -480,6 +480,7 @@ augroup omnisharp_commands autocmd FileType cs nmap osd (omnisharp_documentation) autocmd FileType cs nmap osfs (omnisharp_find_symbol) autocmd FileType cs nmap osfx (omnisharp_fix_usings) + autocmd FileType cs nmap osfo (omnisharp_fold) autocmd FileType cs nmap (omnisharp_signature_help) autocmd FileType cs imap (omnisharp_signature_help) diff --git a/autoload/OmniSharp/actions/codestructure.vim b/autoload/OmniSharp/actions/codestructure.vim index 602fc1188..51d62be2d 100644 --- a/autoload/OmniSharp/actions/codestructure.vim +++ b/autoload/OmniSharp/actions/codestructure.vim @@ -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 diff --git a/autoload/OmniSharp/actions/complete.vim b/autoload/OmniSharp/actions/complete.vim index 7828909e0..0d615cd65 100644 --- a/autoload/OmniSharp/actions/complete.vim +++ b/autoload/OmniSharp/actions/complete.vim @@ -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, @@ -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 diff --git a/autoload/OmniSharp/actions/fold.vim b/autoload/OmniSharp/actions/fold.vim new file mode 100644 index 000000000..10b487bf3 --- /dev/null +++ b/autoload/OmniSharp/actions/fold.vim @@ -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 diff --git a/autoload/OmniSharp/actions/test.vim b/autoload/OmniSharp/actions/test.vim index 5f27d50db..2935cc448 100644 --- a/autoload/OmniSharp/actions/test.vim +++ b/autoload/OmniSharp/actions/test.vim @@ -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 @@ -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 diff --git a/autoload/OmniSharp/util.vim b/autoload/OmniSharp/util.vim index 3c37578cd..00bb32cda 100644 --- a/autoload/OmniSharp/util.vim +++ b/autoload/OmniSharp/util.vim @@ -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 diff --git a/doc/omnisharp-vim.txt b/doc/omnisharp-vim.txt index 5d1133cf9..5b4caf9ab 100644 --- a/doc/omnisharp-vim.txt +++ b/doc/omnisharp-vim.txt @@ -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. @@ -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* @@ -446,6 +465,13 @@ convenient user re-mapping. These can be used like so: > :OmniSharpFixUsings Removes unused using directives + *:OmniSharpFold* + *(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* *(omnisharp_type_lookup)* :OmniSharpTypeLookup diff --git a/ftplugin/cs/OmniSharp.vim b/ftplugin/cs/OmniSharp.vim index 0c7d75168..d4fcc0e88 100644 --- a/ftplugin/cs/OmniSharp.vim +++ b/ftplugin/cs/OmniSharp.vim @@ -34,6 +34,7 @@ command! -buffer -bar -nargs=? OmniSharpFindSymbol call OmniSharp#actions#symbol command! -buffer -bar -nargs=? OmniSharpFindType call OmniSharp#actions#symbols#Find(, '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() @@ -59,6 +60,7 @@ nnoremap (omnisharp_find_symbol) :OmniSharpFindSymbol nnoremap (omnisharp_find_type) :OmniSharpFindType nnoremap (omnisharp_find_usages) :OmniSharpFindUsages nnoremap (omnisharp_fix_usings) :OmniSharpFixUsings +nnoremap (omnisharp_fold) :OmniSharpFold nnoremap (omnisharp_code_actions) :OmniSharpGetCodeActions xnoremap (omnisharp_code_actions) :call OmniSharp#actions#codeactions#Get('visual') nnoremap (omnisharp_code_action_repeat) :OmniSharpRepeatCodeAction @@ -105,6 +107,7 @@ let b:undo_ftplugin .= ' \| delcommand OmniSharpFindType \| delcommand OmniSharpFindUsages \| delcommand OmniSharpFixUsings +\| delcommand OmniSharpFold \| delcommand OmniSharpGetCodeActions \| delcommand OmniSharpGlobalCodeCheck \| delcommand OmniSharpGotoDefinition diff --git a/plugin/OmniSharp.vim b/plugin/OmniSharp.vim index df9bc957a..42a2d7231 100644 --- a/plugin/OmniSharp.vim +++ b/plugin/OmniSharp.vim @@ -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() command! -bar -nargs=? OmniSharpOpenLog call OmniSharp#log#Open() @@ -49,7 +33,7 @@ command! -bar -bang OmniSharpStatus call OmniSharp#Status(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() | diff --git a/python/omnisharp/commands.py b/python/omnisharp/commands.py index a85a7a4e5..296ec1216 100644 --- a/python/omnisharp/commands.py +++ b/python/omnisharp/commands.py @@ -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')))