<commit_before>let s:save_cpo = &cpoptions
set cpoptions&vim

" Accepts a Funcref callback argument, to be called after the response is
" returned (synchronously or asynchronously) with the number of members
function! OmniSharp#actions#members#Find(...) abort
  let opts = a:0 && a:1 isnot 0 ? { 'Callback': a:1 } : {}
  if g:OmniSharp_server_stdio
    call s:StdioFind(function('s:CBFindMembers', [opts]))
  else
    let locs = OmniSharp#py#Eval('findMembers()')
    if OmniSharp#py#CheckForError() | return | endif
    return s:CBFindMembers(opts, locs)
  endif
endfunction

function! s:StdioFind(Callback) abort
  let opts = {
  \ 'ResponseHandler': function('s:StdioFindRH', [a:Callback])
  \}
  call OmniSharp#stdio#Request('/v2/codestructure', opts)
endfunction

function! s:StdioFindRH(Callback, response) abort
  if !a:response.Success | return | endif
  call a:Callback(s:ParseCodeStructure(a:response.Body))
endfunction

function! s:ParseCodeStructure(responseBody) abort
  let locations = []
  let filename = expand('%:p')
  for element in a:responseBody.Elements
    call s:ParseCodeStructureItemRec(element, filename, locations)
  endfor
  return locations
endfunction

function! s:ParseCodeStructureItemRec(item, filename, locations) abort
  call add(a:locations, s:ParseCodeStructureItem(a:item, a:filename))
  let children = get(a:item, 'Children', [])
  if type(children) == type([])
    for child in children
      call s:ParseCodeStructureItemRec(child, a:filename, a:locations)
    endfor
  endif
endfunction

function! s:ParseCodeStructureItem(item, filename) abort
  return {
    \ 'filename': a:filename,
    \ 'lnum':     a:item.Ranges.name.Start.Line,
    \ 'col':      a:item.Ranges.name.Start.Column,
    \ 'end_lnum': a:item.Ranges.name.End.Line,
    \ 'end_col':  a:item.Ranges.name.End.Column - 1,
    \ 'text':     s:ComputeItemSignature(a:item),
    \ 'vcol': 1
  \}
endfunction

function! s:ComputeItemSignature(item) abort
  let line   = a:item.Ranges.name.Start.Line
  let endcol = a:item.Ranges.name.Start.Column - 2
  let textBeforeDisplayName = trim(getline(line)[:endcol], " \t", 1)
  if textBeforeDisplayName !~# '^\(private\|internal\|protected\|public\)'
    let textBeforeDisplayName = a:item.Properties.accessibility . ' ' . textBeforeDisplayName
  endif
  return ReduceToOneCharacter(textBeforeDisplayName) . a:item.DisplayName
endfunction

let s:SingleCharacterSymbolByAccessModifier = {
 \ 'public': '+',
 \ 'private': '-',
 \ 'internal': '&',
 \ 'protected': '|'
\}

function! ReduceToOneCharacter(textBeforeDisplayName) abort
  let accessModifier = matchlist(a:textBeforeDisplayName, '\w\+')[0]
  let accessModifierLen = len(accessModifier)
  return s:SingleCharacterSymbolByAccessModifier[accessModifier] . a:textBeforeDisplayName[accessModifierLen:]
endfunction

function! s:CBFindMembers(opts, locations) abort
  let numMembers = len(a:locations)
  if numMembers > 0
    call OmniSharp#locations#SetQuickfix(a:locations, 'Members')
  endif
  if has_key(a:opts, 'Callback')
    call a:opts.Callback(numMembers)
  endif
  return numMembers
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo

" vim:et:sw=2:sts=2
<commit_msg>Add some sexy yet basic cosmetics<commit_after>let s:save_cpo = &cpoptions
set cpoptions&vim

" Accepts a Funcref callback argument, to be called after the response is
" returned (synchronously or asynchronously) with the number of members
function! OmniSharp#actions#members#Find(...) abort
  let opts = a:0 && a:1 isnot 0 ? { 'Callback': a:1 } : {}
  if g:OmniSharp_server_stdio
    call s:StdioFind(function('s:CBFindMembers', [opts]))
  else
    let locs = OmniSharp#py#Eval('findMembers()')
    if OmniSharp#py#CheckForError() | return | endif
    return s:CBFindMembers(opts, locs)
  endif
endfunction

function! s:StdioFind(Callback) abort
  let opts = {
  \ 'ResponseHandler': function('s:StdioFindRH', [a:Callback])
  \}
  call OmniSharp#stdio#Request('/v2/codestructure', opts)
endfunction

function! s:StdioFindRH(Callback, response) abort
  if !a:response.Success | return | endif
  call a:Callback(s:ParseCodeStructure(a:response.Body))
endfunction

function! s:ParseCodeStructure(responseBody) abort
  let locations = []
  let filename = expand('%:p')
  for element in a:responseBody.Elements
    call s:ParseCodeStructureItemRec(element, filename, locations)
  endfor
  return locations
endfunction

function! s:ParseCodeStructureItemRec(item, filename, locations) abort
  call add(a:locations, s:ParseCodeStructureItem(a:item, a:filename))
  let children = get(a:item, 'Children', [])
  if type(children) == type([])
    for child in children
      call s:ParseCodeStructureItemRec(child, a:filename, a:locations)
    endfor
  endif
endfunction

function! s:ParseCodeStructureItem(item, filename) abort
  return {
    \ 'filename': a:filename,
    \ 'lnum':     a:item.Ranges.name.Start.Line,
    \ 'col':      a:item.Ranges.name.Start.Column,
    \ 'end_lnum': a:item.Ranges.name.End.Line,
    \ 'end_col':  a:item.Ranges.name.End.Column - 1,
    \ 'text':     s:ComputeItemSignature(a:item),
    \ 'vcol': 1
  \}
endfunction

function! s:ComputeItemSignature(item) abort
  let line   = a:item.Ranges.name.Start.Line
  let endcol = a:item.Ranges.name.Start.Column - 2
  let textBeforeDisplayName = trim(getline(line)[:endcol], " \t", 1)
  if textBeforeDisplayName !~# '^\(private\|internal\|protected\|public\)'
    let textBeforeDisplayName = a:item.Properties.accessibility . ' ' . textBeforeDisplayName
  endif
  return ReduceToOneCharacter(textBeforeDisplayName) . a:item.DisplayName
endfunction

let s:SingleCharacterSymbolByAccessModifier = {
 \ 'public': '+',
 \ 'private': '-',
 \ 'internal': '&',
 \ 'protected': '|'
\}

function! ReduceToOneCharacter(textBeforeDisplayName) abort
  let accessModifier = matchlist(a:textBeforeDisplayName, '\w\+')[0]
  let accessModifierLen = len(accessModifier)
  return '['.s:SingleCharacterSymbolByAccessModifier[accessModifier].']' . a:textBeforeDisplayName[accessModifierLen:]
endfunction

function! s:CBFindMembers(opts, locations) abort
  let numMembers = len(a:locations)
  if numMembers > 0
    call OmniSharp#locations#SetQuickfix(a:locations, 'Members')
  endif
  if has_key(a:opts, 'Callback')
    call a:opts.Callback(numMembers)
  endif
  return numMembers
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo

" vim:et:sw=2:sts=2

{'fraction_non_alphanumeric': 0.12769953051643193, 'fraction_numerical': 0.004068857589984351, 'mean_word_length': 4.972897196261682, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4137154', 'n_tokens_mistral': 2161, 'n_tokens_neox': 2109, 'n_words': 449}