add vhdl highlight
This commit is contained in:
parent
f0f31c6c97
commit
b84c30ab71
@ -12,7 +12,7 @@ impl LSPServer {
|
|||||||
&self,
|
&self,
|
||||||
params: DocumentHighlightParams,
|
params: DocumentHighlightParams,
|
||||||
) -> Option<Vec<DocumentHighlight>> {
|
) -> Option<Vec<DocumentHighlight>> {
|
||||||
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 pos = params.text_document_position_params.position;
|
||||||
let file_id = self.srcs.get_id(&uri).to_owned();
|
let file_id = self.srcs.get_id(&uri).to_owned();
|
||||||
self.srcs.wait_parse_ready(file_id, false);
|
self.srcs.wait_parse_ready(file_id, false);
|
||||||
@ -24,7 +24,7 @@ impl LSPServer {
|
|||||||
let language_id = get_language_id_by_uri(&uri);
|
let language_id = get_language_id_by_uri(&uri);
|
||||||
|
|
||||||
match language_id.as_str() {
|
match language_id.as_str() {
|
||||||
"vhdl" => vhdl_document_highlight(),
|
"vhdl" => vhdl_document_highlight(self, ¶ms.text_document_position_params),
|
||||||
"verilog" | "systemverilog" => sv_document_highlight(
|
"verilog" | "systemverilog" => sv_document_highlight(
|
||||||
self,
|
self,
|
||||||
&token,
|
&token,
|
||||||
|
@ -1,5 +1,49 @@
|
|||||||
|
use std::{path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
|
use log::info;
|
||||||
use tower_lsp::lsp_types::*;
|
use tower_lsp::lsp_types::*;
|
||||||
|
|
||||||
pub fn vhdl_document_highlight() -> Option<Vec<DocumentHighlight>> {
|
use crate::{server::LSPServer, utils::{from_lsp_pos, to_escape_path, to_lsp_range}};
|
||||||
None
|
|
||||||
|
pub fn vhdl_document_highlight(
|
||||||
|
server: &LSPServer,
|
||||||
|
params: &TextDocumentPositionParams
|
||||||
|
) -> Option<Vec<DocumentHighlight>> {
|
||||||
|
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))?;
|
||||||
|
|
||||||
|
Some(
|
||||||
|
project
|
||||||
|
.find_all_references_in_source(&source, ent)
|
||||||
|
.iter()
|
||||||
|
.map(|pos| DocumentHighlight {
|
||||||
|
range: to_lsp_range(pos.range()),
|
||||||
|
kind: Some(DocumentHighlightKind::TEXT),
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user