Navigation Menu

Skip to content

Commit

Permalink
Implement HighlightBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
nickspoons committed May 20, 2019
1 parent e8482bc commit 32fc2d1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
32 changes: 22 additions & 10 deletions autoload/OmniSharp.vim
Expand Up @@ -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

Expand All @@ -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<!\<new\>"hs=s+4 end="[;\n{(<\[]"me=e-1
Expand Down Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions autoload/OmniSharp/stdio.vim
Expand Up @@ -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
Expand Down

0 comments on commit 32fc2d1

Please sign in to comment.