From bd96d0b258437cbfcaba5d0a6a79813eaa5f29fe Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jan 2020 11:58:31 +0100 Subject: Minimize visibility --- crates/ra_lsp_server/src/cargo_target_spec.rs | 2 +- crates/ra_lsp_server/src/main_loop/handlers.rs | 10 ++++++---- crates/ra_lsp_server/src/world.rs | 6 +++++- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs index c4a9e7101..594caffe2 100644 --- a/crates/ra_lsp_server/src/cargo_target_spec.rs +++ b/crates/ra_lsp_server/src/cargo_target_spec.rs @@ -63,7 +63,7 @@ impl CargoTargetSpec { None => return Ok(None), }; let file_id = world.analysis().crate_root(crate_id)?; - let path = world.vfs.read().file2path(ra_vfs::VfsFile(file_id.0)); + let path = world.file_id_to_path(file_id); let res = world.workspaces.iter().find_map(|ws| match ws { ProjectWorkspace::Cargo { cargo, .. } => { let tgt = cargo.target_by_root(&path)?; diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 9e9964880..8e43f0575 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -681,10 +681,12 @@ pub fn handle_code_action( continue; } - let edits = vec![TextEdit::new(fix.location.range, fix.replacement.clone())]; - let mut edit_map = std::collections::HashMap::new(); - edit_map.insert(fix.location.uri.clone(), edits); - let edit = WorkspaceEdit::new(edit_map); + let edit = { + let edits = vec![TextEdit::new(fix.location.range, fix.replacement.clone())]; + let mut edit_map = std::collections::HashMap::new(); + edit_map.insert(fix.location.uri.clone(), edits); + WorkspaceEdit::new(edit_map) + }; let action = CodeAction { title: fix.title.clone(), diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 7a3030a51..e7a0acfc7 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -62,9 +62,9 @@ pub struct WorldSnapshot { pub options: Options, pub workspaces: Arc>, pub analysis: Analysis, - pub vfs: Arc>, pub latest_requests: Arc>, pub check_watcher: Arc>, + vfs: Arc>, } impl WorldState { @@ -265,6 +265,10 @@ impl WorldSnapshot { Ok(url) } + pub fn file_id_to_path(&self, id: FileId) -> PathBuf { + self.vfs.read().file2path(VfsFile(id.0)) + } + pub fn file_line_endings(&self, id: FileId) -> LineEndings { self.vfs.read().file_line_endings(VfsFile(id.0)) } -- cgit v1.2.3