实现三种诊断模式
This commit is contained in:
parent
9119cfb0ed
commit
b9c8a2f451
@ -13,7 +13,7 @@ pub fn code_lens(
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
params: &CodeLensParams
|
params: &CodeLensParams
|
||||||
) -> Option<Vec<CodeLens>> {
|
) -> Option<Vec<CodeLens>> {
|
||||||
let hdl_param = server.srcs.hdl_param.clone();
|
let hdl_param = server.db.hdl_param.clone();
|
||||||
let uri = ¶ms.text_document.uri;
|
let uri = ¶ms.text_document.uri;
|
||||||
|
|
||||||
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
|
@ -112,7 +112,7 @@ pub fn vlog_directives_completion(
|
|||||||
let mut completion_items = server.vlog_directives.clone();
|
let mut completion_items = server.vlog_directives.clone();
|
||||||
|
|
||||||
// 再从每个文件中搜集定义的宏
|
// 再从每个文件中搜集定义的宏
|
||||||
let hdl_param = server.srcs.hdl_param.clone();
|
let hdl_param = server.db.hdl_param.clone();
|
||||||
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
|
|
||||||
// 遍历所有的 defines
|
// 遍历所有的 defines
|
||||||
@ -156,7 +156,7 @@ pub fn vlog_directives_completion_without_prefix(
|
|||||||
let mut completion_items = server.vlog_directives.clone();
|
let mut completion_items = server.vlog_directives.clone();
|
||||||
|
|
||||||
// 再从每个文件中搜集定义的宏
|
// 再从每个文件中搜集定义的宏
|
||||||
let hdl_param = server.srcs.hdl_param.clone();
|
let hdl_param = server.db.hdl_param.clone();
|
||||||
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
|
|
||||||
// 遍历所有的 defines
|
// 遍历所有的 defines
|
||||||
@ -253,7 +253,7 @@ fn get_position_port_param_completion(
|
|||||||
language_id: &str
|
language_id: &str
|
||||||
) -> Option<CompletionList> {
|
) -> Option<CompletionList> {
|
||||||
// 判断在不在一个模块内,并获取这个模块
|
// 判断在不在一个模块内,并获取这个模块
|
||||||
let hdl_param = &server.srcs.hdl_param;
|
let hdl_param = &server.db.hdl_param;
|
||||||
let fast_map = hdl_param.path_to_hdl_file.read().unwrap();
|
let fast_map = hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
let path = PathBuf::from_str(url.path()).unwrap();
|
let path = PathBuf::from_str(url.path()).unwrap();
|
||||||
let path = to_escape_path(&path);
|
let path = to_escape_path(&path);
|
||||||
|
@ -15,8 +15,8 @@ pub fn completion(server: &LspServer, params: &CompletionParams) -> Option<Compl
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
server.srcs.wait_parse_ready(&path_string, false);
|
server.db.wait_parse_ready(&path_string, false);
|
||||||
let source = server.srcs.get_source(&path_string)?;
|
let source = server.db.get_source(&path_string)?;
|
||||||
let source = source.read().ok()?;
|
let source = source.read().ok()?;
|
||||||
|
|
||||||
// 获取当前这行的结果和当前光标所在的 token
|
// 获取当前这行的结果和当前光标所在的 token
|
||||||
@ -65,7 +65,7 @@ pub fn completion(server: &LspServer, params: &CompletionParams) -> Option<Compl
|
|||||||
CompletionTriggerKind::INVOKED => {
|
CompletionTriggerKind::INVOKED => {
|
||||||
// 1. 先根据 AST 获取上下文补全项
|
// 1. 先根据 AST 获取上下文补全项
|
||||||
// 去除如下几种情况:module textmacro
|
// 去除如下几种情况:module textmacro
|
||||||
let mut completion_items = server.srcs.get_completions(
|
let mut completion_items = server.db.get_completions(
|
||||||
&token,
|
&token,
|
||||||
source.text.pos_to_byte(&doc.position),
|
source.text.pos_to_byte(&doc.position),
|
||||||
&doc.text_document.uri,
|
&doc.text_document.uri,
|
||||||
@ -216,13 +216,13 @@ fn make_module_completions(
|
|||||||
language_id: &str
|
language_id: &str
|
||||||
) -> Vec<CompletionItem> {
|
) -> Vec<CompletionItem> {
|
||||||
let mut module_completioms = Vec::<CompletionItem>::new();
|
let mut module_completioms = Vec::<CompletionItem>::new();
|
||||||
let hdl_param = server.srcs.hdl_param.clone();
|
let hdl_param = server.db.hdl_param.clone();
|
||||||
|
|
||||||
let prefix = token.to_string().to_lowercase();
|
let prefix = token.to_string().to_lowercase();
|
||||||
let module_name_to_path = hdl_param.module_name_to_path.read().unwrap();
|
let module_name_to_path = hdl_param.module_name_to_path.read().unwrap();
|
||||||
|
|
||||||
// 获取和自动补全相关的配置
|
// 获取和自动补全相关的配置
|
||||||
let auto_add_output_declaration = server.srcs.get_lsp_configuration_bool_value("digital-ide.function.lsp.completion.vlog.auto-add-output-declaration").unwrap_or(true);
|
let auto_add_output_declaration = server.db.get_lsp_configuration_bool_value("digital-ide.function.lsp.completion.vlog.auto-add-output-declaration").unwrap_or(true);
|
||||||
|
|
||||||
// 遍历 hdlparam 中所有的 modules
|
// 遍历 hdlparam 中所有的 modules
|
||||||
for module_name in module_name_to_path.keys() {
|
for module_name in module_name_to_path.keys() {
|
||||||
@ -238,7 +238,7 @@ fn make_module_completions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let (insert_text, module_profile, define_info) = if file_type == "primitives" {
|
let (insert_text, module_profile, define_info) = if file_type == "primitives" {
|
||||||
let primitive_map = server.srcs.primitive_text.name_to_text.read().unwrap();
|
let primitive_map = server.db.primitive_text.name_to_text.read().unwrap();
|
||||||
if let Some(text) = primitive_map.get(&module.name) {
|
if let Some(text) = primitive_map.get(&module.name) {
|
||||||
insert_text.push(make_primitives_instantiation_code(text));
|
insert_text.push(make_primitives_instantiation_code(text));
|
||||||
(
|
(
|
||||||
|
@ -19,8 +19,8 @@ pub fn completion(server: &LspServer, params: &CompletionParams) -> Option<Compl
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
server.srcs.wait_parse_ready(&path_string, false);
|
server.db.wait_parse_ready(&path_string, false);
|
||||||
let source = server.srcs.get_source(&path_string)?;
|
let source = server.db.get_source(&path_string)?;
|
||||||
let source = source.read().ok()?;
|
let source = source.read().ok()?;
|
||||||
|
|
||||||
let line_text = source.text.line(doc.position.line as usize);
|
let line_text = source.text.line(doc.position.line as usize);
|
||||||
@ -30,7 +30,7 @@ pub fn completion(server: &LspServer, params: &CompletionParams) -> Option<Compl
|
|||||||
doc.position,
|
doc.position,
|
||||||
);
|
);
|
||||||
|
|
||||||
let project = server.srcs.vhdl_project.read().ok()?;
|
let project = server.db.vhdl_project.read().ok()?;
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
let global_project = project.as_ref().unwrap();
|
let global_project = project.as_ref().unwrap();
|
||||||
@ -65,7 +65,7 @@ pub fn completion(server: &LspServer, params: &CompletionParams) -> Option<Compl
|
|||||||
// 按下 . 时需要触发的补全效果
|
// 按下 . 时需要触发的补全效果
|
||||||
"." => {
|
"." => {
|
||||||
info!("trigger vhdl dot completion");
|
info!("trigger vhdl dot completion");
|
||||||
let mut completion_items = server.srcs.get_completions(
|
let mut completion_items = server.db.get_completions(
|
||||||
&token,
|
&token,
|
||||||
source.text.pos_to_byte(&doc.position),
|
source.text.pos_to_byte(&doc.position),
|
||||||
&doc.text_document.uri,
|
&doc.text_document.uri,
|
||||||
@ -84,7 +84,7 @@ pub fn completion(server: &LspServer, params: &CompletionParams) -> Option<Compl
|
|||||||
// 一般情况下根据字符触发的补全项目
|
// 一般情况下根据字符触发的补全项目
|
||||||
CompletionTriggerKind::INVOKED => {
|
CompletionTriggerKind::INVOKED => {
|
||||||
// 1. 先根据 AST 获取上下文补全项
|
// 1. 先根据 AST 获取上下文补全项
|
||||||
let mut completion_items = server.srcs.get_completions(
|
let mut completion_items = server.db.get_completions(
|
||||||
&token,
|
&token,
|
||||||
source.text.pos_to_byte(&doc.position),
|
source.text.pos_to_byte(&doc.position),
|
||||||
&doc.text_document.uri,
|
&doc.text_document.uri,
|
||||||
@ -190,7 +190,7 @@ fn make_module_completions(
|
|||||||
language_id: &str
|
language_id: &str
|
||||||
) -> Vec<CompletionItem> {
|
) -> Vec<CompletionItem> {
|
||||||
let mut module_completioms = Vec::<CompletionItem>::new();
|
let mut module_completioms = Vec::<CompletionItem>::new();
|
||||||
let hdl_param = server.srcs.hdl_param.clone();
|
let hdl_param = server.db.hdl_param.clone();
|
||||||
|
|
||||||
let prefix = token.to_string().to_lowercase();
|
let prefix = token.to_string().to_lowercase();
|
||||||
let module_name_to_path = hdl_param.module_name_to_path.read().unwrap();
|
let module_name_to_path = hdl_param.module_name_to_path.read().unwrap();
|
||||||
|
@ -114,17 +114,17 @@ fn goto_instantiation<'a>(
|
|||||||
// let in_scope = compare_pos(&range.start, pos) != 1 && compare_pos(pos, &range.end) != 1;
|
// let in_scope = compare_pos(&range.start, pos) != 1 && compare_pos(pos, &range.end) != 1;
|
||||||
// info!("pos: {pos:?}, param_range: {range:?}, in_scope: {in_scope:?}");
|
// info!("pos: {pos:?}, param_range: {range:?}, in_scope: {in_scope:?}");
|
||||||
if param_range.contains(pos) {
|
if param_range.contains(pos) {
|
||||||
let module = match server.srcs.hdl_param.find_module_by_name(&instance.inst_type) {
|
let module = match server.db.hdl_param.find_module_by_name(&instance.inst_type) {
|
||||||
Some(module) => module,
|
Some(module) => module,
|
||||||
None => return None
|
None => return None
|
||||||
};
|
};
|
||||||
for param in &module.params {
|
for param in &module.params {
|
||||||
if token_name == param.name {
|
if token_name == param.name {
|
||||||
let def_path = server.srcs.hdl_param.find_module_definition_path(&module.name).unwrap();
|
let def_path = server.db.hdl_param.find_module_definition_path(&module.name).unwrap();
|
||||||
let target_uri = Url::from_file_path(def_path).unwrap();
|
let target_uri = Url::from_file_path(def_path).unwrap();
|
||||||
let target_range = param.range.clone();
|
let target_range = param.range.clone();
|
||||||
|
|
||||||
let file_type = server.srcs.hdl_param.find_file_type_by_module_name(&instance.inst_type);
|
let file_type = server.db.hdl_param.find_file_type_by_module_name(&instance.inst_type);
|
||||||
let target_range = match file_type.as_str() {
|
let target_range = match file_type.as_str() {
|
||||||
"common" => {
|
"common" => {
|
||||||
target_range.to_lsp_range()
|
target_range.to_lsp_range()
|
||||||
@ -159,17 +159,17 @@ fn goto_instantiation<'a>(
|
|||||||
// let in_scope = compare_pos(&range.start, pos) != 1 && compare_pos(pos, &range.end) != 1;
|
// let in_scope = compare_pos(&range.start, pos) != 1 && compare_pos(pos, &range.end) != 1;
|
||||||
// info!("pos: {pos:?}, port_range: {range:?}, in_scope: {in_scope:?}");
|
// info!("pos: {pos:?}, port_range: {range:?}, in_scope: {in_scope:?}");
|
||||||
if port_range.contains(pos) {
|
if port_range.contains(pos) {
|
||||||
let module = match server.srcs.hdl_param.find_module_by_name(&instance.inst_type) {
|
let module = match server.db.hdl_param.find_module_by_name(&instance.inst_type) {
|
||||||
Some(module) => module,
|
Some(module) => module,
|
||||||
None => return None
|
None => return None
|
||||||
};
|
};
|
||||||
for port in &module.ports {
|
for port in &module.ports {
|
||||||
if token_name == port.name {
|
if token_name == port.name {
|
||||||
let def_path = server.srcs.hdl_param.find_module_definition_path(&module.name).unwrap();
|
let def_path = server.db.hdl_param.find_module_definition_path(&module.name).unwrap();
|
||||||
let target_uri = Url::from_file_path(def_path).unwrap();
|
let target_uri = Url::from_file_path(def_path).unwrap();
|
||||||
let target_range = port.range.clone();
|
let target_range = port.range.clone();
|
||||||
|
|
||||||
let file_type = server.srcs.hdl_param.find_file_type_by_module_name(&instance.inst_type);
|
let file_type = server.db.hdl_param.find_file_type_by_module_name(&instance.inst_type);
|
||||||
let target_range = match file_type.as_str() {
|
let target_range = match file_type.as_str() {
|
||||||
"common" => {
|
"common" => {
|
||||||
target_range.to_lsp_range()
|
target_range.to_lsp_range()
|
||||||
@ -216,7 +216,7 @@ pub fn goto_position_port_param_definition(
|
|||||||
if name.starts_with(".") {
|
if name.starts_with(".") {
|
||||||
let name = &name[1..];
|
let name = &name[1..];
|
||||||
// 进入最近的 scope 寻找
|
// 进入最近的 scope 寻找
|
||||||
let fast_map = server.srcs.hdl_param.path_to_hdl_file.read().unwrap();
|
let fast_map = server.db.hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
let path = PathBuf::from_str(url.path()).unwrap();
|
let path = PathBuf::from_str(url.path()).unwrap();
|
||||||
let path = to_escape_path(&path);
|
let path = to_escape_path(&path);
|
||||||
let path_string = path.to_str().unwrap();
|
let path_string = path.to_str().unwrap();
|
||||||
@ -237,7 +237,7 @@ pub fn goto_module_declaration_definition(
|
|||||||
server: &LspServer,
|
server: &LspServer,
|
||||||
token_name: &str
|
token_name: &str
|
||||||
) -> Option<GotoDefinitionResponse> {
|
) -> Option<GotoDefinitionResponse> {
|
||||||
let hdl_param = server.srcs.hdl_param.clone();
|
let hdl_param = server.db.hdl_param.clone();
|
||||||
info!("get into goto_module_declaration_definition");
|
info!("get into goto_module_declaration_definition");
|
||||||
|
|
||||||
if let Some((module, file_type, def_path)) = hdl_param.find_module_context_by_name(token_name) {
|
if let Some((module, file_type, def_path)) = hdl_param.find_module_context_by_name(token_name) {
|
||||||
|
@ -15,8 +15,8 @@ pub fn goto_definition(server: &LspServer, params: &GotoDefinitionParams) -> Opt
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
server.srcs.wait_parse_ready(&path_string, false);
|
server.db.wait_parse_ready(&path_string, false);
|
||||||
let source = server.srcs.get_source(&path_string)?;
|
let source = server.db.get_source(&path_string)?;
|
||||||
let source = source.read().ok()?;
|
let source = source.read().ok()?;
|
||||||
|
|
||||||
let line_text = source.text.line(pos.line as usize);
|
let line_text = source.text.line(pos.line as usize);
|
||||||
@ -33,7 +33,7 @@ pub fn goto_definition(server: &LspServer, params: &GotoDefinitionParams) -> Opt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// match instance
|
// match instance
|
||||||
let scope_tree = server.srcs.scope_tree.read().ok()?;
|
let scope_tree = server.db.scope_tree.read().ok()?;
|
||||||
|
|
||||||
// match position port & param
|
// match position port & param
|
||||||
if let Some(definition) = goto_position_port_param_definition(server, &line_text, uri, pos) {
|
if let Some(definition) = goto_position_port_param_definition(server, &line_text, uri, pos) {
|
||||||
|
@ -12,8 +12,8 @@ pub fn goto_vhdl_definition(server: &LspServer, params: &GotoDefinitionParams) -
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
server.srcs.wait_parse_ready(&path_string, false);
|
server.db.wait_parse_ready(&path_string, false);
|
||||||
let source = server.srcs.get_source(&path_string)?;
|
let source = server.db.get_source(&path_string)?;
|
||||||
let source = source.read().ok()?;
|
let source = source.read().ok()?;
|
||||||
|
|
||||||
let line_text = source.text.line(pos.line as usize);
|
let line_text = source.text.line(pos.line as usize);
|
||||||
@ -21,7 +21,7 @@ pub fn goto_vhdl_definition(server: &LspServer, params: &GotoDefinitionParams) -
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
let token: String = get_definition_token(&line_text, pos);
|
let token: String = get_definition_token(&line_text, pos);
|
||||||
|
|
||||||
let project = server.srcs.vhdl_project.read().ok()?;
|
let project = server.db.vhdl_project.read().ok()?;
|
||||||
let global_project = project.as_ref().unwrap();
|
let global_project = project.as_ref().unwrap();
|
||||||
|
|
||||||
let path = match PathBuf::from_str(uri.path()) {
|
let path = match PathBuf::from_str(uri.path()) {
|
||||||
@ -57,7 +57,7 @@ pub fn goto_vhdl_definition(server: &LspServer, params: &GotoDefinitionParams) -
|
|||||||
|
|
||||||
// match instance
|
// match instance
|
||||||
|
|
||||||
// let scope_tree = server.srcs.scope_tree.read().ok()?;
|
// let scope_tree = server.db.scope_tree.read().ok()?;
|
||||||
|
|
||||||
// // match position port & param
|
// // match position port & param
|
||||||
// if let Some(definition) = goto_position_port_param_definition(server, &line_text, doc, pos) {
|
// if let Some(definition) = goto_position_port_param_definition(server, &line_text, doc, pos) {
|
||||||
|
@ -107,9 +107,9 @@ impl AbstractLinterConfiguration for IverilogConfiguration {
|
|||||||
let mut groups = error_description.split(":");
|
let mut groups = error_description.split(":");
|
||||||
if let Some(unknown_module_name) = groups.nth(1) {
|
if let Some(unknown_module_name) = groups.nth(1) {
|
||||||
let unknown_module_name = unknown_module_name.trim();
|
let unknown_module_name = unknown_module_name.trim();
|
||||||
info!("包含 {} ? {}", unknown_module_name, server.srcs.contains_module(unknown_module_name));
|
info!("包含 {} ? {}", unknown_module_name, server.db.contains_module(unknown_module_name));
|
||||||
|
|
||||||
if server.srcs.contains_module(unknown_module_name) {
|
if server.db.contains_module(unknown_module_name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ impl AbstractLinterConfiguration for VerilatorConfiguration {
|
|||||||
|
|
||||||
let output = child.wait_with_output().ok()?;
|
let output = child.wait_with_output().ok()?;
|
||||||
let output_string = String::from_utf8(output.stderr).ok()?;
|
let output_string = String::from_utf8(output.stderr).ok()?;
|
||||||
let lint_level = server.srcs.get_lsp_configuration_string_value("digital-ide.function.lsp.linter.linter-level").unwrap_or("error".to_string());
|
let lint_level = server.db.get_lsp_configuration_string_value("digital-ide.function.lsp.linter.linter-level").unwrap_or("error".to_string());
|
||||||
|
|
||||||
info!("verilator linter: {:?}, output:\n{}", path_string, output_string);
|
info!("verilator linter: {:?}, output:\n{}", path_string, output_string);
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ impl AbstractLinterConfiguration for VerilatorConfiguration {
|
|||||||
// 对于 NOTFOUNDMODULE 进行过滤
|
// 对于 NOTFOUNDMODULE 进行过滤
|
||||||
// 如果存在于 fast 中,则直接跳过
|
// 如果存在于 fast 中,则直接跳过
|
||||||
if let Some(module_name) = match_not_module_found(error_tuple.0.as_str()) {
|
if let Some(module_name) = match_not_module_found(error_tuple.0.as_str()) {
|
||||||
if server.srcs.contains_module(&module_name) {
|
if server.db.contains_module(&module_name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ fn get_all_dependence_files(
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
let mut used_macro_names = HashSet::<String>::new();
|
let mut used_macro_names = HashSet::<String>::new();
|
||||||
|
|
||||||
let hdl_param = server.srcs.hdl_param.clone();
|
let hdl_param = server.db.hdl_param.clone();
|
||||||
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
if let Some(hdl_file) = path_to_hdl_file.get(&path_string) {
|
if let Some(hdl_file) = path_to_hdl_file.get(&path_string) {
|
||||||
for macro_symbol in &hdl_file.parse_result.symbol_table.macro_usages {
|
for macro_symbol in &hdl_file.parse_result.symbol_table.macro_usages {
|
||||||
|
@ -15,8 +15,8 @@ impl LspServer {
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
self.srcs.wait_parse_ready(&path_string, false);
|
self.db.wait_parse_ready(&path_string, false);
|
||||||
let source = self.srcs.get_source(&path_string)?;
|
let source = self.db.get_source(&path_string)?;
|
||||||
let source = source.read().ok()?;
|
let source = source.read().ok()?;
|
||||||
|
|
||||||
let line_text = source.text.line(pos.line as usize);
|
let line_text = source.text.line(pos.line as usize);
|
||||||
|
@ -14,7 +14,7 @@ pub fn document_highlight(
|
|||||||
pos: Position,
|
pos: Position,
|
||||||
uri: &Url
|
uri: &Url
|
||||||
) -> Option<Vec<DocumentHighlight>> {
|
) -> Option<Vec<DocumentHighlight>> {
|
||||||
let scope_tree = server.srcs.scope_tree.read().ok()?;
|
let scope_tree = server.db.scope_tree.read().ok()?;
|
||||||
|
|
||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ pub fn document_highlight(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 获取对应的 AST
|
// 获取对应的 AST
|
||||||
let path_to_hdl_file = server.srcs.hdl_param.path_to_hdl_file.read().unwrap();
|
let path_to_hdl_file = server.db.hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
if let Some(hdl_file) = path_to_hdl_file.get(&path_string) {
|
if let Some(hdl_file) = path_to_hdl_file.get(&path_string) {
|
||||||
if let Some(AstLike::Svlog(syntax_tree)) = &hdl_file.ast_like {
|
if let Some(AstLike::Svlog(syntax_tree)) = &hdl_file.ast_like {
|
||||||
let references = all_identifiers(&syntax_tree, &token);
|
let references = all_identifiers(&syntax_tree, &token);
|
||||||
|
@ -13,7 +13,7 @@ pub fn document_highlight(
|
|||||||
pos: Position,
|
pos: Position,
|
||||||
uri: &Url
|
uri: &Url
|
||||||
) -> Option<Vec<DocumentHighlight>> {
|
) -> Option<Vec<DocumentHighlight>> {
|
||||||
let scope_tree = server.srcs.scope_tree.read().ok()?;
|
let scope_tree = server.db.scope_tree.read().ok()?;
|
||||||
|
|
||||||
// use the byte_idx of the definition if possible, otherwise use the cursor
|
// use the byte_idx of the definition if possible, otherwise use the cursor
|
||||||
let byte_idx = match scope_tree.as_ref()?.get_definition(token, file.text.pos_to_byte(&pos), uri) {
|
let byte_idx = match scope_tree.as_ref()?.get_definition(token, file.text.pos_to_byte(&pos), uri) {
|
||||||
|
@ -10,11 +10,11 @@ pub fn document_symbol(
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
server.srcs.wait_parse_ready(&path_string, false);
|
server.db.wait_parse_ready(&path_string, false);
|
||||||
let source = server.srcs.get_source(&path_string)?;
|
let source = server.db.get_source(&path_string)?;
|
||||||
let source = source.read().ok()?;
|
let source = source.read().ok()?;
|
||||||
|
|
||||||
let scope_tree = server.srcs.scope_tree.read().ok()?;
|
let scope_tree = server.db.scope_tree.read().ok()?;
|
||||||
|
|
||||||
Some(DocumentSymbolResponse::Nested(
|
Some(DocumentSymbolResponse::Nested(
|
||||||
scope_tree.as_ref()?.document_symbols(uri, &source.text),
|
scope_tree.as_ref()?.document_symbols(uri, &source.text),
|
||||||
|
@ -11,13 +11,13 @@ pub fn document_symbol(server: &LspServer, params: &DocumentSymbolParams) -> Opt
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
server.srcs.wait_parse_ready(&path_string, false);
|
server.db.wait_parse_ready(&path_string, false);
|
||||||
// let source_handle = server.srcs.get_source(&path_string)?;
|
// let source_handle = server.db.get_source(&path_string)?;
|
||||||
// let source_handle = source_handle.read().ok()?;
|
// let source_handle = source_handle.read().ok()?;
|
||||||
|
|
||||||
let scope_tree = server.srcs.scope_tree.read().ok()?;
|
let scope_tree = server.db.scope_tree.read().ok()?;
|
||||||
|
|
||||||
let project = server.srcs.vhdl_project.read().ok()?;
|
let project = server.db.vhdl_project.read().ok()?;
|
||||||
let global_project = project.as_ref().unwrap();
|
let global_project = project.as_ref().unwrap();
|
||||||
let path = match PathBuf::from_str(uri.path()) {
|
let path = match PathBuf::from_str(uri.path()) {
|
||||||
Ok(path) => path,
|
Ok(path) => path,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::{path::PathBuf, str::FromStr};
|
use std::{path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
|
use log::info;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tower_lsp::lsp_types::{Diagnostic, Url};
|
use tower_lsp::lsp_types::{Diagnostic, Url};
|
||||||
|
|
||||||
@ -11,7 +12,9 @@ pub async fn publish_diagnostics(
|
|||||||
backend: &Backend,
|
backend: &Backend,
|
||||||
arguments: Vec<Value>
|
arguments: Vec<Value>
|
||||||
) -> tower_lsp::jsonrpc::Result<Option<Value>> {
|
) -> tower_lsp::jsonrpc::Result<Option<Value>> {
|
||||||
let path_string = arguments.get(0).unwrap().to_string();
|
let path_string = arguments.get(0).unwrap().as_str().unwrap();
|
||||||
|
info!("path_string: {:?}", path_string);
|
||||||
|
|
||||||
let uri = Url::from_file_path(path_string).unwrap();
|
let uri = Url::from_file_path(path_string).unwrap();
|
||||||
let path_string = from_uri_to_escape_path_string(&uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(&uri).unwrap();
|
||||||
let pathbuf = PathBuf::from_str(&path_string).unwrap();
|
let pathbuf = PathBuf::from_str(&path_string).unwrap();
|
||||||
@ -35,7 +38,7 @@ pub async fn clear_diagnostics(
|
|||||||
backend: &Backend,
|
backend: &Backend,
|
||||||
arguments: Vec<Value>
|
arguments: Vec<Value>
|
||||||
) -> tower_lsp::jsonrpc::Result<Option<Value>> {
|
) -> tower_lsp::jsonrpc::Result<Option<Value>> {
|
||||||
let path_string = arguments.get(0).unwrap().to_string();
|
let path_string = arguments.get(0).unwrap().as_str().unwrap();
|
||||||
let uri = Url::from_file_path(path_string).unwrap();
|
let uri = Url::from_file_path(path_string).unwrap();
|
||||||
|
|
||||||
let diagnostics = Vec::<Diagnostic>::new();
|
let diagnostics = Vec::<Diagnostic>::new();
|
||||||
|
@ -9,9 +9,9 @@ impl LspServer {
|
|||||||
None
|
None
|
||||||
// let uri = params.text_document.uri;
|
// let uri = params.text_document.uri;
|
||||||
// info!("formatting {}", &uri);
|
// info!("formatting {}", &uri);
|
||||||
// let file_id = self.srcs.get_id(&uri).to_owned();
|
// let file_id = self.db.get_id(&uri).to_owned();
|
||||||
// self.srcs.wait_parse_ready(file_id, false);
|
// self.db.wait_parse_ready(file_id, false);
|
||||||
// let file = self.srcs.get_file(file_id)?;
|
// let file = self.db.get_file(file_id)?;
|
||||||
// let file = file.read().ok()?;
|
// let file = file.read().ok()?;
|
||||||
|
|
||||||
// let conf = self.configuration.read().unwrap();
|
// let conf = self.configuration.read().unwrap();
|
||||||
@ -37,9 +37,9 @@ impl LspServer {
|
|||||||
None
|
None
|
||||||
// let uri = params.text_document.uri;
|
// let uri = params.text_document.uri;
|
||||||
// info!("range formatting {}", &uri);
|
// info!("range formatting {}", &uri);
|
||||||
// let file_id = self.srcs.get_id(&uri).to_owned();
|
// let file_id = self.db.get_id(&uri).to_owned();
|
||||||
// self.srcs.wait_parse_ready(file_id, false);
|
// self.db.wait_parse_ready(file_id, false);
|
||||||
// let file = self.srcs.get_file(file_id)?;
|
// let file = self.db.get_file(file_id)?;
|
||||||
// let file = file.read().ok()?;
|
// let file = file.read().ok()?;
|
||||||
|
|
||||||
// let conf = self.configuration.read().unwrap();
|
// let conf = self.configuration.read().unwrap();
|
||||||
|
@ -235,7 +235,7 @@ fn goto_instantiation<'a>(
|
|||||||
// let in_scope = compare_pos(&range.start, pos) != 1 && compare_pos(pos, &range.end) != 1;
|
// let in_scope = compare_pos(&range.start, pos) != 1 && compare_pos(pos, &range.end) != 1;
|
||||||
// info!("pos: {pos:?}, param_range: {range:?}, in_scope: {in_scope:?}");
|
// info!("pos: {pos:?}, param_range: {range:?}, in_scope: {in_scope:?}");
|
||||||
if param_range.contains(pos) {
|
if param_range.contains(pos) {
|
||||||
let module = match server.srcs.hdl_param.find_module_by_name(&instance.inst_type) {
|
let module = match server.db.hdl_param.find_module_by_name(&instance.inst_type) {
|
||||||
Some(module) => module,
|
Some(module) => module,
|
||||||
None => return None
|
None => return None
|
||||||
};
|
};
|
||||||
@ -244,9 +244,9 @@ fn goto_instantiation<'a>(
|
|||||||
// info!("param_range: {param_range:#?}");
|
// info!("param_range: {param_range:#?}");
|
||||||
// info!("position param find belong module: {:?}", module);
|
// info!("position param find belong module: {:?}", module);
|
||||||
|
|
||||||
let file_type = server.srcs.hdl_param.find_file_type_by_module_name(&instance.inst_type);
|
let file_type = server.db.hdl_param.find_file_type_by_module_name(&instance.inst_type);
|
||||||
if file_type == "primitives" {
|
if file_type == "primitives" {
|
||||||
let primitives_text = server.srcs.primitive_text.clone();
|
let primitives_text = server.db.primitive_text.clone();
|
||||||
let params_assignments = &module.instances.first().unwrap().intstparam_assignments;
|
let params_assignments = &module.instances.first().unwrap().intstparam_assignments;
|
||||||
for assignment in params_assignments {
|
for assignment in params_assignments {
|
||||||
if assignment.parameter.clone().unwrap() == token_name {
|
if assignment.parameter.clone().unwrap() == token_name {
|
||||||
@ -271,7 +271,7 @@ fn goto_instantiation<'a>(
|
|||||||
|
|
||||||
if let Some(port_range) = &instance.instports {
|
if let Some(port_range) = &instance.instports {
|
||||||
if port_range.contains(pos) {
|
if port_range.contains(pos) {
|
||||||
let module = match server.srcs.hdl_param.find_module_by_name(&instance.inst_type) {
|
let module = match server.db.hdl_param.find_module_by_name(&instance.inst_type) {
|
||||||
Some(module) => module,
|
Some(module) => module,
|
||||||
None => return None
|
None => return None
|
||||||
};
|
};
|
||||||
@ -280,9 +280,9 @@ fn goto_instantiation<'a>(
|
|||||||
// info!("port_range: {port_range:#?}");
|
// info!("port_range: {port_range:#?}");
|
||||||
// info!("position port find belong module: {:?}", module);
|
// info!("position port find belong module: {:?}", module);
|
||||||
|
|
||||||
let file_type = server.srcs.hdl_param.find_file_type_by_module_name(&instance.inst_type);
|
let file_type = server.db.hdl_param.find_file_type_by_module_name(&instance.inst_type);
|
||||||
if file_type == "primitives" {
|
if file_type == "primitives" {
|
||||||
let primitives_text = server.srcs.primitive_text.clone();
|
let primitives_text = server.db.primitive_text.clone();
|
||||||
let port_assignments = &module.instances.first().unwrap().intstport_assignments;
|
let port_assignments = &module.instances.first().unwrap().intstport_assignments;
|
||||||
for assignment in port_assignments {
|
for assignment in port_assignments {
|
||||||
if assignment.port.clone().unwrap() == token_name {
|
if assignment.port.clone().unwrap() == token_name {
|
||||||
@ -324,7 +324,7 @@ pub fn hover_position_port_param(
|
|||||||
if name.starts_with(".") {
|
if name.starts_with(".") {
|
||||||
let name = &name[1..];
|
let name = &name[1..];
|
||||||
// 进入最近的 scope 寻找
|
// 进入最近的 scope 寻找
|
||||||
let fast_map = server.srcs.hdl_param.path_to_hdl_file.read().unwrap();
|
let fast_map = server.db.hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
let path = PathBuf::from_str(url.path()).unwrap();
|
let path = PathBuf::from_str(url.path()).unwrap();
|
||||||
let path = to_escape_path(&path);
|
let path = to_escape_path(&path);
|
||||||
let path_string = path.to_str().unwrap();
|
let path_string = path.to_str().unwrap();
|
||||||
@ -448,9 +448,9 @@ pub fn hover_module_declaration(
|
|||||||
) -> Option<Hover> {
|
) -> Option<Hover> {
|
||||||
// info!("hover_module_declaration token: {:?}", token_name);
|
// info!("hover_module_declaration token: {:?}", token_name);
|
||||||
|
|
||||||
// let test = server.srcs.hdl_param.module_name_to_path.read().unwrap();
|
// let test = server.db.hdl_param.module_name_to_path.read().unwrap();
|
||||||
// info!("module name to path: {:#?}", test);
|
// info!("module name to path: {:#?}", test);
|
||||||
let hdl_param = server.srcs.hdl_param.clone();
|
let hdl_param = server.db.hdl_param.clone();
|
||||||
if let Some((module, file_type, def_path)) = hdl_param.find_module_context_by_name(token_name) {
|
if let Some((module, file_type, def_path)) = hdl_param.find_module_context_by_name(token_name) {
|
||||||
match file_type.as_str() {
|
match file_type.as_str() {
|
||||||
"common" => {
|
"common" => {
|
||||||
@ -621,7 +621,7 @@ fn hover_primitives_module_declaration(
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
def_path: &str
|
def_path: &str
|
||||||
) -> Option<Hover> {
|
) -> Option<Hover> {
|
||||||
let primitive_map = server.srcs.primitive_text.name_to_text.read().unwrap();
|
let primitive_map = server.db.primitive_text.name_to_text.read().unwrap();
|
||||||
|
|
||||||
if let Some(text) = primitive_map.get(token_name) {
|
if let Some(text) = primitive_map.get(token_name) {
|
||||||
let mut markdowns = Vec::<MarkedString>::new();
|
let mut markdowns = Vec::<MarkedString>::new();
|
||||||
|
@ -18,8 +18,8 @@ pub fn hover(server: &LspServer, params: &HoverParams) -> Option<Hover> {
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
server.srcs.wait_parse_ready(&path_string, false);
|
server.db.wait_parse_ready(&path_string, false);
|
||||||
let source = server.srcs.get_source(&path_string)?;
|
let source = server.db.get_source(&path_string)?;
|
||||||
let source = source.read().ok()?;
|
let source = source.read().ok()?;
|
||||||
|
|
||||||
let line_text = source.text.line(pos.line as usize);
|
let line_text = source.text.line(pos.line as usize);
|
||||||
@ -55,7 +55,7 @@ pub fn hover(server: &LspServer, params: &HoverParams) -> Option<Hover> {
|
|||||||
return Some(hover);
|
return Some(hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
let scope_tree = server.srcs.scope_tree.read().ok()?;
|
let scope_tree = server.db.scope_tree.read().ok()?;
|
||||||
let global_scope = scope_tree.as_ref().unwrap();
|
let global_scope = scope_tree.as_ref().unwrap();
|
||||||
|
|
||||||
let symbol_definition: GenericDec = global_scope
|
let symbol_definition: GenericDec = global_scope
|
||||||
@ -240,7 +240,7 @@ fn hover_common_symbol(
|
|||||||
// 根据 symbol 的类别进行额外的判断
|
// 根据 symbol 的类别进行额外的判断
|
||||||
match symbol_definition.def_type {
|
match symbol_definition.def_type {
|
||||||
DefinitionType::ModuleInstantiation => {
|
DefinitionType::ModuleInstantiation => {
|
||||||
let hdlparam = server.srcs.hdl_param.clone();
|
let hdlparam = server.db.hdl_param.clone();
|
||||||
let pathbuf = PathBuf::from_str(doc.path()).unwrap();
|
let pathbuf = PathBuf::from_str(doc.path()).unwrap();
|
||||||
let pathbuf = to_escape_path(&pathbuf);
|
let pathbuf = to_escape_path(&pathbuf);
|
||||||
let path_string = pathbuf.to_str().unwrap().replace("\\", "/");
|
let path_string = pathbuf.to_str().unwrap().replace("\\", "/");
|
||||||
@ -301,7 +301,7 @@ fn hover_for_module(server: &LspServer, pos: Position, doc: &Url) -> bool {
|
|||||||
let pathbuf = PathBuf::from_str(doc.path()).unwrap();
|
let pathbuf = PathBuf::from_str(doc.path()).unwrap();
|
||||||
let pathbuf = to_escape_path(&pathbuf);
|
let pathbuf = to_escape_path(&pathbuf);
|
||||||
let path_string = pathbuf.to_str().unwrap().replace("\\", "/");
|
let path_string = pathbuf.to_str().unwrap().replace("\\", "/");
|
||||||
let hdlparam = server.srcs.hdl_param.clone();
|
let hdlparam = server.db.hdl_param.clone();
|
||||||
|
|
||||||
let find_instance_range = |_: &Module, instance: &Instance| {
|
let find_instance_range = |_: &Module, instance: &Instance| {
|
||||||
// info!("instance start pos: {:#?}", instance.range.start);
|
// info!("instance start pos: {:#?}", instance.range.start);
|
||||||
|
@ -16,13 +16,13 @@ pub fn hover(server: &LspServer, params: &HoverParams) -> Option<Hover> {
|
|||||||
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(uri).unwrap();
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
server.srcs.wait_parse_ready(&path_string, false);
|
server.db.wait_parse_ready(&path_string, false);
|
||||||
let source = server.srcs.get_source(&path_string)?;
|
let source = server.db.get_source(&path_string)?;
|
||||||
let source = source.read().ok()?;
|
let source = source.read().ok()?;
|
||||||
|
|
||||||
let line_text = source.text.line(pos.line as usize);
|
let line_text = source.text.line(pos.line as usize);
|
||||||
|
|
||||||
let project = server.srcs.vhdl_project.read().ok()?;
|
let project = server.db.vhdl_project.read().ok()?;
|
||||||
let global_project = project.as_ref().unwrap();
|
let global_project = project.as_ref().unwrap();
|
||||||
|
|
||||||
let path = match PathBuf::from_str(uri.path()) {
|
let path = match PathBuf::from_str(uri.path()) {
|
||||||
@ -56,7 +56,7 @@ pub fn hover(server: &LspServer, params: &HoverParams) -> Option<Hover> {
|
|||||||
// return Some(hover);
|
// return Some(hover);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// let scope_tree = server.srcs.scope_tree.read().ok()?;
|
// let scope_tree = server.db.scope_tree.read().ok()?;
|
||||||
// let global_scope = scope_tree.as_ref().unwrap();
|
// let global_scope = scope_tree.as_ref().unwrap();
|
||||||
|
|
||||||
// let symbol_definition: GenericDec = global_scope
|
// let symbol_definition: GenericDec = global_scope
|
||||||
@ -254,7 +254,7 @@ fn hover_common_symbol(
|
|||||||
// 根据 symbol 的类别进行额外的判断
|
// 根据 symbol 的类别进行额外的判断
|
||||||
match symbol_definition.def_type {
|
match symbol_definition.def_type {
|
||||||
DefinitionType::ModuleInstantiation => {
|
DefinitionType::ModuleInstantiation => {
|
||||||
let hdlparam = server.srcs.hdl_param.clone();
|
let hdlparam = server.db.hdl_param.clone();
|
||||||
let pathbuf = PathBuf::from_str(doc.path()).unwrap();
|
let pathbuf = PathBuf::from_str(doc.path()).unwrap();
|
||||||
let pathbuf = to_escape_path(&pathbuf);
|
let pathbuf = to_escape_path(&pathbuf);
|
||||||
let path_string = pathbuf.to_str().unwrap().replace("\\", "/");
|
let path_string = pathbuf.to_str().unwrap().replace("\\", "/");
|
||||||
|
@ -16,13 +16,13 @@ pub fn inlay_hint(server: &LspServer, params: &InlayHintParams) -> Option<Vec<In
|
|||||||
let visible_range = core::hdlparam::Range::from_lsp_range(¶ms.range);
|
let visible_range = core::hdlparam::Range::from_lsp_range(¶ms.range);
|
||||||
|
|
||||||
// 等待解析完成
|
// 等待解析完成
|
||||||
server.srcs.wait_parse_ready(&path_string, false);
|
server.db.wait_parse_ready(&path_string, false);
|
||||||
let source = server.srcs.get_source(&path_string)?;
|
let source = server.db.get_source(&path_string)?;
|
||||||
let source = source.read().ok()?;
|
let source = source.read().ok()?;
|
||||||
|
|
||||||
let rope = &source.text;
|
let rope = &source.text;
|
||||||
// 先找到 当前 所在的 hdlfile
|
// 先找到 当前 所在的 hdlfile
|
||||||
let path_to_hdl_file = server.srcs.hdl_param.path_to_hdl_file.read().unwrap();
|
let path_to_hdl_file = server.db.hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
if let Some(hdl_file) = &path_to_hdl_file.get(path_string) {
|
if let Some(hdl_file) = &path_to_hdl_file.get(path_string) {
|
||||||
let fast = &hdl_file.fast;
|
let fast = &hdl_file.fast;
|
||||||
let mut hints = Vec::<InlayHint>::new();
|
let mut hints = Vec::<InlayHint>::new();
|
||||||
@ -154,7 +154,7 @@ fn make_instport_hints(
|
|||||||
instance: &core::hdlparam::Instance,
|
instance: &core::hdlparam::Instance,
|
||||||
rope: &Rope
|
rope: &Rope
|
||||||
) -> Vec<InlayHint> {
|
) -> Vec<InlayHint> {
|
||||||
let hdl_param = server.srcs.hdl_param.clone();
|
let hdl_param = server.db.hdl_param.clone();
|
||||||
let mut hints = Vec::<InlayHint>::new();
|
let mut hints = Vec::<InlayHint>::new();
|
||||||
let module_context = hdl_param.find_module_context_by_name(&instance.inst_type);
|
let module_context = hdl_param.find_module_context_by_name(&instance.inst_type);
|
||||||
if module_context.is_none() {
|
if module_context.is_none() {
|
||||||
|
@ -45,7 +45,7 @@ fn update_configuration(
|
|||||||
config_type: String,
|
config_type: String,
|
||||||
backend: &Arc<Backend>
|
backend: &Arc<Backend>
|
||||||
) {
|
) {
|
||||||
let mut lsp_configuration = backend.server.srcs.lsp_configuration.write().unwrap();
|
let mut lsp_configuration = backend.server.db.lsp_configuration.write().unwrap();
|
||||||
|
|
||||||
match config_type.as_str() {
|
match config_type.as_str() {
|
||||||
// 所有配置同步到 lsp_configuration 中
|
// 所有配置同步到 lsp_configuration 中
|
||||||
|
@ -192,7 +192,7 @@ fn do_sv_fast(
|
|||||||
&includes
|
&includes
|
||||||
);
|
);
|
||||||
|
|
||||||
let sources = &backend.server.srcs;
|
let sources = &backend.server.db;
|
||||||
if let Some((syntax_tree, parse_result)) = parse_result {
|
if let Some((syntax_tree, parse_result)) = parse_result {
|
||||||
if let Ok(mut fast) = make_fast_from_syntaxtree(&syntax_tree, &path_buf) {
|
if let Ok(mut fast) = make_fast_from_syntaxtree(&syntax_tree, &path_buf) {
|
||||||
fast.file_type = file_type.to_string();
|
fast.file_type = file_type.to_string();
|
||||||
@ -222,7 +222,7 @@ fn do_vhdl_fast(
|
|||||||
tool_chain: &str,
|
tool_chain: &str,
|
||||||
backend: &Arc<Backend>
|
backend: &Arc<Backend>
|
||||||
) -> Result<FastHdlparam> {
|
) -> Result<FastHdlparam> {
|
||||||
let sources = &backend.server.srcs;
|
let sources = &backend.server.db;
|
||||||
let pathbuf = PathBuf::from_str(path).unwrap();
|
let pathbuf = PathBuf::from_str(path).unwrap();
|
||||||
let hdl_param = sources.hdl_param.clone();
|
let hdl_param = sources.hdl_param.clone();
|
||||||
let vhdl_project = sources.vhdl_project.clone();
|
let vhdl_project = sources.vhdl_project.clone();
|
||||||
@ -377,12 +377,12 @@ pub fn sync_fast(
|
|||||||
let uri = Url::from_file_path(path.to_string()).unwrap();
|
let uri = Url::from_file_path(path.to_string()).unwrap();
|
||||||
let path_string = from_uri_to_escape_path_string(&uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(&uri).unwrap();
|
||||||
|
|
||||||
if let Some(source_handle) = backend.server.srcs.get_source(&path_string) {
|
if let Some(source_handle) = backend.server.db.get_source(&path_string) {
|
||||||
let _unused = source_handle.read().unwrap();
|
let _unused = source_handle.read().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let hdl_param = backend.server.srcs.hdl_param.clone();
|
let hdl_param = backend.server.db.hdl_param.clone();
|
||||||
// TODO: 检查加锁的有效性,因为前端在请求该方法时,后端可能仍然在计算
|
// TODO: 检查加锁的有效性,因为前端在请求该方法时,后端可能仍然在计算
|
||||||
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
if let Some(hdl_file) = path_to_hdl_file.get(&path) {
|
if let Some(hdl_file) = path_to_hdl_file.get(&path) {
|
||||||
|
@ -30,7 +30,7 @@ fn do_primitives_judge(
|
|||||||
name: &str,
|
name: &str,
|
||||||
backend: &Arc<Backend>
|
backend: &Arc<Backend>
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let sources = &backend.server.srcs;
|
let sources = &backend.server.db;
|
||||||
let primitive_text = sources.primitive_text.clone();
|
let primitive_text = sources.primitive_text.clone();
|
||||||
let primitive_map = primitive_text.name_to_text.read().unwrap();
|
let primitive_map = primitive_text.name_to_text.read().unwrap();
|
||||||
primitive_map.contains_key(name)
|
primitive_map.contains_key(name)
|
||||||
|
@ -14,7 +14,7 @@ use tower_lsp::lsp_types::*;
|
|||||||
use tower_lsp::{Client, LanguageServer};
|
use tower_lsp::{Client, LanguageServer};
|
||||||
pub struct LspServer {
|
pub struct LspServer {
|
||||||
/// 文件和 ast 相关的
|
/// 文件和 ast 相关的
|
||||||
pub srcs: Sources,
|
pub db: DigitalDataBase,
|
||||||
/// 缓存
|
/// 缓存
|
||||||
pub cache: CacheManager,
|
pub cache: CacheManager,
|
||||||
/// verilog 关键词的自动补全
|
/// verilog 关键词的自动补全
|
||||||
@ -37,7 +37,7 @@ impl LspServer {
|
|||||||
let user_home = dirs_next::home_dir().unwrap();
|
let user_home = dirs_next::home_dir().unwrap();
|
||||||
let dide_home = user_home.join(".digital-ide");
|
let dide_home = user_home.join(".digital-ide");
|
||||||
LspServer {
|
LspServer {
|
||||||
srcs: Sources::new(),
|
db: DigitalDataBase::new(),
|
||||||
cache: CacheManager::new(dide_home),
|
cache: CacheManager::new(dide_home),
|
||||||
vlog_keyword_completion_items: provide_keyword_completions(VLOG_KEYWORDS),
|
vlog_keyword_completion_items: provide_keyword_completions(VLOG_KEYWORDS),
|
||||||
vhdl_keyword_completiom_items: provide_keyword_completions(VHDL_KEYWORDS),
|
vhdl_keyword_completiom_items: provide_keyword_completions(VHDL_KEYWORDS),
|
||||||
@ -149,17 +149,19 @@ impl LanguageServer for Backend {
|
|||||||
});
|
});
|
||||||
|
|
||||||
info!("当前客户端初始化结果");
|
info!("当前客户端初始化结果");
|
||||||
info!("workspaceFolder: {:?}", configure.workspace_folder);
|
if let Some(workspace_path) = &configure.workspace_folder {
|
||||||
|
info!("workspaceFolder: {:?}", workspace_path.to_file_path());
|
||||||
|
}
|
||||||
info!("extensionPath: {:?}", configure.extension_path);
|
info!("extensionPath: {:?}", configure.extension_path);
|
||||||
info!("toolChain: {:?}", configure.tool_chain);
|
info!("toolChain: {:?}", configure.tool_chain);
|
||||||
|
|
||||||
// 初始化原语系统
|
// 初始化原语系统
|
||||||
self.server.srcs.init_primitive(
|
self.server.db.init_primitive(
|
||||||
&configure.tool_chain,
|
&configure.tool_chain,
|
||||||
&configure.extension_path
|
&configure.extension_path
|
||||||
);
|
);
|
||||||
|
|
||||||
self.server.srcs.init_vhdl_project(&configure.extension_path);
|
self.server.db.init_vhdl_project(&configure.extension_path);
|
||||||
|
|
||||||
// 初始化系统缓存路径
|
// 初始化系统缓存路径
|
||||||
self.server.cache.start(&version);
|
self.server.cache.start(&version);
|
||||||
@ -253,7 +255,7 @@ impl LanguageServer for Backend {
|
|||||||
|
|
||||||
async fn did_close(&self, params: DidCloseTextDocumentParams) {
|
async fn did_close(&self, params: DidCloseTextDocumentParams) {
|
||||||
// 获取诊断相关的配置信息,如果 mode 为 common,则需要清空关闭文件的诊断信息
|
// 获取诊断相关的配置信息,如果 mode 为 common,则需要清空关闭文件的诊断信息
|
||||||
let linter_mode = self.server.srcs.get_lsp_configuration_string_value("digital-ide.function.lsp.linter.linter-mode").unwrap();
|
let linter_mode = self.server.db.get_lsp_configuration_string_value("digital-ide.function.lsp.linter.linter-mode").unwrap();
|
||||||
if linter_mode == "common" {
|
if linter_mode == "common" {
|
||||||
self.client.publish_diagnostics(params.text_document.uri, vec![], None).await;
|
self.client.publish_diagnostics(params.text_document.uri, vec![], None).await;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ impl LspServer {
|
|||||||
let uri = document.uri.clone();
|
let uri = document.uri.clone();
|
||||||
let path_string = from_uri_to_escape_path_string(&uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(&uri).unwrap();
|
||||||
|
|
||||||
if self.srcs.contain_source(&path_string) {
|
if self.db.contain_source(&path_string) {
|
||||||
// 如果已经存在了,则进行增量更新
|
// 如果已经存在了,则进行增量更新
|
||||||
self.did_change(DidChangeTextDocumentParams {
|
self.did_change(DidChangeTextDocumentParams {
|
||||||
text_document: VersionedTextDocumentIdentifier::new(document.uri, document.version),
|
text_document: VersionedTextDocumentIdentifier::new(document.uri, document.version),
|
||||||
@ -52,12 +52,12 @@ impl LspServer {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 如果不存在,直接加入其中
|
// 如果不存在,直接加入其中
|
||||||
self.srcs.add(self, document);
|
self.db.add(self, document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 生成诊断信息
|
// 生成诊断信息
|
||||||
if let Some(source) = self.srcs.get_source(&path_string) {
|
if let Some(source) = self.db.get_source(&path_string) {
|
||||||
let source = source.read().unwrap();
|
let source = source.read().unwrap();
|
||||||
let diagnostics = provide_diagnostics(
|
let diagnostics = provide_diagnostics(
|
||||||
uri,
|
uri,
|
||||||
@ -77,7 +77,7 @@ impl LspServer {
|
|||||||
pub fn did_change(&self, params: DidChangeTextDocumentParams) {
|
pub fn did_change(&self, params: DidChangeTextDocumentParams) {
|
||||||
let path_string = from_uri_to_escape_path_string(¶ms.text_document.uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(¶ms.text_document.uri).unwrap();
|
||||||
|
|
||||||
if let Some(source) = self.srcs.get_source(&path_string) {
|
if let Some(source) = self.db.get_source(&path_string) {
|
||||||
let mut source = source.write().unwrap();
|
let mut source = source.write().unwrap();
|
||||||
|
|
||||||
// 根据输入的 change 动态更新对应的代码的文本片段
|
// 根据输入的 change 动态更新对应的代码的文本片段
|
||||||
@ -93,7 +93,7 @@ impl LspServer {
|
|||||||
drop(source);
|
drop(source);
|
||||||
|
|
||||||
// 唤醒解析线程
|
// 唤醒解析线程
|
||||||
let source_status = self.srcs.get_source_status(&path_string).unwrap();
|
let source_status = self.db.get_source_status(&path_string).unwrap();
|
||||||
let (lock, cvar) = &*source_status.read().unwrap().valid_parse;
|
let (lock, cvar) = &*source_status.read().unwrap().valid_parse;
|
||||||
let mut valid = lock.lock().unwrap();
|
let mut valid = lock.lock().unwrap();
|
||||||
*valid = false;
|
*valid = false;
|
||||||
@ -107,7 +107,7 @@ impl LspServer {
|
|||||||
let uri = params.text_document.uri;
|
let uri = params.text_document.uri;
|
||||||
let path_string = from_uri_to_escape_path_string(&uri).unwrap();
|
let path_string = from_uri_to_escape_path_string(&uri).unwrap();
|
||||||
|
|
||||||
if let Some(source) = self.srcs.get_source(&path_string) {
|
if let Some(source) = self.db.get_source(&path_string) {
|
||||||
let source = source.read().unwrap();
|
let source = source.read().unwrap();
|
||||||
provide_diagnostics(
|
provide_diagnostics(
|
||||||
uri,
|
uri,
|
||||||
@ -131,24 +131,24 @@ impl LspServer {
|
|||||||
|
|
||||||
// 同步
|
// 同步
|
||||||
{
|
{
|
||||||
let mut fast_sync_controller = self.srcs.fast_sync_controller.write().unwrap();
|
let mut fast_sync_controller = self.db.fast_sync_controller.write().unwrap();
|
||||||
fast_sync_controller.remove(&path_string);
|
fast_sync_controller.remove(&path_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hdlparam
|
// hdlparam
|
||||||
{
|
{
|
||||||
self.srcs.hdl_param.delete_file(&path_string);
|
self.db.hdl_param.delete_file(&path_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文本缓冲器
|
// 文本缓冲器
|
||||||
{
|
{
|
||||||
let mut sources = self.srcs.sources.write().unwrap();
|
let mut sources = self.db.sources.write().unwrap();
|
||||||
sources.remove(&path_string);
|
sources.remove(&path_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// scope tree
|
// scope tree
|
||||||
{
|
{
|
||||||
let mut global_scope = self.srcs.scope_tree.write().unwrap();
|
let mut global_scope = self.db.scope_tree.write().unwrap();
|
||||||
match &mut *global_scope {
|
match &mut *global_scope {
|
||||||
Some(scope) => {
|
Some(scope) => {
|
||||||
scope.defs.retain(|x| x.url() != uri);
|
scope.defs.retain(|x| x.url() != uri);
|
||||||
@ -160,7 +160,7 @@ impl LspServer {
|
|||||||
|
|
||||||
// vhdl
|
// vhdl
|
||||||
{
|
{
|
||||||
let mut vhdl_project = self.srcs.vhdl_project.write().unwrap();
|
let mut vhdl_project = self.db.vhdl_project.write().unwrap();
|
||||||
match &mut *vhdl_project {
|
match &mut *vhdl_project {
|
||||||
Some(vhdl_project) => {
|
Some(vhdl_project) => {
|
||||||
let config_file_strs = vhdl_project.config_file_strs.clone()
|
let config_file_strs = vhdl_project.config_file_strs.clone()
|
||||||
@ -206,21 +206,25 @@ pub struct Source {
|
|||||||
/// file metadata, including whether or not the syntax tree is up to date
|
/// file metadata, including whether or not the syntax tree is up to date
|
||||||
pub struct SourceStatus {
|
pub struct SourceStatus {
|
||||||
/// 当前解析的文件的路径
|
/// 当前解析的文件的路径
|
||||||
|
#[allow(unused)]
|
||||||
pub path: String,
|
pub path: String,
|
||||||
/// 用于进行控制的锁
|
/// 用于进行控制的锁
|
||||||
pub valid_parse: Arc<(Mutex<bool>, Condvar)>,
|
pub valid_parse: Arc<(Mutex<bool>, Condvar)>,
|
||||||
/// 解析当前文件的线程句柄
|
/// 解析当前文件的线程句柄,此处必须让句柄被全局变量持有,否则
|
||||||
|
/// 解析线程句柄在离开作用域后会被销毁
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub parse_handle: JoinHandle<()>,
|
pub parse_handle: JoinHandle<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum AstLike {
|
pub enum AstLike {
|
||||||
|
#[allow(unused)]
|
||||||
Svlog(SyntaxTree),
|
Svlog(SyntaxTree),
|
||||||
|
#[allow(unused)]
|
||||||
Vhdl(DesignFile)
|
Vhdl(DesignFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The Sources struct manages all source files
|
/// 用于管理和源代码文本副本、AST、Fast、客户端配置信息等相关的 db 对象
|
||||||
pub struct Sources {
|
pub struct DigitalDataBase {
|
||||||
// 用于存储后端中的前端的文本缓冲区的备份
|
// 用于存储后端中的前端的文本缓冲区的备份
|
||||||
pub sources: Arc<RwLock<HashMap<String, Arc<RwLock<Source>>>>>,
|
pub sources: Arc<RwLock<HashMap<String, Arc<RwLock<Source>>>>>,
|
||||||
// 存储类似于线程句柄等数据的结构
|
// 存储类似于线程句柄等数据的结构
|
||||||
@ -241,13 +245,13 @@ pub struct Sources {
|
|||||||
pub lsp_configuration: Arc<RwLock<HashMap<String, Value>>>
|
pub lsp_configuration: Arc<RwLock<HashMap<String, Value>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::default::Default for Sources {
|
impl std::default::Default for DigitalDataBase {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sources {
|
impl DigitalDataBase {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
sources: Arc::new(RwLock::new(HashMap::new())),
|
sources: Arc::new(RwLock::new(HashMap::new())),
|
||||||
|
@ -8,7 +8,7 @@ impl LspServer {
|
|||||||
/// macro 可以以 ` 开头
|
/// macro 可以以 ` 开头
|
||||||
pub fn find_macros(&self, macro_name: &str) -> Option<(Define, String)> {
|
pub fn find_macros(&self, macro_name: &str) -> Option<(Define, String)> {
|
||||||
let macro_name = macro_name.replace("`", "");
|
let macro_name = macro_name.replace("`", "");
|
||||||
let path_to_hdl_file = self.srcs.hdl_param.path_to_hdl_file.read().unwrap();
|
let path_to_hdl_file = self.db.hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
for (path, hdl_file) in path_to_hdl_file.iter() {
|
for (path, hdl_file) in path_to_hdl_file.iter() {
|
||||||
for define in &hdl_file.fast.fast_macro.defines {
|
for define in &hdl_file.fast.fast_macro.defines {
|
||||||
if define.name == macro_name {
|
if define.name == macro_name {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user