aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShuiRuTian <[email protected]>2021-01-09 17:29:08 +0000
committerShuiRuTian <[email protected]>2021-01-09 17:29:08 +0000
commit0d86e222297233387ad4abc2796dfd27c5333aaa (patch)
tree740e53bdc4ab3b309dbf23471a01511d3ccd281a
parentc08391ce32c471d09fcc6fe48bd295bbb5a7de10 (diff)
beta version for folder rename
-rw-r--r--crates/rust-analyzer/src/caps.rs3
-rw-r--r--crates/rust-analyzer/src/handlers.rs23
-rw-r--r--editors/code/src/client.ts12
3 files changed, 34 insertions, 4 deletions
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs
index 5167a005f..406a93b10 100644
--- a/crates/rust-analyzer/src/caps.rs
+++ b/crates/rust-analyzer/src/caps.rs
@@ -85,8 +85,9 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
85 matches: Some(FileOperationPatternKind::File), 85 matches: Some(FileOperationPatternKind::File),
86 options: None, 86 options: None,
87 }, 87 },
88 },
88 FileOperationFilter { 89 FileOperationFilter {
89 scheme: Some(String::from("untitled")), 90 scheme: Some(String::from("file")),
90 pattern: FileOperationPattern { 91 pattern: FileOperationPattern {
91 glob: String::from("**"), 92 glob: String::from("**"),
92 matches: Some(FileOperationPatternKind::Folder), 93 matches: Some(FileOperationPatternKind::Folder),
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index c13cdc4e3..176774a77 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -432,9 +432,26 @@ pub(crate) fn handle_will_rename_files(
432 // Limit to single-level moves for now. 432 // Limit to single-level moves for now.
433 match (from_path.parent(), to_path.parent()) { 433 match (from_path.parent(), to_path.parent()) {
434 (Some(p1), Some(p2)) if p1 == p2 => { 434 (Some(p1), Some(p2)) if p1 == p2 => {
435 let new_name = to_path.file_stem()?; 435 if from_path.is_dir() {
436 let new_name = new_name.to_str()?; 436 // This is a quick implement, try to use will_rename_file code.
437 Some((snap.url_to_file_id(&from).ok()?, new_name.to_string())) 437 // imitate change the older_folder/mod.rs to older_folder/new_folder.rs
438 let imitate_from_path = from_path.join("mod.rs");
439 let new_from_url = imitate_from_path.to_str()?;
440 let new_from_url = Url::parse(new_from_url).ok()?;
441
442 let new_folder_name = to_path.file_name()?.to_str()?;
443 let mut imite_new_file_name = new_folder_name.to_string();
444 imite_new_file_name.push_str(".rs");
445 let new_to = from_path.join(imite_new_file_name);
446 let new_to = new_to.to_str()?;
447
448 Some((snap.url_to_file_id(&new_from_url).ok()?, new_to.to_string()))
449 }
450 else{
451 let new_name = to_path.file_stem()?;
452 let new_name = new_name.to_str()?;
453 Some((snap.url_to_file_id(&from).ok()?, new_name.to_string()))
454 }
438 } 455 }
439 _ => None, 456 _ => None,
440 } 457 }
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 539e487ec..2a8f2deb4 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -51,12 +51,24 @@ export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc
51 'Rust Analyzer Language Server Trace', 51 'Rust Analyzer Language Server Trace',
52 ); 52 );
53 53
54 const workspace:lc.WorkspaceMiddleware = {
55 willRenameFiles:function<P extends vscode.FileRenameEvent,R extends Thenable<vscode.WorkspaceEdit | null | undefined>>(this: void, data: P, next:(data: P) => R ){
56 // why add this function rather than default:
57 // 1. change `url` parameter to happy format for url crate. (folder should end with '/')
58 // 2. filter some change in here.
59 // 2.1 rename from or to `mod.rs` should be special.
60 // 2.2 not all folder change should be cared, only those have files with ".rs" postfix.
61 return next(data);
62 }
63 }
64
54 const clientOptions: lc.LanguageClientOptions = { 65 const clientOptions: lc.LanguageClientOptions = {
55 documentSelector: [{ scheme: 'file', language: 'rust' }], 66 documentSelector: [{ scheme: 'file', language: 'rust' }],
56 initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"), 67 initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
57 diagnosticCollectionName: "rustc", 68 diagnosticCollectionName: "rustc",
58 traceOutputChannel, 69 traceOutputChannel,
59 middleware: { 70 middleware: {
71 workspace,
60 provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature): vscode.ProviderResult<vscode.SemanticTokens> { 72 provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature): vscode.ProviderResult<vscode.SemanticTokens> {
61 return semanticHighlightingWorkaround(next, document, token); 73 return semanticHighlightingWorkaround(next, document, token);
62 }, 74 },