Skip to content

Commit

Permalink
Cleanup, workaround unecessary cloning of text contents
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis committed Nov 25, 2023
1 parent fd367cc commit 444ff2e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ fn main_loop(
) -> anyhow::Result<()> {
let _params: InitializeParams = serde_json::from_value(params).unwrap();

let mut curr_doc = String::new();
let mut doc_open_params;
let mut doc_change_params;
let curr_doc = String::new();
let mut curr_doc = &curr_doc;
let mut parser = tree_sitter::Parser::new();
parser.set_logger(Some(Box::new(tree_sitter_logger)));
parser.set_language(tree_sitter_asm::language())?;
Expand Down Expand Up @@ -236,16 +239,9 @@ fn main_loop(
}
} else if let Ok((id, params)) = cast_req::<Completion>(req.clone()) {
// CompletionRequest ---------------------------------------------------------------
let res = Response {
id: id.clone(),
result: Some(json!("")),
error: None,
};

// get suggestions ------------------------------------------------------
// format response
let comp_res = get_comp_resp(
&curr_doc,
curr_doc,
&mut parser,
&params,
instruction_completes,
Expand All @@ -263,6 +259,11 @@ fn main_loop(
}
None => {
// don't know what to suggest
let res = Response {
id: id.clone(),
result: Some(json!("")),
error: None,
};
connection.sender.send(Message::Response(res.clone()))?;
}
}
Expand All @@ -272,9 +273,12 @@ fn main_loop(
}
Message::Notification(notif) => {
if let Ok(params) = cast_notif::<DidOpenTextDocument>(notif.clone()) {
curr_doc = params.text_document.text;
// move the notification's params into this variable so we can avoid cloning the document contents
doc_open_params = params;
curr_doc = &doc_open_params.text_document.text;
} else if let Ok(params) = cast_notif::<DidChangeTextDocument>(notif.clone()) {
curr_doc = params.content_changes.last().unwrap().text.clone();
doc_change_params = params;
curr_doc = &doc_change_params.content_changes.last().unwrap().text;
}
}
Message::Response(_resp) => {}
Expand Down

0 comments on commit 444ff2e

Please sign in to comment.