diff options
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/cargo_target_spec.rs | 9 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 74 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 25 |
3 files changed, 69 insertions, 39 deletions
diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs index a66f14b82..db9496bbe 100644 --- a/crates/ra_lsp_server/src/cargo_target_spec.rs +++ b/crates/ra_lsp_server/src/cargo_target_spec.rs | |||
@@ -32,6 +32,15 @@ pub(crate) fn runnable_args( | |||
32 | res.push(path.to_string()); | 32 | res.push(path.to_string()); |
33 | res.push("--nocapture".to_string()); | 33 | res.push("--nocapture".to_string()); |
34 | } | 34 | } |
35 | RunnableKind::Bench { name } => { | ||
36 | res.push("bench".to_string()); | ||
37 | if let Some(spec) = spec { | ||
38 | spec.push_to(&mut res); | ||
39 | } | ||
40 | res.push("--".to_string()); | ||
41 | res.push(name.to_string()); | ||
42 | res.push("--nocapture".to_string()); | ||
43 | } | ||
35 | RunnableKind::Bin => { | 44 | RunnableKind::Bin => { |
36 | res.push("run".to_string()); | 45 | res.push("run".to_string()); |
37 | if let Some(spec) = spec { | 46 | if let Some(spec) = spec { |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a781df181..7326a727d 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -2,22 +2,23 @@ use std::collections::HashMap; | |||
2 | 2 | ||
3 | use gen_lsp_server::ErrorCode; | 3 | use gen_lsp_server::ErrorCode; |
4 | use languageserver_types::{ | 4 | use languageserver_types::{ |
5 | CodeActionResponse, Command, CodeLens, Diagnostic, DiagnosticSeverity, DocumentFormattingParams, | 5 | CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, |
6 | DocumentHighlight, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, | 6 | DocumentFormattingParams, DocumentHighlight, DocumentSymbol, Documentation, FoldingRange, |
7 | FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, | 7 | FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, |
8 | ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, RenameParams, | 8 | MarkupKind, ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, |
9 | SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit, | 9 | RenameParams, SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, |
10 | WorkspaceEdit, | ||
10 | }; | 11 | }; |
11 | use ra_ide_api::{ | 12 | use ra_ide_api::{ |
12 | FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, RangeInfo, | 13 | FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, |
13 | }; | 14 | }; |
14 | use ra_syntax::{TextUnit, AstNode}; | 15 | use ra_syntax::{AstNode, TextUnit}; |
15 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
16 | use serde_json::to_value; | 17 | use serde_json::to_value; |
17 | use std::io::Write; | 18 | use std::io::Write; |
18 | 19 | ||
19 | use crate::{ | 20 | use crate::{ |
20 | cargo_target_spec::{CargoTargetSpec, runnable_args}, | 21 | cargo_target_spec::{runnable_args, CargoTargetSpec}, |
21 | conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith}, | 22 | conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith}, |
22 | req::{self, Decoration}, | 23 | req::{self, Decoration}, |
23 | server_world::ServerWorld, | 24 | server_world::ServerWorld, |
@@ -258,6 +259,7 @@ pub fn handle_runnables( | |||
258 | label: match &runnable.kind { | 259 | label: match &runnable.kind { |
259 | RunnableKind::Test { name } => format!("test {}", name), | 260 | RunnableKind::Test { name } => format!("test {}", name), |
260 | RunnableKind::TestMod { path } => format!("test-mod {}", path), | 261 | RunnableKind::TestMod { path } => format!("test-mod {}", path), |
262 | RunnableKind::Bench { name } => format!("bench {}", name), | ||
261 | RunnableKind::Bin => "run binary".to_string(), | 263 | RunnableKind::Bin => "run binary".to_string(), |
262 | }, | 264 | }, |
263 | bin: "cargo".to_string(), | 265 | bin: "cargo".to_string(), |
@@ -586,35 +588,37 @@ pub fn handle_code_lens( | |||
586 | let mut lenses: Vec<CodeLens> = Default::default(); | 588 | let mut lenses: Vec<CodeLens> = Default::default(); |
587 | 589 | ||
588 | for runnable in world.analysis().runnables(file_id)? { | 590 | for runnable in world.analysis().runnables(file_id)? { |
589 | match &runnable.kind { | 591 | let title = match &runnable.kind { |
590 | RunnableKind::Test { name: _ } | RunnableKind::TestMod { path: _ } => { | 592 | RunnableKind::Test { name: _ } | RunnableKind::TestMod { path: _ } => Some("Run Test"), |
591 | let args = runnable_args(&world, file_id, &runnable.kind)?; | 593 | RunnableKind::Bench { name: _ } => Some("Run Bench"), |
592 | 594 | _ => None, | |
593 | let range = runnable.range.conv_with(&line_index); | 595 | }; |
594 | |||
595 | // This represents the actual command that will be run. | ||
596 | let r: req::Runnable = req::Runnable { | ||
597 | range, | ||
598 | label: Default::default(), | ||
599 | bin: "cargo".into(), | ||
600 | args, | ||
601 | env: Default::default(), | ||
602 | }; | ||
603 | 596 | ||
604 | let lens = CodeLens { | 597 | if let Some(title) = title { |
605 | range, | 598 | let args = runnable_args(&world, file_id, &runnable.kind)?; |
606 | command: Some(Command { | 599 | let range = runnable.range.conv_with(&line_index); |
607 | title: "Run Test".into(), | 600 | |
608 | command: "ra-lsp.run-single".into(), | 601 | // This represents the actual command that will be run. |
609 | arguments: Some(vec![to_value(r).unwrap()]), | 602 | let r: req::Runnable = req::Runnable { |
610 | }), | 603 | range, |
611 | data: None, | 604 | label: Default::default(), |
612 | }; | 605 | bin: "cargo".into(), |
606 | args, | ||
607 | env: Default::default(), | ||
608 | }; | ||
613 | 609 | ||
614 | lenses.push(lens); | 610 | let lens = CodeLens { |
615 | } | 611 | range, |
616 | _ => continue, | 612 | command: Some(Command { |
617 | }; | 613 | title: title.into(), |
614 | command: "ra-lsp.run-single".into(), | ||
615 | arguments: Some(vec![to_value(r).unwrap()]), | ||
616 | }), | ||
617 | data: None, | ||
618 | }; | ||
619 | |||
620 | lenses.push(lens); | ||
621 | } | ||
618 | } | 622 | } |
619 | 623 | ||
620 | return Ok(Some(lenses)); | 624 | return Ok(Some(lenses)); |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 4f3c231d3..d5dbf999f 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -73,7 +73,9 @@ impl ServerWorldState { | |||
73 | if let (Some(&from), Some(&to)) = | 73 | if let (Some(&from), Some(&to)) = |
74 | (sysroot_crates.get(&from), sysroot_crates.get(&to)) | 74 | (sysroot_crates.get(&from), sysroot_crates.get(&to)) |
75 | { | 75 | { |
76 | crate_graph.add_dep(from, name.clone(), to); | 76 | if let Err(_) = crate_graph.add_dep(from, name.clone(), to) { |
77 | log::error!("cyclic dependency between sysroot crates") | ||
78 | } | ||
77 | } | 79 | } |
78 | } | 80 | } |
79 | } | 81 | } |
@@ -108,11 +110,20 @@ impl ServerWorldState { | |||
108 | for &from in pkg_crates.get(&pkg).into_iter().flatten() { | 110 | for &from in pkg_crates.get(&pkg).into_iter().flatten() { |
109 | if let Some(to) = lib_tgt { | 111 | if let Some(to) = lib_tgt { |
110 | if to != from { | 112 | if to != from { |
111 | crate_graph.add_dep(from, pkg.name(&ws.cargo).into(), to); | 113 | if let Err(_) = |
114 | crate_graph.add_dep(from, pkg.name(&ws.cargo).into(), to) | ||
115 | { | ||
116 | log::error!( | ||
117 | "cyclic dependency between targets of {}", | ||
118 | pkg.name(&ws.cargo) | ||
119 | ) | ||
120 | } | ||
112 | } | 121 | } |
113 | } | 122 | } |
114 | if let Some(std) = libstd { | 123 | if let Some(std) = libstd { |
115 | crate_graph.add_dep(from, "std".into(), std); | 124 | if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { |
125 | log::error!("cyclic dependency on std for {}", pkg.name(&ws.cargo)) | ||
126 | } | ||
116 | } | 127 | } |
117 | } | 128 | } |
118 | } | 129 | } |
@@ -123,7 +134,13 @@ impl ServerWorldState { | |||
123 | for dep in pkg.dependencies(&ws.cargo) { | 134 | for dep in pkg.dependencies(&ws.cargo) { |
124 | if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) { | 135 | if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) { |
125 | for &from in pkg_crates.get(&pkg).into_iter().flatten() { | 136 | for &from in pkg_crates.get(&pkg).into_iter().flatten() { |
126 | crate_graph.add_dep(from, dep.name.clone(), to); | 137 | if let Err(_) = crate_graph.add_dep(from, dep.name.clone(), to) { |
138 | log::error!( | ||
139 | "cyclic dependency {} -> {}", | ||
140 | pkg.name(&ws.cargo), | ||
141 | dep.pkg.name(&ws.cargo) | ||
142 | ) | ||
143 | } | ||
127 | } | 144 | } |
128 | } | 145 | } |
129 | } | 146 | } |