diff --git a/src/core/hdlparam.rs b/src/core/hdlparam.rs index eb3b99c..85c5047 100644 --- a/src/core/hdlparam.rs +++ b/src/core/hdlparam.rs @@ -34,11 +34,39 @@ impl Range { LspRange::new(start_pos, end_pos) } + #[allow(unused)] + pub fn from_lsp_range(range: &LspRange) -> Range { + Range { + start: Position { + line: range.start.line, + character: range.start.character + }, + end: Position { + line: range.end.line, + character: range.end.character + } + } + } + /// 判断输入的 position 是否在当前 range 内 pub fn contains(&self, postion: &LspPosition) -> bool { compare_pos(&self.start.to_lsp_position(), postion) != 1 && compare_pos(postion, &self.end.to_lsp_position()) != 1 } + #[allow(unused)] + pub fn before(&self, range: &Range) -> bool { + let current_pos = &self.end.to_lsp_position(); + let target_pos = &range.start.to_lsp_position(); + compare_pos(current_pos, target_pos) != 1 + } + + #[allow(unused)] + pub fn after(&self, range: &Range) -> bool { + let current_pos = &self.start.to_lsp_position(); + let target_pos = &range.end.to_lsp_position(); + compare_pos(current_pos, target_pos) != -1 + } + /// 对所有的 line 或者 所有的 character 进行偏移操作 pub fn affine(&mut self, line_offset: i32, character_offset: i32) -> &Range { if line_offset > 0 { @@ -61,6 +89,10 @@ impl Range { } } +/// 比较两个 pos 的位置关系 +/// 1:pos1 在 pos2 后面 +/// 0:pos1 和 pos2 一样 +/// -1:pos1 在 pos2 前面 fn compare_pos(pos1: &LspPosition, pos2: &LspPosition) -> i32 { if pos1.line > pos2.line { 1 diff --git a/src/inlay_hint/mod.rs b/src/inlay_hint/mod.rs new file mode 100644 index 0000000..9ddbfb7 --- /dev/null +++ b/src/inlay_hint/mod.rs @@ -0,0 +1,27 @@ +use crate::server::LSPServer; +use crate::utils::*; +#[allow(unused)] +use log::info; +use tower_lsp::lsp_types::*; + +mod sv; +mod vhdl; + +impl LSPServer { + pub fn inlay_hint(&self, params: InlayHintParams) -> Option> { + let language_id = get_language_id_by_uri(¶ms.text_document.uri); + match language_id.as_str() { + "vhdl" => vhdl::inlay_hint( + self, + ¶ms + ), + + "verilog" | "systemverilog" => sv::inlay_hint( + self, + ¶ms + ), + + _ => None + } + } +} \ No newline at end of file diff --git a/src/inlay_hint/sv.rs b/src/inlay_hint/sv.rs new file mode 100644 index 0000000..9e59f9d --- /dev/null +++ b/src/inlay_hint/sv.rs @@ -0,0 +1,42 @@ +use std::{path::PathBuf, str::FromStr}; + +use crate::{core, server::LSPServer}; +#[allow(unused)] +use log::info; +use tower_lsp::lsp_types::*; + +use super::to_escape_path; + +pub fn inlay_hint(server: &LSPServer, params: &InlayHintParams) -> Option> { + let uri = ¶ms.text_document.uri; + let path = PathBuf::from_str(uri.path()).unwrap(); + let path = to_escape_path(&path); + let path_string = path.to_str().unwrap(); + let visible_range = core::hdlparam::Range::from_lsp_range(¶ms.range); + + let fast_map = server.srcs.hdl_param.path_to_hdl_file.read().unwrap(); + // 先找到 当前 所在的 hdlfile + if let Some(hdl_file) = &fast_map.get(path_string) { + let fast = &hdl_file.fast; + let mut hints = Vec::::new(); + // 制作例化模块的 hint + for module in &fast.content { + for instance in &module.instances { + if let Some(instport_range) = &instance.instports { + // 根据在可见视图外面的 range 就不管了 + if instport_range.before(&visible_range) || instport_range.after(&visible_range) { + continue; + } + + } + + } + } + } + + None +} + +fn make_instport_hint(params: &InlayHintParams) { + +} \ No newline at end of file diff --git a/src/inlay_hint/vhdl.rs b/src/inlay_hint/vhdl.rs new file mode 100644 index 0000000..625ca03 --- /dev/null +++ b/src/inlay_hint/vhdl.rs @@ -0,0 +1,8 @@ +use crate::server::LSPServer; +#[allow(unused)] +use log::info; +use tower_lsp::lsp_types::*; + +pub fn inlay_hint(server: &LSPServer, params: &InlayHintParams) -> Option> { + None +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 8966cd9..4ab6e0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,9 @@ pub mod document_symbol; // 语法高亮 pub mod document_highlight; +// 内部提示 +pub mod inlay_hint; + // 诊断 pub mod diagnostics; diff --git a/src/main.rs b/src/main.rs index f7b98d6..7db8313 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ mod definition; mod hover; mod document_symbol; mod document_highlight; +mod inlay_hint; mod utils; mod diagnostics; mod format; diff --git a/src/server.rs b/src/server.rs index 5570d59..d2ab856 100644 --- a/src/server.rs +++ b/src/server.rs @@ -304,4 +304,11 @@ impl LanguageServer for Backend { ) -> Result>> { Ok(self.server.document_highlight(params)) } + + async fn inlay_hint( + &self, + params: InlayHintParams + ) -> Result>> { + Ok(self.server.inlay_hint(params)) + } }