test: use global var to fix ownership error
This commit is contained in:
parent
15bf62bc5b
commit
0c56fc4ae9
@ -13,7 +13,7 @@ use crate::core::fast_hdlparam::FastHdlparam;
|
|||||||
use crate::core::sv_parser::make_fast_from_syntaxtree;
|
use crate::core::sv_parser::make_fast_from_syntaxtree;
|
||||||
|
|
||||||
use crate::definition::get_language_id_by_uri;
|
use crate::definition::get_language_id_by_uri;
|
||||||
use crate::server::Backend;
|
use crate::server::{Backend, GLOBAL_BACKEND};
|
||||||
use crate::sources::parse;
|
use crate::sources::parse;
|
||||||
|
|
||||||
|
|
||||||
@ -141,8 +141,8 @@ impl Notification for UpdateFastNotification {
|
|||||||
type Params = Self;
|
type Params = Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_fast_to_client(backend: Arc<Option<&Backend>>, fast: FastHdlparam) {
|
pub fn update_fast_to_client(fast: FastHdlparam) {
|
||||||
let backend = backend.unwrap();
|
let backend = GLOBAL_BACKEND.get().unwrap();
|
||||||
let params = UpdateFastNotification { fast };
|
let params = UpdateFastNotification { fast };
|
||||||
backend.client.send_notification::<UpdateFastNotification>(params);
|
backend.client.send_notification::<UpdateFastNotification>(params);
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ mod custom_request;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod support;
|
mod support;
|
||||||
use server::Backend;
|
use server::{Backend, GLOBAL_BACKEND};
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
#[structopt(name = "Digtal LSP", about = "LSP for Digital IDE")]
|
#[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::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/request", CustomRequest)
|
||||||
.custom_method("custom/paramRequest", CustomParamRequest)
|
.custom_method("custom/paramRequest", CustomParamRequest)
|
||||||
.custom_method("api/fast", DoFastApi)
|
.custom_method("api/fast", DoFastApi)
|
||||||
|
@ -2,6 +2,7 @@ use crate::sources::*;
|
|||||||
use crate::completion::keyword::*;
|
use crate::completion::keyword::*;
|
||||||
use flexi_logger::LoggerHandle;
|
use flexi_logger::LoggerHandle;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use path_clean::PathClean;
|
use path_clean::PathClean;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
@ -15,6 +16,8 @@ use tower_lsp::lsp_types::*;
|
|||||||
use tower_lsp::{Client, LanguageServer};
|
use tower_lsp::{Client, LanguageServer};
|
||||||
use which::which;
|
use which::which;
|
||||||
|
|
||||||
|
pub static GLOBAL_BACKEND: OnceCell<Arc<Backend>> = OnceCell::new();
|
||||||
|
|
||||||
pub struct LSPServer {
|
pub struct LSPServer {
|
||||||
pub srcs: Sources,
|
pub srcs: Sources,
|
||||||
pub key_comps: Vec<CompletionItem>,
|
pub key_comps: Vec<CompletionItem>,
|
||||||
|
@ -218,7 +218,7 @@ impl Sources {
|
|||||||
let scope_handle = self.scope_tree.clone();
|
let scope_handle = self.scope_tree.clone();
|
||||||
let inc_dirs = self.include_dirs.clone();
|
let inc_dirs = self.include_dirs.clone();
|
||||||
|
|
||||||
let backend = Arc::new(backend);
|
// let backend = Arc::new(backend);
|
||||||
|
|
||||||
// spawn parse thread
|
// spawn parse thread
|
||||||
let parse_handle = thread::spawn(move || {
|
let parse_handle = thread::spawn(move || {
|
||||||
@ -252,7 +252,8 @@ impl Sources {
|
|||||||
content: Vec::new()
|
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();
|
let mut file = source_handle.write().unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user