mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 18:58:30 +00:00
fix(els): local variables completion bug
This commit is contained in:
parent
dd1705bba5
commit
32eb893d9d
4 changed files with 24 additions and 15 deletions
|
@ -27,8 +27,16 @@ impl<'a> HIRVisitor<'a> {
|
|||
}
|
||||
|
||||
pub fn get_namespace(&self, pos: Position) -> Vec<Str> {
|
||||
// TODO: other than <module>
|
||||
let namespace = vec![Str::ever("<module>")];
|
||||
let name = self
|
||||
.uri
|
||||
.path()
|
||||
.split('/')
|
||||
.last()
|
||||
.unwrap()
|
||||
.split('.')
|
||||
.next()
|
||||
.unwrap();
|
||||
let namespace = vec![Str::rc(name)];
|
||||
if let Some(ns) = self.get_exprs_ns(namespace.clone(), self.hir.module.iter(), pos) {
|
||||
ns
|
||||
} else {
|
||||
|
|
|
@ -503,18 +503,19 @@ impl<Checker: BuildRunnable> Server<Checker> {
|
|||
pub(crate) fn get_local_ctx(&self, uri: &Url, pos: Position) -> Vec<&Context> {
|
||||
// send_log(format!("scope: {:?}\n", self.module.as_ref().unwrap().scope.keys())).unwrap();
|
||||
let mut ctxs = vec![];
|
||||
if let Some(visitor) = self.get_visitor(uri) {
|
||||
let ns = visitor.get_namespace(pos);
|
||||
for i in 1..ns.len() {
|
||||
let ns = ns[..=ns.len() - i].join("");
|
||||
if let Some(ctx) = self.modules.get(uri).unwrap().scope.get(&ns[..]) {
|
||||
ctxs.push(ctx);
|
||||
if let Some(mod_ctx) = &self.modules.get(uri) {
|
||||
if let Some(visitor) = self.get_visitor(uri) {
|
||||
let ns = visitor.get_namespace(pos);
|
||||
for i in 1..ns.len() {
|
||||
let ns = ns[..=ns.len() - i].join("");
|
||||
if let Some(ctx) = mod_ctx.scope.get(&ns[..]) {
|
||||
ctxs.push(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
ctxs.push(&mod_ctx.context);
|
||||
}
|
||||
let mod_ctx = &self.modules.get(uri).unwrap().context;
|
||||
let builtin_ctx = self.get_builtin_module();
|
||||
ctxs.push(mod_ctx);
|
||||
ctxs.extend(builtin_ctx);
|
||||
ctxs
|
||||
}
|
||||
|
|
|
@ -2840,7 +2840,7 @@ pub struct Identifier {
|
|||
|
||||
impl NestedDisplay for Identifier {
|
||||
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
|
||||
write!(f, "{}{}", self.vis, self.name)
|
||||
write!(f, "{}{}", self.vis.display_as_accessor(), self.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,15 +61,15 @@ impl ASTBuilder {
|
|||
let module = self.runner.parse(src)?;
|
||||
let mut desugarer = Desugarer::new();
|
||||
let module = desugarer.desugar(module);
|
||||
let path = self.runner.cfg().input.full_path();
|
||||
let ast = AST::new(Str::rc(path.to_str().unwrap()), module);
|
||||
let name = self.runner.cfg().input.unescaped_filename();
|
||||
let ast = AST::new(Str::rc(name), module);
|
||||
Ok(ast)
|
||||
}
|
||||
|
||||
pub fn build_without_desugaring(&mut self, src: String) -> Result<AST, ParserRunnerErrors> {
|
||||
let module = self.runner.parse(src)?;
|
||||
let path = self.runner.cfg().input.full_path();
|
||||
let ast = AST::new(Str::rc(path.to_str().unwrap()), module);
|
||||
let name = self.runner.cfg().input.unescaped_filename();
|
||||
let ast = AST::new(Str::rc(name), module);
|
||||
Ok(ast)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue