mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 13:13:18 +00:00 
			
		
		
		
	Merge #5467
5467: Allow null or empty values for configuration r=matklad a=kjeremy
Allow the client to respond to `workspace/configuration` with `null` values. This is allowed per the spec if the client doesn't know about the configuration we've requested.
This also protects against `null` or `{}` during initialize. I'm not sure if we want to interpret `{}` as "don't change anything" but I think that's a reasonable approach to take.
This should help with LSP clients working out of the box.
Fixes #5464 
Co-authored-by: kjeremy <kjeremy@gmail.com>
			
			
This commit is contained in:
		
						commit
						818aeb8a24
					
				@ -178,6 +178,11 @@ impl Config {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    pub fn update(&mut self, json: serde_json::Value) {
 | 
					    pub fn update(&mut self, json: serde_json::Value) {
 | 
				
			||||||
        log::info!("Config::update({:#})", json);
 | 
					        log::info!("Config::update({:#})", json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if json.is_null() || json.as_object().map_or(false, |it| it.is_empty()) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let data = ConfigData::from_json(json);
 | 
					        let data = ConfigData::from_json(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.with_sysroot = data.withSysroot;
 | 
					        self.with_sysroot = data.withSysroot;
 | 
				
			||||||
 | 
				
			|||||||
@ -468,6 +468,8 @@ impl GlobalState {
 | 
				
			|||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            (None, Some(mut configs)) => {
 | 
					                            (None, Some(mut configs)) => {
 | 
				
			||||||
                                if let Some(json) = configs.get_mut(0) {
 | 
					                                if let Some(json) = configs.get_mut(0) {
 | 
				
			||||||
 | 
					                                    // Note that json can be null according to the spec if the client can't
 | 
				
			||||||
 | 
					                                    // provide a configuration. This is handled in Config::update below.
 | 
				
			||||||
                                    let mut config = this.config.clone();
 | 
					                                    let mut config = this.config.clone();
 | 
				
			||||||
                                    config.update(json.take());
 | 
					                                    config.update(json.take());
 | 
				
			||||||
                                    this.update_configuration(config);
 | 
					                                    this.update_configuration(config);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user