@ -38,7 +38,7 @@ use std::{
collections ::{ BTreeMap , HashSet } ,
collections ::{ BTreeMap , HashSet } ,
fmt ::Write ,
fmt ::Write ,
future ::Future ,
future ::Future ,
path ::PathBuf ,
path ::{ Path , PathBuf } ,
} ;
} ;
/// Gets the first language server that is attached to a document which supports a specific feature.
/// Gets the first language server that is attached to a document which supports a specific feature.
@ -134,7 +134,7 @@ struct DiagnosticStyles {
}
}
struct PickerDiagnostic {
struct PickerDiagnostic {
url: lsp ::Url ,
path: PathBuf ,
diag : lsp ::Diagnostic ,
diag : lsp ::Diagnostic ,
offset_encoding : OffsetEncoding ,
offset_encoding : OffsetEncoding ,
}
}
@ -167,8 +167,7 @@ impl ui::menu::Item for PickerDiagnostic {
let path = match format {
let path = match format {
DiagnosticsFormat ::HideSourcePath = > String ::new ( ) ,
DiagnosticsFormat ::HideSourcePath = > String ::new ( ) ,
DiagnosticsFormat ::ShowSourcePath = > {
DiagnosticsFormat ::ShowSourcePath = > {
let file_path = self . url . to_file_path ( ) . unwrap ( ) ;
let path = path ::get_truncated_path ( & self . path ) ;
let path = path ::get_truncated_path ( file_path ) ;
format! ( "{}: " , path . to_string_lossy ( ) )
format! ( "{}: " , path . to_string_lossy ( ) )
}
}
} ;
} ;
@ -208,22 +207,31 @@ fn jump_to_location(
return ;
return ;
}
}
} ;
} ;
jump_to_position ( editor , & path , location . range , offset_encoding , action ) ;
}
let doc = match editor . open ( & path , action ) {
fn jump_to_position (
editor : & mut Editor ,
path : & Path ,
range : lsp ::Range ,
offset_encoding : OffsetEncoding ,
action : Action ,
) {
let doc = match editor . open ( path , action ) {
Ok ( id ) = > doc_mut ! ( editor , & id ) ,
Ok ( id ) = > doc_mut ! ( editor , & id ) ,
Err ( err ) = > {
Err ( err ) = > {
let err = format! ( "failed to open path: {:?}: {:?}" , location . uri , err ) ;
let err = format! ( "failed to open path: {:?}: {:?}" , path , err ) ;
editor . set_error ( err ) ;
editor . set_error ( err ) ;
return ;
return ;
}
}
} ;
} ;
let view = view_mut ! ( editor ) ;
let view = view_mut ! ( editor ) ;
// TODO: convert inside server
// TODO: convert inside server
let new_range =
let new_range = if let Some ( new_range ) = lsp_range_to_range ( doc . text ( ) , range , offset_encoding )
if let Some ( new_range ) = lsp_range_to_range ( doc . text ( ) , location . range , offset_encoding ) {
{
new_range
new_range
} else {
} else {
log ::warn ! ( "lsp position out of bounds - {:?}" , location . range ) ;
log ::warn ! ( "lsp position out of bounds - {:?}" , range ) ;
return ;
return ;
} ;
} ;
// we flip the range so that the cursor sits on the start of the symbol
// we flip the range so that the cursor sits on the start of the symbol
@ -258,21 +266,20 @@ enum DiagnosticsFormat {
fn diag_picker (
fn diag_picker (
cx : & Context ,
cx : & Context ,
diagnostics : BTreeMap < lsp ::Url , Vec < ( lsp ::Diagnostic , usize ) > > ,
diagnostics : BTreeMap < PathBuf , Vec < ( lsp ::Diagnostic , usize ) > > ,
_current_path : Option < lsp ::Url > ,
format : DiagnosticsFormat ,
format : DiagnosticsFormat ,
) -> Picker < PickerDiagnostic > {
) -> Picker < PickerDiagnostic > {
// TODO: drop current_path comparison and instead use workspace: bool flag?
// TODO: drop current_path comparison and instead use workspace: bool flag?
// flatten the map to a vec of (url, diag) pairs
// flatten the map to a vec of (url, diag) pairs
let mut flat_diag = Vec ::new ( ) ;
let mut flat_diag = Vec ::new ( ) ;
for ( url , diags ) in diagnostics {
for ( path , diags ) in diagnostics {
flat_diag . reserve ( diags . len ( ) ) ;
flat_diag . reserve ( diags . len ( ) ) ;
for ( diag , ls ) in diags {
for ( diag , ls ) in diags {
if let Some ( ls ) = cx . editor . language_server_by_id ( ls ) {
if let Some ( ls ) = cx . editor . language_server_by_id ( ls ) {
flat_diag . push ( PickerDiagnostic {
flat_diag . push ( PickerDiagnostic {
url: url . clone ( ) ,
path: path . clone ( ) ,
diag ,
diag ,
offset_encoding : ls . offset_encoding ( ) ,
offset_encoding : ls . offset_encoding ( ) ,
} ) ;
} ) ;
@ -292,22 +299,17 @@ fn diag_picker(
( styles , format ) ,
( styles , format ) ,
move | cx ,
move | cx ,
PickerDiagnostic {
PickerDiagnostic {
url ,
path ,
diag ,
diag ,
offset_encoding ,
offset_encoding ,
} ,
} ,
action | {
action | {
jump_to_location (
jump_to_position ( cx . editor , path , diag . range , * offset_encoding , action )
cx . editor ,
& lsp ::Location ::new ( url . clone ( ) , diag . range ) ,
* offset_encoding ,
action ,
)
} ,
} ,
)
)
. with_preview ( move | _editor , PickerDiagnostic { url , diag , .. } | {
. with_preview ( move | _editor , PickerDiagnostic { path , diag , .. } | {
let l ocation = lsp ::Location ::new ( url . clone ( ) , diag . range ) ;
let line = Some ( ( diag . range . start . line as usize , diag . range . end . line as usize ) ) ;
Some ( location_to_file_location ( & location ) )
Some ( ( path . clone ( ) . into ( ) , line ) )
} )
} )
. truncate_start ( false )
. truncate_start ( false )
}
}
@ -470,17 +472,16 @@ pub fn workspace_symbol_picker(cx: &mut Context) {
pub fn diagnostics_picker ( cx : & mut Context ) {
pub fn diagnostics_picker ( cx : & mut Context ) {
let doc = doc ! ( cx . editor ) ;
let doc = doc ! ( cx . editor ) ;
if let Some ( current_ url) = doc . url ( ) {
if let Some ( current_ path) = doc . path ( ) {
let diagnostics = cx
let diagnostics = cx
. editor
. editor
. diagnostics
. diagnostics
. get ( & current_url )
. get ( current_path )
. cloned ( )
. cloned ( )
. unwrap_or_default ( ) ;
. unwrap_or_default ( ) ;
let picker = diag_picker (
let picker = diag_picker (
cx ,
cx ,
[ ( current_url . clone ( ) , diagnostics ) ] . into ( ) ,
[ ( current_path . clone ( ) , diagnostics ) ] . into ( ) ,
Some ( current_url ) ,
DiagnosticsFormat ::HideSourcePath ,
DiagnosticsFormat ::HideSourcePath ,
) ;
) ;
cx . push_layer ( Box ::new ( overlaid ( picker ) ) ) ;
cx . push_layer ( Box ::new ( overlaid ( picker ) ) ) ;
@ -488,16 +489,9 @@ pub fn diagnostics_picker(cx: &mut Context) {
}
}
pub fn workspace_diagnostics_picker ( cx : & mut Context ) {
pub fn workspace_diagnostics_picker ( cx : & mut Context ) {
let doc = doc ! ( cx . editor ) ;
let current_url = doc . url ( ) ;
// TODO not yet filtered by LanguageServerFeature, need to do something similar as Document::shown_diagnostics here for all open documents
// TODO not yet filtered by LanguageServerFeature, need to do something similar as Document::shown_diagnostics here for all open documents
let diagnostics = cx . editor . diagnostics . clone ( ) ;
let diagnostics = cx . editor . diagnostics . clone ( ) ;
let picker = diag_picker (
let picker = diag_picker ( cx , diagnostics , DiagnosticsFormat ::ShowSourcePath ) ;
cx ,
diagnostics ,
current_url ,
DiagnosticsFormat ::ShowSourcePath ,
) ;
cx . push_layer ( Box ::new ( overlaid ( picker ) ) ) ;
cx . push_layer ( Box ::new ( overlaid ( picker ) ) ) ;
}
}