aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShuiRuTian <[email protected]>2021-01-11 06:45:35 +0000
committerShuiRuTian <[email protected]>2021-01-11 06:45:35 +0000
commitf7cb9e9fbe50e5d0e23e81b8b5b90405ef5c1931 (patch)
tree147a80040e3513a0be3f6fb4c59a6d0dd1a0ecee
parentb9d52444cf621e474e0117e70c335dde2cbf3515 (diff)
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 1aafef78b..17f67d4b7 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(
435 if from_path.is_dir() { 435 if from_path.is_dir() {
436 // This is a quick implement, try to use will_rename_file code. 436 // This is a quick implement, try to use will_rename_file code.
437 // imitate change the older_folder/mod.rs to older_folder/new_folder.rs 437 // imitate change the older_folder/mod.rs to older_folder/new_folder.rs
438 let imitate_from_url = from.join("mod.rs").ok()?; 438
439 // add '/' to end of url -- from `file://path/to/folder` to `file://path/to/folder/`
440 let old_folder_name = from_path.file_stem()?;
441 let old_folder_name = old_folder_name.to_str()?;
442 let mut old_folder_name = old_folder_name.to_string();
443 old_folder_name.push('/');
444 let from_with_trailing_slash = from.join(&old_folder_name).ok()?;
445
446 let imitate_from_url = from_with_trailing_slash.join("mod.rs").ok()?;
439 let imite_new_file_name = to_path.file_name()?.to_str()?; 447 let imite_new_file_name = to_path.file_name()?.to_str()?;
440 Some(( 448 Some((
441 snap.url_to_file_id(&imitate_from_url).ok()?, 449 snap.url_to_file_id(&imitate_from_url).ok()?,
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 772892b07..539e487ec 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
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 const newFiles = data.files.map((file) => {
62 const isFolder = !file.oldUri.path.endsWith(".rs");
63 return !isFolder ? file : {
64 oldUri: vscode.Uri.file(file.oldUri.path + '/'),
65 newUri: vscode.Uri.file(file.newUri.path + '/')
66 };
67 });
68 data = { ...data, files: newFiles };
69 return next(data);
70 }
71 };
72
73 const clientOptions: lc.LanguageClientOptions = { 54 const clientOptions: lc.LanguageClientOptions = {
74 documentSelector: [{ scheme: 'file', language: 'rust' }], 55 documentSelector: [{ scheme: 'file', language: 'rust' }],
75 initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"), 56 initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
76 diagnosticCollectionName: "rustc", 57 diagnosticCollectionName: "rustc",
77 traceOutputChannel, 58 traceOutputChannel,
78 middleware: { 59 middleware: {
79 workspace,
80 provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature): vscode.ProviderResult<vscode.SemanticTokens> { 60 provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature): vscode.ProviderResult<vscode.SemanticTokens> {
81 return semanticHighlightingWorkaround(next, document, token); 61 return semanticHighlightingWorkaround(next, document, token);
82 }, 62 },