add vhdl hover
This commit is contained in:
parent
da06620710
commit
e289d8089f
@ -1,9 +1,46 @@
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
|
||||
use log::info;
|
||||
use tower_lsp::lsp_types::*;
|
||||
use crate::server::LSPServer;
|
||||
|
||||
pub fn hover_vhdl(server: &LSPServer, param: &DocumentSymbolParams) -> Option<Hover> {
|
||||
let design_file = server.srcs.design_file_map.write().unwrap();
|
||||
|
||||
|
||||
None
|
||||
use super::{from_lsp_pos, to_escape_path};
|
||||
|
||||
pub fn hover_vhdl(server: &LSPServer, params: &TextDocumentPositionParams) -> Option<Hover> {
|
||||
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 <goto_include_definition>: {:?}", 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))?;
|
||||
|
||||
let value = project.format_declaration(ent)?;
|
||||
|
||||
Some(Hover {
|
||||
contents: HoverContents::Markup(MarkupContent {
|
||||
kind: MarkupKind::Markdown,
|
||||
value: format!("```vhdl\n{value}\n```"),
|
||||
}),
|
||||
range: None,
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user