完成 vhdl fast 的兼容
This commit is contained in:
parent
69a60a2b8e
commit
1308a35546
19
.vscode/lsp.code-snippets
vendored
Normal file
19
.vscode/lsp.code-snippets
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
// "Print to console": {
|
||||||
|
// "scope": "javascript,typescript",
|
||||||
|
// "prefix": "log",
|
||||||
|
// "body": [
|
||||||
|
// "console.log('$1');",
|
||||||
|
// "$2"
|
||||||
|
// ],
|
||||||
|
// "description": "Log output to console"
|
||||||
|
// }
|
||||||
|
"allow unused": {
|
||||||
|
"scope": "rust",
|
||||||
|
"prefix": "allowunused",
|
||||||
|
"body": [
|
||||||
|
"#[allow(unused)]"
|
||||||
|
],
|
||||||
|
"description": "#[allow(unused)]"
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,10 @@
|
|||||||
use std::{fs, path::PathBuf, str::FromStr};
|
use std::{fs, path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use regex::Regex;
|
|
||||||
use ropey::RopeSlice;
|
use ropey::RopeSlice;
|
||||||
use tower_lsp::lsp_types::{CompletionItem, CompletionItemKind, CompletionItemLabelDetails, CompletionList, Position, Url};
|
use tower_lsp::lsp_types::{CompletionItem, CompletionItemKind, CompletionItemLabelDetails, CompletionList, Position, Url};
|
||||||
|
|
||||||
use crate::{server::LSPServer, utils::{get_word_range_at_position, resolve_path, to_escape_path}};
|
use crate::{server::LSPServer, utils::{resolve_path, to_escape_path}};
|
||||||
|
|
||||||
pub fn include_path_completion(uri: &Url, line: &RopeSlice, pos: Position) -> Option<CompletionList> {
|
pub fn include_path_completion(uri: &Url, line: &RopeSlice, pos: Position) -> Option<CompletionList> {
|
||||||
let line_text = line.as_str().unwrap_or("");
|
let line_text = line.as_str().unwrap_or("");
|
||||||
@ -144,9 +143,11 @@ fn is_port_completion(line: &RopeSlice, pos: &Position) -> bool {
|
|||||||
|
|
||||||
fn get_position_port_param_completion(
|
fn get_position_port_param_completion(
|
||||||
server: &LSPServer,
|
server: &LSPServer,
|
||||||
|
#[allow(unused)]
|
||||||
line: &RopeSlice,
|
line: &RopeSlice,
|
||||||
url: &Url,
|
url: &Url,
|
||||||
pos: &Position,
|
pos: &Position,
|
||||||
|
#[allow(unused)]
|
||||||
language_id: &str
|
language_id: &str
|
||||||
) -> Option<CompletionList> {
|
) -> Option<CompletionList> {
|
||||||
// 判断在不在一个模块内,并获取这个模块
|
// 判断在不在一个模块内,并获取这个模块
|
||||||
@ -225,7 +226,7 @@ fn get_position_port_param_completion(
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_port_desc(port: &crate::core::fast_hdlparam::Port) -> String {
|
fn make_port_desc(port: &crate::core::hdlparam::Port) -> String {
|
||||||
let mut port_desc_array = Vec::<String>::new();
|
let mut port_desc_array = Vec::<String>::new();
|
||||||
port_desc_array.push(port.dir_type.to_string());
|
port_desc_array.push(port.dir_type.to_string());
|
||||||
if port.net_type != "unknown" {
|
if port.net_type != "unknown" {
|
||||||
@ -245,11 +246,12 @@ fn make_port_desc(port: &crate::core::fast_hdlparam::Port) -> String {
|
|||||||
port_desc
|
port_desc
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_param_desc(param: &crate::core::fast_hdlparam::Parameter) -> String {
|
fn make_param_desc(param: &crate::core::hdlparam::Parameter) -> String {
|
||||||
let mut param_desc_array = Vec::<String>::new();
|
let mut param_desc_array = Vec::<String>::new();
|
||||||
param_desc_array.push(format!("parameter {}", param.name));
|
param_desc_array.push(format!("parameter {}", param.name));
|
||||||
|
|
||||||
if param.init != "unknown" {
|
if param.init != "unknown" {
|
||||||
|
param_desc_array.push("=".to_string());
|
||||||
param_desc_array.push(param.init.to_string());
|
param_desc_array.push(param.init.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ pub fn completion(server: &LSPServer, params: &CompletionParams) -> Option<Compl
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn completion_item_to_lsp_item(
|
fn completion_item_to_lsp_item(
|
||||||
|
#[allow(unused)]
|
||||||
server: &LSPServer,
|
server: &LSPServer,
|
||||||
item: vhdl_lang::CompletionItem,
|
item: vhdl_lang::CompletionItem,
|
||||||
) -> CompletionItem {
|
) -> CompletionItem {
|
||||||
|
12
src/core/cache_storage.rs
Normal file
12
src/core/cache_storage.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/// 用于进行高效 IR 缓存的模块
|
||||||
|
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn dump_ir_storage() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn load_ir_storage() {
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
pub mod fast_hdlparam;
|
pub mod hdlparam;
|
||||||
// pub use fast_hdlparam::*;
|
|
||||||
|
|
||||||
pub mod sv_parser;
|
pub mod sv_parser;
|
||||||
// pub use sv_parser::*;
|
|
||||||
|
|
||||||
pub mod vhdl_parser;
|
pub mod vhdl_parser;
|
||||||
|
|
||||||
|
pub mod cache_storage;
|
@ -11,7 +11,7 @@ use sv_parser::{unwrap_node, Locate, RefNode, SyntaxTree};
|
|||||||
use crate::sources::recovery_sv_parse;
|
use crate::sources::recovery_sv_parse;
|
||||||
use crate::utils::to_escape_path;
|
use crate::utils::to_escape_path;
|
||||||
|
|
||||||
use super::fast_hdlparam::{FastHdlparam, Macro};
|
use super::hdlparam::{FastHdlparam, Macro};
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn sv_parser(path: &str) -> Option<FastHdlparam> {
|
pub fn sv_parser(path: &str) -> Option<FastHdlparam> {
|
||||||
@ -86,7 +86,7 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Re
|
|||||||
Some(RefNode::DefaultText(x)) => syntax_tree.get_str(&x.nodes.0).unwrap(),
|
Some(RefNode::DefaultText(x)) => syntax_tree.get_str(&x.nodes.0).unwrap(),
|
||||||
_ => "Unknown"
|
_ => "Unknown"
|
||||||
};
|
};
|
||||||
params_vec.push(crate::core::fast_hdlparam::DefineParam { name: param_name.to_string(), value: param_val.to_string() });
|
params_vec.push(crate::core::hdlparam::DefineParam { name: param_name.to_string(), value: param_val.to_string() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -590,7 +590,7 @@ fn get_identifier(node: RefNode) -> Option<Locate> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_includes(path: &PathBuf) -> Vec<crate::core::fast_hdlparam::Include> {
|
fn get_includes(path: &PathBuf) -> Vec<crate::core::hdlparam::Include> {
|
||||||
let mut includes = Vec::new();
|
let mut includes = Vec::new();
|
||||||
|
|
||||||
let file = File::open(path).unwrap();
|
let file = File::open(path).unwrap();
|
||||||
@ -607,13 +607,13 @@ fn get_includes(path: &PathBuf) -> Vec<crate::core::fast_hdlparam::Include> {
|
|||||||
let path = parts[1];
|
let path = parts[1];
|
||||||
let last_character = line_content.find(path).unwrap() + path.len();
|
let last_character = line_content.find(path).unwrap() + path.len();
|
||||||
|
|
||||||
includes.push(crate::core::fast_hdlparam::Include {
|
includes.push(crate::core::hdlparam::Include {
|
||||||
path: path.to_string(),
|
path: path.to_string(),
|
||||||
range: crate::core::fast_hdlparam::Range {
|
range: crate::core::hdlparam::Range {
|
||||||
start: crate::core::fast_hdlparam::Position {
|
start: crate::core::hdlparam::Position {
|
||||||
line: (line_number + 1) as u32, character: 1
|
line: (line_number + 1) as u32, character: 1
|
||||||
},
|
},
|
||||||
end: crate::core::fast_hdlparam::Position {
|
end: crate::core::hdlparam::Position {
|
||||||
line: (line_number + 1) as u32, character: last_character as u32
|
line: (line_number + 1) as u32, character: last_character as u32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use std::path::PathBuf;
|
|||||||
use vhdl_lang::ast::DesignFile;
|
use vhdl_lang::ast::DesignFile;
|
||||||
use vhdl_lang::{kind_str, Token, VHDLParser, VHDLStandard};
|
use vhdl_lang::{kind_str, Token, VHDLParser, VHDLStandard};
|
||||||
|
|
||||||
use super::fast_hdlparam::*;
|
use super::hdlparam::*;
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn vhdl_parser(path: &str) -> FastHdlparam {
|
pub fn vhdl_parser(path: &str) -> FastHdlparam {
|
||||||
|
@ -5,7 +5,7 @@ use regex::Regex;
|
|||||||
use ropey::RopeSlice;
|
use ropey::RopeSlice;
|
||||||
use tower_lsp::lsp_types::{GotoDefinitionResponse, LocationLink, Position, Range, Url};
|
use tower_lsp::lsp_types::{GotoDefinitionResponse, LocationLink, Position, Range, Url};
|
||||||
|
|
||||||
use crate::{core::fast_hdlparam::FastHdlparam, server::LSPServer, utils::{get_word_range_at_position, resolve_path, to_escape_path}};
|
use crate::{core::hdlparam::FastHdlparam, server::LSPServer, utils::{get_word_range_at_position, resolve_path, to_escape_path}};
|
||||||
|
|
||||||
/// 跳转到 include 的文件
|
/// 跳转到 include 的文件
|
||||||
pub fn goto_include_definition(uri: &Url, line: &RopeSlice, pos: Position) -> Option<GotoDefinitionResponse> {
|
pub fn goto_include_definition(uri: &Url, line: &RopeSlice, pos: Position) -> Option<GotoDefinitionResponse> {
|
||||||
|
@ -5,7 +5,7 @@ use regex::Regex;
|
|||||||
use ropey::RopeSlice;
|
use ropey::RopeSlice;
|
||||||
use tower_lsp::lsp_types::{Hover, HoverContents, LanguageString, MarkedString, Position, Range, Url};
|
use tower_lsp::lsp_types::{Hover, HoverContents, LanguageString, MarkedString, Position, Range, Url};
|
||||||
|
|
||||||
use crate::{core::fast_hdlparam::{Define, FastHdlparam}, server::LSPServer};
|
use crate::{core::hdlparam::{Define, FastHdlparam}, server::LSPServer};
|
||||||
|
|
||||||
use super::{get_word_range_at_position, resolve_path, to_escape_path};
|
use super::{get_word_range_at_position, resolve_path, to_escape_path};
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ pub fn hover_position_port_param(
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_port_desc_hover(port: &crate::core::fast_hdlparam::Port, range: &Range, language_id: &str) -> Hover {
|
fn make_port_desc_hover(port: &crate::core::hdlparam::Port, range: &Range, language_id: &str) -> Hover {
|
||||||
let mut port_desc_array = Vec::<String>::new();
|
let mut port_desc_array = Vec::<String>::new();
|
||||||
port_desc_array.push(port.dir_type.to_string());
|
port_desc_array.push(port.dir_type.to_string());
|
||||||
if port.net_type != "unknown" {
|
if port.net_type != "unknown" {
|
||||||
@ -317,11 +317,12 @@ fn make_port_desc_hover(port: &crate::core::fast_hdlparam::Port, range: &Range,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_param_desc_hover(param: &crate::core::fast_hdlparam::Parameter, range: &Range, language_id: &str) -> Hover {
|
fn make_param_desc_hover(param: &crate::core::hdlparam::Parameter, range: &Range, language_id: &str) -> Hover {
|
||||||
let mut param_desc_array = Vec::<String>::new();
|
let mut param_desc_array = Vec::<String>::new();
|
||||||
param_desc_array.push(format!("parameter {}", param.name));
|
param_desc_array.push(format!("parameter {}", param.name));
|
||||||
|
|
||||||
if param.init != "unknown" {
|
if param.init != "unknown" {
|
||||||
|
param_desc_array.push("=".to_string());
|
||||||
param_desc_array.push(param.init.to_string());
|
param_desc_array.push(param.init.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,7 +395,7 @@ pub fn hover_module_declaration(
|
|||||||
|
|
||||||
|
|
||||||
/// 根据 module 获取 module 的简单描述代码
|
/// 根据 module 获取 module 的简单描述代码
|
||||||
fn make_module_profile_code(module: &crate::core::fast_hdlparam::Module) -> String {
|
fn make_module_profile_code(module: &crate::core::hdlparam::Module) -> String {
|
||||||
let mut codes = Vec::<String>::new();
|
let mut codes = Vec::<String>::new();
|
||||||
let param_num = module.params.len();
|
let param_num = module.params.len();
|
||||||
let port_num = module.ports.len();
|
let port_num = module.ports.len();
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::{fs, future};
|
use std::{fs, future};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -9,9 +11,10 @@ use serde::{Deserialize, Serialize};
|
|||||||
use tower_lsp::jsonrpc::Result;
|
use tower_lsp::jsonrpc::Result;
|
||||||
use tower_lsp::lsp_types::*;
|
use tower_lsp::lsp_types::*;
|
||||||
|
|
||||||
use crate::core::fast_hdlparam::FastHdlparam;
|
use crate::core::hdlparam::FastHdlparam;
|
||||||
use crate::core::sv_parser::make_fast_from_syntaxtree;
|
use crate::core::sv_parser::make_fast_from_syntaxtree;
|
||||||
|
|
||||||
|
use crate::core::vhdl_parser::{make_fast_from_design_file, vhdl_parse};
|
||||||
use crate::utils::*;
|
use crate::utils::*;
|
||||||
use crate::server::{Backend, GLOBAL_BACKEND};
|
use crate::server::{Backend, GLOBAL_BACKEND};
|
||||||
use crate::sources::recovery_sv_parse;
|
use crate::sources::recovery_sv_parse;
|
||||||
@ -85,9 +88,22 @@ fn make_textdocumenitem_from_path(path_buf: &PathBuf) -> Option<TextDocumentItem
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 前端交互接口: do_fast,输入文件路径,计算出对应的 fast 结构
|
/// 前端交互接口: do_fast,输入文件路径,计算出对应的 fast 结构
|
||||||
pub fn do_fast<'a>(path: String, _server: &Arc<Backend>) -> Result<FastHdlparam> {
|
pub fn do_fast<'a>(path: String, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
||||||
info!("parse fast {}", path);
|
info!("parse fast {}", path);
|
||||||
|
|
||||||
|
let language_id = get_language_id_by_path_str(&path);
|
||||||
|
match language_id.as_str() {
|
||||||
|
"vhdl" => do_vhdl_fast(&path, backend),
|
||||||
|
"verilog" | "systemverilog" => do_sv_fast(&path, backend),
|
||||||
|
_ => Err(tower_lsp::jsonrpc::Error {
|
||||||
|
code: tower_lsp::jsonrpc::ErrorCode::InvalidRequest,
|
||||||
|
message: Cow::Owned(format!("invalid file: {path}, expect vhdl, verilog or system verilog!")),
|
||||||
|
data: None
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_sv_fast(path: &str, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
||||||
let path_buf = PathBuf::from(&path);
|
let path_buf = PathBuf::from(&path);
|
||||||
|
|
||||||
let doc = match make_textdocumenitem_from_path(&path_buf) {
|
let doc = match make_textdocumenitem_from_path(&path_buf) {
|
||||||
@ -95,7 +111,7 @@ pub fn do_fast<'a>(path: String, _server: &Arc<Backend>) -> Result<FastHdlparam
|
|||||||
None => {
|
None => {
|
||||||
let api_error = tower_lsp::jsonrpc::Error {
|
let api_error = tower_lsp::jsonrpc::Error {
|
||||||
code: tower_lsp::jsonrpc::ErrorCode::InvalidParams,
|
code: tower_lsp::jsonrpc::ErrorCode::InvalidParams,
|
||||||
message: std::borrow::Cow::Owned(format!("cannot make doc from path : {path}")),
|
message: Cow::Owned(format!("cannot make doc from path : {path}")),
|
||||||
data: None
|
data: None
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,27 +131,42 @@ pub fn do_fast<'a>(path: String, _server: &Arc<Backend>) -> Result<FastHdlparam
|
|||||||
&includes
|
&includes
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let sources = &backend.server.srcs;
|
||||||
if let Some(syntax_tree) = parse_result {
|
if let Some(syntax_tree) = parse_result {
|
||||||
if let Ok(fast) = make_fast_from_syntaxtree(&syntax_tree, &path_buf) {
|
if let Ok(fast) = make_fast_from_syntaxtree(&syntax_tree, &path_buf) {
|
||||||
let hdl_param = _server.server.srcs.hdl_param.clone();
|
let hdl_param = sources.hdl_param.clone();
|
||||||
hdl_param.update_fast(path.to_string(), fast.clone());
|
hdl_param.update_fast(path.to_string(), fast.clone());
|
||||||
return Ok(fast);
|
return Ok(fast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let api_error = tower_lsp::jsonrpc::Error {
|
Err(tower_lsp::jsonrpc::Error {
|
||||||
code: tower_lsp::jsonrpc::ErrorCode::ParseError,
|
code: tower_lsp::jsonrpc::ErrorCode::ParseError,
|
||||||
message: std::borrow::Cow::Owned("message".to_string()),
|
message: Cow::Owned(format!("error happen when parse {path} [do_sv_fast]")),
|
||||||
data: None
|
data: None
|
||||||
};
|
})
|
||||||
|
}
|
||||||
|
|
||||||
Err(api_error)
|
fn do_vhdl_fast(path: &str, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
||||||
|
let sources = &backend.server.srcs;
|
||||||
|
let pathbuf = PathBuf::from_str(path).unwrap();
|
||||||
|
if let Some(design_file) = vhdl_parse(&pathbuf) {
|
||||||
|
let hdl_param = sources.hdl_param.clone();
|
||||||
|
if let Some(fast) = make_fast_from_design_file(&design_file) {
|
||||||
|
hdl_param.update_fast(path.to_string(), fast.clone());
|
||||||
|
return Ok(fast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(tower_lsp::jsonrpc::Error {
|
||||||
|
code: tower_lsp::jsonrpc::ErrorCode::ParseError,
|
||||||
|
message: Cow::Owned(format!("error happen when parse {path} in [do_vhdl_fast]")),
|
||||||
|
data: None
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 下面是服务端发送给客户端的
|
// 下面是服务端发送给客户端的
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct StringNotification {
|
pub struct StringNotification {
|
||||||
pub content: String
|
pub content: String
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::core::fast_hdlparam::HdlParam;
|
use crate::core::hdlparam::HdlParam;
|
||||||
use crate::core::sv_parser::make_fast_from_syntaxtree;
|
use crate::core::sv_parser::make_fast_from_syntaxtree;
|
||||||
use crate::core::vhdl_parser::make_fast_from_design_file;
|
use crate::core::vhdl_parser::make_fast_from_design_file;
|
||||||
use crate::core::vhdl_parser::vhdl_parse;
|
use crate::core::vhdl_parser::vhdl_parse;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
use crate::{core::fast_hdlparam::Define, server::LSPServer};
|
use crate::{core::hdlparam::Define, server::LSPServer};
|
||||||
|
|
||||||
impl LSPServer {
|
impl LSPServer {
|
||||||
/// 根据输入的 macro 名字,寻找 fast 中存在的第一个 macro
|
/// 根据输入的 macro 名字,寻找 fast 中存在的第一个 macro
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{fs, path::PathBuf, str::FromStr};
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use ropey::Rope;
|
use ropey::Rope;
|
||||||
|
@ -79,6 +79,8 @@ pub fn get_word_range_at_position(line: &RopeSlice, pos: Position, regex: Regex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 根据 uri 获取 hdl 的 language id
|
/// 根据 uri 获取 hdl 的 language id
|
||||||
|
/// 返回值为 "vhdl" | "verilog" | "systemverilog" | "plaintext"
|
||||||
|
/// 不采用枚举是因为需要在 lsp 中使用到它们的字符串值
|
||||||
pub fn get_language_id_by_uri(uri: &Url) -> String {
|
pub fn get_language_id_by_uri(uri: &Url) -> String {
|
||||||
let path = uri.path();
|
let path = uri.path();
|
||||||
let ext_name = std::path::Path::new(path)
|
let ext_name = std::path::Path::new(path)
|
||||||
@ -86,13 +88,28 @@ pub fn get_language_id_by_uri(uri: &Url) -> String {
|
|||||||
.and_then(std::ffi::OsStr::to_str)
|
.and_then(std::ffi::OsStr::to_str)
|
||||||
.unwrap_or("");
|
.unwrap_or("");
|
||||||
|
|
||||||
|
get_language_id_by_extname(ext_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 根据路径字符串获取 hdl 的 language id
|
||||||
|
/// 返回值为 "vhdl" | "verilog" | "systemverilog" | "plaintext"
|
||||||
|
/// 不采用枚举是因为需要在 lsp 中使用到它们的字符串值
|
||||||
|
pub fn get_language_id_by_path_str(path_str: &str) -> String {
|
||||||
|
let ext_name = std::path::Path::new(path_str)
|
||||||
|
.extension()
|
||||||
|
.and_then(std::ffi::OsStr::to_str)
|
||||||
|
.unwrap_or("");
|
||||||
|
get_language_id_by_extname(ext_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_language_id_by_extname(ext_name: &str) -> String {
|
||||||
match ext_name {
|
match ext_name {
|
||||||
"vhd" | "vhdl" | "vho" | "vht" => "vhdl".to_string(),
|
"vhd" | "vhdl" | "vho" | "vht" => "vhdl".to_string(),
|
||||||
"v" | "V" | "vh" | "vl" => "verilog".to_string(),
|
"v" | "V" | "vh" | "vl" => "verilog".to_string(),
|
||||||
"sv" | "svh" => "systemverilog".to_string(),
|
"sv" | "svh" => "systemverilog".to_string(),
|
||||||
_ => "plaintext".to_string()
|
_ => "plaintext".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 根据基础路径和给出的 path 路径,计算出绝对路径
|
/// 根据基础路径和给出的 path 路径,计算出绝对路径
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user