@@ -9,20 +9,23 @@ use tower_lsp::lsp_types::{
99 CompletionResponse , DidChangeTextDocumentParams , DidCloseTextDocumentParams ,
1010 DidOpenTextDocumentParams , DocumentFormattingParams , DocumentLink , DocumentLinkOptions ,
1111 DocumentLinkParams , DocumentRangeFormattingParams , DocumentSymbolParams ,
12- DocumentSymbolResponse , FoldingRange , FoldingRangeParams , FoldingRangeProviderCapability ,
13- GotoDefinitionParams , GotoDefinitionResponse , Hover , HoverParams , HoverProviderCapability ,
14- InitializeParams , InitializeResult , InitializedParams , InlayHint , InlayHintParams , OneOf ,
15- PrepareRenameResponse , ReferenceParams , RenameOptions , RenameParams , SelectionRange ,
16- SelectionRangeParams , SelectionRangeProviderCapability , SemanticTokensParams ,
17- SemanticTokensResult , ServerCapabilities , ServerInfo , SymbolInformation ,
18- TextDocumentPositionParams , TextDocumentSyncCapability , TextDocumentSyncKind , TextEdit , Url ,
19- WorkDoneProgressOptions , WorkspaceEdit , WorkspaceSymbolParams ,
12+ DocumentSymbolResponse , FileOperationFilter , FileOperationPattern , FileOperationPatternKind ,
13+ FileOperationRegistrationOptions , FoldingRange , FoldingRangeParams ,
14+ FoldingRangeProviderCapability , GotoDefinitionParams , GotoDefinitionResponse , Hover ,
15+ HoverParams , HoverProviderCapability , InitializeParams , InitializeResult , InitializedParams ,
16+ InlayHint , InlayHintParams , OneOf , PrepareRenameResponse , ReferenceParams , RenameFilesParams ,
17+ RenameOptions , RenameParams , SelectionRange , SelectionRangeParams ,
18+ SelectionRangeProviderCapability , SemanticTokensParams , SemanticTokensResult ,
19+ ServerCapabilities , ServerInfo , SymbolInformation , TextDocumentPositionParams ,
20+ TextDocumentSyncCapability , TextDocumentSyncKind , TextEdit , Url , WorkDoneProgressOptions ,
21+ WorkspaceEdit , WorkspaceFileOperationsServerCapabilities , WorkspaceServerCapabilities ,
22+ WorkspaceSymbolParams ,
2023} ;
2124use tower_lsp:: { Client , LanguageServer } ;
2225
2326use crate :: capabilities:: {
24- code_actions, code_lens, completion, definition, document_links, folding , formatting , hover ,
25- inlay_hints, references, rename, selection_range, semantic_tokens, symbols,
27+ code_actions, code_lens, completion, definition, document_links, file_rename , folding ,
28+ formatting , hover , inlay_hints, references, rename, selection_range, semantic_tokens, symbols,
2629} ;
2730use crate :: state:: Workspace ;
2831
@@ -139,6 +142,23 @@ impl LanguageServer for Backend {
139142 ] ) ,
140143 ..Default :: default ( )
141144 } ) ,
145+ // Enable automatic link updates on file rename
146+ workspace : Some ( WorkspaceServerCapabilities {
147+ file_operations : Some ( WorkspaceFileOperationsServerCapabilities {
148+ will_rename : Some ( FileOperationRegistrationOptions {
149+ filters : vec ! [ FileOperationFilter {
150+ scheme: Some ( "file" . to_string( ) ) ,
151+ pattern: FileOperationPattern {
152+ glob: "**/*.{adoc,asciidoc,asc}" . to_string( ) ,
153+ matches: Some ( FileOperationPatternKind :: File ) ,
154+ options: None ,
155+ } ,
156+ } ] ,
157+ } ) ,
158+ ..Default :: default ( )
159+ } ) ,
160+ ..Default :: default ( )
161+ } ) ,
142162 ..Default :: default ( )
143163 } ,
144164 server_info : Some ( ServerInfo {
@@ -455,4 +475,17 @@ impl LanguageServer for Backend {
455475
456476 Ok ( response)
457477 }
478+
479+ async fn will_rename_files ( & self , params : RenameFilesParams ) -> Result < Option < WorkspaceEdit > > {
480+ tracing:: info!( count = params. files. len( ) , "workspace/willRenameFiles" ) ;
481+ Ok ( file_rename:: compute_file_rename_edits (
482+ & self . workspace ,
483+ & params. files ,
484+ ) )
485+ }
486+
487+ async fn did_rename_files ( & self , params : RenameFilesParams ) {
488+ tracing:: info!( count = params. files. len( ) , "workspace/didRenameFiles" ) ;
489+ file_rename:: update_workspace_after_rename ( & self . workspace , & params. files ) ;
490+ }
458491}
0 commit comments