Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toplevel entity and keyword completion #156

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/analyzer/src/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ impl SymbolTable {
})
.or_insert(HashMap::from([(from, to)]));
}

pub fn get_project_local(&self, prj: StrId) -> Option<HashMap<StrId, StrId>> {
self.project_local_table.get(&prj).cloned()
}
}

impl fmt::Display for SymbolTable {
Expand Down Expand Up @@ -410,6 +414,10 @@ pub fn add_project_local(prj: StrId, from: StrId, to: StrId) {
SYMBOL_TABLE.with(|f| f.borrow_mut().add_project_local(prj, from, to))
}

pub fn get_project_local(prj: StrId) -> Option<HashMap<StrId, StrId>> {
SYMBOL_TABLE.with(|f| f.borrow().get_project_local(prj))
}

#[cfg(test)]
mod tests {
use crate::namespace::Namespace;
Expand Down
33 changes: 33 additions & 0 deletions crates/languageserver/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::env;
use std::fs;
use std::path::PathBuf;

fn main() {
// Skip in GitHub Actions
if let Ok(x) = env::var("GITHUB_ACTIONS") {
if x == "true" {
return;
}
}

let par_file = PathBuf::from("../parser/veryl.par");
let exp_file = PathBuf::from("src/keyword.rs");

let par_modified = fs::metadata(&par_file).unwrap().modified().unwrap();
let exp_modified = fs::metadata(&exp_file).unwrap().modified().unwrap();

if par_modified > exp_modified {
let text = fs::read_to_string(&par_file).unwrap();
let mut keywords = "pub const KEYWORDS: &[&str] = &[\n".to_string();
for line in text.lines() {
if line.contains("(?-u:\\b)") {
let keyword = line.split_ascii_whitespace().nth(2).unwrap();
let keyword = keyword.replace("/(?-u:\\b)", "");
let keyword = keyword.replace("(?-u:\\b)/", "");
keywords.push_str(&format!(" \"{keyword}\",\n"));
}
}
keywords.push_str("];\n");
fs::write(&exp_file, keywords).unwrap();
}
}
55 changes: 55 additions & 0 deletions crates/languageserver/src/keyword.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
pub const KEYWORDS: &[&str] = &[
"always_comb",
"always_ff",
"assign",
"async_high",
"async_low",
"as",
"bit",
"case",
"default",
"else",
"enum",
"export",
"f32",
"f64",
"final",
"for",
"function",
"i32",
"i64",
"if_reset",
"if",
"import",
"initial",
"inout",
"input",
"inst",
"interface",
"in",
"localparam",
"logic",
"lsb",
"modport",
"module",
"msb",
"negedge",
"output",
"package",
"parameter",
"posedge",
"ref",
"repeat",
"return",
"signed",
"step",
"string",
"struct",
"sync_high",
"sync_low",
"tri",
"type",
"u32",
"u64",
"var",
];
1 change: 1 addition & 0 deletions crates/languageserver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use tower_lsp::{LspService, Server};

mod backend;
mod keyword;
mod server;
use backend::Backend;

Expand Down
Loading