@ -51,9 +51,15 @@ LanguageProtocol::TextEdit::TextEdit(const boost::property_tree::ptree &pt, std:
LanguageProtocol : : Client : : Client ( boost : : filesystem : : path root_path_ , std : : string language_id_ ) : root_path ( std : : move ( root_path_ ) ) , language_id ( std : : move ( language_id_ ) ) {
process = std : : make_unique < TinyProcessLib : : Process > (
filesystem : : escape_argument ( language_id + " -language-server " ) , root_path . string ( ) , [ this ] ( const char * bytes , size_t n ) {
filesystem : : escape_argument ( language_id + " -language-server " ) , root_path . string ( ) ,
[ this ] ( const char * bytes , size_t n ) {
server_message_stream . write ( bytes , n ) ;
parse_server_message ( ) ; } , [ ] ( const char * bytes , size_t n ) { std : : cerr . write ( bytes , n ) ; } , true , TinyProcessLib : : Config { 1048576 } ) ;
parse_server_message ( ) ;
} ,
[ ] ( const char * bytes , size_t n ) {
std : : cerr . write ( bytes , n ) ;
} ,
true , TinyProcessLib : : Config { 1048576 } ) ;
}
std : : shared_ptr < LanguageProtocol : : Client > LanguageProtocol : : Client : : get ( const boost : : filesystem : : path & file_path , const std : : string & language_id ) {
@ -126,7 +132,8 @@ LanguageProtocol::Capabilities LanguageProtocol::Client::initialize(Source::Lang
LockGuard lock ( read_write_mutex ) ;
process_id = process - > get_id ( ) ;
}
write_request ( nullptr , " initialize " , " \" processId \" : " + std : : to_string ( process_id ) + R " (, " rootUri " : " ) " + filesystem::get_uri_from_path(root_path) + R " ( " , " capabilities " : {
write_request (
nullptr , " initialize " , " \" processId \" : " + std : : to_string ( process_id ) + R " (, " rootUri " : " ) " + filesystem::get_uri_from_path(root_path) + R " ( " , " capabilities " : {
" workspace " : { " symbol " : { " dynamicRegistration " : true } } ,
" textDocument " : {
" synchronization " : { " dynamicRegistration " : true , " didSave " : true } ,
@ -1024,7 +1031,11 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vector<Language
for ( auto & quickfix_diagnostic : quickfix_diagnostics ) {
if ( diagnostic . message = = quickfix_diagnostic . message & & diagnostic . range = = quickfix_diagnostic . range ) {
auto pair = diagnostic . quickfixes . emplace ( title , std : : vector < Source : : FixIt > { } ) ;
pair . first - > second . emplace_back ( edit . new_text , filesystem : : get_path_from_uri ( file_it - > first ) . string ( ) , std : : make_pair < Offset , Offset > ( Offset ( edit . range . start . line , edit . range . start . character ) , Offset ( edit . range . end . line , edit . range . end . character ) ) ) ;
pair . first - > second . emplace_back (
edit . new_text ,
filesystem : : get_path_from_uri ( file_it - > first ) . string ( ) ,
std : : make_pair < Offset , Offset > ( Offset ( edit . range . start . line , edit . range . start . character ) ,
Offset ( edit . range . end . line , edit . range . end . character ) ) ) ;
break ;
}
}
@ -1034,7 +1045,11 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vector<Language
for ( auto & diagnostic : diagnostics ) {
if ( edit . range . start . line = = diagnostic . range . start . line ) {
auto pair = diagnostic . quickfixes . emplace ( title , std : : vector < Source : : FixIt > { } ) ;
pair . first - > second . emplace_back ( edit . new_text , filesystem : : get_path_from_uri ( file_it - > first ) . string ( ) , std : : make_pair < Offset , Offset > ( Offset ( edit . range . start . line , edit . range . start . character ) , Offset ( edit . range . end . line , edit . range . end . character ) ) ) ;
pair . first - > second . emplace_back (
edit . new_text ,
filesystem : : get_path_from_uri ( file_it - > first ) . string ( ) ,
std : : make_pair < Offset , Offset > ( Offset ( edit . range . start . line , edit . range . start . character ) ,
Offset ( edit . range . end . line , edit . range . end . character ) ) ) ;
break ;
}
}
@ -1400,14 +1415,16 @@ Source::Offset Source::LanguageProtocolView::get_declaration(const Gtk::TextIter
void Source : : LanguageProtocolView : : setup_signals ( ) {
if ( capabilities . text_document_sync = = LanguageProtocol : : Capabilities : : TextDocumentSync : : incremental ) {
get_buffer ( ) - > signal_insert ( ) . connect ( [ this ] ( const Gtk : : TextIter & start , const Glib : : ustring & text_ , int bytes ) {
get_buffer ( ) - > signal_insert ( ) . connect (
[ this ] ( const Gtk : : TextIter & start , const Glib : : ustring & text_ , int bytes ) {
std : : string text = text_ ;
escape_text ( text ) ;
client - > write_notification ( " textDocument/didChange " , R " ( " textDocument " :{ " uri " : " ) " + this->uri + R " ( " , " version " :) " + std : : to_string ( document_version + + ) + " }, \" contentChanges \" :[ " + R " ({ " range " :{ " start " :{ " line " : ) " + std : : to_string ( start . get_line ( ) ) + " , \" character \" : " + std : : to_string ( start . get_line_offset ( ) ) + R " (}, " end " :{ " line " :) " + std : : to_string ( start . get_line ( ) ) + " , \" character \" : " + std : : to_string ( start . get_line_offset ( ) ) + R " (}}, " text " : " ) " + text + " \ " } " + " ] " ) ;
} ,
false ) ;
get_buffer ( ) - > signal_erase ( ) . connect ( [ this ] ( const Gtk : : TextIter & start , const Gtk : : TextIter & end ) {
get_buffer ( ) - > signal_erase ( ) . connect (
[ this ] ( const Gtk : : TextIter & start , const Gtk : : TextIter & end ) {
client - > write_notification ( " textDocument/didChange " , R " ( " textDocument " :{ " uri " : " ) " + this->uri + R " ( " , " version " :) " + std : : to_string ( document_version + + ) + " }, \" contentChanges \" :[ " + R " ({ " range " :{ " start " :{ " line " : ) " + std : : to_string ( start . get_line ( ) ) + " , \" character \" : " + std : : to_string ( start . get_line_offset ( ) ) + R " (}, " end " :{ " line " :) " + std : : to_string ( end . get_line ( ) ) + " , \" character \" : " + std : : to_string ( end . get_line_offset ( ) ) + R " (}}, " text " : " " }) " + " ] " ) ;
} ,
false ) ;
@ -1439,7 +1456,8 @@ void Source::LanguageProtocolView::setup_autocomplete() {
if ( capabilities . signature_help ) {
// Activate argument completions
get_buffer ( ) - > signal_changed ( ) . connect ( [ this ] {
get_buffer ( ) - > signal_changed ( ) . connect (
[ this ] {
if ( ! interactive_completion )
return ;
if ( CompletionDialog : : get ( ) & & CompletionDialog : : get ( ) - > is_visible ( ) )
@ -1450,7 +1468,8 @@ void Source::LanguageProtocolView::setup_autocomplete() {
autocomplete - > stop ( ) ;
autocomplete_show_arguments = false ;
autocomplete_delayed_show_arguments_connection . disconnect ( ) ;
autocomplete_delayed_show_arguments_connection = Glib : : signal_timeout ( ) . connect ( [ this ] ( ) {
autocomplete_delayed_show_arguments_connection = Glib : : signal_timeout ( ) . connect (
[ this ] ( ) {
if ( get_buffer ( ) - > get_has_selection ( ) )
return false ;
if ( CompletionDialog : : get ( ) & & CompletionDialog : : get ( ) - > is_visible ( ) )
@ -1468,7 +1487,8 @@ void Source::LanguageProtocolView::setup_autocomplete() {
false ) ;
// Remove argument completions
signal_key_press_event ( ) . connect ( [ this ] ( GdkEventKey * event ) {
signal_key_press_event ( ) . connect (
[ this ] ( GdkEventKey * event ) {
if ( autocomplete_show_arguments & & CompletionDialog : : get ( ) & & CompletionDialog : : get ( ) - > is_visible ( ) & &
event - > keyval ! = GDK_KEY_Down & & event - > keyval ! = GDK_KEY_Up & &
event - > keyval ! = GDK_KEY_Return & & event - > keyval ! = GDK_KEY_KP_Enter & &
@ -1826,7 +1846,8 @@ void Source::LanguageProtocolView::update_type_coverage() {
if ( update_type_coverage_retries > 0 ) { // Retry typeCoverage request, since these requests can fail while waiting for language server to start
dispatcher . post ( [ this ] {
update_type_coverage_connection . disconnect ( ) ;
update_type_coverage_connection = Glib : : signal_timeout ( ) . connect ( [ this ] ( ) {
update_type_coverage_connection = Glib : : signal_timeout ( ) . connect (
[ this ] ( ) {
- - update_type_coverage_retries ;
update_type_coverage ( ) ;
return false ;