aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs62
1 files changed, 31 insertions, 31 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index b0b983d0c..9e76a51c1 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -161,7 +161,7 @@ pub fn handle_document_symbol(
161pub fn handle_workspace_symbol( 161pub fn handle_workspace_symbol(
162 world: ServerWorld, 162 world: ServerWorld,
163 params: req::WorkspaceSymbolParams, 163 params: req::WorkspaceSymbolParams,
164 token: JobToken, 164 _token: JobToken,
165) -> Result<Option<Vec<SymbolInformation>>> { 165) -> Result<Option<Vec<SymbolInformation>>> {
166 let all_symbols = params.query.contains("#"); 166 let all_symbols = params.query.contains("#");
167 let libs = params.query.contains("*"); 167 let libs = params.query.contains("*");
@@ -181,11 +181,11 @@ pub fn handle_workspace_symbol(
181 q.limit(128); 181 q.limit(128);
182 q 182 q
183 }; 183 };
184 let mut res = exec_query(&world, query, &token)?; 184 let mut res = exec_query(&world, query)?;
185 if res.is_empty() && !all_symbols { 185 if res.is_empty() && !all_symbols {
186 let mut query = Query::new(params.query); 186 let mut query = Query::new(params.query);
187 query.limit(128); 187 query.limit(128);
188 res = exec_query(&world, query, &token)?; 188 res = exec_query(&world, query)?;
189 } 189 }
190 190
191 return Ok(Some(res)); 191 return Ok(Some(res));
@@ -193,10 +193,9 @@ pub fn handle_workspace_symbol(
193 fn exec_query( 193 fn exec_query(
194 world: &ServerWorld, 194 world: &ServerWorld,
195 query: Query, 195 query: Query,
196 token: &JobToken,
197 ) -> Result<Vec<SymbolInformation>> { 196 ) -> Result<Vec<SymbolInformation>> {
198 let mut res = Vec::new(); 197 let mut res = Vec::new();
199 for (file_id, symbol) in world.analysis().symbol_search(query, token) { 198 for (file_id, symbol) in world.analysis().symbol_search(query) {
200 let line_index = world.analysis().file_line_index(file_id); 199 let line_index = world.analysis().file_line_index(file_id);
201 let info = SymbolInformation { 200 let info = SymbolInformation {
202 name: symbol.name.to_string(), 201 name: symbol.name.to_string(),
@@ -214,7 +213,7 @@ pub fn handle_workspace_symbol(
214pub fn handle_goto_definition( 213pub fn handle_goto_definition(
215 world: ServerWorld, 214 world: ServerWorld,
216 params: req::TextDocumentPositionParams, 215 params: req::TextDocumentPositionParams,
217 token: JobToken, 216 _token: JobToken,
218) -> Result<Option<req::GotoDefinitionResponse>> { 217) -> Result<Option<req::GotoDefinitionResponse>> {
219 let file_id = params.text_document.try_conv_with(&world)?; 218 let file_id = params.text_document.try_conv_with(&world)?;
220 let line_index = world.analysis().file_line_index(file_id); 219 let line_index = world.analysis().file_line_index(file_id);
@@ -222,7 +221,7 @@ pub fn handle_goto_definition(
222 let mut res = Vec::new(); 221 let mut res = Vec::new();
223 for (file_id, symbol) in world 222 for (file_id, symbol) in world
224 .analysis() 223 .analysis()
225 .approximately_resolve_symbol(file_id, offset, &token) 224 .approximately_resolve_symbol(file_id, offset)
226 { 225 {
227 let line_index = world.analysis().file_line_index(file_id); 226 let line_index = world.analysis().file_line_index(file_id);
228 let location = to_location(file_id, symbol.node_range, &world, &line_index)?; 227 let location = to_location(file_id, symbol.node_range, &world, &line_index)?;
@@ -255,14 +254,14 @@ pub fn handle_runnables(
255 let line_index = world.analysis().file_line_index(file_id); 254 let line_index = world.analysis().file_line_index(file_id);
256 let offset = params.position.map(|it| it.conv_with(&line_index)); 255 let offset = params.position.map(|it| it.conv_with(&line_index));
257 let mut res = Vec::new(); 256 let mut res = Vec::new();
258 for runnable in world.analysis().runnables(file_id) { 257 for runnable in world.analysis().runnables(file_id)? {
259 if let Some(offset) = offset { 258 if let Some(offset) = offset {
260 if !contains_offset_nonstrict(runnable.range, offset) { 259 if !contains_offset_nonstrict(runnable.range, offset) {
261 continue; 260 continue;
262 } 261 }
263 } 262 }
264 263
265 let args = runnable_args(&world, file_id, &runnable.kind); 264 let args = runnable_args(&world, file_id, &runnable.kind)?;
266 265
267 let r = req::Runnable { 266 let r = req::Runnable {
268 range: runnable.range.conv_with(&line_index), 267 range: runnable.range.conv_with(&line_index),
@@ -282,9 +281,9 @@ pub fn handle_runnables(
282 } 281 }
283 return Ok(res); 282 return Ok(res);
284 283
285 fn runnable_args(world: &ServerWorld, file_id: FileId, kind: &RunnableKind) -> Vec<String> { 284 fn runnable_args(world: &ServerWorld, file_id: FileId, kind: &RunnableKind) -> Result<Vec<String>> {
286 let spec = if let Some(&crate_id) = world.analysis().crate_for(file_id).first() { 285 let spec = if let Some(&crate_id) = world.analysis().crate_for(file_id)?.first() {
287 let file_id = world.analysis().crate_root(crate_id); 286 let file_id = world.analysis().crate_root(crate_id)?;
288 let path = world.path_map.get_path(file_id); 287 let path = world.path_map.get_path(file_id);
289 world 288 world
290 .workspaces 289 .workspaces
@@ -319,7 +318,7 @@ pub fn handle_runnables(
319 } 318 }
320 } 319 }
321 } 320 }
322 res 321 Ok(res)
323 } 322 }
324 323
325 fn spec_args(pkg_name: &str, tgt_name: &str, tgt_kind: TargetKind, buf: &mut Vec<String>) { 324 fn spec_args(pkg_name: &str, tgt_name: &str, tgt_kind: TargetKind, buf: &mut Vec<String>) {
@@ -356,7 +355,7 @@ pub fn handle_decorations(
356 _token: JobToken, 355 _token: JobToken,
357) -> Result<Vec<Decoration>> { 356) -> Result<Vec<Decoration>> {
358 let file_id = params.try_conv_with(&world)?; 357 let file_id = params.try_conv_with(&world)?;
359 Ok(highlight(&world, file_id)) 358 highlight(&world, file_id)
360} 359}
361 360
362pub fn handle_completion( 361pub fn handle_completion(
@@ -367,7 +366,7 @@ pub fn handle_completion(
367 let file_id = params.text_document.try_conv_with(&world)?; 366 let file_id = params.text_document.try_conv_with(&world)?;
368 let line_index = world.analysis().file_line_index(file_id); 367 let line_index = world.analysis().file_line_index(file_id);
369 let offset = params.position.conv_with(&line_index); 368 let offset = params.position.conv_with(&line_index);
370 let items = match world.analysis().completions(file_id, offset) { 369 let items = match world.analysis().completions(file_id, offset)? {
371 None => return Ok(None), 370 None => return Ok(None),
372 Some(items) => items, 371 Some(items) => items,
373 }; 372 };
@@ -427,7 +426,7 @@ pub fn handle_folding_range(
427pub fn handle_signature_help( 426pub fn handle_signature_help(
428 world: ServerWorld, 427 world: ServerWorld,
429 params: req::TextDocumentPositionParams, 428 params: req::TextDocumentPositionParams,
430 token: JobToken, 429 _token: JobToken,
431) -> Result<Option<req::SignatureHelp>> { 430) -> Result<Option<req::SignatureHelp>> {
432 use languageserver_types::{ParameterInformation, SignatureInformation}; 431 use languageserver_types::{ParameterInformation, SignatureInformation};
433 432
@@ -436,7 +435,7 @@ pub fn handle_signature_help(
436 let offset = params.position.conv_with(&line_index); 435 let offset = params.position.conv_with(&line_index);
437 436
438 if let Some((descriptor, active_param)) = 437 if let Some((descriptor, active_param)) =
439 world.analysis().resolve_callable(file_id, offset, &token) 438 world.analysis().resolve_callable(file_id, offset)
440 { 439 {
441 let parameters: Vec<ParameterInformation> = descriptor 440 let parameters: Vec<ParameterInformation> = descriptor
442 .params 441 .params
@@ -466,7 +465,7 @@ pub fn handle_signature_help(
466pub fn handle_prepare_rename( 465pub fn handle_prepare_rename(
467 world: ServerWorld, 466 world: ServerWorld,
468 params: req::TextDocumentPositionParams, 467 params: req::TextDocumentPositionParams,
469 token: JobToken, 468 _token: JobToken,
470) -> Result<Option<PrepareRenameResponse>> { 469) -> Result<Option<PrepareRenameResponse>> {
471 let file_id = params.text_document.try_conv_with(&world)?; 470 let file_id = params.text_document.try_conv_with(&world)?;
472 let line_index = world.analysis().file_line_index(file_id); 471 let line_index = world.analysis().file_line_index(file_id);
@@ -474,7 +473,7 @@ pub fn handle_prepare_rename(
474 473
475 // We support renaming references like handle_rename does. 474 // We support renaming references like handle_rename does.
476 // In the future we may want to reject the renaming of things like keywords here too. 475 // In the future we may want to reject the renaming of things like keywords here too.
477 let refs = world.analysis().find_all_refs(file_id, offset, &token); 476 let refs = world.analysis().find_all_refs(file_id, offset);
478 if refs.is_empty() { 477 if refs.is_empty() {
479 return Ok(None); 478 return Ok(None);
480 } 479 }
@@ -488,7 +487,7 @@ pub fn handle_prepare_rename(
488pub fn handle_rename( 487pub fn handle_rename(
489 world: ServerWorld, 488 world: ServerWorld,
490 params: RenameParams, 489 params: RenameParams,
491 token: JobToken, 490 _token: JobToken,
492) -> Result<Option<WorkspaceEdit>> { 491) -> Result<Option<WorkspaceEdit>> {
493 let file_id = params.text_document.try_conv_with(&world)?; 492 let file_id = params.text_document.try_conv_with(&world)?;
494 let line_index = world.analysis().file_line_index(file_id); 493 let line_index = world.analysis().file_line_index(file_id);
@@ -498,7 +497,7 @@ pub fn handle_rename(
498 return Ok(None); 497 return Ok(None);
499 } 498 }
500 499
501 let refs = world.analysis().find_all_refs(file_id, offset, &token); 500 let refs = world.analysis().find_all_refs(file_id, offset);
502 if refs.is_empty() { 501 if refs.is_empty() {
503 return Ok(None); 502 return Ok(None);
504 } 503 }
@@ -525,13 +524,13 @@ pub fn handle_rename(
525pub fn handle_references( 524pub fn handle_references(
526 world: ServerWorld, 525 world: ServerWorld,
527 params: req::ReferenceParams, 526 params: req::ReferenceParams,
528 token: JobToken, 527 _token: JobToken,
529) -> Result<Option<Vec<Location>>> { 528) -> Result<Option<Vec<Location>>> {
530 let file_id = params.text_document.try_conv_with(&world)?; 529 let file_id = params.text_document.try_conv_with(&world)?;
531 let line_index = world.analysis().file_line_index(file_id); 530 let line_index = world.analysis().file_line_index(file_id);
532 let offset = params.position.conv_with(&line_index); 531 let offset = params.position.conv_with(&line_index);
533 532
534 let refs = world.analysis().find_all_refs(file_id, offset, &token); 533 let refs = world.analysis().find_all_refs(file_id, offset);
535 534
536 Ok(Some(refs.into_iter() 535 Ok(Some(refs.into_iter()
537 .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok()) 536 .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok())
@@ -547,10 +546,10 @@ pub fn handle_code_action(
547 let line_index = world.analysis().file_line_index(file_id); 546 let line_index = world.analysis().file_line_index(file_id);
548 let range = params.range.conv_with(&line_index); 547 let range = params.range.conv_with(&line_index);
549 548
550 let assists = world.analysis().assists(file_id, range).into_iter(); 549 let assists = world.analysis().assists(file_id, range)?.into_iter();
551 let fixes = world 550 let fixes = world
552 .analysis() 551 .analysis()
553 .diagnostics(file_id) 552 .diagnostics(file_id)?
554 .into_iter() 553 .into_iter()
555 .filter_map(|d| Some((d.range, d.fix?))) 554 .filter_map(|d| Some((d.range, d.fix?)))
556 .filter(|(range, _fix)| contains_offset_nonstrict(*range, range.start())) 555 .filter(|(range, _fix)| contains_offset_nonstrict(*range, range.start()))
@@ -579,7 +578,7 @@ pub fn publish_diagnostics(
579 let line_index = world.analysis().file_line_index(file_id); 578 let line_index = world.analysis().file_line_index(file_id);
580 let diagnostics = world 579 let diagnostics = world
581 .analysis() 580 .analysis()
582 .diagnostics(file_id) 581 .diagnostics(file_id)?
583 .into_iter() 582 .into_iter()
584 .map(|d| Diagnostic { 583 .map(|d| Diagnostic {
585 range: d.range.conv_with(&line_index), 584 range: d.range.conv_with(&line_index),
@@ -600,19 +599,20 @@ pub fn publish_decorations(
600 let uri = world.file_id_to_uri(file_id)?; 599 let uri = world.file_id_to_uri(file_id)?;
601 Ok(req::PublishDecorationsParams { 600 Ok(req::PublishDecorationsParams {
602 uri, 601 uri,
603 decorations: highlight(&world, file_id), 602 decorations: highlight(&world, file_id)?,
604 }) 603 })
605} 604}
606 605
607fn highlight(world: &ServerWorld, file_id: FileId) -> Vec<Decoration> { 606fn highlight(world: &ServerWorld, file_id: FileId) -> Result<Vec<Decoration>> {
608 let line_index = world.analysis().file_line_index(file_id); 607 let line_index = world.analysis().file_line_index(file_id);
609 world 608 let res = world
610 .analysis() 609 .analysis()
611 .highlight(file_id) 610 .highlight(file_id)?
612 .into_iter() 611 .into_iter()
613 .map(|h| Decoration { 612 .map(|h| Decoration {
614 range: h.range.conv_with(&line_index), 613 range: h.range.conv_with(&line_index),
615 tag: h.tag, 614 tag: h.tag,
616 }) 615 })
617 .collect() 616 .collect();
617 Ok(res)
618} 618}