@@ -23,7 +23,7 @@ pub(crate) fn document_formatting(
2323) -> anyhow:: Result < Option < Vec < lsp_types:: TextEdit > > > {
2424 let doc = state. get_document ( & params. text_document . uri ) ?;
2525
26- let settings = lsp_state. document_settings ( & params. text_document . uri ) ;
26+ let settings = lsp_state. document_settings ( & params. text_document . uri , & doc . settings ) ;
2727 let format_options = settings. format . to_format_options ( & doc. contents ) ;
2828
2929 if doc. parse . has_errors ( ) {
@@ -68,7 +68,7 @@ pub(crate) fn document_range_formatting(
6868 let range =
6969 from_proto:: text_range ( & doc. line_index . index , params. range , doc. line_index . encoding ) ?;
7070
71- let settings = lsp_state. document_settings ( & params. text_document . uri ) ;
71+ let settings = lsp_state. document_settings ( & params. text_document . uri , & doc . settings ) ;
7272 let format_options = settings. format . to_format_options ( & doc. contents ) ;
7373
7474 let logical_lines = find_deepest_enclosing_logical_lines ( doc. parse . syntax ( ) , range) ;
@@ -521,4 +521,40 @@ mod tests {
521521 insta:: assert_snapshot!( output6) ;
522522 } ) ;
523523 }
524+
525+ #[ test]
526+ fn test_format_indent_options ( ) {
527+ with_client ( |client| async {
528+ let mut client = client. lock ( ) . await ;
529+
530+ #[ rustfmt:: skip]
531+ let mut doc = Document :: doodle ( "{1}" ) ;
532+
533+ doc. settings . indent_width = Some ( settings:: IndentWidth :: try_from ( 8_u8 ) . unwrap ( ) ) ;
534+ let output_8_spaces = client. format_document ( & doc) . await ;
535+ insta:: assert_snapshot!( output_8_spaces) ;
536+
537+ doc. settings . indent_style = Some ( settings:: IndentStyle :: Tab ) ;
538+ let output_tab = client. format_document ( & doc) . await ;
539+ insta:: assert_snapshot!( output_tab) ;
540+ } ) ;
541+ }
542+
543+ #[ test]
544+ fn test_format_range_indent_options ( ) {
545+ with_client ( |client| async {
546+ let mut client = client. lock ( ) . await ;
547+
548+ #[ rustfmt:: skip]
549+ let ( mut doc, range) = Document :: doodle_and_range ( "<<{1}>>" ) ;
550+
551+ doc. settings . indent_width = Some ( settings:: IndentWidth :: try_from ( 8_u8 ) . unwrap ( ) ) ;
552+ let output_8_spaces = client. format_document_range ( & doc, range) . await ;
553+ insta:: assert_snapshot!( output_8_spaces) ;
554+
555+ doc. settings . indent_style = Some ( settings:: IndentStyle :: Tab ) ;
556+ let output_tab = client. format_document_range ( & doc, range) . await ;
557+ insta:: assert_snapshot!( output_tab) ;
558+ } ) ;
559+ }
524560}
0 commit comments