test: use global var to fix ownership error

This commit is contained in:
light-ly 2024-09-23 22:06:51 +08:00
parent 15bf62bc5b
commit 0c56fc4ae9
4 changed files with 15 additions and 7 deletions

View File

@ -13,7 +13,7 @@ use crate::core::fast_hdlparam::FastHdlparam;
use crate::core::sv_parser::make_fast_from_syntaxtree;
use crate::definition::get_language_id_by_uri;
use crate::server::Backend;
use crate::server::{Backend, GLOBAL_BACKEND};
use crate::sources::parse;
@ -141,8 +141,8 @@ impl Notification for UpdateFastNotification {
type Params = Self;
}
pub fn update_fast_to_client(backend: Arc<Option<&Backend>>, fast: FastHdlparam) {
let backend = backend.unwrap();
pub fn update_fast_to_client(fast: FastHdlparam) {
let backend = GLOBAL_BACKEND.get().unwrap();
let params = UpdateFastNotification { fast };
backend.client.send_notification::<UpdateFastNotification>(params);
}

View File

@ -18,7 +18,7 @@ mod custom_request;
#[cfg(test)]
mod support;
use server::Backend;
use server::{Backend, GLOBAL_BACKEND};
#[derive(StructOpt, Debug)]
#[structopt(name = "Digtal LSP", about = "LSP for Digital IDE")]
@ -38,7 +38,11 @@ async fn main() {
// let (service, socket) = LspService::new(|client| Arc::new(Backend::new(client, log_handle)));
let (service, socket) = LspService::build(|client| Arc::new(Backend::new(client, log_handle)))
let (service, socket) = LspService::build(|client| {
let backend = Arc::new(Backend::new(client, log_handle));
let _ = GLOBAL_BACKEND.set(backend.clone());
backend
})
.custom_method("custom/request", CustomRequest)
.custom_method("custom/paramRequest", CustomParamRequest)
.custom_method("api/fast", DoFastApi)

View File

@ -2,6 +2,7 @@ use crate::sources::*;
use crate::completion::keyword::*;
use flexi_logger::LoggerHandle;
use log::{debug, info, warn};
use once_cell::sync::OnceCell;
use path_clean::PathClean;
use serde::{Deserialize, Serialize};
use std::env::current_dir;
@ -15,6 +16,8 @@ use tower_lsp::lsp_types::*;
use tower_lsp::{Client, LanguageServer};
use which::which;
pub static GLOBAL_BACKEND: OnceCell<Arc<Backend>> = OnceCell::new();
pub struct LSPServer {
pub srcs: Sources,
pub key_comps: Vec<CompletionItem>,

View File

@ -218,7 +218,7 @@ impl Sources {
let scope_handle = self.scope_tree.clone();
let inc_dirs = self.include_dirs.clone();
let backend = Arc::new(backend);
// let backend = Arc::new(backend);
// spawn parse thread
let parse_handle = thread::spawn(move || {
@ -252,7 +252,8 @@ impl Sources {
content: Vec::new()
}
};
update_fast_to_client(backend.clone(), fast);
// update_fast_to_client(backend.clone(), fast);
update_fast_to_client(fast);
}
let mut file = source_handle.write().unwrap();