@ -715,6 +715,7 @@ void Source::LanguageProtocolView::initialize() {
Source : : LanguageProtocolView : : ~ LanguageProtocolView ( ) {
Source : : LanguageProtocolView : : ~ LanguageProtocolView ( ) {
autocomplete_delayed_show_arguments_connection . disconnect ( ) ;
autocomplete_delayed_show_arguments_connection . disconnect ( ) ;
resolve_completion_item_connection . disconnect ( ) ;
update_type_coverage_connection . disconnect ( ) ;
update_type_coverage_connection . disconnect ( ) ;
if ( initialize_thread . joinable ( ) )
if ( initialize_thread . joinable ( ) )
@ -1504,7 +1505,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
// Activate argument completions
// Activate argument completions
get_buffer ( ) - > signal_changed ( ) . connect (
get_buffer ( ) - > signal_changed ( ) . connect (
[ this ] {
[ this ] {
autocompete_possibly_no_arguments = false ;
autocompl ete_possibly_no_arguments = false ;
if ( ! interactive_completion )
if ( ! interactive_completion )
return ;
return ;
if ( CompletionDialog : : get ( ) & & CompletionDialog : : get ( ) - > is_visible ( ) )
if ( CompletionDialog : : get ( ) & & CompletionDialog : : get ( ) - > is_visible ( ) )
@ -1732,7 +1733,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
if ( autocomplete_rows . empty ( ) ) {
if ( autocomplete_rows . empty ( ) ) {
dispatcher . post ( [ this ] {
dispatcher . post ( [ this ] {
// Move cursor forward if no arguments in completed function and if cursor is still inside ()
// Move cursor forward if no arguments in completed function and if cursor is still inside ()
if ( autocompete_possibly_no_arguments ) {
if ( autocompl ete_possibly_no_arguments ) {
auto iter = get_buffer ( ) - > get_insert ( ) - > get_iter ( ) ;
auto iter = get_buffer ( ) - > get_insert ( ) - > get_iter ( ) ;
auto prev = iter ;
auto prev = iter ;
if ( prev . backward_char ( ) & & * prev = = ' ( ' & & * iter = = ' ) ' & & iter . forward_char ( ) )
if ( prev . backward_char ( ) & & * prev = = ' ( ' & & * iter = = ' ) ' & & iter . forward_char ( ) )
@ -1882,7 +1883,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
if ( * iter = = ' ) ' & & iter . backward_char ( ) & & * iter = = ' ( ' ) { // If no arguments, try signatureHelp
if ( * iter = = ' ) ' & & iter . backward_char ( ) & & * iter = = ' ( ' ) { // If no arguments, try signatureHelp
last_keyval = ' ( ' ;
last_keyval = ' ( ' ;
if ( is_js ) // Workaround for typescript-language-server
if ( is_js ) // Workaround for typescript-language-server
autocompete_possibly_no_arguments = true ;
autocompl ete_possibly_no_arguments = true ;
autocomplete - > run ( ) ;
autocomplete - > run ( ) ;
}
}
}
}
@ -1916,32 +1917,42 @@ void Source::LanguageProtocolView::setup_autocomplete() {
} ;
} ;
if ( capabilities . completion_resolve & & autocomplete_row . detail . empty ( ) & & autocomplete_row . documentation . value . empty ( ) & & autocomplete_row . item_object ) {
if ( capabilities . completion_resolve & & autocomplete_row . detail . empty ( ) & & autocomplete_row . documentation . value . empty ( ) & & autocomplete_row . item_object ) {
std : : stringstream ss ;
// Prevent several completionItem/resolve requests when no completion item is found from written source (for instance when autocompleting in python : math.___).
bool first = true ;
// This seems to be a bug in Gtk::TreeView::signal_cursor_changed.
for ( auto & child : autocomplete_row . item_object - > children_or_empty ( ) ) {
resolve_completion_item_connection . disconnect ( ) ;
ss < < ( ! first ? " , \" " : " \" " ) < < JSON : : escape_string ( child . first ) < < " \" : " < < child . second ;
resolve_completion_item_connection = Glib : : signal_timeout ( ) . connect (
first = false ;
[ this , last_count , item_object = autocomplete_row . item_object ] {
}
write_request ( " completionItem/resolve " , ss . str ( ) , [ this , last_count ] ( JSON & & result , bool error ) {
if ( ! error ) {
if ( last_count ! = set_tooltip_count )
return ;
auto detail = result . string_or ( " detail " , " " ) ;
auto documentation = LanguageProtocol : : Documentation ( result . child_optional ( " documentation " ) ) ;
if ( detail . empty ( ) & & documentation . value . empty ( ) )
return ;
dispatcher . post ( [ this , last_count , detail = std : : move ( detail ) , documentation = std : : move ( documentation ) ] {
if ( last_count ! = set_tooltip_count )
if ( last_count ! = set_tooltip_count )
return ;
return false ;
autocomplete - > tooltips . clear ( ) ;
std : : stringstream ss ;
auto iter = CompletionDialog : : get ( ) - > start_mark - > get_iter ( ) ;
bool first = true ;
autocomplete - > tooltips . emplace_back ( this , iter , iter , [ this , detail = std : : move ( detail ) , documentation = std : : move ( documentation ) ] ( Tooltip & tooltip ) {
for ( auto & child : item_object - > children_or_empty ( ) ) {
insert_documentation ( this , tooltip , detail , documentation ) ;
ss < < ( ! first ? " , \" " : " \" " ) < < JSON : : escape_string ( child . first ) < < " \" : " < < child . second ;
first = false ;
}
write_request ( " completionItem/resolve " , ss . str ( ) , [ this , last_count ] ( JSON & & result , bool error ) {
if ( ! error ) {
if ( last_count ! = set_tooltip_count )
return ;
auto detail = result . string_or ( " detail " , " " ) ;
auto documentation = LanguageProtocol : : Documentation ( result . child_optional ( " documentation " ) ) ;
if ( detail . empty ( ) & & documentation . value . empty ( ) )
return ;
dispatcher . post ( [ this , last_count , detail = std : : move ( detail ) , documentation = std : : move ( documentation ) ] {
if ( last_count ! = set_tooltip_count )
return ;
autocomplete - > tooltips . clear ( ) ;
auto iter = CompletionDialog : : get ( ) - > start_mark - > get_iter ( ) ;
autocomplete - > tooltips . emplace_back ( this , iter , iter , [ this , detail = std : : move ( detail ) , documentation = std : : move ( documentation ) ] ( Tooltip & tooltip ) {
insert_documentation ( this , tooltip , detail , documentation ) ;
} ) ;
autocomplete - > tooltips . show ( true ) ;
} ) ;
}
} ) ;
} ) ;
autocomplete - > tooltips . show ( true ) ;
return false ;
} ) ;
} ,
}
0 ) ;
} ) ;
return nullptr ;
return nullptr ;
}
}
if ( autocomplete_row . detail . empty ( ) & & autocomplete_row . documentation . value . empty ( ) )
if ( autocomplete_row . detail . empty ( ) & & autocomplete_row . documentation . value . empty ( ) )
@ -1951,6 +1962,12 @@ void Source::LanguageProtocolView::setup_autocomplete() {
insert_documentation ( this , tooltip , autocomplete_row . detail , autocomplete_row . documentation ) ;
insert_documentation ( this , tooltip , autocomplete_row . detail , autocomplete_row . documentation ) ;
} ;
} ;
} ;
} ;
autocomplete - > clear_tooltips = [ this ] {
resolve_completion_item_connection . disconnect ( ) ;
+ + set_tooltip_count ;
autocomplete - > tooltips . hide ( ) ;
} ;
}
}
void Source : : LanguageProtocolView : : update_diagnostics_async ( std : : vector < LanguageProtocol : : Diagnostic > & & diagnostics ) {
void Source : : LanguageProtocolView : : update_diagnostics_async ( std : : vector < LanguageProtocol : : Diagnostic > & & diagnostics ) {