33" Maintainer: Dávid Szabó ( complex857 AT gmail DOT com )
44" Previous Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
55" URL: https://github.com/shawncplus/phpcomplete.vim
6- " Last Change: 2018 Oct 10
6+ " Last Change: 2021 Feb 08
77"
88" OPTIONS:
99"
@@ -122,7 +122,6 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{
122122 endif
123123 endif
124124
125-
126125 " If exists b:php_menu it means completion was already constructed we
127126 " don't need to do anything more
128127 if exists (" b:php_menu" )
@@ -148,8 +147,6 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{
148147 try
149148 let eventignore = &eventignore
150149 let &eventignore = ' all'
151- let winheight = winheight (0 )
152- let winnr = winnr ()
153150
154151 let [current_namespace, imports] = phpcomplete#GetCurrentNameSpace (getline (0 , line (' .' )))
155152
@@ -183,7 +180,6 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{
183180 endif
184181
185182 if filereadable (classlocation)
186- let classfile = readfile (classlocation)
187183 let classcontent = ' '
188184 let classcontent .= " \n " .phpcomplete#GetClassContents (classlocation, classname)
189185 let sccontent = split (classcontent, " \n " )
@@ -217,7 +213,6 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{
217213 return phpcomplete#CompleteGeneral (a: base , current_namespace, imports)
218214 endif
219215 finally
220- silent ! exec winnr .' resize ' .winheight
221216 let &eventignore = eventignore
222217 endtry
223218endfunction
@@ -1025,7 +1020,7 @@ function! phpcomplete#CompleteUserClass(context, base, sccontent, visibility) "
10251020 let c_var = ' $' .c_var
10261021 endif
10271022 let c_variables[c_var] = ' '
1028- if g: phpcomplete_parse_docblock_comments && len (get (variables, var_index)) > 0
1023+ if g: phpcomplete_parse_docblock_comments && len (get (variables, var_index, ' ' )) > 0
10291024 let c_doc[c_var] = phpcomplete#GetDocBlock (a: sccontent , variables[var_index])
10301025 endif
10311026 let var_index += 1
@@ -2082,26 +2077,17 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam
20822077 " ...
20832078 " ]
20842079 "
2085- let full_file_path = fnamemodify (a: file_path , ' :p' )
20862080 let class_name_pattern = ' [a-zA-Z_\x7f-\xff\\][a-zA-Z_0-9\x7f-\xff\\]*'
2087- let cfile = join (a: file_lines , " \n " )
2081+ let full_file_path = fnamemodify (a: file_path , ' :p ' )
20882082 let result = []
2089- " We use new buffer and (later) normal! because
2090- " this is the most efficient way. The other way
2091- " is to go through the looong string looking for
2092- " matching {}
2093-
2094- " remember the window we started at
2095- let phpcomplete_original_window = winnr ()
2096-
2097- silent ! below 1 new
2098- silent ! 0 put = cfile
2099- call search (' \c\(class\|interface\|trait\)\_s\+' .a: class_name .' \(\>\|$\)' )
2100- let cfline = line (' .' )
2101- call search (' {' )
2102- let endline = line (' .' )
2103-
2104- let content = join (getline (cfline, endline), " \n " )
2083+ let popup_id = popup_create (a: file_lines , {' hidden' : v: true })
2084+
2085+ call win_execute (popup_id, ' call search('' \c\(class\|interface\|trait\)\_s\+' .a: class_name .' \(\>\|$\)'' )' )
2086+ call win_execute (popup_id, " let cfline = line('.')" )
2087+ call win_execute (popup_id, " call search('{')" )
2088+ call win_execute (popup_id, " let endline = line('.')" )
2089+
2090+ call win_execute (popup_id, ' let content = join(getline(' .cfline.' , ' .endline.' ), "\n")' )
21052091 " Catch extends
21062092 if content = ~? ' extends'
21072093 let extends_string = matchstr (content, ' \(class\|interface\)\_s\+' .a: class_name .' \_.\+extends\_s\+\zs\(' .class_name_pattern.' \(,\|\_s\)*\)\+\ze\(extends\|{\)' )
@@ -2117,37 +2103,39 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam
21172103 else
21182104 let implemented_interfaces = []
21192105 endif
2120- call searchpair ( ' { ' , ' ' , ' } ' , ' W ' )
2121- let class_closing_bracket_line = line ( ' . ' )
2106+
2107+ call win_execute (popup_id, ' let [ class_closing_bracket_line, class_closing_bracket_col] = searchpairpos("{", "", "}", "W") ' )
21222108
21232109 " Include class docblock
21242110 let doc_line = cfline - 1
2125- if getline (doc_line) = ~? ' ^\s*\*/'
2111+ call win_execute (popup_id, ' let l = getline(' .doc_line.' )' )
2112+ if l = ~? ' ^\s*\*/'
21262113 while doc_line != 0
2127- if getline (doc_line) = ~? ' ^\s*/\*\*'
2114+ call win_execute (popup_id, ' let l = getline(' .doc_line.' )' )
2115+ if l = ~? ' ^\s*/\*\*'
21282116 let cfline = doc_line
21292117 break
21302118 endif
21312119 let doc_line -= 1
21322120 endwhile
21332121 endif
21342122
2135- let classcontent = join (getline (cfline, class_closing_bracket_line), " \n " )
2123+ call win_execute (popup_id, ' let classcontent = join(getline(' . cfline. ' , ' . class_closing_bracket_line. ' ), "\n") ' )
21362124
21372125 let used_traits = []
21382126 " move back to the line next to the class's definition
2139- call cursor (endline + 1 , 1 )
2127+ call win_execute (popup_id, ' call cursor(' .( endline + 1 ). ' , 1) ' )
21402128 let keep_searching = 1
21412129 while keep_searching != 0
21422130 " try to grab "use..." keywords
2143- let [lnum, col ] = searchpos (' \c^\s\+use\s\+' .class_name_pattern, ' cW ' , class_closing_bracket_line)
2144- let syn_name = synIDattr (synID (lnum, col , 0 ), " name" )
2131+ call win_execute (popup_id, ' let [lnum, col] = searchpos('' \c^\s\+use\s\+' .class_name_pattern. ' ' ' , "cW", ' . class_closing_bracket_line. ' ) ' )
2132+ call win_execute (popup_id, ' let syn_name = synIDattr(synID(' . lnum. ' , ' . col . ' , 0), "name") ' )
21452133 if syn_name = ~? ' string\|comment'
2146- call cursor (lnum + 1 , 1 )
2134+ call win_execute (popup_id, ' call cursor(' .( lnum + 1 ). ' , 1) ' )
21472135 continue
21482136 endif
21492137
2150- let trait_line = getline (lnum)
2138+ call win_execute (popup_id, ' let trait_line = getline(' . lnum. ' ) ' )
21512139 if trait_line !~? ' ;'
21522140 " try to find the next line containing ';'
21532141 let l = lnum
@@ -2157,25 +2145,23 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam
21572145 while search_line !~? ' ;' && l > 0
21582146 " file lines are reversed so we need to go backwards
21592147 let l += 1
2160- let search_line = getline (l )
2148+ call win_execute (popup_id, ' let search_line = getline(' . l . ' ) ' )
21612149 let trait_line .= ' ' .substitute (search_line, ' \(^\s\+\|\s\+$\)' , ' ' , ' g' )
21622150 endwhile
21632151 endif
21642152 let use_expression = matchstr (trait_line, ' ^\s*use\s\+\zs.\{-}\ze;' )
21652153 let use_parts = map (split (use_expression, ' \s*,\s*' ), ' substitute(v:val, "\\s+", " ", "g")' )
21662154 let used_traits += map (use_parts, ' substitute(v:val, "\\s", "", "g")' )
2167- call cursor (lnum + 1 , 1 )
2155+ call win_execute (popup_id, ' call cursor(' .( lnum + 1 ). ' , 1) ' )
21682156
21692157 if [lnum, col ] == [0 , 0 ]
21702158 let keep_searching = 0
21712159 endif
21722160 endwhile
21732161
2174- silent ! bw ! %
2162+ call popup_close (popup_id)
21752163
21762164 let [current_namespace, imports] = phpcomplete#GetCurrentNameSpace (a: file_lines [0 :cfline])
2177- " go back to original window
2178- exe phpcomplete_original_window.' wincmd w'
21792165 call add (result, {
21802166 \ ' class' : a: class_name ,
21812167 \ ' content' : classcontent,
@@ -2532,40 +2518,37 @@ function! phpcomplete#FormatDocBlock(info) " {{{
25322518 endif
25332519
25342520 return res
2535- endfunction !
2521+ endfunction
25362522" }}}
25372523
25382524function ! phpcomplete#GetCurrentNameSpace (file_lines) " {{{
2539- let original_window = winnr ()
2540-
2541- silent ! below 1 new
2542- silent ! 0 put = a: file_lines
2543- normal ! G
2525+ let popup_id = popup_create (a: file_lines , {' hidden' : v: true })
2526+ call win_execute (popup_id, ' normal! G' )
25442527
25452528 " clear out classes, functions and other blocks
25462529 while 1
2547- let block_start_pos = searchpos (' \c\(class\|trait\|function\|interface\)\s\+\_.\{-}\zs{' , ' Web' )
2530+ call win_execute (popup_id, ' let block_start_pos = searchpos('' \c\(class\|trait\|function\|interface\)\s\+\_.\{-}\zs{'' , " Web") ' )
25482531 if block_start_pos == [0 , 0 ]
25492532 break
25502533 endif
2551- let block_end_pos = searchpairpos (' { ' , ' ' , ' }\|\%$' , ' W ' , ' synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"' )
2534+ call win_execute (popup_id, ' let block_end_pos = searchpairpos("{", "" , '' }\|\%$'' , "W" , '' synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'' ) ' )
25522535
2536+ let popup_lines = winbufnr (popup_id)- >getbufline (1 , ' $' )
25532537 if block_end_pos != [0 , 0 ]
25542538 " end of the block found, just delete it
2555- silent ! exec block_start_pos[0 ]. ' , ' . block_end_pos[0 ]. ' d _ '
2539+ call remove (popup_lines, block_start_pos[0 ] - 1 , block_end_pos[0 ] - 1 )
25562540 else
25572541 " block pair not found, use block start as beginning and the end
25582542 " of the buffer instead
2559- silent ! exec block_start_pos[0 ]. ' ,$d _ '
2543+ call remove (popup_lines, block_start_pos[0 ] - 1 , -1 )
25602544 endif
2545+ call popup_settext (popup_id, popup_lines)
25612546 endwhile
2562- normal ! G
2547+ call win_execute (popup_id, ' normal! G' , ' silent! ' )
25632548
25642549 " grab the remains
2565- let file_lines = reverse (getline (1 , line (' .' ) - 1 ))
2566-
2567- silent ! bw ! %
2568- exe original_window.' wincmd w'
2550+ call win_execute (popup_id, " let file_lines = reverse(getline(1, line('.')-1))" )
2551+ call popup_close (popup_id)
25692552
25702553 let namespace_name_pattern = ' [a-zA-Z_\x7f-\xff\\][a-zA-Z_0-9\x7f-\xff\\]*'
25712554 let i = 0
0 commit comments