mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 18:29:00 +00:00
chore(els): improve workspace symbol
This commit is contained in:
parent
be87483981
commit
d6d278f99f
7 changed files with 96 additions and 3 deletions
|
@ -45,7 +45,7 @@ use crate::error::{
|
|||
CompileError, CompileErrors, CompileResult, TyCheckError, TyCheckErrors, TyCheckResult,
|
||||
};
|
||||
use crate::hir::Literal;
|
||||
use crate::varinfo::{AbsLocation, Mutability, VarInfo, VarKind};
|
||||
use crate::varinfo::{AbsLocation, AliasInfo, Mutability, VarInfo, VarKind};
|
||||
use crate::{feature_error, hir};
|
||||
use Mutability::*;
|
||||
use RegistrationMode::*;
|
||||
|
@ -300,8 +300,19 @@ impl Context {
|
|||
sig: &ast::VarSignature,
|
||||
body_t: &Type,
|
||||
id: DefId,
|
||||
expr: Option<&hir::Expr>,
|
||||
py_name: Option<Str>,
|
||||
) -> TyCheckResult<VarInfo> {
|
||||
let alias_of = if let Some((origin, name)) =
|
||||
expr.and_then(|exp| exp.var_info().zip(exp.last_name()))
|
||||
{
|
||||
Some(AliasInfo::new(
|
||||
name.inspect().clone(),
|
||||
origin.def_loc.clone(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let ident = match &sig.pat {
|
||||
ast::VarPattern::Ident(ident) => ident,
|
||||
ast::VarPattern::Discard(_) => {
|
||||
|
@ -310,6 +321,7 @@ impl Context {
|
|||
impl_of: self.impl_of(),
|
||||
def_loc: self.absolutize(sig.loc()),
|
||||
py_name,
|
||||
alias_of,
|
||||
..VarInfo::const_default_private()
|
||||
});
|
||||
}
|
||||
|
@ -344,6 +356,9 @@ impl Context {
|
|||
if vi.py_name.is_none() {
|
||||
vi.py_name = py_name;
|
||||
}
|
||||
if vi.alias_of.is_none() {
|
||||
vi.alias_of = alias_of;
|
||||
}
|
||||
self.locals.insert(ident.name.clone(), vi.clone());
|
||||
if let Ok(value) = self.convert_singular_type_into_value(vi.t.clone()) {
|
||||
self.consts.insert(ident.name.clone(), value);
|
||||
|
@ -372,7 +387,7 @@ impl Context {
|
|||
body_t.clone()
|
||||
}
|
||||
});
|
||||
let vi = VarInfo::new(
|
||||
let vi = VarInfo::maybe_alias(
|
||||
t,
|
||||
muty,
|
||||
Visibility::new(vis, self.name.clone()),
|
||||
|
@ -381,6 +396,7 @@ impl Context {
|
|||
self.impl_of(),
|
||||
py_name,
|
||||
self.absolutize(ident.name.loc()),
|
||||
alias_of,
|
||||
);
|
||||
log!(info "Registered {}{}: {}", self.name, ident, vi);
|
||||
self.locals.insert(ident.name.clone(), vi.clone());
|
||||
|
|
|
@ -75,7 +75,7 @@ impl ASTLowerer {
|
|||
} else {
|
||||
self.module
|
||||
.context
|
||||
.assign_var_sig(&sig, found_body_t, id, None)?;
|
||||
.assign_var_sig(&sig, found_body_t, id, Some(&chunk), None)?;
|
||||
}
|
||||
let mut ident = hir::Identifier::bare(ident.clone());
|
||||
let t = match found_body_t {
|
||||
|
@ -657,6 +657,7 @@ impl ASTLowerer {
|
|||
&ast::VarSignature::new(ast::VarPattern::Ident(attr.ident.clone()), None),
|
||||
&t,
|
||||
ast::DefId(0),
|
||||
None,
|
||||
Some(py_name.clone()),
|
||||
)?;
|
||||
if let Some(types) = self
|
||||
|
@ -807,6 +808,7 @@ impl ASTLowerer {
|
|||
&ast::VarSignature::new(ast::VarPattern::Ident(ident.clone()), None),
|
||||
&t,
|
||||
ast::DefId(0),
|
||||
None,
|
||||
Some(py_name),
|
||||
)?;
|
||||
if let Some(gen) = ty_obj {
|
||||
|
|
|
@ -678,6 +678,13 @@ impl Accessor {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn last_name(&self) -> &VarName {
|
||||
match self {
|
||||
Self::Ident(ident) => &ident.raw.name,
|
||||
Self::Attr(attr) => &attr.ident.raw.name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
@ -2547,6 +2554,7 @@ impl Expr {
|
|||
pub fn receiver_t(&self) -> Option<&Type> {
|
||||
match self {
|
||||
Self::Accessor(Accessor::Attr(attr)) => Some(attr.obj.ref_t()),
|
||||
Self::TypeAsc(t_asc) => t_asc.expr.receiver_t(),
|
||||
_other => None,
|
||||
}
|
||||
}
|
||||
|
@ -2554,6 +2562,7 @@ impl Expr {
|
|||
pub fn show_acc(&self) -> Option<String> {
|
||||
match self {
|
||||
Expr::Accessor(acc) => Some(acc.show()),
|
||||
Expr::TypeAsc(t_asc) => t_asc.expr.show_acc(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -2570,6 +2579,7 @@ impl Expr {
|
|||
pub fn qual_name(&self) -> Option<Str> {
|
||||
match self {
|
||||
Expr::Accessor(acc) => acc.qual_name(),
|
||||
Expr::TypeAsc(tasc) => tasc.expr.qual_name(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -2578,6 +2588,7 @@ impl Expr {
|
|||
pub fn local_name(&self) -> Option<&str> {
|
||||
match self {
|
||||
Expr::Accessor(acc) => acc.local_name(),
|
||||
Expr::TypeAsc(tasc) => tasc.expr.local_name(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -2585,10 +2596,19 @@ impl Expr {
|
|||
pub fn is_py_api(&self) -> bool {
|
||||
match self {
|
||||
Expr::Accessor(acc) => acc.is_py_api(),
|
||||
Expr::TypeAsc(tasc) => tasc.expr.is_py_api(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn last_name(&self) -> Option<&VarName> {
|
||||
match self {
|
||||
Expr::Accessor(acc) => Some(acc.last_name()),
|
||||
Expr::TypeAsc(tasc) => tasc.expr.last_name(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_type_asc(&self) -> bool {
|
||||
matches!(self, Expr::TypeAsc(_))
|
||||
}
|
||||
|
|
|
@ -1512,6 +1512,7 @@ impl ASTLowerer {
|
|||
&sig,
|
||||
found_body_t,
|
||||
body.id,
|
||||
block.last(),
|
||||
None,
|
||||
)?;
|
||||
let ident = hir::Identifier::new(ident, None, vi);
|
||||
|
@ -1532,6 +1533,7 @@ impl ASTLowerer {
|
|||
&Type::Failure,
|
||||
ast::DefId(0),
|
||||
None,
|
||||
None,
|
||||
)?;
|
||||
Err(errs)
|
||||
}
|
||||
|
|
|
@ -187,6 +187,18 @@ impl AbsLocation {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct AliasInfo {
|
||||
pub name: Str,
|
||||
pub loc: AbsLocation,
|
||||
}
|
||||
|
||||
impl AliasInfo {
|
||||
pub const fn new(name: Str, loc: AbsLocation) -> Self {
|
||||
Self { name, loc }
|
||||
}
|
||||
}
|
||||
|
||||
/// Has information about the type, variability, visibility, and where the variable was defined (or declared, generated)
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct VarInfo {
|
||||
|
@ -198,6 +210,7 @@ pub struct VarInfo {
|
|||
pub impl_of: Option<Type>,
|
||||
pub py_name: Option<Str>,
|
||||
pub def_loc: AbsLocation,
|
||||
pub alias_of: Option<AliasInfo>,
|
||||
}
|
||||
|
||||
impl fmt::Display for VarInfo {
|
||||
|
@ -284,6 +297,32 @@ impl VarInfo {
|
|||
impl_of,
|
||||
py_name,
|
||||
def_loc,
|
||||
alias_of: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub const fn maybe_alias(
|
||||
t: Type,
|
||||
muty: Mutability,
|
||||
vis: Visibility,
|
||||
kind: VarKind,
|
||||
comptime_decos: Option<Set<Str>>,
|
||||
impl_of: Option<Type>,
|
||||
py_name: Option<Str>,
|
||||
def_loc: AbsLocation,
|
||||
alias_of: Option<AliasInfo>,
|
||||
) -> Self {
|
||||
Self {
|
||||
t,
|
||||
muty,
|
||||
vis,
|
||||
kind,
|
||||
comptime_decos,
|
||||
impl_of,
|
||||
py_name,
|
||||
def_loc,
|
||||
alias_of,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue