Skip to content
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/compiler/ir/ast2ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,9 +1815,9 @@ fn func_call_from_ast(

let expected_arg_types: Vec<Type> = if signature.method_of().is_some()
{
signature.args.iter().skip(1).map(|arg| arg.ty()).collect()
signature.args.iter().skip(1).map(|(_, arg)| arg.ty()).collect()
} else {
signature.args.iter().map(|arg| arg.ty()).collect()
signature.args.iter().map(|(_, arg)| arg.ty()).collect()
};

if arg_types == expected_arg_types {
Expand Down
10 changes: 7 additions & 3 deletions lib/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,11 @@ pub mod mods {

for signature in func.signatures() {
signatures.push(FuncSignature {
args: signature.args.iter().map(Type::from).collect(),
args: signature
.args
.iter()
.map(|(name, ty)| (name.clone(), Type::from(ty)))
.collect(),
ret: Type::from(&signature.result),
description: signature.description.clone(),
});
Expand All @@ -397,8 +401,8 @@ pub mod mods {
/// Describes a function signature.
#[derive(Clone, Debug, PartialEq)]
pub struct FuncSignature {
/// The types of the function arguments.
pub args: Vec<Type>,
/// The names and types of the function arguments.
pub args: Vec<(String, Type)>,
/// The return type for the function.
pub ret: Type,
/// Function's documentation description.
Expand Down
9 changes: 3 additions & 6 deletions lib/src/types/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ where
#[derive(Clone, Serialize, Deserialize, Debug)]
pub(crate) struct FuncSignature {
pub mangled_name: MangledFnName,
pub args: Vec<TypeValue>,
pub arg_names: Vec<String>,
pub args: Vec<(String, TypeValue)>,
pub result: TypeValue,
pub description: Option<Cow<'static, str>>,
}
Expand Down Expand Up @@ -291,13 +290,11 @@ impl<T: Into<String>> From<T> for FuncSignature {
let (args_with_names, result) = mangled_name.unmangle();

let mut args = Vec::with_capacity(args_with_names.len());
let mut arg_names = Vec::with_capacity(args_with_names.len());
for (name, ty) in args_with_names {
args.push(ty);
arg_names.push(name.to_string());
args.push((name.to_string(), ty));
}

Self { mangled_name, args, arg_names, result, description: None }
Self { mangled_name, args, result, description: None }
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ impl WasmExport {
function.add_signature(signature);
} else {
let mut func = Func::from(mangled_name);
// Update the description for the first and only signature in the function.
// Update the description for the first and only signature in
// the function.
let signature = func.signatures_mut().get_mut(0).unwrap();
// It's safe to get a mutable reference to the signature with Rc::get_mut
// because the Rc was just crated and there's a single reference to it.
// It's safe to get a mutable reference to the signature with
// Rc::get_mut because the Rc was just crated and there's a
// single reference to it.
let signature = Rc::get_mut(signature).unwrap();

signature.description = export.description.clone();

functions.insert(export.name, func);
}
}
Expand Down
17 changes: 9 additions & 8 deletions ls/src/features/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,25 +398,26 @@ fn field_suggestions(token: &Token<Immutable>) -> Option<Vec<CompletionItem>> {
.signatures
.iter()
.map(|sig| {
let arg_types = sig
let args = sig
.args
.iter()
.map(ty_to_string)
.map(|(name, ty)| format!("{}: {}", name, ty_to_string(ty)))
.collect::<Vec<_>>();

let args_template = arg_types
let args_template = sig
.args
.iter()
.enumerate()
.map(|(n, arg_type)| {
format!("${{{}:{arg_type}}}", n + 1)
.map(|(n, (name, _))| {
format!("${{{}:{name}}}", n + 1)
})
.join(",");
.join(", ");

CompletionItem {
label: format!(
"{}({})",
name,
arg_types.join(", ")
args.join(", ")
),
kind: Some(CompletionItemKind::METHOD),
insert_text: Some(format!(
Expand All @@ -439,7 +440,7 @@ fn field_suggestions(token: &Token<Immutable>) -> Option<Vec<CompletionItem>> {
name,
sig.args
.iter()
.map(ty_to_string)
.map(|(name, ty)| format!("{}: {}", name, ty_to_string(ty)))
.join(", "),
ty_to_string(&sig.ret),
docs
Expand Down
6 changes: 5 additions & 1 deletion ls/src/features/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ pub fn hover(
signature
.args
.iter()
.map(ty_to_string)
.map(|(name, ty)| format!(
"{}: {}",
name,
ty_to_string(ty)
))
.join(", "),
ty_to_string(&signature.ret),
doc
Expand Down
12 changes: 7 additions & 5 deletions ls/src/features/signature_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ pub fn signature_help(
let mut param_iterator = signature.args.iter();
let mut param_info = Vec::new();

// Traverse all parameters and insert `, ` to the label,
// if the parameters is not last.
if let Some(mut curr_type) = param_iterator.next() {
if let Some((name, ty)) = param_iterator.next() {
let mut curr_name = name;
let mut curr_type = ty;
loop {
let ty_str = ty_to_string(curr_type);
let ty_str =
format!("{}: {}", curr_name, ty_to_string(curr_type));
param_info.push(ParameterInformation {
label: ParameterLabel::LabelOffsets([
curr_signature.len() as u32,
Expand All @@ -85,8 +86,9 @@ pub fn signature_help(
documentation: None,
});
curr_signature.push_str(&ty_str);
if let Some(next_type) = param_iterator.next() {
if let Some((next_name, next_type)) = param_iterator.next() {
curr_signature.push_str(", ");
curr_name = next_name;
curr_type = next_type;
} else {
break;
Expand Down
Loading
Loading