mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
LSP: Signature Help
This commit is contained in:
parent
c52fdd71bc
commit
e3ea25f48c
8 changed files with 380 additions and 27 deletions
|
@ -111,19 +111,19 @@ macro_rules! declare_builtin_function_types {
|
|||
($( $Name:ident $(($Pattern:tt))? : ($( $Arg:expr ),*) -> $ReturnType:expr $(,)? )*) => {
|
||||
#[allow(non_snake_case)]
|
||||
pub struct BuiltinFunctionTypes {
|
||||
$(pub $Name : Type),*
|
||||
$(pub $Name : Rc<Function>),*
|
||||
}
|
||||
impl BuiltinFunctionTypes {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
$($Name : Type::Function(Rc::new(Function{
|
||||
$($Name : Rc::new(Function{
|
||||
args: vec![$($Arg),*],
|
||||
return_type: $ReturnType,
|
||||
}))),*
|
||||
})),*
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ty(&self, function: &BuiltinFunction) -> Type {
|
||||
pub fn ty(&self, function: &BuiltinFunction) -> Rc<Function> {
|
||||
match function {
|
||||
$(BuiltinFunction::$Name $(($Pattern))? => self.$Name.clone()),*
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ declare_builtin_function_types!(
|
|||
);
|
||||
|
||||
impl BuiltinFunction {
|
||||
pub fn ty(&self) -> Type {
|
||||
pub fn ty(&self) -> Rc<Function> {
|
||||
thread_local! {
|
||||
static TYPES: BuiltinFunctionTypes = BuiltinFunctionTypes::new();
|
||||
}
|
||||
|
@ -682,7 +682,7 @@ impl Expression {
|
|||
Expression::CallbackReference(nr, _) => nr.ty(),
|
||||
Expression::FunctionReference(nr, _) => nr.ty(),
|
||||
Expression::PropertyReference(nr) => nr.ty(),
|
||||
Expression::BuiltinFunctionReference(funcref, _) => funcref.ty(),
|
||||
Expression::BuiltinFunctionReference(funcref, _) => Type::Function(funcref.ty()),
|
||||
Expression::MemberFunction { member, .. } => member.ty(),
|
||||
Expression::BuiltinMacroReference { .. } => Type::Invalid, // We don't know the type
|
||||
Expression::ElementReference(_) => Type::ElementReference,
|
||||
|
|
|
@ -276,10 +276,7 @@ impl Expression {
|
|||
},
|
||||
Self::Cast { to, .. } => to.clone(),
|
||||
Self::CodeBlock(sub) => sub.last().map_or(Type::Void, |e| e.ty(ctx)),
|
||||
Self::BuiltinFunctionCall { function, .. } => match function.ty() {
|
||||
Type::Function(function) => function.return_type.clone(),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Self::BuiltinFunctionCall { function, .. } => function.ty().return_type.clone(),
|
||||
Self::CallBackCall { callback, .. } => {
|
||||
if let Type::Callback(callback) = ctx.property_ty(callback) {
|
||||
callback.return_type.clone()
|
||||
|
|
|
@ -162,9 +162,9 @@ pub(crate) fn load_builtins(register: &mut TypeRegister) {
|
|||
})
|
||||
.collect::<Vec<_>>();
|
||||
n.properties.extend(
|
||||
member_functions
|
||||
.iter()
|
||||
.map(|(name, fun)| (name.clone(), BuiltinPropertyInfo::new(fun.ty()))),
|
||||
member_functions.iter().map(|(name, fun)| {
|
||||
(name.clone(), BuiltinPropertyInfo::new(Type::Function(fun.ty())))
|
||||
}),
|
||||
);
|
||||
|
||||
let mut builtin = BuiltinElement::new(Rc::new(n));
|
||||
|
|
|
@ -426,10 +426,7 @@ fn make_default_aspect_ratio_preserving_binding(
|
|||
} else {
|
||||
let implicit_size_var = Box::new(Expression::ReadLocalVariable {
|
||||
name: "image_implicit_size".into(),
|
||||
ty: match BuiltinFunction::ImageSize.ty() {
|
||||
Type::Function(function) => function.return_type.clone(),
|
||||
_ => panic!("invalid type for ImplicitItemSize built-in function"),
|
||||
},
|
||||
ty: BuiltinFunction::ImageSize.ty().return_type.clone(),
|
||||
});
|
||||
|
||||
Expression::CodeBlock(vec![
|
||||
|
|
|
@ -25,10 +25,7 @@ pub fn lower_absolute_coordinates(component: &Rc<Component>) {
|
|||
});
|
||||
});
|
||||
|
||||
let point_type = match BuiltinFunction::ItemAbsolutePosition.ty() {
|
||||
crate::langtype::Type::Function(sig) => sig.return_type.clone(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let point_type = BuiltinFunction::ItemAbsolutePosition.ty().return_type.clone();
|
||||
|
||||
for nr in to_materialize {
|
||||
let elem = nr.element();
|
||||
|
|
|
@ -230,8 +230,16 @@ pub fn reserved_properties() -> impl Iterator<Item = (&'static str, Type, Proper
|
|||
.chain(IntoIterator::into_iter([
|
||||
("absolute-position", logical_point_type(), PropertyVisibility::Output),
|
||||
("forward-focus", Type::ElementReference, PropertyVisibility::Constexpr),
|
||||
("focus", BuiltinFunction::SetFocusItem.ty(), PropertyVisibility::Public),
|
||||
("clear-focus", BuiltinFunction::ClearFocusItem.ty(), PropertyVisibility::Public),
|
||||
(
|
||||
"focus",
|
||||
Type::Function(BuiltinFunction::SetFocusItem.ty()),
|
||||
PropertyVisibility::Public,
|
||||
),
|
||||
(
|
||||
"clear-focus",
|
||||
Type::Function(BuiltinFunction::ClearFocusItem.ty()),
|
||||
PropertyVisibility::Public,
|
||||
),
|
||||
(
|
||||
"dialog-button-role",
|
||||
Type::Enumeration(BUILTIN.with(|e| e.enums.DialogButtonRole.clone())),
|
||||
|
@ -442,13 +450,15 @@ impl TypeRegister {
|
|||
let popup = Rc::get_mut(b).unwrap();
|
||||
popup.properties.insert(
|
||||
"show".into(),
|
||||
BuiltinPropertyInfo::new(BuiltinFunction::ShowPopupWindow.ty()),
|
||||
BuiltinPropertyInfo::new(Type::Function(BuiltinFunction::ShowPopupWindow.ty())),
|
||||
);
|
||||
popup.member_functions.insert("show".into(), BuiltinFunction::ShowPopupWindow);
|
||||
|
||||
popup.properties.insert(
|
||||
"close".into(),
|
||||
BuiltinPropertyInfo::new(BuiltinFunction::ClosePopupWindow.ty()),
|
||||
BuiltinPropertyInfo::new(Type::Function(
|
||||
BuiltinFunction::ClosePopupWindow.ty(),
|
||||
)),
|
||||
);
|
||||
popup.member_functions.insert("close".into(), BuiltinFunction::ClosePopupWindow);
|
||||
|
||||
|
@ -486,7 +496,9 @@ impl TypeRegister {
|
|||
let text_input = Rc::get_mut(b).unwrap();
|
||||
text_input.properties.insert(
|
||||
"set-selection-offsets".into(),
|
||||
BuiltinPropertyInfo::new(BuiltinFunction::SetSelectionOffsets.ty()),
|
||||
BuiltinPropertyInfo::new(Type::Function(
|
||||
BuiltinFunction::SetSelectionOffsets.ty(),
|
||||
)),
|
||||
);
|
||||
text_input
|
||||
.member_functions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue