about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShuiRuTian <158983297@qq.com>2021-01-11 14:45:35 +0800
committerShuiRuTian <158983297@qq.com>2021-01-11 14:45:35 +0800
commitf7cb9e9fbe50e5d0e23e81b8b5b90405ef5c1931 (patch)
tree147a80040e3513a0be3f6fb4c59a6d0dd1a0ecee
parentb9d52444cf621e474e0117e70c335dde2cbf3515 (diff)
downloadrust-f7cb9e9fbe50e5d0e23e81b8b5b90405ef5c1931.tar.gz
rust-f7cb9e9fbe50e5d0e23e81b8b5b90405ef5c1931.zip
move logic from client to server.
-rw-r--r--crates/rust-analyzer/src/handlers.rs10
-rw-r--r--editors/code/src/client.ts20
2 files changed, 9 insertions, 21 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 1aafef78be0..17f67d4b7a9 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -435,7 +435,15 @@ pub(crate) fn handle_will_rename_files(
                     if from_path.is_dir() {
                         // This is a quick implement, try to use will_rename_file code.
                         // imitate change the older_folder/mod.rs to older_folder/new_folder.rs
-                        let imitate_from_url = from.join("mod.rs").ok()?;
+
+                        // add '/' to end of url -- from `file://path/to/folder` to `file://path/to/folder/`
+                        let old_folder_name = from_path.file_stem()?;
+                        let old_folder_name = old_folder_name.to_str()?;
+                        let mut old_folder_name = old_folder_name.to_string();
+                        old_folder_name.push('/');
+                        let from_with_trailing_slash = from.join(&old_folder_name).ok()?;
+
+                        let imitate_from_url = from_with_trailing_slash.join("mod.rs").ok()?;
                         let imite_new_file_name = to_path.file_name()?.to_str()?;
                         Some((
                             snap.url_to_file_id(&imitate_from_url).ok()?,
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 772892b079b..539e487ec96 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -51,32 +51,12 @@ export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc
         'Rust Analyzer Language Server Trace',
     );
 
-    const workspace: lc.WorkspaceMiddleware = {
-        willRenameFiles: function <P extends vscode.FileRenameEvent, R extends Thenable<vscode.WorkspaceEdit | null | undefined>>(this: void, data: P, next: (data: P) => R) {
-            // why add this function rather than default:
-            // 1. change `url` parameter to happy format for url crate. (folder should end with '/')
-            // 2. filter some change in here.
-            //     2.1 rename from or to `mod.rs` should be special. 
-            //     2.2 not all folder change should be cared, only those have files with ".rs" postfix.
-            const newFiles = data.files.map((file) => {
-                const isFolder = !file.oldUri.path.endsWith(".rs");
-                return !isFolder ? file : {
-                    oldUri: vscode.Uri.file(file.oldUri.path + '/'),
-                    newUri: vscode.Uri.file(file.newUri.path + '/')
-                };
-            });
-            data = { ...data, files: newFiles };
-            return next(data);
-        }
-    };
-
     const clientOptions: lc.LanguageClientOptions = {
         documentSelector: [{ scheme: 'file', language: 'rust' }],
         initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
         diagnosticCollectionName: "rustc",
         traceOutputChannel,
         middleware: {
-            workspace,
             provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature): vscode.ProviderResult<vscode.SemanticTokens> {
                 return semanticHighlightingWorkaround(next, document, token);
             },