Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP: Signature Help #6725

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/compiler/expression_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),*
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions internal/compiler/llr/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions internal/compiler/load_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 1 addition & 4 deletions internal/compiler/passes/default_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down
5 changes: 1 addition & 4 deletions internal/compiler/passes/lower_absolute_coordinates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 17 additions & 5 deletions internal/compiler/typeregister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion tools/lsp/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod formatting;
mod goto;
mod hover;
mod semantic_tokens;
mod signature_help;
#[cfg(test)]
pub mod test;
pub mod token_info;
Expand All @@ -25,7 +26,7 @@ use i_slint_compiler::{diagnostics::BuildDiagnostics, langtype::Type};
use lsp_types::request::{
CodeActionRequest, CodeLensRequest, ColorPresentationRequest, Completion, DocumentColor,
DocumentHighlightRequest, DocumentSymbolRequest, ExecuteCommand, Formatting, GotoDefinition,
HoverRequest, PrepareRenameRequest, Rename, SemanticTokensFullRequest,
HoverRequest, PrepareRenameRequest, Rename, SemanticTokensFullRequest, SignatureHelpRequest,
};
use lsp_types::{
ClientCapabilities, CodeActionOrCommand, CodeActionProviderCapability, CodeLens,
Expand Down Expand Up @@ -208,6 +209,11 @@ pub fn server_initialize_result(client_cap: &ClientCapabilities) -> InitializeRe
InitializeResult {
capabilities: ServerCapabilities {
hover_provider: Some(true.into()),
signature_help_provider: Some(lsp_types::SignatureHelpOptions {
trigger_characters: Some(vec!["(".to_owned(), ",".to_owned()]),
retrigger_characters: None,
work_done_progress_options: WorkDoneProgressOptions::default(),
}),
completion_provider: Some(CompletionOptions {
resolve_provider: None,
trigger_characters: Some(vec![".".to_owned()]),
Expand Down Expand Up @@ -311,6 +317,16 @@ pub fn register_request_handlers(rh: &mut RequestHandler) {

Ok(result)
});
rh.register::<SignatureHelpRequest, _>(|params, ctx| async move {
let document_cache = &mut ctx.document_cache.borrow_mut();
let result = token_descr(
document_cache,
&params.text_document_position_params.text_document.uri,
&params.text_document_position_params.position,
)
.and_then(|(token, _)| signature_help::get_signature_help(document_cache, token));
Ok(result)
});
rh.register::<CodeActionRequest, _>(|params, ctx| async move {
let document_cache = &mut ctx.document_cache.borrow_mut();

Expand Down
Loading
Loading