diff --git a/src/core/fast_hdlparam.rs b/src/core/fast_hdlparam.rs index df6d3f7..7be3c17 100644 --- a/src/core/fast_hdlparam.rs +++ b/src/core/fast_hdlparam.rs @@ -100,6 +100,7 @@ pub struct Macro { } #[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] pub struct FastHdlparam { pub fast_macro: Macro, pub content: Vec diff --git a/src/core/sv_parser.rs b/src/core/sv_parser.rs index cee6043..89fc381 100644 --- a/src/core/sv_parser.rs +++ b/src/core/sv_parser.rs @@ -3,6 +3,7 @@ use std::io::BufRead; use std::{collections::HashMap, io::BufReader}; use std::path::PathBuf; use sv_parser::{parse_sv, unwrap_node, ConstantMintypmaxExpression, GateInstantiation, ListOfParameterAssignments, ListOfPortConnections, Locate, PackedDimensionRange, RefNode, SyntaxTree}; + use super::fast_hdlparam::{FastHdlparam, Macro}; pub fn sv_parser(path: &str) -> Option { @@ -586,11 +587,9 @@ fn get_column_by_offset(content: &[String], offset: usize) -> usize { #[cfg(test)] mod tests { use std::fs; - use std::path::Path; - use super::sv_parser; - const testfiles_dir: &str = "testfiles"; + const TESTFILES_DIR: &str = "testfiles"; macro_rules! unwrap_result { ($expr:expr) => { @@ -612,7 +611,7 @@ mod tests { #[test] fn test_sv_parse() { - let entries = unwrap_result!(fs::read_dir(testfiles_dir)); + let entries = unwrap_result!(fs::read_dir(TESTFILES_DIR)); for entry in entries { let entry = unwrap_result!(entry); let file_path = entry.path(); diff --git a/src/custom_request.rs b/src/custom_request.rs index 04af477..08d17c0 100644 --- a/src/custom_request.rs +++ b/src/custom_request.rs @@ -6,7 +6,7 @@ use log::info; use ropey::Rope; use serde::{Deserialize, Serialize}; use tower_lsp::jsonrpc::Result; -use tower_lsp::{lsp_types::*, LanguageServer}; +use tower_lsp::lsp_types::*; use crate::core::fast_hdlparam::FastHdlparam; use crate::core::sv_parser::make_fast_from_syntaxtree; diff --git a/src/definition.rs b/src/definition.rs index 51fddeb..49baaba 100644 --- a/src/definition.rs +++ b/src/definition.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use crate::definition::extract_defs::get_ident; use crate::server::LSPServer; use crate::sources::LSPSupport; @@ -162,6 +164,21 @@ pub fn get_language_id_by_uri(uri: &Url) -> String { } } +pub fn get_language_id_by_path(path: &PathBuf) -> String { + let path = path.as_path(); + let ext_name = std::path::Path::new(path) + .extension() + .and_then(std::ffi::OsStr::to_str) + .unwrap_or(""); + + match ext_name { + "vhd" | "vhdl" | "vho" | "vht" => "vhdl".to_string(), + "v" | "V" | "vh" | "vl" => "verilog".to_string(), + "sv" | "svh" => "systemverilog".to_string(), + _ => "plaintext".to_string() + } +} + type ScopesAndDefs = Option<(Vec>, Vec>)>; /// Take a given syntax node from a sv-parser syntax tree and extract out the definition/scope at diff --git a/src/sources.rs b/src/sources.rs index 166ec50..d159c7a 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -2,7 +2,6 @@ use crate::definition::def_types::*; use crate::definition::get_scopes; use crate::diagnostics::{get_diagnostics, is_hidden}; use crate::server::LSPServer; -use log::info; use log::{debug, error}; use pathdiff::diff_paths; use ropey::{Rope, RopeSlice}; diff --git a/sv-parser b/sv-parser index 4960ea3..af11f5f 160000 --- a/sv-parser +++ b/sv-parser @@ -1 +1 @@ -Subproject commit 4960ea3fb7c848462ce6e78dbae454ffc775803f +Subproject commit af11f5ff1ef091562d2b17cdf4de3614aedf2286