Skip to content

Commit

Permalink
Add unit test framework, hover tests, fix hash collision bug (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis committed Jul 2, 2024
1 parent a0ba554 commit 845d954
Show file tree
Hide file tree
Showing 7 changed files with 1,106 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ flexi_logger = "0.25.3"
log = { version = "0.4.17" }
lsp-server = "0.7.0"
lsp-types = "0.94.0"
quick-xml = "0.28.1"
regex = "1.7.2"
reqwest = { version = "0.11.15", features = ["blocking"] }
strum = "0.24.1"
Expand All @@ -50,5 +49,6 @@ dirs = "5.0.1"
symbolic = { version = "12.8.0", features = ["demangle"] }
symbolic-demangle = "12.8.0"
url-escape = "0.1.1"
quick-xml = "0.35.0"

# [dev-dependencies]
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod lsp;
mod test;
pub mod types;
pub mod x86_parser;

Expand Down
28 changes: 14 additions & 14 deletions src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ pub fn text_doc_change_to_ts_edit(
/// Given a NameTo_SomeItem_ map, returns a `Vec<CompletionItem>` for the items
/// contained within the map
pub fn get_completes<T: Completable, U: ArchOrAssembler>(
map: &HashMap<(U, &str), T>,
map: &HashMap<(U, String), T>,
kind: Option<CompletionItemKind>,
) -> Vec<CompletionItem> {
map.iter()
.map(|((_arch_or_asm, name), item_info)| {
let value = format!("{}", item_info);

CompletionItem {
label: String::from(*name),
label: name.clone(),
kind,
documentation: Some(Documentation::MarkupContent(MarkupContent {
kind: MarkupKind::Markdown,
Expand All @@ -219,9 +219,9 @@ pub fn get_completes<T: Completable, U: ArchOrAssembler>(
pub fn get_hover_resp<T: Hoverable, U: Hoverable, V: Hoverable>(
word: &str,
file_word: &str,
instruction_map: &HashMap<(Arch, &str), T>,
register_map: &HashMap<(Arch, &str), U>,
directive_map: &HashMap<(Assembler, &str), V>,
instruction_map: &HashMap<(Arch, String), T>,
register_map: &HashMap<(Arch, String), U>,
directive_map: &HashMap<(Assembler, String), V>,
include_dirs: &[PathBuf],
) -> Option<Hover> {
let instr_lookup = lookup_hover_resp_by_arch(word, instruction_map);
Expand Down Expand Up @@ -254,7 +254,7 @@ pub fn get_hover_resp<T: Hoverable, U: Hoverable, V: Hoverable>(

fn lookup_hover_resp_by_arch<T: Hoverable>(
word: &str,
map: &HashMap<(Arch, &str), T>,
map: &HashMap<(Arch, String), T>,
) -> Option<Hover> {
// switch over to vec?
let (x86_res, x86_64_res, z80_res) = search_for_hoverable_by_arch(word, map);
Expand Down Expand Up @@ -291,7 +291,7 @@ fn lookup_hover_resp_by_arch<T: Hoverable>(

fn lookup_hover_resp_by_assembler<T: Hoverable>(
word: &str,
map: &HashMap<(Assembler, &str), T>,
map: &HashMap<(Assembler, String), T>,
) -> Option<Hover> {
let (gas_res, go_res) = search_for_hoverable_by_assembler(word, map);

Expand Down Expand Up @@ -901,21 +901,21 @@ pub fn get_ref_resp(
// For now, using 'a for both isn't strictly necessary, but fits our use case
fn search_for_hoverable_by_arch<'a, T: Hoverable>(
word: &'a str,
map: &'a HashMap<(Arch, &str), T>,
map: &'a HashMap<(Arch, String), T>,
) -> (Option<&'a T>, Option<&'a T>, Option<&'a T>) {
let x86_res = map.get(&(Arch::X86, word));
let x86_64_res = map.get(&(Arch::X86_64, word));
let z80_res = map.get(&(Arch::Z80, word));
let x86_res = map.get(&(Arch::X86, word.to_string()));
let x86_64_res = map.get(&(Arch::X86_64, word.to_string()));
let z80_res = map.get(&(Arch::Z80, word.to_string()));

(x86_res, x86_64_res, z80_res)
}

fn search_for_hoverable_by_assembler<'a, T: Hoverable>(
word: &'a str,
map: &'a HashMap<(Assembler, &str), T>,
map: &'a HashMap<(Assembler, String), T>,
) -> (Option<&'a T>, Option<&'a T>) {
let gas_res = map.get(&(Assembler::Gas, word));
let go_res = map.get(&(Assembler::Go, word));
let gas_res = map.get(&(Assembler::Gas, word.to_string()));
let go_res = map.get(&(Assembler::Go, word.to_string()));

(gas_res, go_res)
}
Expand Down
Loading

0 comments on commit 845d954

Please sign in to comment.