@@ -205,16 +205,40 @@ impl App {
205205 let document_links = self . document_links ( & params) . unwrap_or_default ( ) ;
206206 self . reply ( Response :: new_ok ( id, document_links) ) ;
207207 } else if let Some ( ( id, params) ) = cast :: < Formatting > ( & mut req) {
208- let changes = if let Some ( ( ast, code, _) ) = self . files . get ( & params. text_document . uri ) {
209- let fmt = nixpkgs_fmt:: reformat_node ( & ast. node ( ) ) ;
210- vec ! [ TextEdit {
211- range: utils:: range( & code, TextRange :: up_to( ast. node( ) . text( ) . len( ) ) ) ,
212- new_text: fmt. text( ) . to_string( ) ,
213- } ]
208+ if let Some ( ( ast, code, _) ) = self . files . get ( & params. text_document . uri ) {
209+ let node = ast. node ( ) ;
210+ let range = utils:: range ( & code, TextRange :: up_to ( node. text ( ) . len ( ) ) ) ;
211+ if cfg ! ( feature = "alejandra" ) {
212+ #[ cfg( feature = "alejandra" ) ]
213+ match alejandra:: format:: in_memory (
214+ params. text_document . uri . to_string ( ) ,
215+ code. to_string ( ) ,
216+ ) {
217+ ( alejandra:: format:: Status :: Changed ( true ) , new_text) => {
218+ self . reply ( Response :: new_ok ( id, vec ! [ TextEdit { range, new_text } ] ) )
219+ }
220+ ( alejandra:: format:: Status :: Changed ( false ) , _) => {
221+ self . reply ( Response :: new_ok ( id, ( ) ) )
222+ }
223+ ( alejandra:: format:: Status :: Error ( e) , _) => {
224+ self . reply ( Response :: new_err ( id, ErrorCode :: InternalError as i32 , e) )
225+ }
226+ }
227+ } else if cfg ! ( feature = "nixpkgs-fmt-rnix" ) {
228+ #[ cfg( feature = "nixpkgs-fmt-rnix" ) ]
229+ self . reply ( Response :: new_ok (
230+ id,
231+ vec ! [ TextEdit {
232+ range,
233+ new_text: nixpkgs_fmt:: reformat_node( & node) . text( ) . to_string( ) ,
234+ } ] ,
235+ ) ) ;
236+ } else {
237+ self . reply ( Response :: new_ok ( id, ( ) ) )
238+ }
214239 } else {
215- Vec :: new ( )
216- } ;
217- self . reply ( Response :: new_ok ( id, changes) ) ;
240+ self . reply ( Response :: new_ok ( id, ( ) ) )
241+ }
218242 } else if let Some ( ( id, params) ) = cast :: < HoverRequest > ( & mut req) {
219243 if let Some ( ( range, markdown) ) = self . hover ( params) {
220244 self . reply ( Response :: new_ok (
0 commit comments