@@ -2,9 +2,10 @@ use std::path::Path;
22
33use futures:: future:: Future ;
44use lsp_types:: { * , request:: * , notification:: * } ;
5+ use serde_json:: json;
56
6- use crate :: support:: basic_bin_manifest;
7- use crate :: support:: project_builder:: project;
7+ use crate :: support:: { basic_bin_manifest, fixtures_dir } ;
8+ use crate :: support:: project_builder:: { project, ProjectBuilder } ;
89
910#[ allow( dead_code) ]
1011mod support;
@@ -970,3 +971,54 @@ fn client_format_utf16_range() {
970971
971972 rls. shutdown ( ) ;
972973}
974+
975+ #[ test]
976+ fn client_lens_run ( ) {
977+ let p = ProjectBuilder :: try_from_fixture ( fixtures_dir ( ) . join ( "lens_run" ) )
978+ . unwrap ( )
979+ . build ( ) ;
980+ let root_path = p. root ( ) ;
981+ let mut rls = p. spawn_rls_async ( ) ;
982+
983+ rls. request :: < Initialize > ( 0 , lsp_types:: InitializeParams {
984+ process_id : None ,
985+ root_uri : None ,
986+ root_path : Some ( root_path. display ( ) . to_string ( ) ) ,
987+ initialization_options : Some ( json ! ( { "cmdRun" : true } ) ) ,
988+ capabilities : Default :: default ( ) ,
989+ trace : None ,
990+ workspace_folders : None ,
991+ } ) ;
992+
993+ rls. wait_for_indexing ( ) ;
994+ assert ! ( rls. messages( ) . iter( ) . count( ) >= 7 ) ;
995+
996+ let lens = rls. request :: < CodeLensRequest > ( 1 , CodeLensParams {
997+ text_document : TextDocumentIdentifier {
998+ uri : Url :: from_file_path ( p. root ( ) . join ( "src/main.rs" ) ) . unwrap ( ) ,
999+ }
1000+ } ) ;
1001+
1002+ let expected = CodeLens {
1003+ command : Some ( Command {
1004+ command : "rls.run" . to_string ( ) ,
1005+ title : "Run test" . to_string ( ) ,
1006+ arguments : Some ( vec ! [
1007+ json!( {
1008+ "args" : [ "test" , "--" , "--nocapture" , "test_foo" ] ,
1009+ "binary" : "cargo" ,
1010+ "env" : { "RUST_BACKTRACE" : "short" }
1011+ } )
1012+ ] ) ,
1013+ } ) ,
1014+ data : None ,
1015+ range : Range {
1016+ start : Position { line : 14 , character : 3 } ,
1017+ end : Position { line : 14 , character : 11 }
1018+ }
1019+ } ;
1020+
1021+ assert_eq ! ( lens, Some ( vec![ expected] ) ) ;
1022+
1023+ rls. shutdown ( ) ;
1024+ }
0 commit comments