Skip to content

Commit

Permalink
[move-ide] Improvements to on hover for module members (#19619)
Browse files Browse the repository at this point in the history
## Description 

This PR fixes a problem with constants designated to be used for clever
errors not displaying on-hover information when used in assertions.

It also updates symbolicator to use compiler's doc comment extraction
facility instead of the much flakier hand-rolled implementation
originally used in `move-analyzer`. Among other things it allows clean
doc comment extraction in presence of atrributes (new tests added).

Finally, it updates `symbols` tests to Move 2024

## Test plan 

All new and old tests must pass
  • Loading branch information
awelc authored Oct 1, 2024
1 parent ff1aedd commit 9df4177
Show file tree
Hide file tree
Showing 27 changed files with 275 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ impl TypingAnalysisContext<'_> {
}

/// Add use of a const identifier
fn add_const_use_def(&mut self, module_ident: &E::ModuleIdent, name: &ConstantName) {
fn add_const_use_def(&mut self, module_ident: &E::ModuleIdent_, name: &ConstantName) {
if self.traverse_only {
return;
}
let use_pos = name.loc();
let use_name = name.value();
let mod_ident_str = expansion_mod_ident_to_map_key(&module_ident.value);
let mod_ident_str = expansion_mod_ident_to_map_key(module_ident);
let Some(mod_defs) = self.mod_outer_defs.get(&mod_ident_str) else {
return;
};
// insert use of the const's module
let mod_name = module_ident.value.module;
let mod_name = module_ident.module;
if let Some(mod_name_start) = self.file_start_position_opt(&mod_name.loc()) {
// a module will not be present if a constant belongs to an implicit module
self.use_defs.insert(
Expand Down Expand Up @@ -605,7 +605,7 @@ impl TypingAnalysisContext<'_> {
self.process_match_patterm(pat);
}
}
UA::Constant(mod_ident, name) => self.add_const_use_def(mod_ident, name),
UA::Constant(mod_ident, name) => self.add_const_use_def(&mod_ident.value, name),
UA::Or(pat1, pat2) => {
self.process_match_patterm(pat1);
self.process_match_patterm(pat2);
Expand Down Expand Up @@ -1019,7 +1019,7 @@ impl<'a> TypingVisitorContext for TypingAnalysisContext<'a> {
true
}
TE::Constant(mod_ident, name) => {
visitor.add_const_use_def(mod_ident, name);
visitor.add_const_use_def(&mod_ident.value, name);
true
}
TE::ModuleCall(mod_call) => {
Expand Down Expand Up @@ -1085,6 +1085,23 @@ impl<'a> TypingVisitorContext for TypingAnalysisContext<'a> {
v.iter().for_each(|arm| visitor.process_match_arm(arm));
true
}
TE::ErrorConstant {
line_number_loc: _,
error_constant,
} => {
// assume that constant is defined in the same module where it's used
// TODO: if above ever changes, we need to update this (presumably
// `ErrorConstant` will carry module ident at this point)
if let Some(name) = error_constant {
if let Some(mod_def) = visitor
.mod_outer_defs
.get(visitor.current_mod_ident_str.as_ref().unwrap())
{
visitor.add_const_use_def(&mod_def.ident.clone(), name);
}
};
true
}
TE::Unit { .. }
| TE::Builtin(_, _)
| TE::Vector(_, _, _, _)
Expand All @@ -1107,7 +1124,6 @@ impl<'a> TypingVisitorContext for TypingAnalysisContext<'a> {
| TE::TempBorrow(_, _)
| TE::Cast(_, _)
| TE::Annotate(_, _)
| TE::ErrorConstant { .. }
| TE::UnresolvedError => false,
}
}
Expand Down
Loading

0 comments on commit 9df4177

Please sign in to comment.