Skip to content

Commit 1900eff

Browse files
nlopesclaude
andcommitted
feat(lsp): add automatic link updates on file rename
Implement workspace/willRenameFiles LSP request so that when AsciiDoc files are renamed or moved, all cross-file references (xrefs, includes) are automatically updated across the workspace. Also scans non-open workspace files on disk for comprehensive coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7dee3f7 commit 1900eff

File tree

5 files changed

+668
-10
lines changed

5 files changed

+668
-10
lines changed

acdc-lsp/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- **Automatic link updates on file rename** — when an AsciiDoc file is renamed
13+
or moved in the editor, all cross-file references (xrefs, includes) across the
14+
workspace are automatically updated (`workspace/willRenameFiles`). Also scans
15+
non-open workspace files on disk for comprehensive coverage.
1216
- **Link validation diagnostics** — flag missing images, audio, video, and
1317
include files with warning-level diagnostics. Resolves image paths through
1418
the `imagesdir` attribute when set. URLs and icon names are skipped.

acdc-lsp/src/backend.rs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};
2124
use tower_lsp::{Client, LanguageServer};
2225

2326
use 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
};
2730
use 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

Comments
 (0)