Skip to content

Commit

Permalink
fix(diagnostics): now publish on command completion
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Feb 28, 2024
1 parent e1cfcb4 commit 1da200f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
31 changes: 13 additions & 18 deletions harper-ls/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,36 +328,31 @@ impl LanguageServer for Backend {
.into_iter()
.map(|v| serde_json::from_value::<String>(v).unwrap());

match params.command.as_str() {
"AddToUserDict" => {
let Some(first) = string_args.next() else {
return Ok(None);
};
let Some((first, second)) = string_args.next_tuple() else {
return Ok(None);
};

let word = &first.chars().collect::<Vec<_>>();
let word = &first.chars().collect::<Vec<_>>();
let file_url = second.parse().unwrap();

match params.command.as_str() {
"AddToUserDict" => {
let mut dict = self.load_user_dictionary().await;
dict.append_word(word);
self.save_user_dictionary(dict).await.unwrap();

Ok(None)
}
"AddToFileDict" => {
let Some((first, second)) = string_args.next_tuple() else {
return Ok(None);
};

let word = &first.chars().collect::<Vec<_>>();

let file_url = second.parse().unwrap();
let mut dict = self.load_file_dictionary(&file_url).await;
dict.append_word(word);
self.save_file_dictionary(&file_url, dict).await.unwrap();

Ok(None)
}
_ => Ok(None)
_ => ()
}

let _ = self.update_document_from_file(&file_url).await;
self.publish_diagnostics(&file_url).await;

Ok(None)
}

async fn code_action(&self, params: CodeActionParams) -> Result<Option<CodeActionResponse>> {
Expand Down
2 changes: 1 addition & 1 deletion harper-ls/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn lint_to_code_actions<'a>(
results.push(CodeActionOrCommand::Command(Command::new(
format!("Add \"{}\" to the global dictionary.", orig),
"AddToUserDict".to_string(),
Some(vec![orig.clone().into()])
Some(vec![orig.clone().into(), url.to_string().into()])
)));

results.push(CodeActionOrCommand::Command(Command::new(
Expand Down

0 comments on commit 1da200f

Please sign in to comment.