Process configuration response draft

This commit is contained in:
Kirill Bulatov 2020-03-19 23:56:32 +02:00
parent 8c4aab0c80
commit 019f269a0a
2 changed files with 24 additions and 23 deletions

View file

@ -40,6 +40,7 @@ use crate::{
world::{Options, WorldSnapshot, WorldState}, world::{Options, WorldSnapshot, WorldState},
Result, ServerConfig, Result, ServerConfig,
}; };
use req::ConfigurationParams;
#[derive(Debug)] #[derive(Debug)]
pub struct LspError { pub struct LspError {
@ -336,10 +337,10 @@ struct LoopState {
in_flight_libraries: usize, in_flight_libraries: usize,
pending_libraries: Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)>, pending_libraries: Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)>,
workspace_loaded: bool, workspace_loaded: bool,
roots_progress_reported: Option<usize>, roots_progress_reported: Option<usize>,
roots_scanned: usize, roots_scanned: usize,
roots_total: usize, roots_total: usize,
configuration_request_id: Option<RequestId>,
} }
impl LoopState { impl LoopState {
@ -397,15 +398,14 @@ fn loop_turn(
req, req,
)?, )?,
Message::Notification(not) => { Message::Notification(not) => {
on_notification( on_notification(&connection.sender, world_state, loop_state, not)?;
&connection.sender,
world_state,
&mut loop_state.pending_requests,
&mut loop_state.subscriptions,
not,
)?;
} }
Message::Response(resp) => { Message::Response(resp) => {
if Some(&resp.id) == loop_state.configuration_request_id.as_ref() {
loop_state.configuration_request_id.take();
eprintln!("!!!!!!!!!!!!!!1");
dbg!(&resp);
}
let removed = loop_state.pending_responses.remove(&resp.id); let removed = loop_state.pending_responses.remove(&resp.id);
if !removed { if !removed {
log::error!("unexpected response: {:?}", resp) log::error!("unexpected response: {:?}", resp)
@ -569,8 +569,7 @@ fn on_request(
fn on_notification( fn on_notification(
msg_sender: &Sender<Message>, msg_sender: &Sender<Message>,
state: &mut WorldState, state: &mut WorldState,
pending_requests: &mut PendingRequests, loop_state: &mut LoopState,
subs: &mut Subscriptions,
not: Notification, not: Notification,
) -> Result<()> { ) -> Result<()> {
let not = match notification_cast::<req::Cancel>(not) { let not = match notification_cast::<req::Cancel>(not) {
@ -579,7 +578,7 @@ fn on_notification(
NumberOrString::Number(id) => id.into(), NumberOrString::Number(id) => id.into(),
NumberOrString::String(id) => id.into(), NumberOrString::String(id) => id.into(),
}; };
if pending_requests.cancel(&id) { if loop_state.pending_requests.cancel(&id) {
let response = Response::new_err( let response = Response::new_err(
id, id,
ErrorCode::RequestCanceled as i32, ErrorCode::RequestCanceled as i32,
@ -598,7 +597,7 @@ fn on_notification(
if let Some(file_id) = if let Some(file_id) =
state.vfs.write().add_file_overlay(&path, params.text_document.text) state.vfs.write().add_file_overlay(&path, params.text_document.text)
{ {
subs.add_sub(FileId(file_id.0)); loop_state.subscriptions.add_sub(FileId(file_id.0));
} }
return Ok(()); return Ok(());
} }
@ -629,7 +628,7 @@ fn on_notification(
let uri = params.text_document.uri; let uri = params.text_document.uri;
let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) { if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) {
subs.remove_sub(FileId(file_id.0)); loop_state.subscriptions.remove_sub(FileId(file_id.0));
} }
let params = let params =
req::PublishDiagnosticsParams { uri, diagnostics: Vec::new(), version: None }; req::PublishDiagnosticsParams { uri, diagnostics: Vec::new(), version: None };
@ -641,15 +640,17 @@ fn on_notification(
}; };
let not = match notification_cast::<req::DidChangeConfiguration>(not) { let not = match notification_cast::<req::DidChangeConfiguration>(not) {
Ok(_params) => { Ok(_params) => {
dbg!(_params); let request_id = loop_state.next_request_id();
// let request = request_new::<req::WorkspaceConfiguration>( let request = request_new::<req::WorkspaceConfiguration>(
// loop_state.next_request_id(), request_id.clone(),
// ConfigurationParams::default(), ConfigurationParams::default(),
// ); );
// let zz = connection.sender.send(request.into()).unwrap(); msg_sender.send(request.into()).unwrap();
loop_state.configuration_request_id.replace(request_id);
return Ok(()); return Ok(());
} }
Err(not) => dbg!(not), Err(not) => not,
}; };
let not = match notification_cast::<req::DidChangeWatchedFiles>(not) { let not = match notification_cast::<req::DidChangeWatchedFiles>(not) {
Ok(params) => { Ok(params) => {

View file

@ -12,9 +12,9 @@ export class Config {
private readonly requiresReloadOpts = [ private readonly requiresReloadOpts = [
"serverPath", "serverPath",
"cargoFeatures", "cargoFeatures",
"cargo-watch", "excludeGlobs",
"highlighting.semanticTokens", "useClientWatching",
"inlayHints", "highlighting",
"updates.channel", "updates.channel",
] ]
.map(opt => `${this.rootSection}.${opt}`); .map(opt => `${this.rootSection}.${opt}`);