diff options
Diffstat (limited to 'crates/libanalysis/src/lib.rs')
-rw-r--r-- | crates/libanalysis/src/lib.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index ea759f8e3..5168814e4 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs | |||
@@ -141,16 +141,16 @@ impl WorldState { | |||
141 | } | 141 | } |
142 | 142 | ||
143 | impl World { | 143 | impl World { |
144 | pub fn file_syntax(&self, file_id: FileId) -> Result<File> { | 144 | pub fn file_syntax(&self, file_id: FileId) -> File { |
145 | let data = self.file_data(file_id)?; | 145 | self.file_data(file_id).syntax().clone() |
146 | Ok(data.syntax().clone()) | ||
147 | } | 146 | } |
148 | 147 | ||
149 | pub fn file_line_index(&self, id: FileId) -> Result<LineIndex> { | 148 | pub fn file_line_index(&self, id: FileId) -> LineIndex { |
150 | let data = self.file_data(id)?; | 149 | let data = self.file_data(id); |
151 | let index = data.lines | 150 | data |
152 | .get_or_init(|| LineIndex::new(&data.text)); | 151 | .lines |
153 | Ok(index.clone()) | 152 | .get_or_init(|| LineIndex::new(&data.text)) |
153 | .clone() | ||
154 | } | 154 | } |
155 | 155 | ||
156 | pub fn world_symbols(&self, mut query: Query) -> Vec<(FileId, FileSymbol)> { | 156 | pub fn world_symbols(&self, mut query: Query) -> Vec<(FileId, FileSymbol)> { |
@@ -170,7 +170,7 @@ impl World { | |||
170 | .parent_modules( | 170 | .parent_modules( |
171 | id, | 171 | id, |
172 | &*self.file_resolver, | 172 | &*self.file_resolver, |
173 | &|file_id| self.file_syntax(file_id).unwrap(), | 173 | &|file_id| self.file_syntax(file_id), |
174 | ) | 174 | ) |
175 | .into_iter() | 175 | .into_iter() |
176 | .map(|(id, name, node)| { | 176 | .map(|(id, name, node)| { |
@@ -189,11 +189,11 @@ impl World { | |||
189 | &self, | 189 | &self, |
190 | id: FileId, | 190 | id: FileId, |
191 | offset: TextUnit, | 191 | offset: TextUnit, |
192 | ) -> Result<Vec<(FileId, FileSymbol)>> { | 192 | ) -> Vec<(FileId, FileSymbol)> { |
193 | let file = self.file_syntax(id)?; | 193 | let file = self.file_syntax(id); |
194 | let syntax = file.syntax(); | 194 | let syntax = file.syntax(); |
195 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { | 195 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { |
196 | return Ok(self.index_resolve(name_ref)); | 196 | return self.index_resolve(name_ref); |
197 | } | 197 | } |
198 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { | 198 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { |
199 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { | 199 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { |
@@ -212,15 +212,15 @@ impl World { | |||
212 | (id, symbol) | 212 | (id, symbol) |
213 | }).collect(); | 213 | }).collect(); |
214 | 214 | ||
215 | return Ok(res); | 215 | return res; |
216 | } | 216 | } |
217 | } | 217 | } |
218 | } | 218 | } |
219 | Ok(vec![]) | 219 | vec![] |
220 | } | 220 | } |
221 | 221 | ||
222 | pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { | 222 | pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { |
223 | let syntax = self.file_syntax(file_id).unwrap(); | 223 | let syntax = self.file_syntax(file_id); |
224 | let mut res = libeditor::diagnostics(&syntax) | 224 | let mut res = libeditor::diagnostics(&syntax) |
225 | .into_iter() | 225 | .into_iter() |
226 | .map(|d| Diagnostic { range: d.range, message: d.msg, fix: None }) | 226 | .map(|d| Diagnostic { range: d.range, message: d.msg, fix: None }) |
@@ -229,7 +229,7 @@ impl World { | |||
229 | self.data.module_map.problems( | 229 | self.data.module_map.problems( |
230 | file_id, | 230 | file_id, |
231 | &*self.file_resolver, | 231 | &*self.file_resolver, |
232 | &|file_id| self.file_syntax(file_id).unwrap(), | 232 | &|file_id| self.file_syntax(file_id), |
233 | |name_node, problem| { | 233 | |name_node, problem| { |
234 | let diag = match problem { | 234 | let diag = match problem { |
235 | Problem::UnresolvedModule { candidate } => { | 235 | Problem::UnresolvedModule { candidate } => { |
@@ -272,7 +272,7 @@ impl World { | |||
272 | } | 272 | } |
273 | 273 | ||
274 | pub fn assists(&self, file_id: FileId, offset: TextUnit) -> Vec<SourceChange> { | 274 | pub fn assists(&self, file_id: FileId, offset: TextUnit) -> Vec<SourceChange> { |
275 | let file = self.file_syntax(file_id).unwrap(); | 275 | let file = self.file_syntax(file_id); |
276 | let actions = vec![ | 276 | let actions = vec![ |
277 | ("flip comma", libeditor::flip_comma(&file, offset).map(|f| f())), | 277 | ("flip comma", libeditor::flip_comma(&file, offset).map(|f| f())), |
278 | ("add `#[derive]`", libeditor::add_derive(&file, offset).map(|f| f())), | 278 | ("add `#[derive]`", libeditor::add_derive(&file, offset).map(|f| f())), |
@@ -308,7 +308,7 @@ impl World { | |||
308 | .child_module_by_name( | 308 | .child_module_by_name( |
309 | id, name.as_str(), | 309 | id, name.as_str(), |
310 | &*self.file_resolver, | 310 | &*self.file_resolver, |
311 | &|file_id| self.file_syntax(file_id).unwrap(), | 311 | &|file_id| self.file_syntax(file_id), |
312 | ) | 312 | ) |
313 | .into_iter() | 313 | .into_iter() |
314 | .map(|id| module_map.module2file(id)) | 314 | .map(|id| module_map.module2file(id)) |
@@ -326,10 +326,10 @@ impl World { | |||
326 | } | 326 | } |
327 | } | 327 | } |
328 | 328 | ||
329 | fn file_data(&self, file_id: FileId) -> Result<Arc<FileData>> { | 329 | fn file_data(&self, file_id: FileId) -> Arc<FileData> { |
330 | match self.data.file_map.get(&file_id) { | 330 | match self.data.file_map.get(&file_id) { |
331 | Some(data) => Ok(data.clone()), | 331 | Some(data) => data.clone(), |
332 | None => bail!("unknown file: {:?}", file_id), | 332 | None => panic!("unknown file: {:?}", file_id), |
333 | } | 333 | } |
334 | } | 334 | } |
335 | } | 335 | } |