<commit_before>function! ember_tools#Init()
  if !filereadable('ember-cli-build.js')
    return
  endif

  setlocal includeexpr=ember_tools#Includeexpr()
endfunction

" TODO (2016-02-16) Improve search under cursor, make it work with \zs
" TODO (2016-02-22) Use separate callback for every matcher, then either
" return or continue trying
function! ember_tools#Includeexpr()
  let current_file     = expand('%')
  let current_file_dir = expand('%:h')
  let saved_iskeyword  = &iskeyword

  call ember_tools#cursors#Push()

  try
    set iskeyword+=.,-,/

    if &filetype == 'coffee'
      " TODO (2016-02-22) No corresponding push, needs to be rewritten with
      " callbacks
      if current_file == 'app/router.coffee'
        if ember_tools#search#UnderCursor('@route [''"]\zs\k\+[''"]')
          let route_name = expand('<cword>')
          return s:FindRouteFile(route_name)
        endif
      endif
      call ember_tools#cursors#Pop()

      call ember_tools#cursors#Push()
      if ember_tools#search#UnderCursor('^\s*\zs\k\+:\s*Ember\.inject\.service()')
        let property = expand('<cword>')
        return s:FindService(property)
      endif
      call ember_tools#cursors#Pop()

      call ember_tools#cursors#Push()
      if ember_tools#search#UnderCursor('@get[( ][''"]\zs\k\+[''"]')
        let property = expand('<cword>')
        return s:FindService(property)
      endif
      call ember_tools#cursors#Pop()

      call ember_tools#cursors#Push()
      if ember_tools#search#UnderCursor('createRecord[( ][''"]\zs\k\+[''"]')
        let model_name = expand('<cword>')
        return s:FindModel(model_name)
      endif
      " TODO (2016-02-22) No corresponding pop, needs to be rewritten with
      " callbacks
    endif

    if &filetype == 'emblem'
      if ember_tools#search#UnderCursor('^\s*=\{}\s*\zs\k\+')
        let component_name = expand('<cword>')
        return s:FindComponentFile(component_name)
      endif
    endif

    if current_file =~ '^.'
      exe 'cd '.current_file_dir
      let absolute_path = expand('<cfile>:p')
      cd -
      return fnamemodify(absolute_path.'.coffee', ':.')
    endif

    return current_file
  finally
    call ember_tools#cursors#Pop()
    let &iskeyword = saved_iskeyword
  endtry
endfunction

function! s:FindComponentFile(component_name)
  let component_name = a:component_name

  if filereadable('app/components/'.component_name.'.coffee')
    return 'app/components/'.component_name.'.coffee'
  elseif filereadable('app/components/'.component_name.'/component.coffee')
    return 'app/components/'.component_name.'/component.coffee'
  else
    echoerr "Can't find component: ".component_name
    return ''
  endif
endfunction

function! s:FindRouteFile(route_name)
  let route_name = a:route_name
  let route_path = [route_name]
  let route_pattern = '@route [''"]\zs\k\+[''"]'

  " Find any parent routes
  let indent = indent('.')

  call ember_tools#cursors#Push()
  while search('^ \{'.(indent - &sw).'}'.route_pattern, 'bW')
    let route = expand('<cword>')
    call insert(route_path, route, 0)
    let indent = indent('.')
  endwhile
  call ember_tools#cursors#Pop()

  return 'app/routes/'.join(route_path, '/').'.coffee'<commit_msg>Don't look for parents of routes with resetNamespace: true<commit_after>function! ember_tools#Init()
  if !filereadable('ember-cli-build.js')
    return
  endif

  setlocal includeexpr=ember_tools#Includeexpr()
endfunction

" TODO (2016-02-16) Improve search under cursor, make it work with \zs
" TODO (2016-02-22) Use separate callback for every matcher, then either
" return or continue trying
function! ember_tools#Includeexpr()
  let current_file     = expand('%')
  let current_file_dir = expand('%:h')
  let saved_iskeyword  = &iskeyword

  call ember_tools#cursors#Push()

  try
    set iskeyword+=.,-,/

    if &filetype == 'coffee'
      " TODO (2016-02-22) No corresponding push, needs to be rewritten with
      " callbacks
      if current_file == 'app/router.coffee'
        if ember_tools#search#UnderCursor('@route [''"]\zs\k\+[''"]')
          let route_name = expand('<cword>')
          return s:FindRouteFile(route_name)
        endif
      endif
      call ember_tools#cursors#Pop()

      call ember_tools#cursors#Push()
      if ember_tools#search#UnderCursor('^\s*\zs\k\+:\s*Ember\.inject\.service()')
        let property = expand('<cword>')
        return s:FindService(property)
      endif
      call ember_tools#cursors#Pop()

      call ember_tools#cursors#Push()
      if ember_tools#search#UnderCursor('@get[( ][''"]\zs\k\+[''"]')
        let property = expand('<cword>')
        return s:FindService(property)
      endif
      call ember_tools#cursors#Pop()

      call ember_tools#cursors#Push()
      if ember_tools#search#UnderCursor('createRecord[( ][''"]\zs\k\+[''"]')
        let model_name = expand('<cword>')
        return s:FindModel(model_name)
      endif
      " TODO (2016-02-22) No corresponding pop, needs to be rewritten with
      " callbacks
    endif

    if &filetype == 'emblem'
      if ember_tools#search#UnderCursor('^\s*=\{}\s*\zs\k\+')
        let component_name = expand('<cword>')
        return s:FindComponentFile(component_name)
      endif
    endif

    if current_file =~ '^.'
      exe 'cd '.current_file_dir
      let absolute_path = expand('<cfile>:p')
      cd -
      return fnamemodify(absolute_path.'.coffee', ':.')
    endif

    return current_file
  finally
    call ember_tools#cursors#Pop()
    let &iskeyword = saved_iskeyword
  endtry
endfunction

function! s:FindComponentFile(component_name)
  let component_name = a:component_name

  if filereadable('app/components/'.component_name.'.coffee')
    return 'app/components/'.component_name.'.coffee'
  elseif filereadable('app/components/'.component_name.'/component.coffee')
    return 'app/components/'.component_name.'/component.coffee'
  else
    echoerr "Can't find component: ".component_name
    return ''
  endif
endfunction

function! s:FindRouteFile(route_name)
  let route_name = a:route_name
  let route_path = [route_name]
  let route_pattern = '@route [''"]\zs\k\+[''"]'

  if getline('.') =~ '\<resetNamespace: true\>'
    return 'app/routes/'.route_name.'.coffee'
  endif

  " Find any parent routes
  let indent = indent('.')

  call ember_tools#cursors#Push()
  while search('^ \{'.(indent - &sw).'}'.route_pattern, 'bW')
    let route = expand('<cword>')
    call insert(route_path, route, 0)
    let indent = indent('.')

    if getline('.') =~ '\<resetNamespace: true\>'
      break
    endif
  endwhile
  call ember_tools#cursors#Pop()

  return 'app/routes/'.join(route_path, '/').'.coffee'
{'fraction_non_alphanumeric': 0.14375655823714587, 'fraction_numerical': 0.009893569180032978, 'mean_word_length': 3.380827314510834, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '1426167', 'n_tokens_mistral': 2296, 'n_tokens_neox': 2158, 'n_words': 470}