Repository: lapce/lapce
File: lapce-proxy/src/lsp.rs (Rust)

Code before:
        lsp_client.handle_stdout(stdout);
        lsp_client.initialize();

        lsp_client
    }

    fn handle_stdout(&self, stdout: ChildStdout) {
        let local_lsp_client = self.clone();
        thread::spawn(move || {
            let mut reader = Box::new(BufReader::new(stdout));
            loop {
                match read_message(&mut reader) {
                    Ok(message_str) => {
                        local_lsp_client.handle_message(message_str.as_ref());
                    }
                    Err(_err) => {
                        local_lsp_client.stop();
                        local_lsp_client.reload();
                        return;
                    }
                };
            }
        });
    }

    fn process(exec_path: &str, binary_args: Vec<String>) -> Child {
        let mut process = Command::new(exec_path);

        for arg in binary_args {
            process.arg(arg);
        }
        #[cfg(target_os = "windows")]
        let process = process.creation_flags(0x08000000);
        process
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .expect("Error Occurred")
    }

    fn reload(&self) {
        //TODO: avoid clone using a &[String] ?
        let mut process = Self::process(&self.exec_path, self.binary_args.clone());
        let writer = Box::new(BufWriter::new(process.stdin.take().unwrap()));
        let stdout = process.stdout.take().unwrap();

        let mut state = self.state.lock();
        state.next_id = 0;
        state.pending.clear();
        state.opened_documents.clear();
        state.server_capabilities = None;

Review comment (suggestion):
```suggestion
    fn process(exec_path: &str, binary_args: &[String]) -> Child {
```

Oh, I see this is one of your TODOs.

Code after:
        thread::spawn(move || {
            let mut reader = Box::new(BufReader::new(stdout));
            loop {
                match read_message(&mut reader) {
                    Ok(message_str) => {
                        local_lsp_client.handle_message(message_str.as_ref());
                    }
                    Err(_err) => {
                        local_lsp_client.stop();
                        local_lsp_client.reload();
                        return;
                    }
                };
            }
        });
    }

    fn process(exec_path: &str, args: Vec<String>) -> Child {
        let mut process = Command::new(exec_path);

        process.args(args);

        #[cfg(target_os = "windows")]
        let process = process.creation_flags(0x08000000);
        process
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .expect("Error Occurred")
    }

    fn reload(&self) {
        //TODO: avoid clone using a &[String] ?
        let mut process = Self::process(&self.exec_path, self.args.clone());
        let writer = Box::new(BufWriter::new(process.stdin.take().unwrap()));
        let stdout = process.stdout.take().unwrap();

        let mut state = self.state.lock();
        state.next_id = 0;
        state.pending.clear();
        state.opened_documents.clear();
        state.server_capabilities = None;
        state.is_initialized = false;
        state.writer = writer;
        state.process = process;

        self.handle_stdout(stdout);
        self.initialize();
    }

    fn stop(&self) {