Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(harper-typst): ignore arguments that accept file path
Donny Kimaedc356567bd
diff --git a/harper-typst/src/typst_translator.rs b/harper-typst/src/typst_translator.rsindex f2a5391f6..8bc81dd57 100644--- a/harper-typst/src/typst_translator.rs+++ b/harper-typst/src/typst_translator.rs@@ -7,8 +7,8 @@ use itertools::Itertools;use typst_syntax::{Source,ast::{- Arg, ArrayItem, AstNode, DestructuringItem, DictItem, Expr, Ident, LetBindingKind, Param,- Pattern, Spread,+ Arg, ArrayItem, AstNode, DestructuringItem, DictItem, Expr, FuncCall, Ident,+ LetBindingKind, Param, Pattern, Spread,},};@@ -203,6 +203,38 @@ impl<'a> TypstTranslator<'a> {)};+ // Parse a function call+ let parse_func_call = |func: FuncCall| {+ let parse_args_without = |pos: bool, nameds: &[&str]| {+ let (dead, alive): (Vec<_>, Vec<_>) = func.args().items().partition(|a| match a {+ Arg::Pos(_) => pos,+ Arg::Named(named) => nameds.contains(&named.name().as_str()),+ Arg::Spread(_) => false,+ });++ Some(+ dead.iter()+ .flat_map(|a| token!(a, TokenKind::Unlintable))+ .chain(parse_args(&mut alive.into_iter()))+ .flatten()+ .collect_vec(),+ )+ };++ merge![+ token!(func.callee(), TokenKind::Unlintable),+ match get_text!(func.callee()) {+ "color.rgb" | "rgb" => parse_args_without(true, &[]),+ "std.plugin" | "plugin" => parse_args_without(true, &[]),+ "std.bibliography" | "bibliography" => parse_args_without(true, &["style"]),+ "std.cite" | "cite" => parse_args_without(true, &["style"]),+ "std.raw" | "raw" => parse_args_without(false, &["syntaxes", "theme"]),+ "std.image" | "image" => parse_args_without(true, &[]),+ _ => parse_args(&mut func.args().items()),+ }+ ]+ };+// Delegate parsing based on the kind of Typst expression.// Not all expression kinds have defined behavior, so the default behavior is// an [`harper_core::TokenKind::Unlintable`] token.@@ -330,15 +362,7 @@ impl<'a> TypstTranslator<'a> {parse_params(&mut closure.params().children()),recurse!(closure.body())],- Expr::FuncCall(func) => {- merge![- token!(func.callee(), TokenKind::Unlintable),- match get_text!(func.callee()) {- "color.rgb" | "rgb" => token!(func.args(), TokenKind::Unlintable),- _ => parse_args(&mut func.args().items()),- }- ]- }+ Expr::FuncCall(func) => parse_func_call(func),a => token!(a, TokenKind::Unlintable),}}diff --git a/harper-typst/tests/run_tests.rs b/harper-typst/tests/run_tests.rsindex 088245418..e46c45dc0 100644--- a/harper-typst/tests/run_tests.rs+++ b/harper-typst/tests/run_tests.rs@@ -38,3 +38,4 @@ create_test!(complex_document.typ, 0);create_test!(simplified_document.typ, 0);create_test!(complex_document_with_spelling_mistakes.typ, 4);// create_test!(issue_399.typ, 3);+create_test!(function_with_path.typ, 8);diff --git a/harper-typst/tests/test_sources/function_with_path.typ b/harper-typst/tests/test_sources/function_with_path.typnew file mode 100644index 000000000..99cb9bdfb--- /dev/null+++ b/harper-typst/tests/test_sources/function_with_path.typ@@ -0,0 +1,10 @@+#plugin("../a.wasm")+#bibliography(("../a.bib", "../b.bib"), style: "../c.csl", title: [Errorz])+#cite(style: "../a.csl", supplement: [Errorz])+#raw(syntaxes: ("../a", "../b"), theme: "../c", [Errorz])+#image("../a", caption: [Errorz])+#std.plugin("../a.wasm")+#std.bibliography(("../a.bib", "../b.bib"), style: "../c.csl", title: [Errorz])+#std.cite(style: "../a.csl", supplement: [Errorz])+#std.raw(syntaxes: ("../a", "../b"), theme: "../c", [Errorz])+#std.image("../a", caption: [Errorz])