@ -546,19 +546,33 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
} ;
}
if ( capabilities . references ) {
if ( capabilities . references | | capabilities . document_highlight ) {
get_usages = [ this ] {
auto iter = get_buffer ( ) - > get_insert ( ) - > get_iter ( ) ;
std : : vector < std : : pair < Offset , std : : string > > usages ;
std : : vector < Offset > end_offsets ;
std : : promise < void > result_processed ;
client - > write_request ( this , " textDocument/references " , R " ( " textDocument " :{ " uri " : " ) " + uri + R " ( " }, " position " : { " line " : ) " + std : : to_string ( iter . get_line ( ) ) + " , \" character \" : " + std : : to_string ( iter . get_line_offset ( ) ) + R " (}, " context " : { " includeDeclaration " : true}) " , [ & usages , & end_offsets , & result_processed ] ( const boost : : property_tree : : ptree & result , bool error ) {
std : : string method ;
if ( capabilities . document_highlight )
method = " textDocument/documentHighlight " ;
else
method = " textDocument/references " ;
client - > write_request ( this , method , R " ( " textDocument " :{ " uri " : " ) " + uri + R " ( " }, " position " : { " line " : ) " + std : : to_string ( iter . get_line ( ) ) + " , \" character \" : " + std : : to_string ( iter . get_line_offset ( ) ) + R " (}, " context " : { " includeDeclaration " : true}) " , [ this , & usages , & end_offsets , & result_processed ] ( const boost : : property_tree : : ptree & result , bool error ) {
if ( ! error ) {
try {
for ( auto it = result . begin ( ) ; it ! = result . end ( ) ; + + it ) {
auto path = it - > second . get < std : : string > ( " uri " , " " ) ;
if ( path . size ( ) > = 7 ) {
std : : string path ;
if ( capabilities . document_highlight )
path = file_path . string ( ) ;
else {
path = it - > second . get < std : : string > ( " uri " , " " ) ;
if ( path . size ( ) > = 7 )
path . erase ( 0 , 7 ) ;
else
continue ;
}
auto range_it = it - > second . find ( " range " ) ;
if ( range_it ! = it - > second . not_found ( ) ) {
auto start_it = range_it - > second . find ( " start " ) ;
@ -570,7 +584,6 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
}
}
}
}
catch ( . . . ) {
usages . clear ( ) ;
end_offsets . clear ( ) ;
@ -582,7 +595,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
auto embolden_token = [ ] ( std : : string & line_ , unsigned token_start_pos , unsigned token_end_pos ) {
Glib : : ustring line = line_ ;
if ( token_start_pos > = line . size ( ) | | token_end_pos > = line . size ( ) )
if ( token_start_pos > line . size ( ) | | token_end_pos > line . size ( ) )
return ;
//markup token as bold
@ -683,7 +696,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
return get_buffer ( ) - > get_text ( start , end ) ;
} ;
if ( capabilities . rename ) {
if ( capabilities . rename | | capabilities . document_highlight ) {
rename_similar_tokens = [ this ] ( const std : : string & text ) {
class Usages {
public :
@ -699,6 +712,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
auto iter = get_buffer ( ) - > get_insert ( ) - > get_iter ( ) ;
std : : vector < Usages > usages ;
std : : promise < void > result_processed ;
if ( capabilities . rename ) {
client - > write_request ( this , " textDocument/rename " , R " ( " textDocument " :{ " uri " : " ) " + uri + R " ( " }, " position " : { " line " : ) " + std : : to_string ( iter . get_line ( ) ) + " , \" character \" : " + std : : to_string ( iter . get_line_offset ( ) ) + R " (}, " newName " : " ) " + text + " \ " " , [ this , & usages , & result_processed ] ( const boost : : property_tree : : ptree & result , bool error ) {
if ( ! error ) {
boost : : filesystem : : path project_path ;
@ -771,6 +785,31 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
}
result_processed . set_value ( ) ;
} ) ;
}
else {
client - > write_request ( this , " textDocument/documentHighlight " , R " ( " textDocument " :{ " uri " : " ) " + uri + R " ( " }, " position " : { " line " : ) " + std : : to_string ( iter . get_line ( ) ) + " , \" character \" : " + std : : to_string ( iter . get_line_offset ( ) ) + R " (}, " context " : { " includeDeclaration " : true}) " , [ this , & usages , & result_processed ] ( const boost : : property_tree : : ptree & result , bool error ) {
if ( ! error ) {
try {
usages . emplace_back ( Usages { file_path , nullptr , std : : vector < std : : pair < Offset , Offset > > ( ) } ) ;
for ( auto it = result . begin ( ) ; it ! = result . end ( ) ; + + it ) {
auto range_it = it - > second . find ( " range " ) ;
if ( range_it ! = it - > second . not_found ( ) ) {
auto start_it = range_it - > second . find ( " start " ) ;
auto end_it = range_it - > second . find ( " end " ) ;
if ( start_it ! = range_it - > second . not_found ( ) & & end_it ! = range_it - > second . not_found ( ) ) {
usages . back ( ) . offsets . emplace_back ( std : : make_pair ( Offset ( start_it - > second . get < unsigned > ( " line " ) , start_it - > second . get < unsigned > ( " character " ) ) ,
Offset ( end_it - > second . get < unsigned > ( " line " ) , end_it - > second . get < unsigned > ( " character " ) ) ) ) ;
}
}
}
}
catch ( . . . ) {
usages . clear ( ) ;
}
}
result_processed . set_value ( ) ;
} ) ;
}
result_processed . get_future ( ) . get ( ) ;
std : : vector < Usages * > usages_renamed ;