Merge branch 'main' into fix-els

This commit is contained in:
Shunsuke Shibayama 2023-08-22 11:47:22 +09:00
commit b5787cb697
4 changed files with 31 additions and 12 deletions

View file

@ -444,6 +444,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
&self, &self,
uri: &NormalizedUrl, uri: &NormalizedUrl,
arg_pt: Option<ParamTy>, arg_pt: Option<ParamTy>,
already_appeared: &mut Set<String>,
) -> Vec<CompletionItem> { ) -> Vec<CompletionItem> {
let mut comps = vec![]; let mut comps = vec![];
for mod_ctx in self.get_neighbor_ctxs(uri) { for mod_ctx in self.get_neighbor_ctxs(uri) {
@ -451,6 +452,9 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
if vi.vis.is_private() { if vi.vis.is_private() {
continue; continue;
} }
if already_appeared.contains(&name.inspect()[..]) {
continue;
}
let Some(path) = vi.def_loc.module.as_ref() else { let Some(path) = vi.def_loc.module.as_ref() else {
continue; continue;
}; };
@ -474,6 +478,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
}]); }]);
item.insert_text = Some(name.inspect().trim_end_matches('\0').to_string()); item.insert_text = Some(name.inspect().trim_end_matches('\0').to_string());
item.filter_text = Some(name.inspect().to_string()); item.filter_text = Some(name.inspect().to_string());
already_appeared.insert(name.inspect().to_string());
comps.push(item); comps.push(item);
} }
} }
@ -621,7 +626,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
self.comp_cache.insert("<module>".into(), comps.clone()); self.comp_cache.insert("<module>".into(), comps.clone());
result.extend(comps); result.extend(comps);
} }
result.extend(self.neighbor_completion(&uri, arg_pt)); self.neighbor_completion(&uri, arg_pt, &mut already_appeared);
} }
send_log(format!("completion items: {}", result.len()))?; send_log(format!("completion items: {}", result.len()))?;
Ok(Some(CompletionResponse::Array(result))) Ok(Some(CompletionResponse::Array(result)))

View file

@ -2277,7 +2277,13 @@ impl Context {
guard: GuardType, guard: GuardType,
overwritten: &mut Vec<(VarName, VarInfo)>, overwritten: &mut Vec<(VarName, VarInfo)>,
) -> TyCheckResult<()> { ) -> TyCheckResult<()> {
if let Variable::Var(name, _) = &guard.var { if let Variable::Var {
namespace, name, ..
} = &guard.var
{
if !self.name.starts_with(&namespace[..]) {
return Ok(());
}
let vi = if let Some((name, vi)) = self.locals.remove_entry(name) { let vi = if let Some((name, vi)) = self.locals.remove_entry(name) {
overwritten.push((name, vi.clone())); overwritten.push((name, vi.clone()));
vi vi

View file

@ -50,11 +50,15 @@ use crate::{feature_error, unreachable_error};
use VisibilityModifier::*; use VisibilityModifier::*;
pub fn acc_to_variable(acc: &ast::Accessor) -> Option<Variable> { pub fn acc_to_variable(namespace: Str, acc: &ast::Accessor) -> Option<Variable> {
match acc { match acc {
ast::Accessor::Ident(ident) => Some(Variable::Var(ident.inspect().clone(), ident.loc())), ast::Accessor::Ident(ident) => Some(Variable::Var {
namespace,
name: ident.inspect().clone(),
loc: ident.loc(),
}),
ast::Accessor::Attr(attr) => Some(Variable::attr( ast::Accessor::Attr(attr) => Some(Variable::attr(
expr_to_variable(&attr.obj)?, expr_to_variable(namespace, &attr.obj)?,
attr.ident.inspect().clone(), attr.ident.inspect().clone(),
attr.loc(), attr.loc(),
)), )),
@ -62,9 +66,9 @@ pub fn acc_to_variable(acc: &ast::Accessor) -> Option<Variable> {
} }
} }
pub fn expr_to_variable(expr: &ast::Expr) -> Option<Variable> { pub fn expr_to_variable(namespace: Str, expr: &ast::Expr) -> Option<Variable> {
match expr { match expr {
ast::Expr::Accessor(acc) => acc_to_variable(acc), ast::Expr::Accessor(acc) => acc_to_variable(namespace, acc),
_ => None, _ => None,
} }
} }
@ -743,9 +747,9 @@ impl ASTLowerer {
fn get_guard_type(&self, op: &Token, lhs: &ast::Expr, rhs: &ast::Expr) -> Option<Type> { fn get_guard_type(&self, op: &Token, lhs: &ast::Expr, rhs: &ast::Expr) -> Option<Type> {
let var = if op.kind == TokenKind::ContainsOp { let var = if op.kind == TokenKind::ContainsOp {
expr_to_variable(rhs)? expr_to_variable(self.module.context.name.clone(), rhs)?
} else { } else {
expr_to_variable(lhs)? expr_to_variable(self.module.context.name.clone(), lhs)?
}; };
match op.kind { match op.kind {
// l in T -> T contains l // l in T -> T contains l

View file

@ -756,7 +756,11 @@ pub enum Variable {
name: Str, name: Str,
loc: Location, loc: Location,
}, },
Var(Str, Location), Var {
namespace: Str,
name: Str,
loc: Location,
},
Attr { Attr {
receiver: Box<Variable>, receiver: Box<Variable>,
attr: Str, attr: Str,
@ -768,7 +772,7 @@ impl fmt::Display for Variable {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
Self::Param { nth, name, .. } => write!(f, "{name}#{nth}"), Self::Param { nth, name, .. } => write!(f, "{name}#{nth}"),
Self::Var(name, _) => write!(f, "{name}"), Self::Var { name, .. } => write!(f, "{name}"),
Self::Attr { receiver, attr, .. } => write!(f, "{receiver}.{attr}"), Self::Attr { receiver, attr, .. } => write!(f, "{receiver}.{attr}"),
} }
} }
@ -778,7 +782,7 @@ impl Locational for Variable {
fn loc(&self) -> Location { fn loc(&self) -> Location {
match self { match self {
Self::Param { loc, .. } => *loc, Self::Param { loc, .. } => *loc,
Self::Var(_, loc) => *loc, Self::Var { loc, .. } => *loc,
Self::Attr { loc, .. } => *loc, Self::Attr { loc, .. } => *loc,
} }
} }