Skip to content

Commit

Permalink
Fix case sensitivity issue with intel syntax instruction names (berge…
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis authored Oct 29, 2023
1 parent 67cf7f3 commit 3350b3c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ fn main_loop(
// format response
match word {
Ok(word) => {
let (x86_instruction, x86_64_instruction) = (
names_to_instructions.get(&(Arch::X86, &*word)),
names_to_instructions.get(&(Arch::X86_64, &*word)),
);
let (x86_instruction, x86_64_instruction) =
search_for_instr(&word, names_to_instructions);

let hover_res: Option<Hover> =
match (x86_instruction.is_some(), x86_64_instruction.is_some())
{
Expand Down
21 changes: 20 additions & 1 deletion src/lsp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::types::Column;
use crate::{Instruction, TargetConfig};
use crate::{Arch, Instruction, NameToInstructionMap, TargetConfig};
use log::{error, info};
use lsp_types::{InitializeParams, TextDocumentPositionParams, Url};
use std::fs::File;
Expand Down Expand Up @@ -53,6 +53,25 @@ pub fn get_word_from_file_params(
}
}

// Note: Have to call .cloned() on the results of .get()
// here because of compiler issue regarding entangled lifetimes: https://github.com/rust-lang/rust/issues/80389
pub fn search_for_instr<'a: 'b, 'b>(
word: &str,
map: &'a NameToInstructionMap<'a>,
) -> (Option<&'b Instruction>, Option<&'b Instruction>) {
let raised_word = word.to_uppercase();
let x86_instruction = map
.get(&(Arch::X86, word))
.or_else(|| map.get(&(Arch::X86, &raised_word)))
.cloned();
let x86_64_instruction = map
.get(&(Arch::X86_64, word))
.or_else(|| map.get(&(Arch::X86_64, &raised_word)))
.cloned();

(x86_instruction, x86_64_instruction)
}

pub fn get_target_config(params: &InitializeParams) -> TargetConfig {
// 1. if we have workspace folders, then iterate through them and assign the first valid one to
// the root path
Expand Down

0 comments on commit 3350b3c

Please sign in to comment.