aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-29 16:12:28 +0100
committerAleksey Kladov <[email protected]>2018-08-29 16:12:28 +0100
commit0f968ee43047af9d7bcf2953f1b367c38cb8bf1b (patch)
tree36a15fba4e1577a1d1cf4424e19eecda30c89422 /crates/libanalysis/src
parent4dd4571bfe5220354f00e030f0a2d0a45e185712 (diff)
minor
Diffstat (limited to 'crates/libanalysis/src')
-rw-r--r--crates/libanalysis/src/api.rs3
-rw-r--r--crates/libanalysis/src/lib.rs42
2 files changed, 21 insertions, 24 deletions
diff --git a/crates/libanalysis/src/api.rs b/crates/libanalysis/src/api.rs
index 2872d01e9..8882268e6 100644
--- a/crates/libanalysis/src/api.rs
+++ b/crates/libanalysis/src/api.rs
@@ -55,11 +55,9 @@ pub struct Analysis {
55impl Analysis { 55impl Analysis {
56 pub fn file_syntax(&self, file_id: FileId) -> File { 56 pub fn file_syntax(&self, file_id: FileId) -> File {
57 self.imp.file_syntax(file_id) 57 self.imp.file_syntax(file_id)
58 .unwrap()
59 } 58 }
60 pub fn file_line_index(&self, file_id: FileId) -> LineIndex { 59 pub fn file_line_index(&self, file_id: FileId) -> LineIndex {
61 self.imp.file_line_index(file_id) 60 self.imp.file_line_index(file_id)
62 .unwrap()
63 } 61 }
64 pub fn extend_selection(&self, file: &File, range: TextRange) -> TextRange { 62 pub fn extend_selection(&self, file: &File, range: TextRange) -> TextRange {
65 libeditor::extend_selection(file, range).unwrap_or(range) 63 libeditor::extend_selection(file, range).unwrap_or(range)
@@ -88,7 +86,6 @@ impl Analysis {
88 } 86 }
89 pub fn approximately_resolve_symbol(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, FileSymbol)> { 87 pub fn approximately_resolve_symbol(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, FileSymbol)> {
90 self.imp.approximately_resolve_symbol(file_id, offset) 88 self.imp.approximately_resolve_symbol(file_id, offset)
91 .unwrap()
92 } 89 }
93 pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { 90 pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> {
94 self.imp.parent_module(file_id) 91 self.imp.parent_module(file_id)
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
143impl World { 143impl 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}