PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/.vim/eclim/autoload/eclim/php/search.vim

http://github.com/dakrone/dakrone-dotfiles
Vim Script | 163 lines | 104 code | 16 blank | 43 comment | 13 complexity | ff8d52d5dc610ccc3b95c9ca9b744546 MD5 | raw file
Possible License(s): CC-BY-SA-4.0, GPL-3.0
  1. " Author: Eric Van Dewoestine
  2. "
  3. " Description: {{{
  4. " see http://eclim.sourceforge.net/vim/php/search.html
  5. "
  6. " License:
  7. "
  8. " Copyright (C) 2005 - 2009 Eric Van Dewoestine
  9. "
  10. " This program is free software: you can redistribute it and/or modify
  11. " it under the terms of the GNU General Public License as published by
  12. " the Free Software Foundation, either version 3 of the License, or
  13. " (at your option) any later version.
  14. "
  15. " This program is distributed in the hope that it will be useful,
  16. " but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. " GNU General Public License for more details.
  19. "
  20. " You should have received a copy of the GNU General Public License
  21. " along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. "
  23. " }}}
  24. " Global Varables {{{
  25. if !exists("g:EclimPhpSearchSingleResult")
  26. " possible values ('split', 'edit', 'lopen')
  27. let g:EclimPhpSearchSingleResult = "split"
  28. endif
  29. " }}}
  30. " Script Varables {{{
  31. let s:search_element =
  32. \ '-command dltk_search -n "<project>" -f "<file>" ' .
  33. \ '-o <offset> -l <length> -e <encoding> -x <context>'
  34. let s:search_pattern = '-command dltk_search -n "<project>" <args>'
  35. let s:buildpaths = '-command dltk_buildpaths -p "<project>"'
  36. let s:options = ['-p', '-t', '-s', '-x', '-i']
  37. let s:scopes = ['all', 'project']
  38. let s:types = [
  39. \ 'class',
  40. \ 'function',
  41. \ 'constant'
  42. \ ]
  43. let s:contexts = [
  44. \ 'all',
  45. \ 'declarations',
  46. \ 'references'
  47. \ ]
  48. " }}}
  49. " Search(argline {{{
  50. " Executes a search.
  51. function! eclim#php#search#Search(argline)
  52. return eclim#lang#Search(
  53. \ s:search_pattern, g:EclimPhpSearchSingleResult, a:argline)
  54. endfunction " }}}
  55. " FindDefinition(context) {{{
  56. " Finds the defintion of the element under the cursor.
  57. function eclim#php#search#FindDefinition(context)
  58. return eclim#lang#FindDefinition(
  59. \ s:search_element, g:EclimPhpSearchSingleResult, a:context)
  60. endfunction " }}}
  61. " FindInclude() {{{
  62. " Finds the include file under the cursor
  63. function eclim#php#search#FindInclude()
  64. if !eclim#project#util#IsCurrentFileInProject(1)
  65. return
  66. endif
  67. let file = substitute(getline('.'),
  68. \ ".*\\<\\(require\\|include\\)\\(_once\\)\\?\\s*[(]\\?['\"]\\([^'\"]*\\)['\"].*", '\3', '')
  69. let project = eclim#project#util#GetCurrentProjectName()
  70. let command = s:buildpaths
  71. let command = substitute(command, '<project>', project, '')
  72. let result = eclim#ExecuteEclim(command)
  73. let paths = split(result, '\n')
  74. let results = split(globpath(expand('%:h') . ',' . join(paths, ','), file), '\n')
  75. if !empty(results)
  76. call eclim#util#SetLocationList(eclim#util#ParseLocationEntries(results))
  77. " single result in another file.
  78. if len(results) == 1 && g:EclimPhpSearchSingleResult != "lopen"
  79. let entry = getloclist(0)[0]
  80. call eclim#util#GoToBufferWindowOrOpen
  81. \ (bufname(entry.bufnr), g:EclimPhpSearchSingleResult)
  82. call eclim#display#signs#Update()
  83. else
  84. lopen
  85. endif
  86. else
  87. call eclim#util#EchoInfo("File not found.")
  88. endif
  89. endfunction " }}}
  90. " SearchContext() {{{
  91. " Executes a contextual search.
  92. function! eclim#php#search#SearchContext()
  93. if getline('.')[col('.') - 1] == '$'
  94. call cursor(line('.'), col('.') + 1)
  95. let cnum = eclim#util#GetCurrentElementColumn()
  96. call cursor(line('.'), col('.') - 1)
  97. else
  98. let cnum = eclim#util#GetCurrentElementColumn()
  99. endif
  100. if getline('.') =~ "\\<\\(require\\|include\\)\\(_once\\)\\?\\s*[(]\\?['\"][^'\"]*\\%" . cnum . "c"
  101. call eclim#php#search#FindInclude()
  102. return
  103. elseif getline('.') =~ '\<\(class\|function\)\s\+\%' . cnum . 'c'
  104. call eclim#php#search#FindDefinition('references')
  105. return
  106. elseif getline('.') =~ "\\<define\\s*(['\"]\\%" . cnum . "c"
  107. call eclim#util#EchoInfo("TODO: Search constant references")
  108. return
  109. "elseif getline('.') =~ '\<var\s\+[$]\?\%' . cnum . 'c'
  110. " call eclim#util#EchoInfo("TODO: Search var references")
  111. " return
  112. endif
  113. call eclim#php#search#FindDefinition('declarations')
  114. endfunction " }}}
  115. " CommandCompletePhpSearch(argLead, cmdLine, cursorPos) {{{
  116. " Custom command completion for PhpSearch
  117. function! eclim#php#search#CommandCompletePhpSearch(argLead, cmdLine, cursorPos)
  118. let cmdLine = strpart(a:cmdLine, 0, a:cursorPos)
  119. let cmdTail = strpart(a:cmdLine, a:cursorPos)
  120. let argLead = substitute(a:argLead, cmdTail . '$', '', '')
  121. if cmdLine =~ '-s\s\+[a-z]*$'
  122. let scopes = deepcopy(s:scopes)
  123. call filter(scopes, 'v:val =~ "^' . argLead . '"')
  124. return scopes
  125. elseif cmdLine =~ '-t\s\+[a-z]*$'
  126. let types = deepcopy(s:types)
  127. call filter(types, 'v:val =~ "^' . argLead . '"')
  128. return types
  129. elseif cmdLine =~ '-x\s\+[a-z]*$'
  130. let contexts = deepcopy(s:contexts)
  131. call filter(contexts, 'v:val =~ "^' . argLead . '"')
  132. return contexts
  133. elseif cmdLine =~ '\s\+[-]\?$'
  134. let options = deepcopy(s:options)
  135. let index = 0
  136. for option in options
  137. if a:cmdLine =~ option
  138. call remove(options, index)
  139. else
  140. let index += 1
  141. endif
  142. endfor
  143. return options
  144. endif
  145. return []
  146. endfunction " }}}
  147. " vim:ft=vim:fdm=marker