取消 loop 中的 fast 计算
This commit is contained in:
parent
10d8e91b6c
commit
ca272a67b8
@ -2,6 +2,7 @@ use crate::definition::extract_defs::get_ident;
|
|||||||
use crate::server::LSPServer;
|
use crate::server::LSPServer;
|
||||||
use crate::sources::LSPSupport;
|
use crate::sources::LSPSupport;
|
||||||
|
|
||||||
|
use log::info;
|
||||||
use ropey::{Rope, RopeSlice};
|
use ropey::{Rope, RopeSlice};
|
||||||
use sv_parser::*;
|
use sv_parser::*;
|
||||||
use tower_lsp::lsp_types::*;
|
use tower_lsp::lsp_types::*;
|
||||||
@ -23,6 +24,8 @@ impl LSPServer {
|
|||||||
let file = file.read().ok()?;
|
let file = file.read().ok()?;
|
||||||
let token: String = get_definition_token(file.text.line(pos.line as usize), pos);
|
let token: String = get_definition_token(file.text.line(pos.line as usize), pos);
|
||||||
|
|
||||||
|
info!("definition token: {:?}", token);
|
||||||
|
|
||||||
let scope_tree = self.srcs.scope_tree.read().ok()?;
|
let scope_tree = self.srcs.scope_tree.read().ok()?;
|
||||||
|
|
||||||
let def = scope_tree
|
let def = scope_tree
|
||||||
|
@ -9,3 +9,4 @@ pub mod server;
|
|||||||
pub mod sources;
|
pub mod sources;
|
||||||
pub mod support;
|
pub mod support;
|
||||||
pub mod custom_request;
|
pub mod custom_request;
|
||||||
|
pub mod test;
|
@ -36,6 +36,8 @@ macro_rules! unwrap_result {
|
|||||||
|
|
||||||
impl LSPServer {
|
impl LSPServer {
|
||||||
pub fn did_open(&self, params: DidOpenTextDocumentParams) -> PublishDiagnosticsParams {
|
pub fn did_open(&self, params: DidOpenTextDocumentParams) -> PublishDiagnosticsParams {
|
||||||
|
info!("[LSPServer] did open");
|
||||||
|
|
||||||
let document: TextDocumentItem = params.text_document;
|
let document: TextDocumentItem = params.text_document;
|
||||||
let uri = document.uri.clone();
|
let uri = document.uri.clone();
|
||||||
|
|
||||||
@ -62,7 +64,8 @@ impl LSPServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn did_change(&self, params: DidChangeTextDocumentParams) {
|
pub fn did_change(&self, params: DidChangeTextDocumentParams) {
|
||||||
debug!("did_change: {}", ¶ms.text_document.uri);
|
info!("[LSPServer] did change");
|
||||||
|
|
||||||
let file_id = self.srcs.get_id(¶ms.text_document.uri);
|
let file_id = self.srcs.get_id(¶ms.text_document.uri);
|
||||||
let file = self.srcs.get_file(file_id).unwrap();
|
let file = self.srcs.get_file(file_id).unwrap();
|
||||||
let mut file = file.write().unwrap();
|
let mut file = file.write().unwrap();
|
||||||
@ -87,6 +90,8 @@ impl LSPServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn did_save(&self, params: DidSaveTextDocumentParams) -> PublishDiagnosticsParams {
|
pub fn did_save(&self, params: DidSaveTextDocumentParams) -> PublishDiagnosticsParams {
|
||||||
|
info!("[LSPServer] did save");
|
||||||
|
|
||||||
let urls = self.srcs.names.read().unwrap().keys().cloned().collect();
|
let urls = self.srcs.names.read().unwrap().keys().cloned().collect();
|
||||||
let file_id = self.srcs.get_id(¶ms.text_document.uri);
|
let file_id = self.srcs.get_id(¶ms.text_document.uri);
|
||||||
let file = self.srcs.get_file(file_id).unwrap();
|
let file = self.srcs.get_file(file_id).unwrap();
|
||||||
@ -241,26 +246,26 @@ impl Sources {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 计算 fast
|
// 计算 fast
|
||||||
if let Some(syntax_tree) = &syntax_tree {
|
// if let Some(syntax_tree) = &syntax_tree {
|
||||||
let path = PathBuf::from(uri.path().to_string());
|
// let path = PathBuf::from(uri.path().to_string());
|
||||||
let fast = if let Ok(fast) = make_fast_from_syntaxtree(&syntax_tree, &path) {
|
// let fast = if let Ok(fast) = make_fast_from_syntaxtree(&syntax_tree, &path) {
|
||||||
fast
|
// fast
|
||||||
} else {
|
// } else {
|
||||||
crate::core::fast_hdlparam::FastHdlparam {
|
// crate::core::fast_hdlparam::FastHdlparam {
|
||||||
fast_macro: crate::core::fast_hdlparam::Macro {
|
// fast_macro: crate::core::fast_hdlparam::Macro {
|
||||||
defines: Vec::new(),
|
// defines: Vec::new(),
|
||||||
errors: Vec::new(),
|
// errors: Vec::new(),
|
||||||
includes: Vec::new(),
|
// includes: Vec::new(),
|
||||||
invalid: Vec::new()
|
// invalid: Vec::new()
|
||||||
},
|
// },
|
||||||
content: Vec::new()
|
// content: Vec::new()
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
// update_fast_to_client(backend.clone(), fast);
|
// // update_fast_to_client(backend.clone(), fast);
|
||||||
block_on(async {
|
// block_on(async {
|
||||||
update_fast_to_client(fast, &path).await;
|
// update_fast_to_client(fast, &path).await;
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
let mut file = source_handle.write().unwrap();
|
let mut file = source_handle.write().unwrap();
|
||||||
|
|
||||||
|
196
src/test/mod.rs
Normal file
196
src/test/mod.rs
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
#[allow(unused)]
|
||||||
|
const TESTFILES_DIR: &str = "testfiles";
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
const DIGTIAL_IDE_TEST: &str = "/home/dide/project/Digital-Test/Digital-IDE-test/user";
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
macro_rules! unwrap_result {
|
||||||
|
($expr:expr) => {
|
||||||
|
match $expr {
|
||||||
|
Ok(e) => e,
|
||||||
|
Err(_) => return
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
macro_rules! unwrap_option {
|
||||||
|
($expr:expr) => {
|
||||||
|
match $expr {
|
||||||
|
Some(e) => e,
|
||||||
|
None => return
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test_fast {
|
||||||
|
use std::{fs, path::Path};
|
||||||
|
use crate::core::sv_parser::sv_parser;
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_testfiles() {
|
||||||
|
let entries = unwrap_result!(fs::read_dir(TESTFILES_DIR));
|
||||||
|
for entry in entries {
|
||||||
|
let entry = unwrap_result!(entry);
|
||||||
|
let file_path = entry.path();
|
||||||
|
if file_path.is_file() {
|
||||||
|
let extension = unwrap_option!(file_path.extension());
|
||||||
|
let file_path = unwrap_option!(file_path.to_str());
|
||||||
|
if extension == "v" || extension == "sv" {
|
||||||
|
println!("Test file: {:?}", file_path);
|
||||||
|
let _ = sv_parser(file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_digital_ide_test() {
|
||||||
|
// 判断路径是否存在且为文件夹
|
||||||
|
let path = Path::new(DIGTIAL_IDE_TEST);
|
||||||
|
if path.exists() && path.is_dir() {
|
||||||
|
// 递归遍历文件夹
|
||||||
|
if let Err(e) = traverse_directory(path) {
|
||||||
|
eprintln!("Error: {}", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Path does not exist or is not a directory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn traverse_directory(dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
if dir.is_dir() {
|
||||||
|
for entry in fs::read_dir(dir)? {
|
||||||
|
let entry = entry?;
|
||||||
|
let path = entry.path();
|
||||||
|
|
||||||
|
if path.is_dir() {
|
||||||
|
// 递归遍历子文件夹
|
||||||
|
traverse_directory(&path)?;
|
||||||
|
} else if path.is_file() {
|
||||||
|
// 检查文件扩展名
|
||||||
|
if let Some(ext) = path.extension() {
|
||||||
|
if ext == "v" || ext == "sv" {
|
||||||
|
println!("Test file: {:?}", path);
|
||||||
|
// TODO: Check Stack Overflow tests
|
||||||
|
if path.to_str().unwrap() == "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/svlog/tools/ivtest/comp1001.sv" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if path.to_str().unwrap() == "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/svlog/tools/ivtest/comp1000.sv" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if path.to_str().unwrap() == "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/svlog/tools/ivtest/br_gh330.sv" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if path.to_str().unwrap() == "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/svlog/tools/hdlconv/pri_encoder_using_assign.sv" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let file_path = path.to_str().unwrap();
|
||||||
|
let _ = sv_parser(file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test_scope_tree {
|
||||||
|
use std::{collections::HashMap, fs, path::{Path, PathBuf}};
|
||||||
|
use crate::definition::{get_scopes, GenericScope};
|
||||||
|
use sv_parser::parse_sv;
|
||||||
|
use tower_lsp::lsp_types::Url;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn get_scope_tree(file_path: &str) -> Option<GenericScope> {
|
||||||
|
let defines = HashMap::new();
|
||||||
|
let includes: Vec<PathBuf> = Vec::new();
|
||||||
|
|
||||||
|
let result = parse_sv(file_path, &defines, &includes, true, true);
|
||||||
|
if let Ok((syntax_tree, _)) = result {
|
||||||
|
let file_url = format!("file://{}", file_path);
|
||||||
|
let uri = Url::parse(&file_url);
|
||||||
|
if let Ok(uri) = uri {
|
||||||
|
return get_scopes(&syntax_tree, &uri);
|
||||||
|
} else {
|
||||||
|
eprintln!("error happen when unwrap uri: {:?}", uri);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_testfiles() {
|
||||||
|
let entries = unwrap_result!(fs::read_dir(TESTFILES_DIR));
|
||||||
|
for entry in entries {
|
||||||
|
let entry = unwrap_result!(entry);
|
||||||
|
let file_path = entry.path();
|
||||||
|
if file_path.is_file() {
|
||||||
|
let extension = unwrap_option!(file_path.extension());
|
||||||
|
let file_path = unwrap_option!(file_path.to_str());
|
||||||
|
if extension == "v" || extension == "sv" {
|
||||||
|
println!("Test file: {:?}", file_path);
|
||||||
|
let _ = get_scope_tree(file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_digital_ide_test() {
|
||||||
|
// 判断路径是否存在且为文件夹
|
||||||
|
let path = Path::new(DIGTIAL_IDE_TEST);
|
||||||
|
if path.exists() && path.is_dir() {
|
||||||
|
// 递归遍历文件夹
|
||||||
|
if let Err(e) = traverse_directory(path) {
|
||||||
|
eprintln!("Error: {}", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Path does not exist or is not a directory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn traverse_directory(dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
if dir.is_dir() {
|
||||||
|
for entry in fs::read_dir(dir)? {
|
||||||
|
let entry = entry?;
|
||||||
|
let path = entry.path();
|
||||||
|
|
||||||
|
if path.is_dir() {
|
||||||
|
// 递归遍历子文件夹
|
||||||
|
traverse_directory(&path)?;
|
||||||
|
} else if path.is_file() {
|
||||||
|
// 检查文件扩展名
|
||||||
|
if let Some(ext) = path.extension() {
|
||||||
|
if ext == "v" || ext == "sv" {
|
||||||
|
println!("Test file: {:?}", path);
|
||||||
|
// TODO: Check Stack Overflow tests
|
||||||
|
if path.to_str().unwrap() == "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/svlog/tools/ivtest/comp1001.sv" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if path.to_str().unwrap() == "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/svlog/tools/ivtest/comp1000.sv" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if path.to_str().unwrap() == "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/svlog/tools/ivtest/br_gh330.sv" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if path.to_str().unwrap() == "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/svlog/tools/hdlconv/pri_encoder_using_assign.sv" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let file_path = path.to_str().unwrap();
|
||||||
|
let _ = get_scope_tree(file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user