aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/world.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-06-04 23:14:46 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-06-04 23:14:46 +0100
commit5deb907b4321d8328978d3322b0826b781814452 (patch)
tree2baa3b75b1ef62c02617c37ba9b800c41a3dd102 /crates/ra_lsp_server/src/world.rs
parent8bd0e844247dc28d6ceb24b00f3cc3396bd5bf03 (diff)
parentaa30c4909ebb1e85f1591f465c9e2875aa4d394e (diff)
Merge #1374
1374: Implement `cargo lint` and fix some clippy errors r=alanhdu a=alanhdu This creates a `cargo lint` command that runs clippy with certain lints disabled. I've also gone ahead and fixed some of the lint errors, although there are many more still to go. cc #848 Co-authored-by: Alan Du <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/world.rs')
-rw-r--r--crates/ra_lsp_server/src/world.rs29
1 files changed, 12 insertions, 17 deletions
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs
index e0d2f6306..cd8df4fdb 100644
--- a/crates/ra_lsp_server/src/world.rs
+++ b/crates/ra_lsp_server/src/world.rs
@@ -60,14 +60,14 @@ impl WorldState {
60 for r in vfs_roots { 60 for r in vfs_roots {
61 let vfs_root_path = vfs.root2path(r); 61 let vfs_root_path = vfs.root2path(r);
62 let is_local = folder_roots.iter().any(|it| vfs_root_path.starts_with(it)); 62 let is_local = folder_roots.iter().any(|it| vfs_root_path.starts_with(it));
63 change.add_root(SourceRootId(r.0.into()), is_local); 63 change.add_root(SourceRootId(r.0), is_local);
64 } 64 }
65 65
66 // Create crate graph from all the workspaces 66 // Create crate graph from all the workspaces
67 let mut crate_graph = CrateGraph::default(); 67 let mut crate_graph = CrateGraph::default();
68 let mut load = |path: &std::path::Path| { 68 let mut load = |path: &std::path::Path| {
69 let vfs_file = vfs.load(path); 69 let vfs_file = vfs.load(path);
70 vfs_file.map(|f| FileId(f.0.into())) 70 vfs_file.map(|f| FileId(f.0))
71 }; 71 };
72 for ws in workspaces.iter() { 72 for ws in workspaces.iter() {
73 crate_graph.extend(ws.to_crate_graph(&mut load)); 73 crate_graph.extend(ws.to_crate_graph(&mut load));
@@ -105,29 +105,24 @@ impl WorldState {
105 if is_local { 105 if is_local {
106 self.roots_to_scan -= 1; 106 self.roots_to_scan -= 1;
107 for (file, path, text) in files { 107 for (file, path, text) in files {
108 change.add_file( 108 change.add_file(SourceRootId(root.0), FileId(file.0), path, text);
109 SourceRootId(root.0.into()),
110 FileId(file.0.into()),
111 path,
112 text,
113 );
114 } 109 }
115 } else { 110 } else {
116 let files = files 111 let files = files
117 .into_iter() 112 .into_iter()
118 .map(|(vfsfile, path, text)| (FileId(vfsfile.0.into()), path, text)) 113 .map(|(vfsfile, path, text)| (FileId(vfsfile.0), path, text))
119 .collect(); 114 .collect();
120 libs.push((SourceRootId(root.0.into()), files)); 115 libs.push((SourceRootId(root.0), files));
121 } 116 }
122 } 117 }
123 VfsChange::AddFile { root, file, path, text } => { 118 VfsChange::AddFile { root, file, path, text } => {
124 change.add_file(SourceRootId(root.0.into()), FileId(file.0.into()), path, text); 119 change.add_file(SourceRootId(root.0), FileId(file.0), path, text);
125 } 120 }
126 VfsChange::RemoveFile { root, file, path } => { 121 VfsChange::RemoveFile { root, file, path } => {
127 change.remove_file(SourceRootId(root.0.into()), FileId(file.0.into()), path) 122 change.remove_file(SourceRootId(root.0), FileId(file.0), path)
128 } 123 }
129 VfsChange::ChangeFile { file, text } => { 124 VfsChange::ChangeFile { file, text } => {
130 change.change_file(FileId(file.0.into()), text); 125 change.change_file(FileId(file.0), text);
131 } 126 }
132 } 127 }
133 } 128 }
@@ -178,18 +173,18 @@ impl WorldSnapshot {
178 message: "Rust file outside current workspace is not supported yet.".to_string(), 173 message: "Rust file outside current workspace is not supported yet.".to_string(),
179 }) 174 })
180 })?; 175 })?;
181 Ok(FileId(file.0.into())) 176 Ok(FileId(file.0))
182 } 177 }
183 178
184 pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> { 179 pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> {
185 let path = self.vfs.read().file2path(VfsFile(id.0.into())); 180 let path = self.vfs.read().file2path(VfsFile(id.0));
186 let url = Url::from_file_path(&path) 181 let url = Url::from_file_path(&path)
187 .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; 182 .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
188 Ok(url) 183 Ok(url)
189 } 184 }
190 185
191 pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result<Url> { 186 pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result<Url> {
192 let base = self.vfs.read().root2path(VfsRoot(root.0.into())); 187 let base = self.vfs.read().root2path(VfsRoot(root.0));
193 let path = path.to_path(base); 188 let path = path.to_path(base);
194 let url = Url::from_file_path(&path) 189 let url = Url::from_file_path(&path)
195 .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; 190 .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
@@ -212,7 +207,7 @@ impl WorldSnapshot {
212 } 207 }
213 208
214 pub fn workspace_root_for(&self, file_id: FileId) -> Option<&Path> { 209 pub fn workspace_root_for(&self, file_id: FileId) -> Option<&Path> {
215 let path = self.vfs.read().file2path(VfsFile(file_id.0.into())); 210 let path = self.vfs.read().file2path(VfsFile(file_id.0));
216 self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path)) 211 self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path))
217 } 212 }
218} 213}