@@ -564,6 +564,89 @@ function! hdevtools#type_clear()
564
564
endif
565
565
endfunction
566
566
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 "
571
+ \ . " hdevtools.vim doesn't support running on "
572
+ \ . " an unnamed buffer."
573
+ \ )
574
+ return
575
+ endif
576
+
577
+ if &l: modified
578
+ call hdevtools#print_warning ( ' hdevtools#insert_type: '
579
+ \ . ' The buffer has been modified but not written.'
580
+ \ )
581
+ endif
582
+
583
+ let l: line = line (' .' )
584
+ let l: col = col (' .' )
585
+ let l: get_pos_of_identifier = hdevtools#build_command_bare
586
+ \ ( ' type'
587
+ \ , shellescape (l: file ) . ' ' . l: line . ' ' . l: col
588
+ \ )
589
+ let l: pos_raw = system (l: get_pos_of_identifier )
590
+ let l: pos_lines = split (l: pos_raw , ' \n' )
591
+
592
+ if v: shell_error != 0
593
+ call hdevtools#print_error ( ' hdevtools#insert_type: No Type Information. '
594
+ \ . ' hdevtools answered:'
595
+ \ )
596
+ for l: line in pos_lines
597
+ call hdevtools#print_error (l: line )
598
+ endfor
599
+ return
600
+ endif
601
+
602
+ if len (l: pos_lines ) == 0
603
+ call hdevtools#print_error (' hdevtools#insert_type: No Type Information.' )
604
+ return
605
+ endif
606
+ let l: pos_line = l: pos_lines [-1 ]
607
+ let l: pos_parsed = matchlist (l: pos_line , ' \(\d\+\) \(\d\+\) \(\d\+\) \(\d\+\) "\([^"]\+\)"' )
608
+ if len (l: pos_parsed ) == 0
609
+ call hdevtools#print_error ( ' hdevtools#insert_type: No Type Information.'
610
+ \ . ' hdevtools answered:'
611
+ \ )
612
+ for l: line in l: pos_lines
613
+ call hdevtools#print_error (l: line )
614
+ endfor
615
+ return
616
+ endif
617
+ let l: id_linenumber = l: pos_parsed [1 ]
618
+ let l: id_colmnumber = l: pos_parsed [2 ]
619
+ let l: id_line = getline (l: id_linenumber )
620
+ let l: identifier = s: extract_identifier (l: id_line , l: id_colmnumber )
621
+
622
+ if l: id_colmnumber != 1
623
+ call hdevtools#print_error ( ' hdevtools#insert_type: `' . l: identifier
624
+ \ . ' ` is not a top level variable identifier.'
625
+ \ )
626
+ return
627
+ endif
628
+ let l: get_type_of_identifier = hdevtools#build_command_bare
629
+ \ ( ' info'
630
+ \ , shellescape (l: file ) . ' ' . shellescape (l: identifier )
631
+ \ )
632
+ let l: output_for_type = system (l: get_type_of_identifier )
633
+
634
+ if v: shell_error != 0
635
+ call hdevtools#print_error ( " hdevtools#insert_type: Couldn't get type for "
636
+ \ . l: identifier . ' . hdevtools answered:'
637
+ \ )
638
+ for l: line in split (l: output_for_type , ' \n' )
639
+ call hdevtools#print_error (l: line )
640
+ endfor
641
+ return
642
+ endif
643
+
644
+ let l: type_lines = split (l: output_for_type , ' \n' )
645
+ let l: type_definition = l: type_lines [0 ]
646
+
647
+ execute (l: id_linenumber . " pu!='" . l: type_definition . " '" )
648
+ endfunction
649
+
567
650
function ! hdevtools#print_error (msg)
568
651
echohl ErrorMsg
569
652
echomsg a: msg
0 commit comments