diff --git a/src/document_highlight/mod.rs b/src/document_highlight/mod.rs index ea9f358..1530789 100644 --- a/src/document_highlight/mod.rs +++ b/src/document_highlight/mod.rs @@ -12,7 +12,7 @@ impl LSPServer { &self, params: DocumentHighlightParams, ) -> Option> { - let uri = params.text_document_position_params.text_document.uri; + let uri = ¶ms.text_document_position_params.text_document.uri; let pos = params.text_document_position_params.position; let file_id = self.srcs.get_id(&uri).to_owned(); self.srcs.wait_parse_ready(file_id, false); @@ -24,7 +24,7 @@ impl LSPServer { let language_id = get_language_id_by_uri(&uri); match language_id.as_str() { - "vhdl" => vhdl_document_highlight(), + "vhdl" => vhdl_document_highlight(self, ¶ms.text_document_position_params), "verilog" | "systemverilog" => sv_document_highlight( self, &token, diff --git a/src/document_highlight/vhdl.rs b/src/document_highlight/vhdl.rs index 6eeca88..e62de6b 100644 --- a/src/document_highlight/vhdl.rs +++ b/src/document_highlight/vhdl.rs @@ -1,5 +1,49 @@ +use std::{path::PathBuf, str::FromStr}; + +use log::info; use tower_lsp::lsp_types::*; -pub fn vhdl_document_highlight() -> Option> { - None +use crate::{server::LSPServer, utils::{from_lsp_pos, to_escape_path, to_lsp_range}}; + +pub fn vhdl_document_highlight( + server: &LSPServer, + params: &TextDocumentPositionParams +) -> Option> { + let uri = ¶ms.text_document.uri; + let file_id = server.srcs.get_id(&uri).to_owned(); + server.srcs.wait_parse_ready(file_id, false); + let projects = server.srcs.design_file_map.read().ok()?; + + let path = match PathBuf::from_str(uri.path()) { + Ok(path) => path, + Err(error) => { + info!("error happen in : {:?}", error); + return None; + } + }; + let escape_path = to_escape_path(&path); + let escape_path_string = escape_path.to_str().unwrap_or(""); + if escape_path_string.len() == 0 { + info!("error happen in [vhdl_parser_pipeline], escape_path_string is empty"); + return None; + } + let project = match projects.get(escape_path_string) { + Some(project) => project, + None => return None + }; + + let source = project.get_source(&escape_path)?; + + let ent = project.find_declaration(&source, from_lsp_pos(params.position))?; + + Some( + project + .find_all_references_in_source(&source, ent) + .iter() + .map(|pos| DocumentHighlight { + range: to_lsp_range(pos.range()), + kind: Some(DocumentHighlightKind::TEXT), + }) + .collect(), + ) } \ No newline at end of file