mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix set rule autocomplete filter
This commit is contained in:
parent
35b16e545b
commit
ba384e5bb6
@ -108,7 +108,7 @@ fn complete_rules(ctx: &mut CompletionContext) -> bool {
|
|||||||
/// Complete call and set rule parameters.
|
/// Complete call and set rule parameters.
|
||||||
fn complete_params(ctx: &mut CompletionContext) -> bool {
|
fn complete_params(ctx: &mut CompletionContext) -> bool {
|
||||||
// Ensure that we are in a function call or set rule's argument list.
|
// Ensure that we are in a function call or set rule's argument list.
|
||||||
let (callee, args) = if_chain! {
|
let (callee, set, args) = if_chain! {
|
||||||
if let Some(parent) = ctx.leaf.parent();
|
if let Some(parent) = ctx.leaf.parent();
|
||||||
if let Some(parent) = match parent.kind() {
|
if let Some(parent) = match parent.kind() {
|
||||||
SyntaxKind::Named => parent.parent(),
|
SyntaxKind::Named => parent.parent(),
|
||||||
@ -117,13 +117,14 @@ fn complete_params(ctx: &mut CompletionContext) -> bool {
|
|||||||
if let Some(args) = parent.cast::<ast::Args>();
|
if let Some(args) = parent.cast::<ast::Args>();
|
||||||
if let Some(grand) = parent.parent();
|
if let Some(grand) = parent.parent();
|
||||||
if let Some(expr) = grand.cast::<ast::Expr>();
|
if let Some(expr) = grand.cast::<ast::Expr>();
|
||||||
|
let set = matches!(expr, ast::Expr::Set(_));
|
||||||
if let Some(callee) = match expr {
|
if let Some(callee) = match expr {
|
||||||
ast::Expr::FuncCall(call) => call.callee().as_untyped().cast(),
|
ast::Expr::FuncCall(call) => call.callee().as_untyped().cast(),
|
||||||
ast::Expr::Set(set) => Some(set.target()),
|
ast::Expr::Set(set) => Some(set.target()),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
then {
|
then {
|
||||||
(callee, args)
|
(callee, set, args)
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -173,7 +174,7 @@ fn complete_params(ctx: &mut CompletionContext) -> bool {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
ctx.param_completions(&callee, &exclude);
|
ctx.param_completions(&callee, set, &exclude);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -427,7 +428,12 @@ impl<'a> CompletionContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add completions for the parameters of a function.
|
/// Add completions for the parameters of a function.
|
||||||
fn param_completions(&mut self, callee: &ast::Ident, exclude: &[ast::Ident]) {
|
fn param_completions(
|
||||||
|
&mut self,
|
||||||
|
callee: &ast::Ident,
|
||||||
|
set: bool,
|
||||||
|
exclude: &[ast::Ident],
|
||||||
|
) {
|
||||||
let info = if_chain! {
|
let info = if_chain! {
|
||||||
if let Some(Value::Func(func)) = self.scope.get(callee);
|
if let Some(Value::Func(func)) = self.scope.get(callee);
|
||||||
if let Some(info) = func.info();
|
if let Some(info) = func.info();
|
||||||
@ -444,6 +450,10 @@ impl<'a> CompletionContext<'a> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if set && !param.settable {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if param.named {
|
if param.named {
|
||||||
self.completions.push(Completion {
|
self.completions.push(Completion {
|
||||||
kind: CompletionKind::Param,
|
kind: CompletionKind::Param,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user