You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: server_state.rs
    path of file: ./repos/sway/sway-lsp/src
    
    the code of the file until where you have to start completion: //! The context or environment in which the l
    
    pub fn spawn_compilation_thread(&self) {
        let is_compiling = self.is_compiling.clone();
        let retrigger_compilation = self.retrigger_compilation.clone();
        let finished_compilation = self.finished_compilation.clone();
        let rx = self.cb_rx.clone();
        let last_compilation_state = self.last_compilation_state.clone();
        let experimental = sway_core::ExperimentalFlags {
            new_encoding: false,
        };
        std::thread::spawn(move || {
            while let Ok(msg) = rx.recv() {
                match msg {
                    TaskMessage::CompilationContext(ctx) => {
                        let uri = ctx.uri.as_ref().unwrap().clone();
                        let session = ctx.session.as_ref().unwrap().clone();
                        let mut engines_clone = session.engines.read().clone();

                        if let Some(version) = ctx.version {
                            // Garbage collection is fairly expsensive so we only clear on every 3rd keystroke.
                            // Waiting too long to clear can cause a stack overflow to occur.
                            if version % 3 == 0 {
                                // Call this on the engines clone so we don't clear types that are still in use
                                // and might be needed in the case cancel compilation was triggered.
                                if let Err(err) = session.garbage_collect(&mut engines_clone) {
                                    tracing::error!(
                                        "Unable to perform garbage collection: {}",
                                        err.to_string()
                                    );
                                }
                            }
                        }

                        let lsp_mode = Some(LspConfig {
                            optimized_build: ctx.optimized_build,
                        });

                        // Set the is_compiling flag to true so that the wait_for_parsing function knows that we are compiling
                        is_compiling.store(true, Ordering::SeqCst);
                        match session::parse_project(
                            &uri,
                            &engines_clone,
                            Some(retrigger_compilation.clone()),
                            lsp_mode,
                            session.clone(),
                            experimental,
                        ) {
                            Ok(_) => {
                                mem::swap(&mut *session.engines.write(), &mut engines_clone);
                                *last_compilation_state.write() = LastCompilationState::Success;
                            }
                            Err(_err) => {
                                *last_compilation_state.write() = LastCompilationState::Failed;
                            }
                        }

                        // Reset the flags to false
                        is_compiling.store(false, Ordering::SeqCst);
                        retrigger_compilation.store(false, Ordering::SeqCst);

                        // Make sure there isn't any pending compilation work
                        if rx.is_empty() {
                            // finished compilation, notify waiters
                            finished_compilation.notify_waiters();
                        }
                    }
                    TaskMessage::Terminate => {
                        // If we receive a terminate message, we need to exit the thread
                        return;
                    }
                }
            }
        });
    }