@@ -564,6 +564,56 @@ function! hdevtools#type_clear()
564564 endif
565565endfunction
566566
567+ function ! hdevtools#insert_type ()
568+ let l: file = expand (' %' )
569+ if l: file == # ' '
570+ call hdevtools#print_warning (" hdevtool#insert_type: current version of hdevtools.vim doesn't support running on an unnamed buffer." )
571+ return
572+ endif
573+
574+ if &l: modified
575+ call hdevtools#print_warning (' hdevtools#insert_type: the buffer has been modified but not written' )
576+ endif
577+
578+ let l: line = line (' .' )
579+ let l: col = col (' .' )
580+ let l: cmd_to_get_pos_of_identifier = hdevtools#build_command_bare (' type' , shellescape (l: file ) . ' ' . l: line . ' ' . l: col )
581+ let l: output_for_pos = system (l: cmd_to_get_pos_of_identifier )
582+
583+ if v: shell_error != 0
584+ for l: line in split (l: output_for_pos , ' \n' )
585+ call hdevtools#print_error (l: line )
586+ endfor
587+ return
588+ endif
589+
590+ let l: pos_lines = split (l: output_for_pos , ' \n' )
591+ let l: pos_last_line = l: pos_lines [-1 ]
592+ let l: pos_last_line_parsed = matchlist (l: pos_last_line , ' \(\d\+\) \(\d\+\) \(\d\+\) \(\d\+\) "\([^"]\+\)"' )
593+ if len (l: pos_last_line_parsed ) == 0
594+ call hdevtools#print_error (' hdevtools#insert_type: No Type Information. hdevtools answered: ' . l: last_line )
595+ return
596+ endif
597+ let l: linenumber_of_identifier = l: pos_last_line_parsed [1 ]
598+ let l: string_at_linenumber = getline (l: linenumber_of_identifier )
599+ let l: identifier = (split (l: string_at_linenumber ))[0 ]
600+
601+ let l: cmd_to_get_type_of_identifier = hdevtools#build_command_bare (' info' , shellescape (l: file ) . ' ' . l: identifier )
602+ let l: output_for_type = system (l: cmd_to_get_type_of_identifier )
603+
604+ if v: shell_error != 0
605+ for l: line in split (l: output_for_type , ' \n' )
606+ call hdevtools#print_error (l: line )
607+ endfor
608+ return
609+ endif
610+
611+ let l: type_lines = split (l: output_for_type , ' \n' )
612+ let l: type_definition = l: type_lines [0 ]
613+
614+ execute (l: linenumber_of_identifier . " pu!='" . l: type_definition . " '" )
615+ endfunction
616+
567617function ! hdevtools#print_error (msg)
568618 echohl ErrorMsg
569619 echomsg a: msg
0 commit comments