Skip to content

Commit

Permalink
fix: formatting the spyglys grammar of the active profile instead of …
Browse files Browse the repository at this point in the history
…one selected in settings
  • Loading branch information
BrewingWeasel committed Aug 16, 2024
1 parent b8cf009 commit 61356ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
25 changes: 5 additions & 20 deletions src-tauri/src/spyglys_integration.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -94,28 +93,14 @@ pub fn load_spyglys(state: &mut MutexGuard<SharedInfo>) -> Result<Interpreter, K
}

#[tauri::command]
pub async fn get_spyglys_functions(
state: State<'_, KalbaState>,
) -> Result<Vec<String>, KalbaError> {
let current_interpreter = load_spyglys(&mut state.0.lock().await)?;
pub async fn get_spyglys_functions(spyglys_grammar: String) -> Result<Vec<String>, 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<String, KalbaError> {
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<String, KalbaError> {
let parsed = spyglys::parse_string(&spyglys_grammar)?;

Ok(spyglys::formatter::pretty_file(&parsed))
}
6 changes: 4 additions & 2 deletions src/pages/settings/components/Grammar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ console.log(runOnLemmas.value);
console.log(suggestOnLemmas.value);
async function checkSpyglys() {
await invoke<string[]>("get_spyglys_functions")
await invoke<string[]>("get_spyglys_functions", {
spyglys_grammar: parser.value,
})
.then((response) => {
functions.value = response;
error.value = null;
Expand All @@ -32,7 +34,7 @@ async function checkSpyglys() {
}
async function formatSpyglys() {
await invoke<string>("format_spyglys")
await invoke<string>("format_spyglys", { spyglys_grammar: parser.value })
.then((formmated) => {
parser.value = formmated;
})
Expand Down

0 comments on commit 61356ff

Please sign in to comment.