From 32fc2d171367db35571381f2bb22e04503177532 Mon Sep 17 00:00:00 2001 From: Nick Jensen Date: Thu, 9 May 2019 10:07:00 +1200 Subject: [PATCH] Implement HighlightBuffer --- autoload/OmniSharp.vim | 32 ++++++++++++++++++++--------- autoload/OmniSharp/stdio.vim | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/autoload/OmniSharp.vim b/autoload/OmniSharp.vim index b546f9aba..39b4bd265 100644 --- a/autoload/OmniSharp.vim +++ b/autoload/OmniSharp.vim @@ -481,11 +481,18 @@ function! OmniSharp#HighlightBuffer() abort if bufname('%') ==# '' || OmniSharp#FugitiveCheck() | return | endif if !OmniSharp#IsServerRunning() | return | endif - let ret = OmniSharp#py#eval('findHighlightTypes()') - if OmniSharp#CheckPyError() | return | endif + if g:OmniSharp_server_stdio + let ret = OmniSharp#stdio#FindHighlightTypes(function('s:CBHighlightBuffer')) + else + let hltypes = OmniSharp#py#eval('findHighlightTypes()') + if OmniSharp#CheckPyError() | return | endif + return s:CBHighlightBuffer(hltypes) + endif +endfunction - if has_key(ret, 'error') - echohl WarningMsg | echom ret.error | echohl None +function! s:CBHighlightBuffer(hltypes) abort + if has_key(a:hltypes, 'error') + echohl WarningMsg | echom a:hltypes.error | echohl None return endif @@ -500,10 +507,10 @@ function! OmniSharp#HighlightBuffer() abort endfor let b:OmniSharp_hl_matches = [] - call s:Highlight(ret.identifiers, 'csUserIdentifier') - call s:Highlight(ret.interfaces, 'csUserInterface') - call s:Highlight(ret.methods, 'csUserMethod') - call s:Highlight(ret.types, 'csUserType') + call s:Highlight(a:hltypes.identifiers, 'csUserIdentifier') + call s:Highlight(a:hltypes.interfaces, 'csUserInterface') + call s:Highlight(a:hltypes.methods, 'csUserMethod') + call s:Highlight(a:hltypes.types, 'csUserType') silent call s:ClearHighlight('csNewType') syntax region csNewType start="@\@1"hs=s+4 end="[;\n{(<\[]"me=e-1 @@ -605,8 +612,13 @@ function! OmniSharp#IsServerRunning(...) abort return 1 endif - let alive = OmniSharp#py#eval('checkAliveStatus()') - if OmniSharp#CheckPyError() | return 0 | endif + if g:OmniSharp_server_stdio + " TODO: Call "/checkalivestatus"? + let alive = 1 + else + let alive = OmniSharp#py#eval('checkAliveStatus()') + if OmniSharp#CheckPyError() | return 0 | endif + endif if alive " Cache the alive status so subsequent calls are faster call add(s:alive_cache, sln_or_dir) diff --git a/autoload/OmniSharp/stdio.vim b/autoload/OmniSharp/stdio.vim index 1119f71dc..0eda222d6 100644 --- a/autoload/OmniSharp/stdio.vim +++ b/autoload/OmniSharp/stdio.vim @@ -67,6 +67,45 @@ function! OmniSharp#stdio#HandleResponse(channelid, message) abort call EndPointResponseHandler(response) endfunction +function! OmniSharp#stdio#FindHighlightTypes(Callback) abort + let bufferLines = getline(1, '$') + call s:Request('highlight', function('s:FindHighlightTypesResponseHandler', [a:Callback, bufferLines])) +endfunction + +function! s:FindHighlightTypesResponseHandler(Callback, bufferLines, response) abort + let highlights = get(a:response.Body, 'Highlights', []) + let identifierKinds = ['constant name', 'enum member name', 'field name', + \ 'identifier', 'local name', 'parameter name', 'property name', + \ 'static symbol'] + let interfaceKinds = ['interface name'] + let methodKinds = ['extension method name', 'method name'] + let typeKinds = ['class name', 'enum name', 'namespace name', 'struct name'] + let types = [] + for hl in highlights + let lnum = hl.StartLine - 1 + if lnum >= len(a:bufferLines) + " An error has occurred with invalid line endings - perhaps a combination + " of unix and dos line endings? + call a:Callback({'error': 'Invalid buffer - check line endings'}) + return + endif + let line = a:bufferLines[lnum] + call add(types, { + \ 'kind': hl['Kind'], + \ 'name': line[hl['StartColumn'] - 1 : hl['EndColumn'] - 2] + \}) + endfor + + let hltypes = { + \ 'identifiers': map(filter(copy(types), 'index(identifierKinds, v:val.kind) >= 0'), 'v:val.name'), + \ 'interfaces': map(filter(copy(types), 'index(interfaceKinds, v:val.kind) >= 0'), 'v:val.name'), + \ 'methods': map(filter(copy(types), 'index(methodKinds, v:val.kind) >= 0'), 'v:val.name'), + \ 'types': map(filter(copy(types), 'index(typeKinds, v:val.kind) >= 0'), 'v:val.name') + \} + + call a:Callback(hltypes) +endfunction + function! OmniSharp#stdio#GotoDefinition(Callback) abort call s:Request('gotodefinition', function('s:GotoDefinitionResponseHandler', [a:Callback])) endfunction