mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-27 11:59:05 +00:00
chore(els): improve completion
This commit is contained in:
parent
ecd8ea6769
commit
461e8229d7
2 changed files with 28 additions and 3 deletions
|
@ -271,6 +271,10 @@ impl<'a> HIRVisitor<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_call_t(&self, call: &Call, token: &Token) -> Option<Type> {
|
fn get_call_t(&self, call: &Call, token: &Token) -> Option<Type> {
|
||||||
|
if call.args.paren.is_some() && call.ln_end() == token.ln_end() {
|
||||||
|
// call: `f(x)`, token: `)`
|
||||||
|
return Some(call.t());
|
||||||
|
}
|
||||||
if let Some(attr) = &call.attr_name {
|
if let Some(attr) = &call.attr_name {
|
||||||
if let Some(t) = self.return_expr_t_if_same(attr, attr.name.token(), token) {
|
if let Some(t) = self.return_expr_t_if_same(attr, attr.name.token(), token) {
|
||||||
return Some(t);
|
return Some(t);
|
||||||
|
@ -355,6 +359,10 @@ impl<'a> HIRVisitor<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_array_t(&self, arr: &Array, token: &Token) -> Option<Type> {
|
fn get_array_t(&self, arr: &Array, token: &Token) -> Option<Type> {
|
||||||
|
if arr.ln_end() == token.ln_end() {
|
||||||
|
// arr: `[1, 2]`, token: `]`
|
||||||
|
return Some(arr.t());
|
||||||
|
}
|
||||||
match arr {
|
match arr {
|
||||||
Array::Normal(arr) => self.get_args_t(&arr.elems, token),
|
Array::Normal(arr) => self.get_args_t(&arr.elems, token),
|
||||||
_ => None, // todo!(),
|
_ => None, // todo!(),
|
||||||
|
@ -362,6 +370,10 @@ impl<'a> HIRVisitor<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_dict_t(&self, dict: &Dict, token: &Token) -> Option<Type> {
|
fn get_dict_t(&self, dict: &Dict, token: &Token) -> Option<Type> {
|
||||||
|
if dict.ln_end() == token.ln_end() {
|
||||||
|
// arr: `{...}`, token: `}`
|
||||||
|
return Some(dict.t());
|
||||||
|
}
|
||||||
match dict {
|
match dict {
|
||||||
Dict::Normal(dict) => {
|
Dict::Normal(dict) => {
|
||||||
for kv in &dict.kvs {
|
for kv in &dict.kvs {
|
||||||
|
@ -378,6 +390,10 @@ impl<'a> HIRVisitor<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_record_t(&self, record: &Record, token: &Token) -> Option<Type> {
|
fn get_record_t(&self, record: &Record, token: &Token) -> Option<Type> {
|
||||||
|
if record.ln_end() == token.ln_end() {
|
||||||
|
// arr: `{...}`, token: `}`
|
||||||
|
return Some(record.t());
|
||||||
|
}
|
||||||
for field in record.attrs.iter() {
|
for field in record.attrs.iter() {
|
||||||
if let Some(expr) = self.get_block_t(&field.body.block, token) {
|
if let Some(expr) = self.get_block_t(&field.body.block, token) {
|
||||||
return Some(expr);
|
return Some(expr);
|
||||||
|
@ -387,6 +403,10 @@ impl<'a> HIRVisitor<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_set_t(&self, set: &Set, token: &Token) -> Option<Type> {
|
fn get_set_t(&self, set: &Set, token: &Token) -> Option<Type> {
|
||||||
|
if set.ln_end() == token.ln_end() {
|
||||||
|
// arr: `{...}`, token: `}`
|
||||||
|
return Some(set.t());
|
||||||
|
}
|
||||||
match set {
|
match set {
|
||||||
Set::Normal(set) => self.get_args_t(&set.elems, token),
|
Set::Normal(set) => self.get_args_t(&set.elems, token),
|
||||||
_ => None, // todo!(),
|
_ => None, // todo!(),
|
||||||
|
@ -395,8 +415,13 @@ impl<'a> HIRVisitor<'a> {
|
||||||
|
|
||||||
fn get_tuple_t(&self, tuple: &Tuple, token: &Token) -> Option<Type> {
|
fn get_tuple_t(&self, tuple: &Tuple, token: &Token) -> Option<Type> {
|
||||||
match tuple {
|
match tuple {
|
||||||
Tuple::Normal(tuple) => self.get_args_t(&tuple.elems, token),
|
Tuple::Normal(tuple) => {
|
||||||
// _ => None, // todo!(),
|
if tuple.elems.paren.is_some() && tuple.ln_end() == token.ln_end() {
|
||||||
|
// arr: `(1, 2)`, token: `)`
|
||||||
|
return Some(tuple.t());
|
||||||
|
}
|
||||||
|
self.get_args_t(&tuple.elems, token)
|
||||||
|
} // _ => None, // todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ pub struct Args {
|
||||||
pub pos_args: Vec<PosArg>,
|
pub pos_args: Vec<PosArg>,
|
||||||
pub var_args: Option<Box<PosArg>>,
|
pub var_args: Option<Box<PosArg>>,
|
||||||
pub kw_args: Vec<KwArg>,
|
pub kw_args: Vec<KwArg>,
|
||||||
paren: Option<(Token, Token)>,
|
pub paren: Option<(Token, Token)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NestedDisplay for Args {
|
impl NestedDisplay for Args {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue