From 61356ff4a5b34c6543b92f7ea9f43d5b2314026b Mon Sep 17 00:00:00 2001 From: Finn Brewer Date: Fri, 16 Aug 2024 11:59:00 -0700 Subject: [PATCH] fix: formatting the spyglys grammar of the active profile instead of one selected in settings --- src-tauri/src/spyglys_integration.rs | 25 +++++------------------ src/pages/settings/components/Grammar.vue | 6 ++++-- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src-tauri/src/spyglys_integration.rs b/src-tauri/src/spyglys_integration.rs index 10369c6..edda454 100644 --- a/src-tauri/src/spyglys_integration.rs +++ b/src-tauri/src/spyglys_integration.rs @@ -1,8 +1,7 @@ use spyglys::interpreter::{Interpreter, RuntimeError, Value}; -use tauri::State; use tokio::sync::MutexGuard; -use crate::{KalbaError, KalbaState, SharedInfo}; +use crate::{KalbaError, SharedInfo}; pub fn handle_lemma( lemma: &str, @@ -94,28 +93,14 @@ pub fn load_spyglys(state: &mut MutexGuard) -> Result, -) -> Result, KalbaError> { - let current_interpreter = load_spyglys(&mut state.0.lock().await)?; +pub async fn get_spyglys_functions(spyglys_grammar: String) -> Result, KalbaError> { + let current_interpreter = spyglys::contents_to_interpreter(&spyglys_grammar)?; Ok(current_interpreter.get_functions()) } #[tauri::command] -pub async fn format_spyglys(state: State<'_, KalbaState>) -> Result { - let state = state.0.lock().await; - let current_language = state - .current_language - .as_ref() - .expect("language to already be selected"); - let parsed = spyglys::parse_string( - &state - .settings - .languages - .get(current_language) - .expect("language to exist") - .grammar_parser, - )?; +pub async fn format_spyglys(spyglys_grammar: String) -> Result { + let parsed = spyglys::parse_string(&spyglys_grammar)?; Ok(spyglys::formatter::pretty_file(&parsed)) } diff --git a/src/pages/settings/components/Grammar.vue b/src/pages/settings/components/Grammar.vue index a3fa8a6..7cc0bf8 100644 --- a/src/pages/settings/components/Grammar.vue +++ b/src/pages/settings/components/Grammar.vue @@ -21,7 +21,9 @@ console.log(runOnLemmas.value); console.log(suggestOnLemmas.value); async function checkSpyglys() { - await invoke("get_spyglys_functions") + await invoke("get_spyglys_functions", { + spyglys_grammar: parser.value, + }) .then((response) => { functions.value = response; error.value = null; @@ -32,7 +34,7 @@ async function checkSpyglys() { } async function formatSpyglys() { - await invoke("format_spyglys") + await invoke("format_spyglys", { spyglys_grammar: parser.value }) .then((formmated) => { parser.value = formmated; })