@@ -17,14 +17,12 @@ use lsp_types::{
17
17
SemanticTokensParams , SemanticTokensRangeParams , SemanticTokensRangeResult ,
18
18
SemanticTokensResult , SymbolInformation , TextDocumentIdentifier , Url , WorkspaceEdit ,
19
19
} ;
20
- use ra_cfg:: CfgExpr ;
21
20
use ra_ide:: {
22
- FileId , FilePosition , FileRange , Query , RangeInfo , Runnable , RunnableKind , SearchScope ,
23
- TextEdit ,
21
+ FileId , FilePosition , FileRange , Query , RangeInfo , RunnableKind , SearchScope , TextEdit ,
24
22
} ;
25
23
use ra_prof:: profile;
26
24
use ra_project_model:: TargetKind ;
27
- use ra_syntax:: { AstNode , SmolStr , SyntaxKind , TextRange , TextSize } ;
25
+ use ra_syntax:: { AstNode , SyntaxKind , TextRange , TextSize } ;
28
26
use rustc_hash:: FxHashMap ;
29
27
use serde:: { Deserialize , Serialize } ;
30
28
use serde_json:: to_value;
@@ -416,7 +414,7 @@ pub fn handle_runnables(
416
414
}
417
415
}
418
416
}
419
- res. push ( to_lsp_runnable ( & world, file_id, runnable) ?) ;
417
+ res. push ( to_proto :: runnable ( & world, file_id, runnable) ?) ;
420
418
}
421
419
422
420
// Add `cargo check` and `cargo test` for the whole package
@@ -784,7 +782,7 @@ pub fn handle_code_lens(
784
782
}
785
783
} ;
786
784
787
- let mut r = to_lsp_runnable ( & world, file_id, runnable) ?;
785
+ let mut r = to_proto :: runnable ( & world, file_id, runnable) ?;
788
786
if world. config . lens . run {
789
787
let lens = CodeLens {
790
788
range : r. range ,
@@ -959,65 +957,6 @@ pub fn publish_diagnostics(world: &WorldSnapshot, file_id: FileId) -> Result<Dia
959
957
Ok ( DiagnosticTask :: SetNative ( file_id, diagnostics) )
960
958
}
961
959
962
- fn to_lsp_runnable (
963
- world : & WorldSnapshot ,
964
- file_id : FileId ,
965
- runnable : Runnable ,
966
- ) -> Result < lsp_ext:: Runnable > {
967
- let spec = CargoTargetSpec :: for_file ( world, file_id) ?;
968
- let target = spec. as_ref ( ) . map ( |s| s. target . clone ( ) ) ;
969
- let mut features_needed = vec ! [ ] ;
970
- for cfg_expr in & runnable. cfg_exprs {
971
- collect_minimal_features_needed ( cfg_expr, & mut features_needed) ;
972
- }
973
- let ( args, extra_args) =
974
- CargoTargetSpec :: runnable_args ( spec, & runnable. kind , & features_needed) ?;
975
- let line_index = world. analysis ( ) . file_line_index ( file_id) ?;
976
- let label = match & runnable. kind {
977
- RunnableKind :: Test { test_id, .. } => format ! ( "test {}" , test_id) ,
978
- RunnableKind :: TestMod { path } => format ! ( "test-mod {}" , path) ,
979
- RunnableKind :: Bench { test_id } => format ! ( "bench {}" , test_id) ,
980
- RunnableKind :: DocTest { test_id, .. } => format ! ( "doctest {}" , test_id) ,
981
- RunnableKind :: Bin => {
982
- target. map_or_else ( || "run binary" . to_string ( ) , |t| format ! ( "run {}" , t) )
983
- }
984
- } ;
985
-
986
- Ok ( lsp_ext:: Runnable {
987
- range : to_proto:: range ( & line_index, runnable. range ) ,
988
- label,
989
- kind : lsp_ext:: RunnableKind :: Cargo ,
990
- args,
991
- extra_args,
992
- env : {
993
- let mut m = FxHashMap :: default ( ) ;
994
- m. insert ( "RUST_BACKTRACE" . to_string ( ) , "short" . to_string ( ) ) ;
995
- m
996
- } ,
997
- cwd : world. workspace_root_for ( file_id) . map ( |root| root. to_owned ( ) ) ,
998
- } )
999
- }
1000
-
1001
- /// Fill minimal features needed
1002
- fn collect_minimal_features_needed ( cfg_expr : & CfgExpr , features : & mut Vec < SmolStr > ) {
1003
- match cfg_expr {
1004
- CfgExpr :: KeyValue { key, value } if key == "feature" => features. push ( value. clone ( ) ) ,
1005
- CfgExpr :: All ( preds) => {
1006
- preds. iter ( ) . for_each ( |cfg| collect_minimal_features_needed ( cfg, features) ) ;
1007
- }
1008
- CfgExpr :: Any ( preds) => {
1009
- for cfg in preds {
1010
- let len_features = features. len ( ) ;
1011
- collect_minimal_features_needed ( cfg, features) ;
1012
- if len_features != features. len ( ) {
1013
- break ;
1014
- }
1015
- }
1016
- }
1017
- _ => { }
1018
- }
1019
- }
1020
-
1021
960
pub fn handle_inlay_hints (
1022
961
world : WorldSnapshot ,
1023
962
params : InlayHintsParams ,
@@ -1154,54 +1093,3 @@ pub fn handle_semantic_tokens_range(
1154
1093
let semantic_tokens = to_proto:: semantic_tokens ( & text, & line_index, highlights) ;
1155
1094
Ok ( Some ( semantic_tokens. into ( ) ) )
1156
1095
}
1157
-
1158
- #[ cfg( test) ]
1159
- mod tests {
1160
- use super :: * ;
1161
-
1162
- use mbe:: { ast_to_token_tree, TokenMap } ;
1163
- use ra_cfg:: parse_cfg;
1164
- use ra_syntax:: {
1165
- ast:: { self , AstNode } ,
1166
- SmolStr ,
1167
- } ;
1168
-
1169
- fn get_token_tree_generated ( input : & str ) -> ( tt:: Subtree , TokenMap ) {
1170
- let source_file = ast:: SourceFile :: parse ( input) . ok ( ) . unwrap ( ) ;
1171
- let tt = source_file. syntax ( ) . descendants ( ) . find_map ( ast:: TokenTree :: cast) . unwrap ( ) ;
1172
- ast_to_token_tree ( & tt) . unwrap ( )
1173
- }
1174
-
1175
- #[ test]
1176
- fn test_cfg_expr_minimal_features_needed ( ) {
1177
- let ( subtree, _) = get_token_tree_generated ( r#"#![cfg(feature = "baz")]"# ) ;
1178
- let cfg_expr = parse_cfg ( & subtree) ;
1179
- let mut min_features = vec ! [ ] ;
1180
- collect_minimal_features_needed ( & cfg_expr, & mut min_features) ;
1181
-
1182
- assert_eq ! ( min_features, vec![ SmolStr :: new( "baz" ) ] ) ;
1183
-
1184
- let ( subtree, _) =
1185
- get_token_tree_generated ( r#"#![cfg(all(feature = "baz", feature = "foo"))]"# ) ;
1186
- let cfg_expr = parse_cfg ( & subtree) ;
1187
-
1188
- let mut min_features = vec ! [ ] ;
1189
- collect_minimal_features_needed ( & cfg_expr, & mut min_features) ;
1190
- assert_eq ! ( min_features, vec![ SmolStr :: new( "baz" ) , SmolStr :: new( "foo" ) ] ) ;
1191
-
1192
- let ( subtree, _) =
1193
- get_token_tree_generated ( r#"#![cfg(any(feature = "baz", feature = "foo", unix))]"# ) ;
1194
- let cfg_expr = parse_cfg ( & subtree) ;
1195
-
1196
- let mut min_features = vec ! [ ] ;
1197
- collect_minimal_features_needed ( & cfg_expr, & mut min_features) ;
1198
- assert_eq ! ( min_features, vec![ SmolStr :: new( "baz" ) ] ) ;
1199
-
1200
- let ( subtree, _) = get_token_tree_generated ( r#"#![cfg(foo)]"# ) ;
1201
- let cfg_expr = parse_cfg ( & subtree) ;
1202
-
1203
- let mut min_features = vec ! [ ] ;
1204
- collect_minimal_features_needed ( & cfg_expr, & mut min_features) ;
1205
- assert ! ( min_features. is_empty( ) ) ;
1206
- }
1207
- }
0 commit comments