File tree 4 files changed +70
-0
lines changed
test_data/no_cargo_toml/src
4 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,15 @@ impl ActionContext {
83
83
client_capabilities : lsp_data:: ClientCapabilities ,
84
84
out : O ,
85
85
) {
86
+ let cargo_toml = current_project. join ( "Cargo.toml" ) ;
87
+ if !cargo_toml. is_file ( ) {
88
+ let warning: Notification < ShowMessage > = Notification :: new ( ShowMessageParams {
89
+ typ : MessageType :: Warning ,
90
+ message : format ! ( "A {:?} file is required to support all RLS features" , cargo_toml)
91
+ } ) ;
92
+ out. notify ( warning) ;
93
+ }
94
+
86
95
let ctx = match * self {
87
96
ActionContext :: Uninit ( ref uninit) => {
88
97
let ctx = InitActionContext :: new (
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ extern crate json;
15
15
16
16
#[ macro_use]
17
17
mod harness;
18
+ mod warnings;
18
19
19
20
use analysis;
20
21
use actions:: { requests, notifications} ;
Original file line number Diff line number Diff line change
1
+ use super :: * ;
2
+
3
+ #[ test]
4
+ fn warn_missing_root_cargo_toml ( ) {
5
+ let mut env = Environment :: new ( "no_cargo_toml" ) ;
6
+
7
+ let root_path = env. cache . abs_path ( Path :: new ( "." ) ) ;
8
+ let messages = vec ! [
9
+ initialize( 0 , root_path. as_os_str( ) . to_str( ) . map( |x| x. to_owned( ) ) ) . to_string( ) ,
10
+ ] ;
11
+
12
+ let ( mut server, results) = env. mock_server ( messages) ;
13
+ // Initialize and build.
14
+ assert_eq ! (
15
+ ls_server:: LsService :: handle_message( & mut server) ,
16
+ ls_server:: ServerStateChange :: Continue
17
+ ) ;
18
+ {
19
+ wait_for_n_results ! ( 1 , results) ;
20
+ let response = json:: parse ( & results. lock ( ) . unwrap ( ) . remove ( 0 ) ) . unwrap ( ) ;
21
+ println ! ( "{}" , response. pretty( 2 ) ) ;
22
+ assert ! ( response[ "result" ] [ "capabilities" ] . is_object( ) ) ;
23
+ }
24
+ {
25
+ // showMessage warning
26
+ wait_for_n_results ! ( 1 , results) ;
27
+ let response = json:: parse ( & results. lock ( ) . unwrap ( ) . remove ( 0 ) ) . unwrap ( ) ;
28
+ println ! ( "{}" , response. pretty( 2 ) ) ;
29
+ assert_eq ! ( response[ "method" ] , "window/showMessage" ) ;
30
+ assert_eq ! ( response[ "params" ] [ "type" ] , 2 , "Expected 'warning' message type" ) ;
31
+ let message = response[ "params" ] [ "message" ] . as_str ( ) . unwrap ( ) ;
32
+ assert ! ( message. contains( "Cargo.toml" ) ) ;
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+ struct Bar {
11
+ x : u64 ,
12
+ }
13
+
14
+ #[ test]
15
+ pub fn test_fn ( ) {
16
+ let bar = Bar { x : 4 } ;
17
+ println ! ( "bar: {}" , bar. x) ;
18
+ }
19
+
20
+ pub fn main ( ) {
21
+ let world = "world" ;
22
+ println ! ( "Hello, {}!" , world) ;
23
+
24
+ let bar2 = Bar { x : 5 } ;
25
+ println ! ( "bar2: {}" , bar2. x) ;
26
+ }
You can’t perform that action at this time.
0 commit comments