完成 fast 的 notification

This commit is contained in:
锦恢 2024-09-24 00:34:16 +08:00
parent 0c56fc4ae9
commit 30cd26cab9
7 changed files with 49 additions and 7 deletions

13
Cargo.lock generated
View File

@ -205,6 +205,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"flexi_logger", "flexi_logger",
"futures",
"log", "log",
"once_cell", "once_cell",
"path-clean", "path-clean",
@ -284,6 +285,7 @@ checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-executor",
"futures-io", "futures-io",
"futures-sink", "futures-sink",
"futures-task", "futures-task",
@ -306,6 +308,17 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
[[package]]
name = "futures-executor"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]] [[package]]
name = "futures-io" name = "futures-io"
version = "0.3.28" version = "0.3.28"

View File

@ -7,6 +7,7 @@ edition = "2018"
[dependencies] [dependencies]
sv-parser = { version = "0.13.3", path = "sv-parser/sv-parser"} sv-parser = { version = "0.13.3", path = "sv-parser/sv-parser"}
once_cell = "1.8" once_cell = "1.8"
futures = "0.3"
log = "0.4.19" log = "0.4.19"
tower-lsp = "0.20.0" tower-lsp = "0.20.0"
flexi_logger = "0.29.0" flexi_logger = "0.29.0"

View File

@ -3,6 +3,7 @@ use std::io::BufRead;
use std::{collections::HashMap, io::BufReader}; use std::{collections::HashMap, io::BufReader};
use std::path::PathBuf; use std::path::PathBuf;
use anyhow::Error; use anyhow::Error;
use log::info;
use sv_parser::{parse_sv, unwrap_node, ConstantMintypmaxExpression, GateInstantiation, ListOfParameterAssignments, ListOfPortConnections, Locate, PackedDimensionRange, RefNode, SyntaxTree}; use sv_parser::{parse_sv, unwrap_node, ConstantMintypmaxExpression, GateInstantiation, ListOfParameterAssignments, ListOfPortConnections, Locate, PackedDimensionRange, RefNode, SyntaxTree};
use super::fast_hdlparam::{FastHdlparam, Macro}; use super::fast_hdlparam::{FastHdlparam, Macro};

View File

@ -131,9 +131,22 @@ pub fn do_fast(path: String) -> Result<FastHdlparam> {
// 下面是服务端发送给客户端的 // 下面是服务端发送给客户端的
#[derive(Serialize, Deserialize)]
pub struct StringNotification {
pub content: String
}
impl Notification for StringNotification {
const METHOD: &'static str = "update/string";
type Params = Self;
}
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct UpdateFastNotification { pub struct UpdateFastNotification {
pub fast: FastHdlparam pub fast: FastHdlparam,
pub path: String
} }
impl Notification for UpdateFastNotification { impl Notification for UpdateFastNotification {
@ -141,8 +154,16 @@ impl Notification for UpdateFastNotification {
type Params = Self; type Params = Self;
} }
pub fn update_fast_to_client(fast: FastHdlparam) {
pub async fn update_fast_to_client(fast: FastHdlparam, path: &PathBuf) {
// info!("send fast to foreend {:?}", fast);
info!("send fast to foreend");
let backend = GLOBAL_BACKEND.get().unwrap(); let backend = GLOBAL_BACKEND.get().unwrap();
let params = UpdateFastNotification { fast }; let path = path.to_str().unwrap_or("").to_string();
backend.client.send_notification::<UpdateFastNotification>(params);
let params = UpdateFastNotification { fast, path };
info!("backend client: {:?}", backend.client);
backend.client.send_notification::<UpdateFastNotification>(params).await;
} }

View File

@ -1,3 +1,4 @@
use crate::custom_request::StringNotification;
use crate::sources::*; use crate::sources::*;
use crate::completion::keyword::*; use crate::completion::keyword::*;
use flexi_logger::LoggerHandle; use flexi_logger::LoggerHandle;
@ -299,6 +300,7 @@ impl LanguageServer for Backend {
.log_message(MessageType::INFO, "digital lsp initialized!") .log_message(MessageType::INFO, "digital lsp initialized!")
.await; .await;
// self.client.send_notification::<StringNotification>(StringNotification { content: "hello from lsp server".to_string() }).await;
} }
async fn shutdown(&self) -> Result<()> { async fn shutdown(&self) -> Result<()> {

View File

@ -1,11 +1,12 @@
use crate::core::sv_parser::make_fast_from_syntaxtree; use crate::core::sv_parser::make_fast_from_syntaxtree;
use crate::custom_request::update_fast_to_client; use crate::custom_request::update_fast_to_client;
use crate::custom_request::UpdateFastNotification;
use crate::definition::def_types::*; use crate::definition::def_types::*;
use crate::definition::get_scopes; use crate::definition::get_scopes;
use crate::diagnostics::{get_diagnostics, is_hidden}; use crate::diagnostics::{get_diagnostics, is_hidden};
use crate::server::Backend; use crate::server::Backend;
use crate::server::LSPServer; use crate::server::LSPServer;
use futures::executor::block_on;
use log::info;
use log::{debug, error}; use log::{debug, error};
use pathdiff::diff_paths; use pathdiff::diff_paths;
use ropey::{Rope, RopeSlice}; use ropey::{Rope, RopeSlice};
@ -13,6 +14,7 @@ use std::cmp::min;
use std::collections::HashMap; use std::collections::HashMap;
use std::env::current_dir; use std::env::current_dir;
use std::fs; use std::fs;
use std::ops::Deref;
use std::ops::Range as StdRange; use std::ops::Range as StdRange;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::{Arc, Condvar, Mutex, RwLock}; use std::sync::{Arc, Condvar, Mutex, RwLock};
@ -253,7 +255,9 @@ impl Sources {
} }
}; };
// update_fast_to_client(backend.clone(), fast); // update_fast_to_client(backend.clone(), fast);
update_fast_to_client(fast); block_on(async {
update_fast_to_client(fast, &path).await;
});
} }
let mut file = source_handle.write().unwrap(); let mut file = source_handle.write().unwrap();

@ -1 +1 @@
Subproject commit af11f5ff1ef091562d2b17cdf4de3614aedf2286 Subproject commit 4960ea3fb7c848462ce6e78dbae454ffc775803f